Skip to content

Commit

Permalink
Merge pull request #1294 from georust/rtree-triangle
Browse files Browse the repository at this point in the history
Implement `RTreeObject` for `Triangle`
  • Loading branch information
urschrei authored Jan 5, 2025
2 parents deeda72 + 8f3f489 commit 161cbd0
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 3 deletions.
2 changes: 2 additions & 0 deletions geo-types/CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

## Unreleased

- Implement `RTreeObject` for `Triangle`.

## 0.7.14

- POSSIBLY BREAKING: Minimum supported version of Rust (MSRV) is now 1.75
Expand Down
3 changes: 1 addition & 2 deletions geo-types/src/geometry/line.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,7 @@ macro_rules! impl_rstar_line {
type Envelope = ::$rstar::AABB<Point<T>>;

fn envelope(&self) -> Self::Envelope {
let bounding_rect = crate::private_utils::line_bounding_rect(*self);
::$rstar::AABB::from_corners(bounding_rect.min().into(), bounding_rect.max().into())
::$rstar::AABB::from_corners(self.start_point(), self.end_point())
}
}

Expand Down
41 changes: 40 additions & 1 deletion geo-types/src/geometry/triangle.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{polygon, Coord, CoordNum, Line, Polygon};
use crate::{polygon, Coord, CoordNum, Line, Point, Polygon};

#[cfg(any(feature = "approx", test))]
use approx::{AbsDiffEq, RelativeEq};
Expand Down Expand Up @@ -148,3 +148,42 @@ where
true
}
}

#[cfg(any(
feature = "rstar_0_8",
feature = "rstar_0_9",
feature = "rstar_0_10",
feature = "rstar_0_11",
feature = "rstar_0_12"
))]
macro_rules! impl_rstar_triangle {
($rstar:ident) => {
impl<T> ::$rstar::RTreeObject for Triangle<T>
where
T: ::num_traits::Float + ::$rstar::RTreeNum,
{
type Envelope = ::$rstar::AABB<Point<T>>;

fn envelope(&self) -> Self::Envelope {
let bounding_rect =
crate::private_utils::get_bounding_rect(self.to_array().into_iter()).unwrap();
::$rstar::AABB::from_corners(bounding_rect.min().into(), bounding_rect.max().into())
}
}
};
}

#[cfg(feature = "rstar_0_8")]
impl_rstar_triangle!(rstar_0_8);

#[cfg(feature = "rstar_0_9")]
impl_rstar_triangle!(rstar_0_9);

#[cfg(feature = "rstar_0_10")]
impl_rstar_triangle!(rstar_0_10);

#[cfg(feature = "rstar_0_11")]
impl_rstar_triangle!(rstar_0_11);

#[cfg(feature = "rstar_0_12")]
impl_rstar_triangle!(rstar_0_12);

0 comments on commit 161cbd0

Please sign in to comment.