| 102370 | return result; |
| 102371 | } |
| 102372 | function bisectPolygon(positions, edgeTypes, size, startIndex, endIndex, bbox, edge) { |
| 102373 | const numPoints = (endIndex - startIndex) / size; |
| 102374 | const resultLow = []; |
| 102375 | const resultHigh = []; |
| 102376 | const typesLow = []; |
| 102377 | const typesHigh = []; |
| 102378 | const scratchPoint = []; |
| 102379 | let p; |
| 102380 | let side; |
| 102381 | let type; |
| 102382 | const prev = (0, _utils.getPointAtIndex)(positions, numPoints - 1, size, startIndex); |
| 102383 | let prevSide = Math.sign(edge & 8 ? prev[1] - bbox[3] : prev[0] - bbox[2]); |
| 102384 | let prevType = edgeTypes && edgeTypes[numPoints - 1]; |
| 102385 | let lowPointCount = 0; |
| 102386 | let highPointCount = 0; |
| 102387 | for(let i = 0; i < numPoints; i++){ |
| 102388 | p = (0, _utils.getPointAtIndex)(positions, i, size, startIndex, p); |
| 102389 | side = Math.sign(edge & 8 ? p[1] - bbox[3] : p[0] - bbox[2]); |
| 102390 | type = edgeTypes && edgeTypes[startIndex / size + i]; |
| 102391 | if (side && prevSide && prevSide !== side) { |
| 102392 | (0, _lineclip.intersect)(prev, p, edge, bbox, scratchPoint); |
| 102393 | (0, _utils.push)(resultLow, scratchPoint) && typesLow.push(prevType); |
| 102394 | (0, _utils.push)(resultHigh, scratchPoint) && typesHigh.push(prevType); |
| 102395 | } |
| 102396 | if (side <= 0) { |
| 102397 | (0, _utils.push)(resultLow, p) && typesLow.push(type); |
| 102398 | lowPointCount -= side; |
| 102399 | } else if (typesLow.length) typesLow[typesLow.length - 1] = TYPE_INSIDE; |
| 102400 | if (side >= 0) { |
| 102401 | (0, _utils.push)(resultHigh, p) && typesHigh.push(type); |
| 102402 | highPointCount += side; |
| 102403 | } else if (typesHigh.length) typesHigh[typesHigh.length - 1] = TYPE_INSIDE; |
| 102404 | (0, _utils.copy)(prev, p); |
| 102405 | prevSide = side; |
| 102406 | prevType = type; |
| 102407 | } |
| 102408 | return [ |
| 102409 | lowPointCount ? { |
| 102410 | pos: resultLow, |
| 102411 | types: edgeTypes && typesLow |
| 102412 | } : null, |
| 102413 | highPointCount ? { |
| 102414 | pos: resultHigh, |
| 102415 | types: edgeTypes && typesHigh |
| 102416 | } : null |
| 102417 | ]; |
| 102418 | } |
| 102419 | function getGridCell(p, gridResolution, gridOffset, out) { |
| 102420 | const left = Math.floor((p[0] - gridOffset[0]) / gridResolution) * gridResolution + gridOffset[0]; |
| 102421 | const bottom = Math.floor((p[1] - gridOffset[1]) / gridResolution) * gridResolution + gridOffset[1]; |