Skip to content

Guard Relate geometry graph construction against NaN coordinates - #1556

Open
LucaCappelletti94 wants to merge 1 commit into
georust:mainfrom
LucaCappelletti94:fix/relate-nan-panic
Open

Guard Relate geometry graph construction against NaN coordinates#1556
LucaCappelletti94 wants to merge 1 commit into
georust:mainfrom
LucaCappelletti94:fix/relate-nan-panic

Conversation

@LucaCappelletti94

Copy link
Copy Markdown
Contributor

Relate panicked via debug_assert!(linear_ring.is_closed()) in geometry graph construction when a polygon ring contained NaN coordinates, because is_closed uses == comparison and NaN != NaN. This affected every relate-based predicate (is_intersects, is_contains, is_within, and others).

The fix adds non-finite coordinate checks at each geometry entry point in GeometryGraph: add_polygon_ring, add_line_string, add_line, and add_point. Each returns early without contributing to the graph when NaN coordinates are encountered, so the relate operation completes with a degenerate but defined result instead of panicking. A now-unreachable NaN assert in NodeMap is removed.

return;
}
self.insert_boundary_point(line.start);
self.insert_boundary_point(line.end);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did this go away?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is me doing merge collisions poorly, but it surprises me that the test suite did not go red. I am doing now some mutation testing to make the test suite more resilient.

///
/// Note: Coords must be non-NaN.
pub fn insert_node_with_coordinate(&mut self, coord: Coord<F>) -> &mut NF::Node {
debug_assert!(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leave the assert please. The point is to enforce things that "should never happen".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants