citygml-validate-shell
Advanced tools
Comparing version 0.1.14 to 0.1.15
34
index.js
@@ -337,2 +337,3 @@ // Note: QIE paper states that only LOD1–3 geometries are to be tested, | ||
var polygonPoints = []; | ||
var polygonWindings = []; | ||
@@ -351,2 +352,8 @@ _.each(shell, function(polygonXML) { | ||
_.each(polygonPoints, function(pPoints) { | ||
var points2d = points3dto2d(pPoints); | ||
var poly = polygonjs(points2d.points); | ||
// Find winding | ||
polygonWindings.push(poly.winding()); | ||
// Find top-most point | ||
@@ -398,9 +405,9 @@ _.each(pPoints, function(point) { | ||
var checkPoints2d = points3dto2d(outerPolygon[0], false); | ||
var checkPolygon = polygonjs(checkPoints2d.points); | ||
var checkWinding = checkPolygon.winding(); | ||
// If normal has a negative Z then fail as shallowest (top-most) polygon | ||
// will always have a positive Z normal | ||
if (outerPolygonNormal[2] < 0) { | ||
var checkPoints2d = points3dto2d(outerPolygon[0], false); | ||
var checkPolygon = polygonjs(checkPoints2d.points); | ||
var checkWinding = checkPolygon.winding(); | ||
var insideOut = true; | ||
@@ -450,4 +457,21 @@ | ||
// All edges match up, now check windings match | ||
// It's possible that a polygon can have matched edges yet still be pointing | ||
// the wrong way. Eg. A flipped polygon would behave this way. | ||
// We can't just check winding *or* edges as it's also possible for all | ||
// polygons to be wound correctly yet not share edges properly. | ||
if (flipped.length === 0) { | ||
callback(null); | ||
var wrongWinding = false; | ||
_.each(polygonWindings, function(winding) { | ||
if (winding !== checkWinding) { | ||
wrongWinding = true; | ||
} | ||
}); | ||
if (!wrongWinding) { | ||
callback(null); | ||
} else { | ||
callback(null, [new Error("GE_S_POLYGON_WRONG_ORIENTATION: When an exterior polygon is viewed from outside the shell the points must be ordered counterclockwise"), polygonWindings]); | ||
} | ||
} else { | ||
@@ -454,0 +478,0 @@ callback(null, [new Error("GE_S_POLYGON_WRONG_ORIENTATION: When an exterior polygon is viewed from outside the shell the points must be ordered counterclockwise"), flipped]); |
{ | ||
"name": "citygml-validate-shell", | ||
"version": "0.1.14", | ||
"version": "0.1.15", | ||
"description": "Validate a CityGML shell against the QIE suite", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
24957
547