-
-
Notifications
You must be signed in to change notification settings - Fork 76
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
TypeError: Cannot read properties of undefined (reading 'depth') #155
Comments
Some good old fashioned println in
The subdivision step seems okay. Inside |
Even simpler example: Which can be reproduced using: const boolean = require('martinez-polygon-clipping')
const poly1 = [[
[ 4.707106781186547, 0.7071067811865477 ], // B
[ 4, 1 ], // C
[ 3.05083120710486, 0.8101662414209719 ], // G
[ 4.707106781186547, 0.7071067811865477 ] // B
]]
const poly2 = [[
[ 2, 0.75 ], // A
[ 4.707106781186547, 0.7071067811865477 ], // B
[ 3.477592250072517, 0.7836116248912244 ], // E
[ 4, 1 ], // C
[ 2, 0.75 ] // A
]]
const out = boolean.union(poly1, poly2)
There seems to be an issue with the order in which nodes are processed for splitting GB at point E. Will continue digging... |
I have isolated the cause of this bug. The implementation of A minimal failing test case can be added to const E = [3.477592250072517, 0.7836116248912244];
const B = [4.707106781186547, 0.7071067811865477];
const G = [3.05083120710486, 0.8101662414209719];
t.deepEqual(intersection(E, B, G, B, true), [E, B], 'partial overlap'); This happens because the check for parallel lines is strict I wanted to see if this was a problem specific to
I think the answer is to un-comment the epsilon check here. However, the |
Thank you so much! I will try to run the tests with it
…On Thu, 12 Jan 2023 at 07:06, Kenny ***@***.***> wrote:
I have isolated the cause of this bug. The implementation of
segment_intersection returns no intersections for edges EB and GB.
A minimal failing test case can be added to segment_intersection.test.js:
const E = [3.477592250072517, 0.7836116248912244];
const B = [4.707106781186547, 0.7071067811865477];
const G = [3.05083120710486, 0.8101662414209719];
t.deepEqual(intersection(E, B, G, B, true), [E, B], 'partial overlap');
This happens because the check for parallel lines is strict if (sqrKross
> 0). Unfortunately computing the cross product is prone to catastrophic
cancellation <https://en.wikipedia.org/wiki/Catastrophic_cancellation>.
Since the cross product is the difference of two large numbers, floating
point errors make it unlikely that the cross product comes out to exactly
zero, even if the lines are actually parallel.
I wanted to see if this was a problem specific to w8r/martinez or if it
was a more general problem across implementations. The reference C++
implementation, and the other javascript implementations all handled this
case correctly. Interestingly, the only implementation I found that also
crashed on this example was the rust 21re/rust-geo-booleanop which is
ported directly from this repo.
-
w8r/martinez implementation of segment_intersection determines if
segments are parallel when the cross product is 0. No epsilon check,
although it has one commented out.
https://github.com/w8r/martinez/blob/738a698a49f21d7e9f631ce435a12bdbde3ebff0/src/segment_intersection.js#L81
-
mfogel/polygon-clipping explicitly checks for T interections. So it
doesn't depend on epsilon at all for intersection checks. Very interesting.
https://github.com/mfogel/polygon-clipping/blob/main/src/segment.js#L246-L255
-
velipso/polybooljs does a check on the cross product, but with epsilon
https://github.com/velipso/polybooljs/blob/master/lib/epsilon.js#L74
-
The martinez C++ reference implementation does an epsilon check
https://github.com/akavel/martinez-src/blob/master/cageo141/utilities.cpp#L45
I think the answer is to un-comment the epsilon check here
<https://github.com/w8r/martinez/blob/738a698a49f21d7e9f631ce435a12bdbde3ebff0/src/segment_intersection.js#L81>.
However, the mfogel implementation of getIntersection is quite
interesting too.
—
Reply to this email directly, view it on GitHub
<#155 (comment)>, or
unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAGSBBMBAIBJ5YXIW6EYOLWR6NO3ANCNFSM6AAAAAATORIAJU>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
I think I found a bug that results in an exception being thrown. It happens when doing a union of two polygons. The polygons in this example have a co-linear edge, although I don't know if that's relevant.
I made a test case which demonstrates the problem. Add this under
test/genericTestCases/colinear.json
:Running
npm test
then gives the exception:The exception happens on
connect_edges.js
line 121 here.Tracing the error backwards reveals that
lowerContourId
is set to-1
.The text was updated successfully, but these errors were encountered: