* 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 )
| 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 | /** |
no test coverage detected