-
Notifications
You must be signed in to change notification settings - Fork 892
Updated onSegment.h and both segment intersections #78
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
Updated onSegment.h and both segment intersections #78
Conversation
The new version is definitely better. Easy to change to return a bool as well. |
|
Argh, pressed enter too early.
This is my main worry as well. Does one really want epsilon checks everywhere? I'm not sure... I'll need to ponder this. Additionally, using |
|
If we want to handle the |
simonlindholm
left a comment
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.
Looks good. I made a few comments.
|
Also, I'm happy you changed |
See #77.
This is a good win. Naively, we only use 24 lines now, compared to 50 lines previously. However, that isn't completely fair, as this new one introduces more dependencies. Even including all dependencies however, the functions required for the new
SegmentIntersection.htotal 21 lines, while the previous function was 27 lines.I also shortened the function names (
segmentIntersectionis too verbose), in line with how most modern KACTL code is written.I also changed the API a bit for SegmentIntersection.h. Instead of returning
cntand up to 2 points in separate variables, the new API simply returns a vector with 0,1, or 2 elements.I deleted
SegmentIntersectionQ.h, as I don't think there's much point in it anymore. Previously,SegmentIntersection.hwas extremely verbose and had a somewhat cumbersome API where you'd need to create 2 dummy points even if you didn't want them. For the new API, you can use it very similarly to the oldSegmentIntersectionQ.hif desired.sz(segInter(a,b,c,d))>0is equivalent to the oldsegmentIntersectionQ(a,b,c,d).I also added a fuzz test trying a bunch of integer points on a 5x5 grid. I think trying integer points is the right thing to do, as an important part of this function is handling the "degenerate cases" correctly.
I also submitted to https://open.kattis.com/problems/segmentintersection and passed it with the new code: https://ideone.com/xT9jXo
Primary points of contention:
Point.h:sgn(x). Simply returns thesignof a value, with some epsilon handling. My coach strongly suggested this as a good way of dealing with epsilons. I'm not sure what the philosophy is in KACTL for how to deal with epsilon issues in geometry, but I think this is a solid method.