-
Notifications
You must be signed in to change notification settings - Fork 199
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
Panic in bool-ops intersection #867
Comments
The error seems to occur due to the edge case of overlap only on one line which is shared by both polygons and the individual lines having different |
The issue seems to be due to finite-precision arithmetic. The line-segments that seemingly overlap, are apparently not overlapping. Refer Now, this should imply that fn snip() {
let l1 = Line::new(
coord!(x: 17.576085274796423, y: -15.791540153598898),
coord!(x: 18.06452454246989, y: -17.693907532504),
);
let l2 = Line::new(
coord!(x: 17.724912058920285, y: -16.37118892052372),
coord!(x: 18.06452454246989, y: -17.693907532504),
);
let l3 = Line::new(
coord!(x: 17.724912058920285, y: -16.37118892052372),
coord!(x: 19.09389292605319, y: -17.924001641855178),
);
let i12 = line_intersection(l1, l2);
eprintln!("l1 x l2 = {i12:?}");
let i13 = line_intersection(l1, l3);
eprintln!("l1 x l3 = {i13:?}");
} The output is:
We have been trying to fix these issues using f64::nextafter. Essentially, we act like the intersection of l1 x l3 is at the start of l3 + a small epsilon. Adding this fix does solve this issue, but I am yet to wrap my head around the correctness of the fix. |
I investigated the issue a bit further and found the following. I don't how closely this is related to the problem you were talking about. So I was curious how the
In your example above we would expect, that we get In
Then we would expect the conditional at the bottom of the snippet to exectue. However, it doesn't. This comes from floating point precision issues in the
We get collinear only in the
I suggest not comparing to 0.0 at this point and using some |
Nevermind, scratch that. I tried changing it for my use-case and it only made things worse. |
@RobWalt FP arithmetic throws many suprises. For instance, the pt |
I get a panic for some boolean operations.
For some very basic shapes:
I use
T=f64
and the error is probably related to some overflow/underflow. A very similar thing happens in #531 at the same place in the code although there some other algorithm uses the function that panics.Here is a short snippet of code to reproduce the panic with the values from above:
The text was updated successfully, but these errors were encountered: