MCPcopy Create free account
hub / github.com/Stanko/offset-polygon / edgesIntersection

Function edgesIntersection

src/offset-polygon.ts:103–132  ·  view source on GitHub ↗
(edgeA: Edge | OffsetEdge, edgeB: Edge | OffsetEdge)

Source from the content-addressed store, hash-verified

101// based on http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/, edgeA => "line a", edgeB => "line b"
102
103function edgesIntersection(edgeA: Edge | OffsetEdge, edgeB: Edge | OffsetEdge) {
104 const den =
105 (edgeB.vertex2.y - edgeB.vertex1.y) * (edgeA.vertex2.x - edgeA.vertex1.x) -
106 (edgeB.vertex2.x - edgeB.vertex1.x) * (edgeA.vertex2.y - edgeA.vertex1.y);
107
108 if (den == 0) {
109 return null; // lines are parallel or coincident
110 }
111
112 const ua =
113 ((edgeB.vertex2.x - edgeB.vertex1.x) * (edgeA.vertex1.y - edgeB.vertex1.y) -
114 (edgeB.vertex2.y - edgeB.vertex1.y) *
115 (edgeA.vertex1.x - edgeB.vertex1.x)) /
116 den;
117
118 const ub =
119 ((edgeA.vertex2.x - edgeA.vertex1.x) * (edgeA.vertex1.y - edgeB.vertex1.y) -
120 (edgeA.vertex2.y - edgeA.vertex1.y) *
121 (edgeA.vertex1.x - edgeB.vertex1.x)) /
122 den;
123
124 // Edges are not intersecting but the lines defined by them are
125 const isIntersectionOutside = ua < 0 || ub < 0 || ua > 1 || ub > 1;
126
127 return {
128 x: edgeA.vertex1.x + ua * (edgeA.vertex2.x - edgeA.vertex1.x),
129 y: edgeA.vertex1.y + ua * (edgeA.vertex2.y - edgeA.vertex1.y),
130 isIntersectionOutside,
131 };
132}
133
134function appendArc(
135 arcSegments: number,

Callers 2

createMarginPolygonFunction · 0.70
createPaddingPolygonFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected