MCPcopy
hub / github.com/microsoft/SandDance / clipPolyline

Function clipPolyline

docs/app/js/sanddance-app.js:102131–102170  ·  view source on GitHub ↗
(positions, bbox, options)

Source from the content-addressed store, hash-verified

102129parcelHelpers.export(exports, "bitCode", ()=>bitCode);
102130var _utils = require("./utils");
102131function clipPolyline(positions, bbox, options) {
102132 const { size =2 , startIndex =0 , endIndex =positions.length } = options || {};
102133 const numPoints = (endIndex - startIndex) / size;
102134 const result = [];
102135 let part = [];
102136 let a;
102137 let b;
102138 let codeA = -1;
102139 let codeB;
102140 let lastCode;
102141 for(let i = 1; i < numPoints; i++){
102142 a = (0, _utils.getPointAtIndex)(positions, i - 1, size, startIndex, a);
102143 b = (0, _utils.getPointAtIndex)(positions, i, size, startIndex, b);
102144 if (codeA < 0) codeA = bitCode(a, bbox);
102145 codeB = lastCode = bitCode(b, bbox);
102146 while(true){
102147 if (!(codeA | codeB)) {
102148 (0, _utils.push)(part, a);
102149 if (codeB !== lastCode) {
102150 (0, _utils.push)(part, b);
102151 if (i < numPoints - 1) {
102152 result.push(part);
102153 part = [];
102154 }
102155 } else if (i === numPoints - 1) (0, _utils.push)(part, b);
102156 break;
102157 } else if (codeA & codeB) break;
102158 else if (codeA) {
102159 intersect(a, b, codeA, bbox, a);
102160 codeA = bitCode(a, bbox);
102161 } else {
102162 intersect(a, b, codeB, bbox, b);
102163 codeB = bitCode(b, bbox);
102164 }
102165 }
102166 codeA = lastCode;
102167 }
102168 if (part.length) result.push(part);
102169 return result;
102170}
102171function clipPolygon(positions, bbox, options) {
102172 const { size =2 , endIndex =positions.length } = options || {};
102173 let { startIndex =0 } = options || {};

Callers

nothing calls this directly

Calls 2

bitCodeFunction · 0.70
intersectFunction · 0.70

Tested by

no test coverage detected