-
Notifications
You must be signed in to change notification settings - Fork 756
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
Halfplane Intersection #90
base: main
Are you sure you want to change the base?
Conversation
Quick question: do you support infinite intersections? That may or may not be good to include. |
I don't think we do. I think supporting infinite intersections can be done fairly easily manually, no? Just add a really big bounding box. Ie:
|
Sure, good solution. I remember Gennady had some code that supported it, but bounding box works fine. |
b246350
to
95b770b
Compare
Precision starts to become a large issue even with very small inputs. See this example vector<Line> t({{P(8,9),P(8,2)},{P(3,9),P(5,2)},{P(8,2),P(8,3)},{P(7,2),P(1,7)},{P(1,0),P(7,1)},{P(9,2),P(5,6)},{P(10,10),P(-10,10)},{P(-10,10),P(-10,-10)},{P(-10,-10),P(10,-10)},{P(10,-10),P(10,10)}});
auto res = halfPlaneIntersection(t);
cout<<polygonArea2(res)<<endl;
cout << sjtu::halfPlaneIntersection(t)<<endl; Our code currently outputs
I think we should probably add epsilon checks to With either one of those fixes, the function passes as much fuzz testing as I have been able to run. |
Somewhat interestingly, it seems like |
Ok, I've updated with a stable version. It currently passes some fairly exhaustive fuzz testing. |
Is the only fix to the precision issue the new lineIntersection? Naively, that would seem to fix only the case with integer coordinates <= ~2^16, since lineIntersection uses products of three numbers, and above that the divisions are no longer precise. (If it needs mathematically unequal divisions to generate unequal results it might be lower, and some property of the code might well make it higher). That's pretty low... Do we have a nice characterization of the failure case? Is it only for area 0, for one? |
Ok, so I modified the
With |
Apparently the implementation is a bit slow; it got within 66% of the TL on https://ncpc20.kattis.com/problems/bigbrother. Probably due to calling atan2 in the comparator. |
Currently, this code is somewhat a mix of Zimpha's code, MIT's code, and SJTU's code.
One thing in particular I thought was interesting was this comparator from MIT. Considering they have the more "obvious" comparator commented out, I presume this one has superior numerical precision.
This code has been tested on an easy half plane problem.