MCPcopy Create free account
hub / github.com/microsoft/SandDance / cutPolylineByGrid

Function cutPolylineByGrid

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

Source from the content-addressed store, hash-verified

102262var _lineclip = require("./lineclip");
102263var _utils = require("./utils");
102264function cutPolylineByGrid(positions, options) {
102265 const { size =2 , broken =false , gridResolution =10 , gridOffset =[
102266 0,
102267 0
102268 ] , startIndex =0 , endIndex =positions.length } = options || {};
102269 const numPoints = (endIndex - startIndex) / size;
102270 let part = [];
102271 const result = [
102272 part
102273 ];
102274 const a = (0, _utils.getPointAtIndex)(positions, 0, size, startIndex);
102275 let b;
102276 let codeB;
102277 const cell = getGridCell(a, gridResolution, gridOffset, []);
102278 const scratchPoint = [];
102279 (0, _utils.push)(part, a);
102280 for(let i = 1; i < numPoints; i++){
102281 b = (0, _utils.getPointAtIndex)(positions, i, size, startIndex, b);
102282 codeB = (0, _lineclip.bitCode)(b, cell);
102283 while(codeB){
102284 (0, _lineclip.intersect)(a, b, codeB, cell, scratchPoint);
102285 const codeAlt = (0, _lineclip.bitCode)(scratchPoint, cell);
102286 if (codeAlt) {
102287 (0, _lineclip.intersect)(a, scratchPoint, codeAlt, cell, scratchPoint);
102288 codeB = codeAlt;
102289 }
102290 (0, _utils.push)(part, scratchPoint);
102291 (0, _utils.copy)(a, scratchPoint);
102292 moveToNeighborCell(cell, gridResolution, codeB);
102293 if (broken && part.length > size) {
102294 part = [];
102295 result.push(part);
102296 (0, _utils.push)(part, a);
102297 }
102298 codeB = (0, _lineclip.bitCode)(b, cell);
102299 }
102300 (0, _utils.push)(part, b);
102301 (0, _utils.copy)(a, b);
102302 }
102303 return broken ? result : result[0];
102304}
102305const TYPE_INSIDE = 0;
102306const TYPE_BORDER = 1;
102307function concatInPlace(arr1, arr2) {

Callers

nothing calls this directly

Calls 2

getGridCellFunction · 0.70
moveToNeighborCellFunction · 0.70

Tested by

no test coverage detected