segmentsIntersect
Checks whether the line segments p1q1 && p2q2 intersect.
Basic example
Section titled “Basic example”True when the two segments share a point. Unlike lineIntersection, the crossing has to fall within both segments’ extents.
import {segmentsIntersect} from "@d3plus/math";
segmentsIntersect([20, 160], [240, 40], [20, 40], [240, 160]);
Disjoint
Section titled “Disjoint”These segments lie on lines that do meet, but past their ends, so they do not intersect. Network and Sankey layouts use this check to detect overlapping links.
import {segmentsIntersect} from "@d3plus/math";
segmentsIntersect([20, 160], [100, 120], [160, 40], [240, 80]);
Parameters
import {segmentsIntersect} from "@d3plus/math";
p1requiredPointThe first point of the first line segment, which should always be an
[x, y]formatted Array.q1requiredPointThe second point of the first line segment, which should always be an
[x, y]formatted Array.p2requiredPointThe first point of the second line segment, which should always be an
[x, y]formatted Array.q2requiredPointThe second point of the second line segment, which should always be an
[x, y]formatted Array.