MCPcopy
hub / github.com/williamngan/pts / intersectPolygon2D

Method intersectPolygon2D

src/Op.ts:224–236  ·  view source on GitHub ↗

* Given a line segemnt or a ray (infinite line), find its intersection point(s) with a polygon. * @param lineOrRay a Group or an Iterable with 2 Pt representing a line or ray * @param poly a Group or an Iterable representing a polygon * @param sourceIsRay a boolean value to treat th

( lineOrRay:PtIterable, poly:PtIterable, sourceIsRay:boolean=false )

Source from the content-addressed store, hash-verified

222 * @param sourceIsRay a boolean value to treat the line as a ray (infinite line). Default is `false`.
223 */
224 static intersectPolygon2D( lineOrRay:PtIterable, poly:PtIterable, sourceIsRay:boolean=false ):Group {
225 let _lineOrRay = Util.iterToArray( lineOrRay );
226 let _poly = Util.iterToArray( poly );
227
228 let fn = sourceIsRay ? Line.intersectLineWithRay2D : Line.intersectLine2D;
229 let pts = new Group();
230 for (let i=0, len=_poly.length; i<len; i++) {
231 let next = (i === len-1) ? 0 : i+1;
232 let d = fn( [_poly[i], _poly[next]], _lineOrRay );
233 if (d) pts.push( d );
234 }
235 return (pts.length > 0) ? pts : undefined;
236 }
237
238
239 /**

Callers 3

intersectPolygon2DMethod · 0.45

Calls 2

fnFunction · 0.85
iterToArrayMethod · 0.80

Tested by

no test coverage detected