Copilot commented on code in PR #261:
URL: https://github.com/apache/sedona-db/pull/261#discussion_r2479912454
##########
rust/sedona-geo-generic-alg/src/algorithm/intersects/triangle.rs:
##########
@@ -90,3 +91,153 @@ where
self.to_polygon().intersects_trait(&rhs.to_polygon())
}
}
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, PolygonTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: PolygonTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // empty polygon cannot intersect with rectangle
Review Comment:
The comment mentions 'rectangle' but the code is checking intersection with
a polygon. Update the comment to say 'empty polygon cannot intersect with
triangle' for accuracy.
```suggestion
// empty polygon cannot intersect with triangle
```
##########
rust/sedona-geo-generic-alg/src/algorithm/intersects/triangle.rs:
##########
@@ -90,3 +91,153 @@ where
self.to_polygon().intersects_trait(&rhs.to_polygon())
}
}
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, PolygonTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: PolygonTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // empty polygon cannot intersect with rectangle
+ let Some(exterior) = rhs.exterior_ext() else {
+ return false;
+ };
+ if exterior.num_coords() == 0 {
+ return false;
+ }
+
+ // if any of the polygon's corners intersect the rectangle
+ let first_coord = unsafe { exterior.geo_coord_unchecked(0) };
+ if self.intersects(&first_coord) {
+ return true;
+ }
+
+ // or any point of the rectangle intersects the polygon
Review Comment:
The comment mentions 'rectangle' but should say 'triangle' for consistency
with the actual geometry type being handled.
```suggestion
// or any point of the triangle intersects the polygon
```
##########
rust/sedona-geo-generic-alg/src/algorithm/intersects/triangle.rs:
##########
@@ -90,3 +91,153 @@ where
self.to_polygon().intersects_trait(&rhs.to_polygon())
}
}
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, PolygonTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: PolygonTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // empty polygon cannot intersect with rectangle
+ let Some(exterior) = rhs.exterior_ext() else {
+ return false;
+ };
+ if exterior.num_coords() == 0 {
+ return false;
+ }
+
+ // if any of the polygon's corners intersect the rectangle
Review Comment:
The comment mentions 'rectangle' but should say 'triangle' since this is
Triangle-Polygon intersection logic.
##########
rust/sedona-geo-generic-alg/src/algorithm/intersects/triangle.rs:
##########
@@ -90,3 +91,153 @@ where
self.to_polygon().intersects_trait(&rhs.to_polygon())
}
}
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, PolygonTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: PolygonTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // empty polygon cannot intersect with rectangle
+ let Some(exterior) = rhs.exterior_ext() else {
+ return false;
+ };
+ if exterior.num_coords() == 0 {
+ return false;
+ }
+
+ // if any of the polygon's corners intersect the rectangle
+ let first_coord = unsafe { exterior.geo_coord_unchecked(0) };
+ if self.intersects(&first_coord) {
+ return true;
+ }
+
+ // or any point of the rectangle intersects the polygon
+ if self.first_coord().intersects(rhs) {
+ return true;
+ }
+
+ let rect_lines = self.to_lines();
+
+ // or any of the polygon's lines intersect the rectangle's lines
+ if exterior.lines().any(|rhs_line| {
+ rect_lines
+ .iter()
+ .any(|self_line| self_line.intersects(&rhs_line))
+ }) {
+ return true;
+ }
+ rhs.interiors_ext().any(|interior| {
+ interior.lines().any(|rhs_line| {
+ rect_lines
+ .iter()
+ .any(|self_line| self_line.intersects(&rhs_line))
+ })
+ })
+ }
+}
+
+symmetric_intersects_trait_impl!(
+ GeoNum,
+ PolygonTraitExt,
+ PolygonTag,
+ TriangleTraitExt,
+ TriangleTag
+);
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, RectTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: RectTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // if any of the triangle's corners intersect the rectangle
+ self.intersects(&rhs.min_coord())
+
+ // or some corner of the triangle intersects the rectangle
Review Comment:
[nitpick] The comment says 'some corner of the triangle' but the code checks
`self.first_coord()`, which is specifically the first coordinate. Consider
clarifying to 'or the triangle's first corner intersects the rectangle'.
```suggestion
// or the triangle's first corner intersects the rectangle
```
##########
rust/sedona-geo-generic-alg/src/algorithm/intersects/triangle.rs:
##########
@@ -90,3 +91,153 @@ where
self.to_polygon().intersects_trait(&rhs.to_polygon())
}
}
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, PolygonTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: PolygonTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // empty polygon cannot intersect with rectangle
+ let Some(exterior) = rhs.exterior_ext() else {
+ return false;
+ };
+ if exterior.num_coords() == 0 {
+ return false;
+ }
+
+ // if any of the polygon's corners intersect the rectangle
+ let first_coord = unsafe { exterior.geo_coord_unchecked(0) };
+ if self.intersects(&first_coord) {
+ return true;
+ }
+
+ // or any point of the rectangle intersects the polygon
+ if self.first_coord().intersects(rhs) {
+ return true;
+ }
+
+ let rect_lines = self.to_lines();
+
+ // or any of the polygon's lines intersect the rectangle's lines
+ if exterior.lines().any(|rhs_line| {
+ rect_lines
+ .iter()
+ .any(|self_line| self_line.intersects(&rhs_line))
+ }) {
+ return true;
+ }
+ rhs.interiors_ext().any(|interior| {
+ interior.lines().any(|rhs_line| {
+ rect_lines
+ .iter()
+ .any(|self_line| self_line.intersects(&rhs_line))
+ })
+ })
+ }
+}
+
+symmetric_intersects_trait_impl!(
+ GeoNum,
+ PolygonTraitExt,
+ PolygonTag,
+ TriangleTraitExt,
+ TriangleTag
+);
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, RectTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: RectTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // if any of the triangle's corners intersect the rectangle
Review Comment:
This comment correctly identifies both geometries. However, it's checking if
the rectangle's min_coord intersects the triangle, not the triangle's corners.
Consider rewording to 'if the rectangle's min corner intersects the triangle'
for clarity.
```suggestion
// if the rectangle's min corner intersects the triangle
```
##########
rust/sedona-geo-generic-alg/src/algorithm/intersects/triangle.rs:
##########
@@ -90,3 +91,153 @@ where
self.to_polygon().intersects_trait(&rhs.to_polygon())
}
}
+
+impl<T, LHS, RHS> IntersectsTrait<TriangleTag, PolygonTag, RHS> for LHS
+where
+ T: GeoNum,
+ LHS: TriangleTraitExt<T = T>,
+ RHS: PolygonTraitExt<T = T>,
+{
+ fn intersects_trait(&self, rhs: &RHS) -> bool {
+ // simplified logic based on Polygon intersects Polygon
+
+ if has_disjoint_bboxes(self, rhs) {
+ return false;
+ }
+
+ // empty polygon cannot intersect with rectangle
+ let Some(exterior) = rhs.exterior_ext() else {
+ return false;
+ };
+ if exterior.num_coords() == 0 {
+ return false;
+ }
+
+ // if any of the polygon's corners intersect the rectangle
+ let first_coord = unsafe { exterior.geo_coord_unchecked(0) };
+ if self.intersects(&first_coord) {
+ return true;
+ }
+
+ // or any point of the rectangle intersects the polygon
+ if self.first_coord().intersects(rhs) {
+ return true;
+ }
+
+ let rect_lines = self.to_lines();
+
+ // or any of the polygon's lines intersect the rectangle's lines
Review Comment:
The comment refers to 'rectangle's lines' but should say 'triangle's lines'
to match the actual implementation.
```suggestion
// or any of the polygon's lines intersect the triangle's lines
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]