Skip to content

feat: port S2EdgeCrosser and edge crossing predicates from C++#103

Merged
brawer merged 2 commits into
yjh0502:masterfrom
HLennart:feature/edge-crossings
Jul 14, 2026
Merged

feat: port S2EdgeCrosser and edge crossing predicates from C++#103
brawer merged 2 commits into
yjh0502:masterfrom
HLennart:feature/edge-crossings

Conversation

@HLennart

@HLennart HLennart commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

hey, i've been using the s2 library for a solid bit but i needed edge crossing, so i ported the c++ version. aside from arbitrary precision floats. the rust version behaves like the c++ (tested by porting the c++ unit tests (unless otherwise noted in the test mods) and running a quick script comparing the outputs of c++ vs. this rust one)

few notes:

  • i split it up into s2/edge_crossings/mod.rs and s2/edge_crossings/crosser.rs mainly to somewhat mirror the c++ headers but with a rust module
  • for c++ function overloads, i wrote separate chain_* functions
  • not using a separate S2CopyingEdgeCrosser, we just copy by default and don't do pointer shenanigans like c++ does
  • I'm strongly typing SignedCrossing instead of using -1 0 1 integers (with a conversion function)
  • Most of the documentation is straight copied from the c++ implementation and then adapted to the rust specifics

please note the addition of Clone & Copy on Direction so i can store it in a Copy (and Clone) type

fixes #78

ports the robust spherical edge intersection algorithms from the C++
s2edge_crossings and s2edge_crosser headers

notable details:
- Omitted the C++ implementation's exact float fallbacks
- Translated the C++ function overloads into chain_* functions
- Skipped the S2CopyingEdgeCrosser - instead just natively copy Points
- Strongly type Direction instead of using -1 0 1 integers
@HLennart HLennart mentioned this pull request Jul 13, 2026
@HLennart

Copy link
Copy Markdown
Contributor Author

note that it currently links to a crate::s2::contains_vertex_query::ContainsVertexQuery which doesn't exist (yet), which i'd hopefully port aswell

@brawer brawer left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Oooh, nice!!! ❤️

@brawer brawer merged commit d482764 into yjh0502:master Jul 14, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Implement edge crosser

2 participants