@flatten-js/core
Advanced tools
Comparing version 1.2.19 to 1.2.20
{ | ||
"name": "@flatten-js/core", | ||
"version": "1.2.19", | ||
"version": "1.2.20", | ||
"description": "Javascript library for 2d geometry", | ||
@@ -5,0 +5,0 @@ "main": "dist/main.cjs.js", |
@@ -171,2 +171,5 @@ /** | ||
for (let i = 0; i < points.length; i++) { | ||
// skip zero length segment | ||
if (points[i].equalTo(points[(i + 1) % points.length])) | ||
continue; | ||
segments.push(new Flatten.Segment(points[i], points[(i + 1) % points.length])); | ||
@@ -173,0 +176,0 @@ } |
@@ -58,3 +58,12 @@ /** | ||
for (let loop of argsArray) { // multi-loop polygon | ||
this.faces.add(new Flatten.Face(this, loop)); | ||
/* Check extra level of nesting for GeoJSON-style multi polygons */ | ||
if (loop instanceof Array && loop[0] instanceof Array && | ||
loop[0].every( el => {return el instanceof Array && el.length === 2 && typeof(el[0]) === "number" && typeof(el[1]) === "number"} )) { | ||
for (let loop1 of loop) { | ||
this.faces.add(new Flatten.Face(this, loop1)); | ||
} | ||
} | ||
else { | ||
this.faces.add(new Flatten.Face(this, loop)); | ||
} | ||
} | ||
@@ -61,0 +70,0 @@ } |
@@ -120,2 +120,133 @@ /** | ||
}); | ||
it( 'Uncaught ReferenceError: Illegal Parameters for Nested Multipolygon #79', () => { | ||
const smallPoly = [ | ||
[ | ||
[ | ||
[ | ||
1, | ||
1 | ||
], | ||
[ | ||
1, | ||
2 | ||
], | ||
[ | ||
2, | ||
2 | ||
], | ||
[ | ||
2, | ||
1 | ||
] | ||
] | ||
], | ||
[ | ||
[ | ||
[ | ||
4, | ||
4 | ||
], | ||
[ | ||
4, | ||
5 | ||
], | ||
[ | ||
5, | ||
5 | ||
], | ||
[ | ||
5, | ||
4 | ||
] | ||
] | ||
] | ||
] | ||
const poly = new Polygon(smallPoly); | ||
expect(poly.faces.size).to.equal(2); | ||
expect(poly.edges.size).to.equal(8); | ||
}); | ||
it('Can parse GeoJSON one-loop polygon', () => { | ||
let geoJSON = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
] | ||
] | ||
} | ||
const poly = new Polygon(geoJSON.coordinates); | ||
expect(poly.faces.size).to.equal(1); | ||
expect(poly.edges.size).to.equal(4); // zero-length segment should be skipped | ||
}); | ||
it('Can parse GeoJSON polygon with hole', () => { | ||
let geoJSON = { | ||
"type": "Polygon", | ||
"coordinates": [ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
], | ||
[ | ||
[100.8, 0.8], | ||
[100.8, 0.2], | ||
[100.2, 0.2], | ||
[100.2, 0.8], | ||
[100.8, 0.8] | ||
] | ||
] | ||
} | ||
const poly = new Polygon(geoJSON.coordinates); | ||
expect(poly.faces.size).to.equal(2); | ||
expect(poly.edges.size).to.equal(8); // zero-length segment should be skipped | ||
const [o1, o2] = [...poly.faces].map( face => face.orientation()); | ||
expect(o1).to.not.equal(o2); | ||
}); | ||
it('Can parse GeoJSON multi-polygon', () => { | ||
let geoJSON = { | ||
"type": "MultiPolygon", | ||
"coordinates": [ | ||
[ | ||
[ | ||
[102.0, 2.0], | ||
[103.0, 2.0], | ||
[103.0, 3.0], | ||
[102.0, 3.0], | ||
[102.0, 2.0] | ||
] | ||
], | ||
[ | ||
[ | ||
[100.0, 0.0], | ||
[101.0, 0.0], | ||
[101.0, 1.0], | ||
[100.0, 1.0], | ||
[100.0, 0.0] | ||
], | ||
[ | ||
[100.2, 0.2], | ||
[100.2, 0.8], | ||
[100.8, 0.8], | ||
[100.8, 0.2], | ||
[100.2, 0.2] | ||
] | ||
] | ||
] | ||
} | ||
const poly = new Polygon(geoJSON.coordinates); | ||
expect(poly.faces.size).to.equal(3); | ||
expect(poly.edges.size).to.equal(12); | ||
const [o1, o2, o3] = [...poly.faces].map( face => face.orientation()); | ||
expect(o1).to.equal(o2); | ||
expect(o2).to.not.equal(o3); | ||
}); | ||
it('Can remove faces from polygon', function () { | ||
@@ -122,0 +253,0 @@ let polygon = new Polygon(); |
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is too big to display
5420820
34665