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

Function clipPolygon

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

Source from the content-addressed store, hash-verified

102169 return result;
102170}
102171function clipPolygon(positions, bbox, options) {
102172 const { size =2 , endIndex =positions.length } = options || {};
102173 let { startIndex =0 } = options || {};
102174 let numPoints = (endIndex - startIndex) / size;
102175 let result;
102176 let p;
102177 let prev;
102178 let inside;
102179 let prevInside;
102180 for(let edge = 1; edge <= 8; edge *= 2){
102181 result = [];
102182 prev = (0, _utils.getPointAtIndex)(positions, numPoints - 1, size, startIndex, prev);
102183 prevInside = !(bitCode(prev, bbox) & edge);
102184 for(let i = 0; i < numPoints; i++){
102185 p = (0, _utils.getPointAtIndex)(positions, i, size, startIndex, p);
102186 inside = !(bitCode(p, bbox) & edge);
102187 if (inside !== prevInside) (0, _utils.push)(result, intersect(prev, p, edge, bbox));
102188 if (inside) (0, _utils.push)(result, p);
102189 (0, _utils.copy)(prev, p);
102190 prevInside = inside;
102191 }
102192 positions = result;
102193 startIndex = 0;
102194 numPoints = result.length / size;
102195 if (!numPoints) break;
102196 }
102197 return result;
102198}
102199function intersect(a, b, edge, bbox, out = []) {
102200 let t;
102201 let snap;

Callers

nothing calls this directly

Calls 2

bitCodeFunction · 0.70
intersectFunction · 0.70

Tested by

no test coverage detected