Skip to content

Commit

Permalink
Merge pull request bjornharrtell#87 from johanhasselstrom/master
Browse files Browse the repository at this point in the history
Various porting errors
  • Loading branch information
bjornharrtell committed Dec 20, 2011
2 parents 24817a8 + 54748bf commit 96c73c1
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
4 changes: 4 additions & 0 deletions src/jsts/geomgraph/GeometryGraph.js
Expand Up @@ -460,6 +460,10 @@
this.insertPoint(argIndex, coord, loc);
};

jsts.geomgraph.GeometryGraph.prototype.getInvalidPoint = function() {
return this.invalidPoint;
};

})();

// TODO: port rest of class
5 changes: 2 additions & 3 deletions src/jsts/index/bintree/Node.js
Expand Up @@ -11,6 +11,8 @@

/**
* @requires jsts/index/bintree/NodeBase.js
* @requires jsts/index/bintree/Interval.js
* @requires jsts/index/bintree/Key.js
*/

var NodeBase = jsts.index.bintree.NodeBase;
Expand Down Expand Up @@ -144,9 +146,6 @@

var index = NodeBase.getSubnodeIndex(node.interval, this.centre), childNode;
if (node.level === this.level - 1) {
if (index === 1 && node.interval.min < 0) {
var stop;
}
this.subnode[index] = node;
} else {
// the node is not a direct child, so make a new child node to contain it
Expand Down
2 changes: 1 addition & 1 deletion src/jsts/operation/valid/ConnectedInteriorTester.js
Expand Up @@ -165,7 +165,7 @@ jsts.operation.valid.ConnectedInteriorTester.prototype.visitShellInteriors = fun
var mp = g;
for (var i = 0; i < mp.getNumGeometries(); i++) {
var p = mp.getGeometryN(i);
visitInteriorRing(p.getExteriorRing(), graph);
this.visitInteriorRing(p.getExteriorRing(), graph);
}
}
};
Expand Down
14 changes: 7 additions & 7 deletions src/jsts/operation/valid/IsValidOp.js
Expand Up @@ -247,7 +247,7 @@ jsts.operation.valid.IsValidOp.prototype.checkValidMultiPolygon = function(g) {
if (this.validErr != null) {
return;
}
if (!isSelfTouchingRingFormingHoleValid) {
if (!this.isSelfTouchingRingFormingHoleValid) {
this.checkNoSelfIntersectingRings(graph);
if (this.validErr != null) {
return;
Expand Down Expand Up @@ -535,13 +535,13 @@ jsts.operation.valid.IsValidOp.prototype.checkShellNotNested = function(shell,
// test if shell is inside polygon shell
var polyShell = p.getExteriorRing();
var polyPts = polyShell.getCoordinates();
var shellPt = this.findPtNotNode(shellPts, polyShell, graph);
var shellPt = jsts.operation.valid.IsValidOp.findPtNotNode(shellPts, polyShell, graph);
// if no point could be found, we can assume that the shell is outside the
// polygon
if (shellPt == null) {
return;
}
var insidePolyShell = CGAlgorithms.isPointInRing(shellPt, polyPts);
var insidePolyShell = jsts.algorithm.CGAlgorithms.isPointInRing(shellPt, polyPts);
if (!insidePolyShell) {
return;
}
Expand Down Expand Up @@ -583,20 +583,20 @@ jsts.operation.valid.IsValidOp.prototype.checkShellInsideHole = function(shell,
var shellPts = shell.getCoordinates();
var holePts = hole.getCoordinates();
// TODO: improve performance of this - by sorting pointlists for instance?
var shellPt = this.findPtNotNode(shellPts, hole, graph);
var shellPt = jsts.operation.valid.IsValidOp.findPtNotNode(shellPts, hole, graph);
// if point is on shell but not hole, check that the shell is inside the
// hole
if (shellPt != null) {
var insideHole = CGAlgorithms.isPointInRing(shellPt, holePts);
var insideHole = jsts.algorithm.CGAlgorithms.isPointInRing(shellPt, holePts);
if (!insideHole) {
return shellPt;
}
}
var holePt = this.findPtNotNode(holePts, shell, graph);
var holePt = jsts.operation.valid.IsValidOp.findPtNotNode(holePts, shell, graph);
// if point is on hole but not shell, check that the hole is outside the
// shell
if (holePt != null) {
var insideShell = CGAlgorithms.isPointInRing(holePt, shellPts);
var insideShell = jsts.algorithm.CGAlgorithms.isPointInRing(holePt, shellPts);
if (insideShell) {
return holePt;
}
Expand Down
22 changes: 22 additions & 0 deletions test/spec/jsts/operation/valid/IsValidOp.js
Expand Up @@ -89,4 +89,26 @@ describe('jsts.operation.valid.IsValidOp', function() {
expect(valid).toBeFalsy();
expect(err.getErrorType()).toBe(jsts.operation.valid.TopologyValidationError.SELF_INTERSECTION);
});

it('Handles MultiPolygons', function() {
var multiPoly = wktReader.read('MULTIPOLYGON(((0 0, 0 1, 1 1, 1 0, 0 0)),((10 10, 10 11, 11 11, 11 10, 10 10)))');
isValidOp = new jsts.operation.valid.IsValidOp(multiPoly);
valid = isValidOp.isValid();
err = isValidOp.getValidationError();
expect(valid).toBeTruthy();
});

it('Detects too few points in a polygon.', function() {
var p1 = new jsts.geom.Coordinate(0,0);
var p2 = new jsts.geom.Coordinate(1,1);
var points = [p1,p2,p1];
var ring = new jsts.geom.LinearRing(points);
var poly = new jsts.geom.Polygon(ring,[]);

isValidOp = new jsts.operation.valid.IsValidOp(poly);
valid = isValidOp.isValid();
err = isValidOp.getValidationError();
expect(valid).toBeFalsy();
expect(err.getErrorType()).toBe(jsts.operation.valid.TopologyValidationError.TOO_FEW_POINTS);
});
});

0 comments on commit 96c73c1

Please sign in to comment.