MCPcopy Index your code
hub / github.com/microsoft/SandDance / object

Function object

docs/app/js/sanddance-app.js:109472–109531  ·  view source on GitHub ↗
(topology, o2)

Source from the content-addressed store, hash-verified

109470 };
109471}
109472function object(topology, o2) {
109473 var transformPoint = (0, _transformJsDefault.default)(topology.transform), arcs1 = topology.arcs;
109474 function arc(i, points) {
109475 if (points.length) points.pop();
109476 for(var a = arcs1[i < 0 ? ~i : i], k = 0, n = a.length; k < n; ++k)points.push(transformPoint(a[k], k));
109477 if (i < 0) (0, _reverseJsDefault.default)(points, n);
109478 }
109479 function point(p) {
109480 return transformPoint(p);
109481 }
109482 function line(arcs) {
109483 var points = [];
109484 for(var i = 0, n = arcs.length; i < n; ++i)arc(arcs[i], points);
109485 if (points.length < 2) points.push(points[0]); // This should never happen per the specification.
109486 return points;
109487 }
109488 function ring(arcs) {
109489 var points = line(arcs);
109490 while(points.length < 4)points.push(points[0]); // This may happen if an arc has only two points.
109491 return points;
109492 }
109493 function polygon(arcs) {
109494 return arcs.map(ring);
109495 }
109496 function geometry(o) {
109497 var type = o.type, coordinates;
109498 switch(type){
109499 case "GeometryCollection":
109500 return {
109501 type: type,
109502 geometries: o.geometries.map(geometry)
109503 };
109504 case "Point":
109505 coordinates = point(o.coordinates);
109506 break;
109507 case "MultiPoint":
109508 coordinates = o.coordinates.map(point);
109509 break;
109510 case "LineString":
109511 coordinates = line(o.arcs);
109512 break;
109513 case "MultiLineString":
109514 coordinates = o.arcs.map(line);
109515 break;
109516 case "Polygon":
109517 coordinates = polygon(o.arcs);
109518 break;
109519 case "MultiPolygon":
109520 coordinates = o.arcs.map(polygon);
109521 break;
109522 default:
109523 return null;
109524 }
109525 return {
109526 type: type,
109527 coordinates: coordinates
109528 };
109529 }

Callers 3

customConverterFunction · 0.70
featureFunction · 0.70
conftest.pyFile · 0.50

Calls 1

geometryFunction · 0.70

Tested by

no test coverage detected