Skip to content

Commit

Permalink
Merge upstream
Browse files Browse the repository at this point in the history
  • Loading branch information
johanhasselstrom committed Dec 18, 2011
2 parents 224c216 + 6c19cce commit 9ce6955
Show file tree
Hide file tree
Showing 28 changed files with 896 additions and 133 deletions.
1 change: 1 addition & 0 deletions ChangeLog
Expand Up @@ -4,6 +4,7 @@
Remove hard dependency on OpenLayers (#79)
Bintree index port (#76)
LineStringSnapper port (#75)
Buffering fails on complex cases that requires precision reduction (#66)

2011-10-07: Version 0.10.0

Expand Down
18 changes: 12 additions & 6 deletions examples/debug.html
Expand Up @@ -79,9 +79,16 @@
<script type="text/javascript" src="../src/jsts/index/strtree/ItemBoundable.js"></script>
<script type="text/javascript" src="../src/jsts/index/strtree/SIRtree.js"></script>
<script type="text/javascript" src="../src/jsts/index/strtree/STRtree.js"></script>
<script type="text/javascript" src="../src/jsts/index/bintree/Interval.js"></script>
<script type="text/javascript" src="../src/jsts/index/bintree/NodeBase.js"></script>
<script type="text/javascript" src="../src/jsts/index/bintree/Key.js"></script>
<script type="text/javascript" src="../src/jsts/index/bintree/Node.js"></script>
<script type="text/javascript" src="../src/jsts/index/bintree/Root.js"></script>
<script type="text/javascript" src="../src/jsts/index/bintree/Bintree.js"></script>
<script type="text/javascript" src="../src/jsts/noding/SegmentIntersector.js"></script>
<script type="text/javascript" src="../src/jsts/noding/InteriorIntersectionFinder.js"></script>
<script type="text/javascript" src="../src/jsts/noding/IntersectionAdder.js"></script>
<script type="text/javascript" src="../src/jsts/noding/IntersectionFinderAdder.js"></script>
<script type="text/javascript" src="../src/jsts/noding/SegmentString.js"></script>
<script type="text/javascript" src="../src/jsts/noding/BasicSegmentString.js"></script>
<script type="text/javascript" src="../src/jsts/noding/NodableSegmentString.js"></script>
Expand All @@ -93,9 +100,13 @@
<script type="text/javascript" src="../src/jsts/noding/FastNodingValidator.js"></script>
<script type="text/javascript" src="../src/jsts/noding/Octant.js"></script>
<script type="text/javascript" src="../src/jsts/noding/OrientedCoordinateArray.js"></script>
<script type="text/javascript" src="../src/jsts/noding/ScaledNoder.js"></script>
<script type="text/javascript" src="../src/jsts/noding/SegmentNode.js"></script>
<script type="text/javascript" src="../src/jsts/noding/SegmentNodeList.js"></script>
<script type="text/javascript" src="../src/jsts/noding/SegmentPointComparator.js"></script>
<script type="text/javascript" src="../src/jsts/noding/snapround/HotPixel.js"></script>
<script type="text/javascript" src="../src/jsts/noding/snapround/MCIndexPointSnapper.js"></script>
<script type="text/javascript" src="../src/jsts/noding/snapround/MCIndexSnapRounder.js"></script>
<script type="text/javascript" src="../src/jsts/geomgraph/Position.js"></script>
<script type="text/javascript" src="../src/jsts/geomgraph/Depth.js"></script>
<script type="text/javascript" src="../src/jsts/geomgraph/GraphComponent.js"></script>
Expand Down Expand Up @@ -152,6 +163,7 @@
<script type="text/javascript" src="../src/jsts/operation/overlay/OverlayOp.js"></script>
<script type="text/javascript" src="../src/jsts/operation/overlay/snap/SnapOverlayOp.js"></script>
<script type="text/javascript" src="../src/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js"></script>
<script type="text/javascript" src="../src/jsts/operation/overlay/snap/LineStringSnapper.js"></script>
<script type="text/javascript" src="../src/jsts/operation/relate/EdgeEndBuilder.js"></script>
<script type="text/javascript" src="../src/jsts/operation/relate/EdgeEndBundle.js"></script>
<script type="text/javascript" src="../src/jsts/operation/relate/EdgeEndBundleStar.js"></script>
Expand Down Expand Up @@ -187,12 +199,6 @@
console.log(buffer.compareTo(b));
console.log(buffer.toString());
console.log(b.toString());

// TODO: find out why buffering fails (depth calc issues) with this poly
var polygon = reader.read('POLYGON ((80 300, 280 300, 280 80, 80 80, 80 300), (260 280, 180 200, 100 280, 100 100, 260 100, 260 280))');
var geometry = polygon.buffer(-10);

console.log(geometry.toString());
}
</script>
</head>
Expand Down
160 changes: 95 additions & 65 deletions lib/jsts.js

Large diffs are not rendered by default.

5 changes: 4 additions & 1 deletion src/jsts.js
Expand Up @@ -40,7 +40,10 @@ jsts = {
/** @namespace */
io: {},
/** @namespace */
noding: {},
noding: {
/** @namespace */
snapround: {}
},
/** @namespace */
operation: {
/** @namespace */
Expand Down
4 changes: 2 additions & 2 deletions src/jsts/algorithm/RobustLineIntersector.js
Expand Up @@ -66,7 +66,7 @@ jsts.algorithm.RobustLineIntersector.prototype.computeIntersection = function(
* q1
* @param {Coordinate}
* q2
* @return {int}
* @return {Number}
* @protected
*/
jsts.algorithm.RobustLineIntersector.prototype.computeIntersect = function(p1,
Expand Down Expand Up @@ -167,7 +167,7 @@ jsts.algorithm.RobustLineIntersector.prototype.computeIntersect = function(p1,
* q1
* @param {Coordinate}
* q2
* @return {int}
* @return {Number}
* @private
*/
jsts.algorithm.RobustLineIntersector.prototype.computeCollinearIntersection = function(
Expand Down
5 changes: 2 additions & 3 deletions src/jsts/geom/Coordinate.js
Expand Up @@ -151,9 +151,8 @@
return 0;
};

jsts.geom.Coordinate.prototype.hashCode = function() {
// TODO: might not work as expected, JTS does some magic here.
return '' + this.x + this.y;
jsts.geom.Coordinate.prototype.toString = function() {
return '(' + this.x + ', ' + this.y + ')';
};

})();
35 changes: 25 additions & 10 deletions src/jsts/geom/PrecisionModel.js
Expand Up @@ -72,12 +72,26 @@ jsts.geom.PrecisionModel.prototype.modelType = null;

/**
* Tests whether the precision model supports floating point
*
* @return {boolean} if the precision model supports floating point.
*/
jsts.geom.PrecisionModel.prototype.isFloating = function() {
return this.modelType === jsts.geom.PrecisionModel.FLOATING || this.modelType === jsts.geom.PrecisionModel.FLOATING_SINLGE;
return this.modelType === jsts.geom.PrecisionModel.FLOATING ||
this.modelType === jsts.geom.PrecisionModel.FLOATING_SINLGE;
};

/**
* Returns the scale factor used to specify a fixed precision model. The number
* of decimal places of precision is equal to the base-10 logarithm of the scale
* factor. Non-integral and negative scale factors are supported. Negative scale
* factors indicate that the places of precision is to the left of the decimal
* point.
*
* @return the scale factor for the fixed precision model.
*/
jsts.geom.PrecisionModel.prototype.getScale = function() {
return this.scale;
};

/**
* @return {string} always jsts.geom.PrecisionModel.FLOATING.
Expand All @@ -99,15 +113,14 @@ jsts.geom.PrecisionModel.prototype.equals = function(other) {


/**
* Rounds a numeric value to the PrecisionModel grid.
* Asymmetric Arithmetic Rounding is used, to provide
* uniform rounding behaviour no matter where the number is
* on the number line.
* Rounds a numeric value to the PrecisionModel grid. Asymmetric Arithmetic
* Rounding is used, to provide uniform rounding behaviour no matter where the
* number is on the number line.
* <p>
* This method has no effect on NaN values.
* <p>
* <b>Note:</b> Java's <code>Math#rint</code> uses the "Banker's Rounding" algorithm,
* which is not suitable for precision operations elsewhere in JTS.
* <b>Note:</b> Java's <code>Math#rint</code> uses the "Banker's Rounding"
* algorithm, which is not suitable for precision operations elsewhere in JTS.
*/
jsts.geom.PrecisionModel.prototype.makePrecise = function(val) {
if (val instanceof jsts.geom.Coordinate) {
Expand All @@ -116,7 +129,8 @@ jsts.geom.PrecisionModel.prototype.makePrecise = function(val) {
}

// don't change NaN values
if (isNaN(val)) return val;
if (isNaN(val))
return val;

// TODO: support single precision?
/*if (this.modelType == FLOATING_SINGLE) {
Expand All @@ -136,11 +150,12 @@ jsts.geom.PrecisionModel.prototype.makePrecise = function(val) {
*/
jsts.geom.PrecisionModel.prototype.makePrecise2 = function(coord) {
// optimization for full precision
if (this.modelType === jsts.geom.PrecisionModel.FLOATING) return;
if (this.modelType === jsts.geom.PrecisionModel.FLOATING)
return;

coord.x = this.makePrecise(coord.x);
coord.y = this.makePrecise(coord.y);
//MD says it's OK that we're not makePrecise'ing the z [Jon Aquino]
// MD says it's OK that we're not makePrecise'ing the z [Jon Aquino]
};


Expand Down
3 changes: 2 additions & 1 deletion src/jsts/geomgraph/DirectedEdgeStar.js
Expand Up @@ -153,7 +153,7 @@
* @private
*/
jsts.geomgraph.DirectedEdgeStar.prototype.getResultAreaEdges = function() {
if (this.resultAreaEdgeList != null)
if (this.resultAreaEdgeList !== null)
return this.resultAreaEdgeList;
this.resultAreaEdgeList = new javascript.util.ArrayList();
for (var it = this.iterator(); it.hasNext();) {
Expand Down Expand Up @@ -349,6 +349,7 @@
jsts.geomgraph.DirectedEdgeStar.prototype.computeDepths = function(de) {
if (arguments.length === 2) {
this.computeDepths2.apply(this, arguments);
// NOTE: intentional, this function returns void
return;
}

Expand Down
2 changes: 1 addition & 1 deletion src/jsts/geomgraph/Edge.js
Expand Up @@ -26,7 +26,7 @@ jsts.geomgraph.Edge = function(pts, label) {
};

jsts.geomgraph.Edge.prototype = new jsts.geomgraph.GraphComponent();

jsts.geomgraph.Edge.constructor = jsts.geomgraph.Edge;

/**
* Updates an IM from the label for an edge. Handles edges from both L and A
Expand Down
4 changes: 2 additions & 2 deletions src/jsts/geomgraph/EdgeEndStar.js
Expand Up @@ -268,7 +268,7 @@ jsts.geomgraph.EdgeEndStar.prototype.propagateSideLabels = function(geomIndex) {
}

// no labelled sides found, so no labels to propagate
if (startLoc == jsts.geom.Location.NONE)
if (startLoc === jsts.geom.Location.NONE)
return;

var currLoc = startLoc;
Expand All @@ -285,7 +285,7 @@ jsts.geomgraph.EdgeEndStar.prototype.propagateSideLabels = function(geomIndex) {
.getLocation(geomIndex, jsts.geomgraph.Position.RIGHT);
// if there is a right location, that is the next location to propagate
if (rightLoc !== jsts.geom.Location.NONE) {
if (rightLoc != currLoc)
if (rightLoc !== currLoc)
throw new jsts.error.TopologyError('side location conflict', e
.getCoordinate());
if (leftLoc === jsts.geom.Location.NONE) {
Expand Down
6 changes: 2 additions & 4 deletions src/jsts/geomgraph/GeometryGraph.js
Expand Up @@ -48,7 +48,7 @@
};

jsts.geomgraph.GeometryGraph.prototype = new jsts.geomgraph.PlanarGraph();

jsts.geomgraph.GeometryGraph.constructor = jsts.geomgraph.GeometryGraph;

/**
* @return {EdgeSetIntersector}
Expand Down Expand Up @@ -85,8 +85,6 @@
* to the edges which are derived from them. This is used to efficiently
* perform findEdge queries
*
* NOTE: In JSTS a JS object replaces HashMap.
*
* @type {Object}
* @private
*/
Expand Down Expand Up @@ -175,7 +173,7 @@

jsts.geomgraph.GeometryGraph.prototype.findEdge = function(line) {
return this.lineEdgeMap.get(line);
}
};

jsts.geomgraph.GeometryGraph.prototype.computeSplitEdges = function(edgelist) {
for (var i = this.edges.iterator(); i.hasNext();) {
Expand Down
9 changes: 1 addition & 8 deletions src/jsts/geomgraph/PlanarGraph.js
Expand Up @@ -106,7 +106,7 @@
* @return {javascript.util.Iterator}
*/
jsts.geomgraph.PlanarGraph.prototype.getNodeIterator = function() {
return this.nodes.values().iterator();
return this.nodes.iterator();
};

/**
Expand All @@ -117,15 +117,8 @@
};

jsts.geomgraph.PlanarGraph.prototype.addNode = function(node) {
if (node instanceof jsts.geom.Coordinate) {
return this.addNode2(node);
}

return this.nodes.addNode(node);
};
jsts.geomgraph.PlanarGraph.prototype.addNode2 = function(coord) {
return this.nodes.addNode(coord);
};

/**
* Add a set of edges to the graph. For each edge two DirectedEdges will be
Expand Down
1 change: 0 additions & 1 deletion src/jsts/index/chain/MonotoneChain.js
Expand Up @@ -146,7 +146,6 @@ jsts.index.chain.MonotoneChain.prototype.getCoordinates = function() {
* mcs the select action to execute on selected segments.
*/
jsts.index.chain.MonotoneChain.prototype.select = function(searchEnv, mcs) {
//this.computeSelect2(searchEnv, start, end, mcs);
this.computeSelect2(searchEnv, this.start, this.end, mcs);
};

Expand Down
2 changes: 1 addition & 1 deletion src/jsts/index/strtree/AbstractSTRtree.js
Expand Up @@ -344,7 +344,7 @@ jsts.index.strtree.AbstractSTRtree.prototype.query2 = function(searchBounds,
jsts.util.Assert.isTrue(this.root.getBounds() === null);
}
if (this.getIntersectsOp().intersects(this.root.getBounds(), searchBounds)) {
this.query4(searchBounds, root, visitor);
this.query4(searchBounds, this.root, visitor);
}
};

Expand Down
10 changes: 5 additions & 5 deletions src/jsts/index/strtree/STRtree.js
Expand Up @@ -194,13 +194,13 @@ jsts.index.strtree.STRtree.prototype.verticalSlices = function(childBoundables,
var sliceCapacity = Math.ceil(childBoundables.length / sliceCount);
var slices = [];

var i = 0, boundablesAddedToSlice, childBoundable;

for (var j = 0; j < sliceCount; j++) {
slices[j] = [];
var boundablesAddedToSlice = 0;
for (var i = 0; i < childBoundables.length; i++) {
if (boundablesAddedToSlice >= sliceCapacity)
break;
var childBoundable = childBoundables[i];
boundablesAddedToSlice = 0;
while (i < childBoundables.length && boundablesAddedToSlice < sliceCapacity) {
childBoundable = childBoundables[i++];
slices[j].push(childBoundable);
boundablesAddedToSlice++;
}
Expand Down
79 changes: 79 additions & 0 deletions src/jsts/noding/IntersectionFinderAdder.js
@@ -0,0 +1,79 @@
/* Copyright (c) 2011 by The Authors.
* Published under the LGPL 2.1 license.
* See /license-notice.txt for the full text of the license notice.
* See /license.txt for the full text of the license.
*/

/**
* Port source:
* /jts/jts/java/src/com/vividsolutions/jts/noding/IntersectionFinderAdder.java
* Revision: 108
*/

/**
* Finds proper and interior intersections in a set of SegmentStrings,
* and adds them as nodes.
*/

/**
* Creates an intersection finder which finds all proper intersections
*
* @param li
* the LineIntersector to use.
*/
jsts.noding.IntersectionFinderAdder = function(li) {
this.li = li;
this.interiorIntersections = new javascript.util.ArrayList();
};

jsts.noding.IntersectionFinderAdder.prototype = new jsts.noding.SegmentIntersector();
jsts.noding.IntersectionFinderAdder.constructor = jsts.noding.IntersectionFinderAdder;


jsts.noding.IntersectionFinderAdder.prototype.li = null;
jsts.noding.IntersectionFinderAdder.prototype.interiorIntersections = null;


jsts.noding.IntersectionFinderAdder.prototype.getInteriorIntersections = function() {
return this.interiorIntersections;
};

/**
* This method is called by clients of the {@link SegmentIntersector} class to
* process intersections for two segments of the {@link SegmentString}s being
* intersected. Note that some clients (such as {@link MonotoneChain}s) may
* optimize away this call for segment pairs which they have determined do not
* intersect (e.g. by an disjoint envelope test).
*/
jsts.noding.IntersectionFinderAdder.prototype.processIntersections = function(
e0, segIndex0, e1, segIndex1) {
// don't bother intersecting a segment with itself
if (e0 === e1 && segIndex0 === segIndex1)
return;

var p00 = e0.getCoordinates()[segIndex0];
var p01 = e0.getCoordinates()[segIndex0 + 1];
var p10 = e1.getCoordinates()[segIndex1];
var p11 = e1.getCoordinates()[segIndex1 + 1];

this.li.computeIntersection(p00, p01, p10, p11);

if (this.li.hasIntersection()) {
if (this.li.isInteriorIntersection()) {
for (var intIndex = 0; intIndex < this.li.getIntersectionNum(); intIndex++) {
this.interiorIntersections.add(this.li.getIntersection(intIndex));
}
e0.addIntersections(this.li, segIndex0, 0);
e1.addIntersections(this.li, segIndex1, 1);
}
}
};

/**
* Always process all intersections
*
* @return false always.
*/
jsts.noding.IntersectionFinderAdder.prototype.isDone = function() {
return false;
};
1 change: 0 additions & 1 deletion src/jsts/noding/MCIndexNoder.js
Expand Up @@ -20,7 +20,6 @@
var NodedSegmentString = jsts.noding.NodedSegmentString;
var MonotoneChainBuilder = jsts.index.chain.MonotoneChainBuilder;


/**
* @constructor
* @private
Expand Down

0 comments on commit 9ce6955

Please sign in to comment.