Skip to content

Commit

Permalink
added some inline(always) hints
Browse files Browse the repository at this point in the history
  • Loading branch information
JeroenGar committed Mar 3, 2025
1 parent f3398b3 commit cd3010d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions jagua-rs/src/geometry/primitives/aa_rectangle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,27 +219,31 @@ impl Shape for AARectangle {
}

impl CollidesWith<AARectangle> for AARectangle {
#[inline(always)]
fn collides_with(&self, other: &AARectangle) -> bool {
fsize::max(self.x_min, other.x_min) <= fsize::min(self.x_max, other.x_max)
&& fsize::max(self.y_min, other.y_min) <= fsize::min(self.y_max, other.y_max)
}
}

impl AlmostCollidesWith<AARectangle> for AARectangle {
#[inline(always)]
fn almost_collides_with(&self, other: &AARectangle) -> bool {
FPA(fsize::max(self.x_min, other.x_min)) <= FPA(fsize::min(self.x_max, other.x_max))
&& FPA(fsize::max(self.y_min, other.y_min)) <= FPA(fsize::min(self.y_max, other.y_max))
}
}

impl CollidesWith<Point> for AARectangle {
#[inline(always)]
fn collides_with(&self, point: &Point) -> bool {
let Point(x, y) = *point;
x >= self.x_min && x <= self.x_max && y >= self.y_min && y <= self.y_max
}
}

impl AlmostCollidesWith<Point> for AARectangle {
#[inline(always)]
fn almost_collides_with(&self, point: &Point) -> bool {
let (x, y) = (*point).into();
FPA(x) >= FPA(self.x_min)
Expand Down Expand Up @@ -300,6 +304,7 @@ impl CollidesWith<Edge> for AARectangle {
}

impl Distance<Point> for AARectangle {
#[inline(always)]
fn sq_distance(&self, point: &Point) -> fsize {
let Point(x, y) = *point;
let mut distance: fsize = 0.0;
Expand All @@ -316,17 +321,20 @@ impl Distance<Point> for AARectangle {
distance.abs()
}

#[inline(always)]
fn distance(&self, point: &Point) -> fsize {
self.sq_distance(point).sqrt()
}
}

impl SeparationDistance<Point> for AARectangle {
#[inline(always)]
fn separation_distance(&self, point: &Point) -> (GeoPosition, fsize) {
let (position, sq_distance) = self.sq_separation_distance(point);
(position, sq_distance.sqrt())
}

#[inline(always)]
fn sq_separation_distance(&self, point: &Point) -> (GeoPosition, fsize) {
match self.collides_with(point) {
false => (GeoPosition::Exterior, self.sq_distance(point)),
Expand Down
4 changes: 4 additions & 0 deletions jagua-rs/src/geometry/primitives/edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,7 @@ impl Shape for Edge {
}

impl Distance<Point> for Edge {
#[inline(always)]
fn sq_distance(&self, point: &Point) -> fsize {
let Point(x, y) = point;
let Point(xx, yy) = self.closest_point_on_edge(point);
Expand All @@ -157,12 +158,14 @@ impl Distance<Point> for Edge {
dx.powi(2) + dy.powi(2)
}

#[inline(always)]
fn distance(&self, point: &Point) -> fsize {
fsize::sqrt(self.sq_distance(point))
}
}

impl CollidesWith<Edge> for Edge {
#[inline(always)]
fn collides_with(&self, other: &Edge) -> bool {
match edge_intersection(self, other, false) {
Intersection::No => false,
Expand All @@ -172,6 +175,7 @@ impl CollidesWith<Edge> for Edge {
}

impl CollidesWith<AARectangle> for Edge {
#[inline(always)]
fn collides_with(&self, other: &AARectangle) -> bool {
other.collides_with(self)
}
Expand Down
2 changes: 2 additions & 0 deletions jagua-rs/src/geometry/primitives/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,12 @@ impl Point {
}

impl Distance<Point> for Point {
#[inline(always)]
fn distance(&self, other: &Point) -> fsize {
((self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)).sqrt()
}

#[inline(always)]
fn sq_distance(&self, other: &Point) -> fsize {
(self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)
}
Expand Down

0 comments on commit cd3010d

Please sign in to comment.