-
-
Notifications
You must be signed in to change notification settings - Fork 345
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Handle line segments intersecting at their endpoints. The algorithm I #378
base: main
Are you sure you want to change the base?
Conversation
ported ages ago doesn't handle this, and somehow I didn't notice until b2519e3.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- /// Undefined if the two lines have more than one intersection point
Is there a clear behavior for collinear lines now?
It seems like in the case that their endpoints overlap we have clear behavior, but what if their overlap is more than a point?
if self.pt1() == other.pt2() { | ||
return Some(self.pt1()); | ||
} | ||
if self.pt2() == other.pt1() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
equality is reflexive, so this one check is redundant ( the subsequent p2 == p2
check should stay though)
Oh, hmm... you mean the lines (0.0, 0.0) -> (1.0, 1.0) and (2.0, 2.0) -> (1.0, 1.0)? Those indeed are collinear. Does their code not work with collinear lines or something? |
It returns collinear in this case, but I'd expect just the endpoint (1, 1). Maybe it depends if the line segment endpoints are open or closed; the docs use
I'll add some more tests and figure out how to implement. I would expect |
I mentioned this in Slack, but depending on how urgent this is I'm hoping the |
I might hold off on this, then -- thanks! No rush; not planning to work on intersection geometry anytime soon again |
ported ages ago doesn't handle this, and somehow I didn't notice until
b2519e3.
@michaelkirk, any thoughts on this incremental improvement? I wanted to take this opportunity to rely on a better tested library for line segment intersection, but all I found was https://crates.io/crates/line_intersection. I gave it a shot at https://github.com/dabreegster/abstreet/blob/21eb14ba52afd549f0d6d0732ec3fe405a19869e/geom/src/line.rs#L75, but it said the line segments in the unit test were co-linear, which doesn't seem correct to me.
I'll keep looking around for ways to reduce the core code in
geom
. Ideally it'd mostly just wrap other crates that're better tested.