-
-
Notifications
You must be signed in to change notification settings - Fork 21.4k
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
GDScript::Geometry2D.segment_intersects_segment() returns null on valid intersection point #86651
Comments
|
Sounds like a precision error, see: |
Good to kill two birds with one stone! ;) Are there any plans to fix this? |
Double precision is something you can enable, this isn't solved yet and it was just a guess that this is because of precision, my suspicion is that this should be a documentation thing unless something is wrong in the code, I suspect it's not though and it's just a reality of the code Can you check if |
From my past experience line_intersects_line() used to work! Here are the results: Code used:
|
I rely on Geometry2D.segment_intersects_segment(from_a, to_a, from_b, to_b) and can't use line_intersects_line() in my project. |
This is likely the code that fails in this case: real_t ABpos = D.x + (C.x - D.x) * D.y / (D.y - C.y);
// Fail if segment C-D crosses line A-B outside of segment A-B.
if ((ABpos < 0) || (ABpos > 1)) {
return false;
} Due to precision errors, but unsure, it's possible that a fix can be made, but unable to test or verify any code right now |
Is there another way then compiling the source? Are there some official builds provided which have this activated already? |
No, not currently, see: |
Another combination: leads to: And the translated GDScript code results in: ABpos= -0.00000009536743 |
As it looks like - see above comment - field ABpos caries values which are close to the bounds check.
|
This would introduce some errors in the other direction, which would need to be weighed against this case |
I understood that's what this proposal is all about?! |
That's unrelated, just about exposing it to GDScript, this wouldn't affect the c++ code |
I know. What I mean is do not compare floats with == or != and comparison operators like < or > also need precision tolerance ... |
Tested versions
v4.3.dev1.official [9d1cbab]
System information
Godot v4.3.dev1 - Windows 10.0.19045 - GLES3 (Compatibility) - Quadro K1000M () - Intel(R) Core(TM) i7-3740QM CPU @ 2.70GHz (8 Threads)
Issue description
Geometry2D.segment_intersects_segment() returns null as a result although a valid intersection point exists.
1st segment has a starting point exactly residing on 2nd segment.
2nd segment is vertical.
Swapping from with to hence exchanging the start point with the end point leads to correct result.
I expect Geometry2D.segment_intersects_segment() to always return the same result regardless of the order of start and end points of segments given.
Steps to reproduce
Geometry2D.segment_intersects_segment(from_a, to_a, from_b, to_b) returns null for
var from_a := Vector2(585, 95)
var to_a := Vector2(581, 98)
var from_b := Vector2(585, 105)
var to_b := Vector2(585, 45)
Correct result is (585, 95).
Proof via swapping from_b with to_b:
Geometry2D.segment_intersects_segment(from_a, to_a, to_b, from_b) returns (585, 95).
Minimal reproduction project (MRP)
segment_bug.zip
The text was updated successfully, but these errors were encountered: