jsts-rails 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/lib/jsts-rails/version.rb +1 -1
- data/vendor/assets/javascripts/javascript.util.js +33 -1
- data/vendor/assets/javascripts/jsts-original.js +164 -1573
- data/vendor/assets/javascripts/jsts.js +197 -0
- data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
- data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
- data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
- data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
- data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
- data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
- data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
- data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
- data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
- data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
- data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
- data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
- data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
- data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
- data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
- data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
- data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
- data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
- data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
- data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
- data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
- data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
- data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
- data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
- data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
- data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
- data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
- data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
- data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
- data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
- data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
- data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
- data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
- data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
- data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
- data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
- data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
- data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
- data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
- data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
- data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
- data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
- data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
- data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
- data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
- data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
- data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
- data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
- data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
- data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
- data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
- data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
- data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
- data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
- data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
- data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
- data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
- data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
- data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
- data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
- data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
- data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
- data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
- data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
- data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
- data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
- data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
- data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
- data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
- data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
- metadata +204 -1
@@ -0,0 +1,220 @@
|
|
1
|
+
/* Copyright (c) 2011 by The Authors.
|
2
|
+
* Published under the LGPL 2.1 license.
|
3
|
+
* See /license-notice.txt for the full text of the license notice.
|
4
|
+
* See /license.txt for the full text of the license.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* The base class for nodes in a {@link Bintree}.
|
9
|
+
*/
|
10
|
+
(function() {
|
11
|
+
|
12
|
+
/**
|
13
|
+
* Constructs a new NodeBase
|
14
|
+
*
|
15
|
+
* @constructor
|
16
|
+
*/
|
17
|
+
var NodeBase = function() {
|
18
|
+
this.items = new javascript.util.ArrayList();
|
19
|
+
|
20
|
+
/**
|
21
|
+
* subnodes are numbered as follows:
|
22
|
+
*
|
23
|
+
* 0 | 1
|
24
|
+
*/
|
25
|
+
this.subnode = [null, null];
|
26
|
+
};
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Returns the index of the subnode that wholely contains the given interval.
|
30
|
+
* If none does, returns -1.
|
31
|
+
*
|
32
|
+
* @param {jsts.index.bintree.Interval}
|
33
|
+
* interval the interval.
|
34
|
+
* @param {Number}
|
35
|
+
* centre
|
36
|
+
*/
|
37
|
+
NodeBase.getSubnodeIndex = function(interval, centre) {
|
38
|
+
var subnodeIndex = -1;
|
39
|
+
if (interval.min >= centre) {
|
40
|
+
subnodeIndex = 1;
|
41
|
+
}
|
42
|
+
if (interval.max <= centre) {
|
43
|
+
subnodeIndex = 0;
|
44
|
+
}
|
45
|
+
return subnodeIndex;
|
46
|
+
};
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Gets the items
|
50
|
+
*
|
51
|
+
* @return {javascript.util.ArrayList}
|
52
|
+
*/
|
53
|
+
NodeBase.prototype.getItems = function() {
|
54
|
+
return this.items;
|
55
|
+
};
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Adds an item
|
59
|
+
*
|
60
|
+
* @param {Object}
|
61
|
+
* item the item to add.
|
62
|
+
*/
|
63
|
+
NodeBase.prototype.add = function(item) {
|
64
|
+
this.items.add(item);
|
65
|
+
};
|
66
|
+
|
67
|
+
/**
|
68
|
+
* Adds all items from this tree to the provided items
|
69
|
+
*
|
70
|
+
* @param {javascript.util.ArrayList}
|
71
|
+
* items the list to add to.
|
72
|
+
* @return {javscript.util.ArrayList} the input list filled with items.
|
73
|
+
*/
|
74
|
+
NodeBase.prototype.addAllItems = function(items) {
|
75
|
+
// TODO: Check if addAll really takes an ordinary javascript array
|
76
|
+
items.addAll(this.items);
|
77
|
+
var i = 0, il = 2;
|
78
|
+
for (i; i < il; i++) {
|
79
|
+
if (this.subnode[i] !== null) {
|
80
|
+
this.subnode[i].addAllItems(items);
|
81
|
+
}
|
82
|
+
}
|
83
|
+
return items;
|
84
|
+
};
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Adds items in the tree which potentially overlap the query interval to the
|
88
|
+
* given collection. If the query interval is <tt>null</tt>, add all items
|
89
|
+
* in the tree.
|
90
|
+
*
|
91
|
+
* @param {jsts.index.bintree.Interval}
|
92
|
+
* interval a query nterval, or null.
|
93
|
+
* @param {javascript.util.Collection}
|
94
|
+
* resultItems the candidate items found.
|
95
|
+
*/
|
96
|
+
NodeBase.prototype.addAllItemsFromOverlapping = function(interval,
|
97
|
+
resultItems) {
|
98
|
+
if (interval !== null && !this.isSearchMatch(interval)) {
|
99
|
+
return;
|
100
|
+
}
|
101
|
+
|
102
|
+
// some of these may not actually overlap - this is allowed by the bintree
|
103
|
+
// contract
|
104
|
+
resultItems.addAll(this.items);
|
105
|
+
|
106
|
+
if (this.subnode[0] !== null) {
|
107
|
+
this.subnode[0].addAllItemsFromOverlapping(interval, resultItems);
|
108
|
+
}
|
109
|
+
|
110
|
+
if (this.subnode[1] !== null) {
|
111
|
+
this.subnode[1].addAllItemsFromOverlapping(interval, resultItems);
|
112
|
+
}
|
113
|
+
};
|
114
|
+
|
115
|
+
/**
|
116
|
+
* Removes a single item from this subtree.
|
117
|
+
*
|
118
|
+
* @param {jsts.index.bintree.Interval}
|
119
|
+
* itemInterval the envelope containing the item.
|
120
|
+
* @param {Object}
|
121
|
+
* item the item to remove.
|
122
|
+
* @return <code>true</code> if the item was found and removed.
|
123
|
+
*/
|
124
|
+
NodeBase.prototype.remove = function(itemInterval, item) {
|
125
|
+
if (!this.isSearchMatch(itemInterval)) {
|
126
|
+
return false;
|
127
|
+
}
|
128
|
+
|
129
|
+
var found = false, i = 0, il = 2;
|
130
|
+
for (i; i < il; i++) {
|
131
|
+
if (this.subnode[i] !== null) {
|
132
|
+
found = this.subnode[i].remove(itemInterval, item);
|
133
|
+
if (found) {
|
134
|
+
// trim subtree if empty
|
135
|
+
if (this.subnode[i].isPrunable()) {
|
136
|
+
this.subnode[i] = null;
|
137
|
+
}
|
138
|
+
break;
|
139
|
+
}
|
140
|
+
}
|
141
|
+
}
|
142
|
+
|
143
|
+
// if item was found lower down, don't need to search for it here
|
144
|
+
if (found) {
|
145
|
+
return found;
|
146
|
+
}
|
147
|
+
|
148
|
+
// otherwise, try and remove the item from the list of items in this node
|
149
|
+
found = this.items.remove(item);
|
150
|
+
return found;
|
151
|
+
};
|
152
|
+
|
153
|
+
/**
|
154
|
+
* Checks if this tree has any children or items
|
155
|
+
*
|
156
|
+
* @return {Boolean} true if it has children or items (or both).
|
157
|
+
*/
|
158
|
+
NodeBase.prototype.isPrunable = function() {
|
159
|
+
return !(this.hasChildren() || this.hasItems());
|
160
|
+
};
|
161
|
+
|
162
|
+
/**
|
163
|
+
* Checks if this tree has any children
|
164
|
+
*
|
165
|
+
* @return {Boolean} true if it has children.
|
166
|
+
*/
|
167
|
+
NodeBase.prototype.hasChildren = function() {
|
168
|
+
var i = 0, il = 2;
|
169
|
+
for (i; i < il; i++) {
|
170
|
+
if (this.subnode[i] !== null) {
|
171
|
+
return true;
|
172
|
+
}
|
173
|
+
}
|
174
|
+
return false;
|
175
|
+
};
|
176
|
+
|
177
|
+
/**
|
178
|
+
* Checks i this node has any items
|
179
|
+
*
|
180
|
+
* @return {Boolean} true if it has items.
|
181
|
+
*/
|
182
|
+
NodeBase.prototype.hasItems = function() {
|
183
|
+
return !this.items.isEmpty();
|
184
|
+
};
|
185
|
+
|
186
|
+
NodeBase.prototype.depth = function() {
|
187
|
+
var maxSubDepth = 0, i = 0, il = 2, sqd;
|
188
|
+
for (i; i < il; i++) {
|
189
|
+
if (this.subnode[i] !== null) {
|
190
|
+
sqd = this.subnode[i].depth();
|
191
|
+
if (sqd > maxSubDepth) {
|
192
|
+
maxSubDepth = sqd;
|
193
|
+
}
|
194
|
+
}
|
195
|
+
}
|
196
|
+
return maxSubDepth + 1;
|
197
|
+
};
|
198
|
+
|
199
|
+
NodeBase.prototype.size = function() {
|
200
|
+
var subSize = 0, i = 0, il = 2;
|
201
|
+
for (i; i < il; i++) {
|
202
|
+
if (this.subnode[i] !== null) {
|
203
|
+
subSize += this.subnode[i].size();
|
204
|
+
}
|
205
|
+
}
|
206
|
+
return subSize + this.items.size();
|
207
|
+
};
|
208
|
+
|
209
|
+
NodeBase.prototype.nodeSize = function() {
|
210
|
+
var subSize = 0, i = 0, il = 2;
|
211
|
+
for (i; i < il; i++) {
|
212
|
+
if (this.subnode[i] !== null) {
|
213
|
+
subSize += this.subnode[i].nodeSize();
|
214
|
+
}
|
215
|
+
}
|
216
|
+
return subSize + 1;
|
217
|
+
};
|
218
|
+
|
219
|
+
jsts.index.bintree.NodeBase = NodeBase;
|
220
|
+
})();
|
@@ -0,0 +1,113 @@
|
|
1
|
+
/* Copyright (c) 2011 by The Authors.
|
2
|
+
* Published under the LGPL 2.1 license.
|
3
|
+
* See /license-notice.txt for the full text of the license notice.
|
4
|
+
* See /license.txt for the full text of the license.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* The root node of a single {@link Bintree}. It is centred at the origin, and
|
9
|
+
* does not have a defined extent.
|
10
|
+
*/
|
11
|
+
(function() {
|
12
|
+
|
13
|
+
/**
|
14
|
+
* @requires jsts/index/bintree/NodeBase.js
|
15
|
+
* @requires jsts/index/bintree/Node.js
|
16
|
+
*/
|
17
|
+
|
18
|
+
var Node = jsts.index.bintree.Node;
|
19
|
+
var NodeBase = jsts.index.bintree.NodeBase;
|
20
|
+
|
21
|
+
/**
|
22
|
+
* Constructs a new Root
|
23
|
+
*
|
24
|
+
* @constructor
|
25
|
+
*/
|
26
|
+
var Root = function() {
|
27
|
+
/**
|
28
|
+
* subnodes are numbered as follows:
|
29
|
+
*
|
30
|
+
* 0 | 1
|
31
|
+
*/
|
32
|
+
this.subnode = [null, null];
|
33
|
+
this.items = new javascript.util.ArrayList();
|
34
|
+
};
|
35
|
+
Root.prototype = new jsts.index.bintree.NodeBase();
|
36
|
+
Root.constructor = Root;
|
37
|
+
|
38
|
+
// the singleton root node is centred at the origin.
|
39
|
+
Root.origin = 0.0;
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Insert an item into the tree this is the root of.
|
43
|
+
*
|
44
|
+
* @param {jsts.index.bintree.Interval}
|
45
|
+
* itemInterval the interval of the item.
|
46
|
+
* @param {Object}
|
47
|
+
* item the item to insert.
|
48
|
+
*/
|
49
|
+
Root.prototype.insert = function(itemInterval, item) {
|
50
|
+
var index = NodeBase.getSubnodeIndex(itemInterval, Root.origin), node, largerNode;
|
51
|
+
// if index is -1, itemEnv must contain the origin.
|
52
|
+
if (index === -1) {
|
53
|
+
this.add(item);
|
54
|
+
return;
|
55
|
+
}
|
56
|
+
|
57
|
+
/**
|
58
|
+
* the item must be contained in one interval, so insert it into the tree
|
59
|
+
* for that interval (which may not yet exist)
|
60
|
+
*/
|
61
|
+
node = this.subnode[index];
|
62
|
+
|
63
|
+
/**
|
64
|
+
* If the subnode doesn't exist or this item is not contained in it, have to
|
65
|
+
* expand the tree upward to contain the item.
|
66
|
+
*/
|
67
|
+
|
68
|
+
if (node === null || !node.getInterval().contains(itemInterval)) {
|
69
|
+
largerNode = Node.createExpanded(node, itemInterval);
|
70
|
+
this.subnode[index] = largerNode;
|
71
|
+
}
|
72
|
+
|
73
|
+
/**
|
74
|
+
* At this point we have a subnode which exists and must contain contains
|
75
|
+
* the env for the item. Insert the item into the tree.
|
76
|
+
*/
|
77
|
+
this.insertContained(this.subnode[index], itemInterval, item);
|
78
|
+
};
|
79
|
+
|
80
|
+
/**
|
81
|
+
* insert an item which is known to be contained in the tree rooted at the
|
82
|
+
* given Node. Lower levels of the tree will be created if necessary to hold
|
83
|
+
* the item.
|
84
|
+
*
|
85
|
+
* @param {jsts.index.bintree.Node}
|
86
|
+
* tree the subtree.
|
87
|
+
* @param {jsts.index.bintree.Interval}
|
88
|
+
* itemInterval the interval.
|
89
|
+
* @param {Object}
|
90
|
+
* item the item to insert.
|
91
|
+
*/
|
92
|
+
Root.prototype.insertContained = function(tree, itemInterval, item) {
|
93
|
+
var isZeroArea, node;
|
94
|
+
/**
|
95
|
+
* Do NOT create a new node for zero-area intervals - this would lead to
|
96
|
+
* infinite recursion. Instead, use a heuristic of simply returning the
|
97
|
+
* smallest existing node containing the query
|
98
|
+
*/
|
99
|
+
isZeroArea = jsts.index.IntervalSize.isZeroWidth(itemInterval
|
100
|
+
.getMin(), itemInterval.getMax());
|
101
|
+
node = isZeroArea ? tree.find(itemInterval) : tree.getNode(itemInterval);
|
102
|
+
node.add(item);
|
103
|
+
};
|
104
|
+
|
105
|
+
/**
|
106
|
+
* The root node matches all searches
|
107
|
+
*/
|
108
|
+
Root.prototype.isSearchMatch = function(interval) {
|
109
|
+
return true;
|
110
|
+
};
|
111
|
+
|
112
|
+
jsts.index.bintree.Root = Root;
|
113
|
+
})();
|
@@ -0,0 +1,244 @@
|
|
1
|
+
/* Copyright (c) 2011 by The Authors.
|
2
|
+
* Published under the LGPL 2.1 license.
|
3
|
+
* See /license-notice.txt for the full text of the license notice.
|
4
|
+
* See /license.txt for the full text of the license.
|
5
|
+
*/
|
6
|
+
|
7
|
+
/**
|
8
|
+
* Monotone Chains are a way of partitioning the segments of a linestring to
|
9
|
+
* allow for fast searching of intersections. They have the following
|
10
|
+
* properties:
|
11
|
+
* <ol>
|
12
|
+
* <li>the segments within a monotone chain never intersect each other
|
13
|
+
* <li>the envelope of any contiguous subset of the segments in a monotone
|
14
|
+
* chain is equal to the envelope of the endpoints of the subset.
|
15
|
+
* </ol>
|
16
|
+
* Property 1 means that there is no need to test pairs of segments from within
|
17
|
+
* the same monotone chain for intersection.
|
18
|
+
* <p>
|
19
|
+
* Property 2 allows an efficient binary search to be used to find the
|
20
|
+
* intersection points of two monotone chains. For many types of real-world
|
21
|
+
* data, these properties eliminate a large number of segment comparisons,
|
22
|
+
* producing substantial speed gains.
|
23
|
+
* <p>
|
24
|
+
* One of the goals of this implementation of MonotoneChains is to be as space
|
25
|
+
* and time efficient as possible. One design choice that aids this is that a
|
26
|
+
* MonotoneChain is based on a subarray of a list of points. This means that new
|
27
|
+
* arrays of points (potentially very large) do not have to be allocated.
|
28
|
+
* <p>
|
29
|
+
*
|
30
|
+
* MonotoneChains support the following kinds of queries:
|
31
|
+
* <ul>
|
32
|
+
* <li>Envelope select: determine all the segments in the chain which intersect
|
33
|
+
* a given envelope
|
34
|
+
* <li>Overlap: determine all the pairs of segments in two chains whose
|
35
|
+
* envelopes overlap
|
36
|
+
* </ul>
|
37
|
+
*
|
38
|
+
* This implementation of MonotoneChains uses the concept of internal iterators
|
39
|
+
* to return the resultsets for the above queries. This has time and space
|
40
|
+
* advantages, since it is not necessary to build lists of instantiated objects
|
41
|
+
* to represent the segments returned by the query. However, it does mean that
|
42
|
+
* the queries are not thread-safe.
|
43
|
+
*
|
44
|
+
* @constructor
|
45
|
+
*/
|
46
|
+
jsts.index.chain.MonotoneChain = function(pts, start, end, context) {
|
47
|
+
this.pts = pts;
|
48
|
+
this.start = start;
|
49
|
+
this.end = end;
|
50
|
+
this.context = context;
|
51
|
+
};
|
52
|
+
|
53
|
+
/**
|
54
|
+
* @type {Array.<jsts.geom.Coordinate>}
|
55
|
+
* @private
|
56
|
+
*/
|
57
|
+
jsts.index.chain.MonotoneChain.prototype.pts = null;
|
58
|
+
/**
|
59
|
+
* @type {number}
|
60
|
+
* @private
|
61
|
+
*/
|
62
|
+
jsts.index.chain.MonotoneChain.prototype.start = null;
|
63
|
+
/**
|
64
|
+
* @type {number}
|
65
|
+
* @private
|
66
|
+
*/
|
67
|
+
jsts.index.chain.MonotoneChain.prototype.end = null;
|
68
|
+
/**
|
69
|
+
* @type {Envelope}
|
70
|
+
* @private
|
71
|
+
*/
|
72
|
+
jsts.index.chain.MonotoneChain.prototype.env = null;
|
73
|
+
/**
|
74
|
+
* user-defined information
|
75
|
+
*
|
76
|
+
* @type {Object}
|
77
|
+
* @private
|
78
|
+
*/
|
79
|
+
jsts.index.chain.MonotoneChain.prototype.context = null;
|
80
|
+
/**
|
81
|
+
* useful for optimizing chain comparisons
|
82
|
+
*
|
83
|
+
* @type {number}
|
84
|
+
* @private
|
85
|
+
*/
|
86
|
+
jsts.index.chain.MonotoneChain.prototype.id = null;
|
87
|
+
|
88
|
+
jsts.index.chain.MonotoneChain.prototype.setId = function(id) {
|
89
|
+
this.id = id;
|
90
|
+
};
|
91
|
+
jsts.index.chain.MonotoneChain.prototype.getId = function() {
|
92
|
+
return this.id;
|
93
|
+
};
|
94
|
+
|
95
|
+
jsts.index.chain.MonotoneChain.prototype.getContext = function() {
|
96
|
+
return this.context;
|
97
|
+
};
|
98
|
+
|
99
|
+
jsts.index.chain.MonotoneChain.prototype.getEnvelope = function() {
|
100
|
+
if (this.env == null) {
|
101
|
+
var p0 = this.pts[this.start];
|
102
|
+
var p1 = this.pts[this.end];
|
103
|
+
this.env = new jsts.geom.Envelope(p0, p1);
|
104
|
+
}
|
105
|
+
return this.env;
|
106
|
+
};
|
107
|
+
|
108
|
+
jsts.index.chain.MonotoneChain.prototype.getStartIndex = function() {
|
109
|
+
return this.start;
|
110
|
+
};
|
111
|
+
jsts.index.chain.MonotoneChain.prototype.getEndIndex = function() {
|
112
|
+
return this.end;
|
113
|
+
};
|
114
|
+
|
115
|
+
jsts.index.chain.MonotoneChain.prototype.getLineSegment = function(index, ls) {
|
116
|
+
ls.p0 = this.pts[index];
|
117
|
+
ls.p1 = this.pts[index + 1];
|
118
|
+
};
|
119
|
+
/**
|
120
|
+
* Return the subsequence of coordinates forming this chain. Allocates a new
|
121
|
+
* array to hold the Coordinates
|
122
|
+
*/
|
123
|
+
jsts.index.chain.MonotoneChain.prototype.getCoordinates = function() {
|
124
|
+
var coord = [];
|
125
|
+
var index = 0;
|
126
|
+
for (var i = this.start; i <= this.end; i++) {
|
127
|
+
coord[index++] = this.pts[i];
|
128
|
+
}
|
129
|
+
return coord;
|
130
|
+
};
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Determine all the line segments in the chain whose envelopes overlap the
|
134
|
+
* searchEnvelope, and process them.
|
135
|
+
* <p>
|
136
|
+
* The monotone chain search algorithm attempts to optimize performance by not
|
137
|
+
* calling the select action on chain segments which it can determine are not in
|
138
|
+
* the search envelope. However, it *may* call the select action on segments
|
139
|
+
* which do not intersect the search envelope. This saves on the overhead of
|
140
|
+
* checking envelope intersection each time, since clients may be able to do
|
141
|
+
* this more efficiently.
|
142
|
+
*
|
143
|
+
* @param {Envelope}
|
144
|
+
* searchEnv the search envelope.
|
145
|
+
* @param {MonotoneChainSelectAction}
|
146
|
+
* mcs the select action to execute on selected segments.
|
147
|
+
*/
|
148
|
+
jsts.index.chain.MonotoneChain.prototype.select = function(searchEnv, mcs) {
|
149
|
+
this.computeSelect2(searchEnv, this.start, this.end, mcs);
|
150
|
+
};
|
151
|
+
|
152
|
+
/**
|
153
|
+
* @private
|
154
|
+
*/
|
155
|
+
jsts.index.chain.MonotoneChain.prototype.computeSelect2 = function(searchEnv,
|
156
|
+
start0, end0, mcs) {
|
157
|
+
var p0 = this.pts[start0];
|
158
|
+
var p1 = this.pts[end0];
|
159
|
+
mcs.tempEnv1.init(p0, p1);
|
160
|
+
|
161
|
+
// terminating condition for the recursion
|
162
|
+
if (end0 - start0 === 1) {
|
163
|
+
mcs.select(this, start0);
|
164
|
+
return;
|
165
|
+
}
|
166
|
+
// nothing to do if the envelopes don't overlap
|
167
|
+
if (!searchEnv.intersects(mcs.tempEnv1))
|
168
|
+
return;
|
169
|
+
|
170
|
+
// the chains overlap, so split each in half and iterate (binary search)
|
171
|
+
var mid = parseInt((start0 + end0) / 2);
|
172
|
+
|
173
|
+
// Assert: mid != start or end (since we checked above for end - start <= 1)
|
174
|
+
// check terminating conditions before recursing
|
175
|
+
if (start0 < mid) {
|
176
|
+
this.computeSelect2(searchEnv, start0, mid, mcs);
|
177
|
+
}
|
178
|
+
if (mid < end0) {
|
179
|
+
this.computeSelect2(searchEnv, mid, end0, mcs);
|
180
|
+
}
|
181
|
+
};
|
182
|
+
|
183
|
+
/**
|
184
|
+
* Determine all the line segments in two chains which may overlap, and process
|
185
|
+
* them.
|
186
|
+
* <p>
|
187
|
+
* The monotone chain search algorithm attempts to optimize performance by not
|
188
|
+
* calling the overlap action on chain segments which it can determine do not
|
189
|
+
* overlap. However, it *may* call the overlap action on segments which do not
|
190
|
+
* actually interact. This saves on the overhead of checking intersection each
|
191
|
+
* time, since clients may be able to do this more efficiently.
|
192
|
+
*
|
193
|
+
* @param {MonotoneChain}
|
194
|
+
* searchEnv the search envelope.
|
195
|
+
* @param {MonotoneChainOverlapAction}
|
196
|
+
* mco the overlap action to execute on selected segments.
|
197
|
+
*/
|
198
|
+
jsts.index.chain.MonotoneChain.prototype.computeOverlaps = function(mc, mco) {
|
199
|
+
if (arguments.length === 6) {
|
200
|
+
return this.computeOverlaps2.apply(this, arguments);
|
201
|
+
}
|
202
|
+
this.computeOverlaps2(this.start, this.end, mc, mc.start, mc.end, mco);
|
203
|
+
};
|
204
|
+
|
205
|
+
/**
|
206
|
+
* @private
|
207
|
+
*/
|
208
|
+
jsts.index.chain.MonotoneChain.prototype.computeOverlaps2 = function(start0,
|
209
|
+
end0, mc, start1, end1, mco) {
|
210
|
+
var p00 = this.pts[start0];
|
211
|
+
var p01 = this.pts[end0];
|
212
|
+
var p10 = mc.pts[start1];
|
213
|
+
var p11 = mc.pts[end1];
|
214
|
+
// Debug.println("computeIntersectsForChain:" + p00 + p01 + p10 + p11);
|
215
|
+
// terminating condition for the recursion
|
216
|
+
if (end0 - start0 === 1 && end1 - start1 === 1) {
|
217
|
+
mco.overlap(this, start0, mc, start1);
|
218
|
+
return;
|
219
|
+
}
|
220
|
+
// nothing to do if the envelopes of these chains don't overlap
|
221
|
+
mco.tempEnv1.init(p00, p01);
|
222
|
+
mco.tempEnv2.init(p10, p11);
|
223
|
+
if (!mco.tempEnv1.intersects(mco.tempEnv2))
|
224
|
+
return;
|
225
|
+
|
226
|
+
// the chains overlap, so split each in half and iterate (binary search)
|
227
|
+
var mid0 = parseInt((start0 + end0) / 2);
|
228
|
+
var mid1 = parseInt((start1 + end1) / 2);
|
229
|
+
|
230
|
+
// Assert: mid != start or end (since we checked above for end - start <= 1)
|
231
|
+
// check terminating conditions before recursing
|
232
|
+
if (start0 < mid0) {
|
233
|
+
if (start1 < mid1)
|
234
|
+
this.computeOverlaps2(start0, mid0, mc, start1, mid1, mco);
|
235
|
+
if (mid1 < end1)
|
236
|
+
this.computeOverlaps2(start0, mid0, mc, mid1, end1, mco);
|
237
|
+
}
|
238
|
+
if (mid0 < end0) {
|
239
|
+
if (start1 < mid1)
|
240
|
+
this.computeOverlaps2(mid0, end0, mc, start1, mid1, mco);
|
241
|
+
if (mid1 < end1)
|
242
|
+
this.computeOverlaps2(mid0, end0, mc, mid1, end1, mco);
|
243
|
+
}
|
244
|
+
};
|