8000 MNT: alternate method of identifying 0 length segments · matplotlib/matplotlib@325d0ce · GitHub
[go: up one dir, main page]

Skip to content

Commit 325d0ce

Browse files
committed
MNT: alternate method of identifying 0 length segments
Use length square being close to 0 rather than strict. I have a worry that because we are using "close" for identifying the determinant is 0, if we use strict equality for the length, then we may pass through the length check, but erroneously go through the den == 0 path.
1 parent 7ff95a4 commit 325d0ce

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/_path.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,8 +836,12 @@ inline bool segments_intersect(const double &x1,
836836
const double atol = 1e-13;
837837

838838
// if either segment is 0 length, they do not intersect
839+
// length-squared of each segment
840+
const double lensq_A = (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
841+
const double lenqs_B = (x3 - x4) * (x3 - x4) + (y3 - y4) * (y3 - y4);
839842

840-
if ((x1 == x2 && y1 == y2) || (x3 == x3 && y3 == y4)) {
843+
// one of the segments is 0 length
844+
if (isclose(lensq_A, 0, rtol, atol) || isclose(lenqs_B, 0, rtol, atol)) {
841845
return false;
842846
}
843847

0 commit comments

Comments
 (0)
0