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,106 @@
|
|
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
|
+
* Constructs {@link MonotoneChain}s for sequences of {@link Coordinate}s.
|
9
|
+
*
|
10
|
+
* @constructor
|
11
|
+
*/
|
12
|
+
jsts.index.chain.MonotoneChainBuilder = function() {
|
13
|
+
|
14
|
+
};
|
15
|
+
|
16
|
+
jsts.index.chain.MonotoneChainBuilder.toIntArray = function(list) {
|
17
|
+
var array = [];
|
18
|
+
for (var i = 0; i < list.length; i++) {
|
19
|
+
array[i] = list[i];
|
20
|
+
}
|
21
|
+
return array;
|
22
|
+
};
|
23
|
+
|
24
|
+
jsts.index.chain.MonotoneChainBuilder.getChains = function(pts) {
|
25
|
+
if (arguments.length === 2) {
|
26
|
+
return jsts.index.chain.MonotoneChainBuilder.getChains2.apply(this, arguments);
|
27
|
+
}
|
28
|
+
|
29
|
+
return jsts.index.chain.MonotoneChainBuilder.getChains2(pts, null);
|
30
|
+
};
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Return a list of the {@link MonotoneChain}s for the given list of
|
34
|
+
* coordinates.
|
35
|
+
*/
|
36
|
+
jsts.index.chain.MonotoneChainBuilder.getChains2 = function(pts, context) {
|
37
|
+
var mcList = [];
|
38
|
+
var startIndex = jsts.index.chain.MonotoneChainBuilder
|
39
|
+
.getChainStartIndices(pts);
|
40
|
+
for (var i = 0; i < startIndex.length - 1; i++) {
|
41
|
+
var mc = new jsts.index.chain.MonotoneChain(pts, startIndex[i],
|
42
|
+
startIndex[i + 1], context);
|
43
|
+
mcList.push(mc);
|
44
|
+
}
|
45
|
+
return mcList;
|
46
|
+
};
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Return an array containing lists of start/end indexes of the monotone chains
|
50
|
+
* for the given list of coordinates. The last entry in the array points to the
|
51
|
+
* end point of the point array, for use as a sentinel.
|
52
|
+
*/
|
53
|
+
jsts.index.chain.MonotoneChainBuilder.getChainStartIndices = function(pts) {
|
54
|
+
// find the startpoint (and endpoints) of all monotone chains in this edge
|
55
|
+
var start = 0;
|
56
|
+
var startIndexList = [];
|
57
|
+
startIndexList.push(start);
|
58
|
+
do {
|
59
|
+
var last = jsts.index.chain.MonotoneChainBuilder.findChainEnd(pts, start);
|
60
|
+
startIndexList.push(last);
|
61
|
+
start = last;
|
62
|
+
} while (start < pts.length - 1);
|
63
|
+
// copy list to an array of ints, for efficiency
|
64
|
+
var startIndex = jsts.index.chain.MonotoneChainBuilder
|
65
|
+
.toIntArray(startIndexList);
|
66
|
+
return startIndex;
|
67
|
+
};
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Finds the index of the last point in a monotone chain starting at a given
|
71
|
+
* point. Any repeated points (0-length segments) will be included in the
|
72
|
+
* monotone chain returned.
|
73
|
+
*
|
74
|
+
* @return the index of the last point in the monotone chain starting at
|
75
|
+
* <code>start</code>.
|
76
|
+
* @private
|
77
|
+
*/
|
78
|
+
jsts.index.chain.MonotoneChainBuilder.findChainEnd = function(pts, start) {
|
79
|
+
var safeStart = start;
|
80
|
+
// skip any zero-length segments at the start of the sequence
|
81
|
+
// (since they cannot be used to establish a quadrant)
|
82
|
+
while (safeStart < pts.length - 1 &&
|
83
|
+
pts[safeStart].equals2D(pts[safeStart + 1])) {
|
84
|
+
safeStart++;
|
85
|
+
}
|
86
|
+
// check if there are NO non-zero-length segments
|
87
|
+
if (safeStart >= pts.length - 1) {
|
88
|
+
return pts.length - 1;
|
89
|
+
}
|
90
|
+
// determine overall quadrant for chain (which is the starting quadrant)
|
91
|
+
var chainQuad = jsts.geomgraph.Quadrant.quadrant(pts[safeStart],
|
92
|
+
pts[safeStart + 1]);
|
93
|
+
var last = start + 1;
|
94
|
+
while (last < pts.length) {
|
95
|
+
// skip zero-length segments, but include them in the chain
|
96
|
+
if (!pts[last - 1].equals2D(pts[last])) {
|
97
|
+
// compute quadrant for next possible segment in chain
|
98
|
+
var quad = jsts.geomgraph.Quadrant.quadrant(pts[last - 1],
|
99
|
+
pts[last]);
|
100
|
+
if (quad !== chainQuad)
|
101
|
+
break;
|
102
|
+
}
|
103
|
+
last++;
|
104
|
+
}
|
105
|
+
return last - 1;
|
106
|
+
};
|
@@ -0,0 +1,56 @@
|
|
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
|
+
* @requires jsts/geom/Envelope.js
|
9
|
+
* @requires jsts/geom/LineSegment.js
|
10
|
+
*/
|
11
|
+
|
12
|
+
/**
|
13
|
+
* The action for the internal iterator for performing overlap queries on a
|
14
|
+
* MonotoneChain
|
15
|
+
*
|
16
|
+
* @constructor
|
17
|
+
*/
|
18
|
+
jsts.index.chain.MonotoneChainOverlapAction = function() {
|
19
|
+
this.tempEnv1 = new jsts.geom.Envelope();
|
20
|
+
this.tempEnv2 = new jsts.geom.Envelope();
|
21
|
+
this.overlapSeg1 = new jsts.geom.LineSegment();
|
22
|
+
this.overlapSeg2 = new jsts.geom.LineSegment();
|
23
|
+
};
|
24
|
+
|
25
|
+
// these envelopes are used during the MonotoneChain search process
|
26
|
+
jsts.index.chain.MonotoneChainOverlapAction.prototype.tempEnv1 = null;
|
27
|
+
jsts.index.chain.MonotoneChainOverlapAction.prototype.tempEnv2 = null;
|
28
|
+
|
29
|
+
jsts.index.chain.MonotoneChainOverlapAction.prototype.overlapSeg1 = null;
|
30
|
+
jsts.index.chain.MonotoneChainOverlapAction.prototype.overlapSeg2 = null;
|
31
|
+
|
32
|
+
/**
|
33
|
+
* This function can be overridden if the original chains are needed
|
34
|
+
*
|
35
|
+
* @param start1
|
36
|
+
* the index of the start of the overlapping segment from mc1.
|
37
|
+
* @param start2
|
38
|
+
* the index of the start of the overlapping segment from mc2.
|
39
|
+
*/
|
40
|
+
jsts.index.chain.MonotoneChainOverlapAction.prototype.overlap = function(mc1,
|
41
|
+
start1, mc2, start2) {
|
42
|
+
this.mc1.getLineSegment(start1, this.overlapSeg1);
|
43
|
+
this.mc2.getLineSegment(start2, this.overlapSeg2);
|
44
|
+
this.overlap2(this.overlapSeg1, this.overlapSeg2);
|
45
|
+
};
|
46
|
+
|
47
|
+
/**
|
48
|
+
* This is a convenience function which can be overridden to obtain the actual
|
49
|
+
* line segments which overlap
|
50
|
+
*
|
51
|
+
* @param seg1
|
52
|
+
* @param seg2
|
53
|
+
*/
|
54
|
+
jsts.index.chain.MonotoneChainOverlapAction.prototype.overlap2 = function(seg1,
|
55
|
+
seg2) {
|
56
|
+
};
|
@@ -0,0 +1,44 @@
|
|
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
|
+
* @requires jsts/geom/Envelope.js
|
9
|
+
* @requires jsts/geom/LineSegment.js
|
10
|
+
*/
|
11
|
+
|
12
|
+
/**
|
13
|
+
* The action for the internal iterator for performing envelope select queries
|
14
|
+
* on a MonotoneChain
|
15
|
+
*
|
16
|
+
* @constructor
|
17
|
+
*/
|
18
|
+
jsts.index.chain.MonotoneChainSelectAction = function() {
|
19
|
+
this.tempEnv1 = new jsts.geom.Envelope();
|
20
|
+
this.selectedSegment = new jsts.geom.LineSegment();
|
21
|
+
};
|
22
|
+
|
23
|
+
|
24
|
+
|
25
|
+
jsts.index.chain.MonotoneChainSelectAction.prototype.tempEnv1 = null;
|
26
|
+
|
27
|
+
jsts.index.chain.MonotoneChainSelectAction.prototype.selectedSegment = null;
|
28
|
+
|
29
|
+
/**
|
30
|
+
* This function can be overridden if the original chain is needed.
|
31
|
+
*/
|
32
|
+
jsts.index.chain.MonotoneChainSelectAction.prototype.select = function(mc,
|
33
|
+
start) {
|
34
|
+
mc.getLineSegment(start, this.selectedSegment);
|
35
|
+
this.select2(this.selectedSegment);
|
36
|
+
};
|
37
|
+
|
38
|
+
/**
|
39
|
+
* This is a convenience function which can be overridden to obtain the actual
|
40
|
+
* line segment which is selected.
|
41
|
+
*
|
42
|
+
* @param seg
|
43
|
+
*/
|
44
|
+
jsts.index.chain.MonotoneChainSelectAction.prototype.select2 = function(seg) {};
|
@@ -0,0 +1,171 @@
|
|
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
|
4
|
+
* notice.
|
5
|
+
* See /license.txt for the full text of the license.
|
6
|
+
*/
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
/**
|
11
|
+
* A node of a {@link KdTree}, which represents one or more points in the same
|
12
|
+
* location.
|
13
|
+
*
|
14
|
+
* Creates a new KdNode. Will call appropriate *initialize-function depending on
|
15
|
+
* arguments.
|
16
|
+
*
|
17
|
+
* @constructor
|
18
|
+
*/
|
19
|
+
jsts.index.kdtree.KdNode = function() {
|
20
|
+
this.left = null;
|
21
|
+
this.right = null;
|
22
|
+
this.count = 1;
|
23
|
+
|
24
|
+
if (arguments.length === 2) {
|
25
|
+
this.initializeFromCoordinate.apply(this, arguments[0], arguments[1]);
|
26
|
+
} else if (arguments.length === 3) {
|
27
|
+
this.initializeFromXY.apply(this, arguments[0], arguments[1], arguments[2]);
|
28
|
+
}
|
29
|
+
};
|
30
|
+
|
31
|
+
|
32
|
+
/**
|
33
|
+
* Creates a new KdNode.
|
34
|
+
*
|
35
|
+
* @param {Number}
|
36
|
+
* x coordinate of point.
|
37
|
+
* @param {Number}
|
38
|
+
* y coordinate of point.
|
39
|
+
* @param {Object}
|
40
|
+
* data a data objects to associate with this node.
|
41
|
+
*/
|
42
|
+
jsts.index.kdtree.KdNode.prototype.initializeFromXY = function(x, y, data) {
|
43
|
+
this.p = new jsts.geom.Coordinate(x, y);
|
44
|
+
this.data = data;
|
45
|
+
};
|
46
|
+
|
47
|
+
|
48
|
+
/**
|
49
|
+
* Creates a new KdNode.
|
50
|
+
*
|
51
|
+
* @param {jsts.geom.Coordinate}
|
52
|
+
* p point location of new node.
|
53
|
+
* @param {Object}
|
54
|
+
* data a data objects to associate with this node.
|
55
|
+
*/
|
56
|
+
jsts.index.kdtree.KdNode.prototype.initializeFromCoordinate = function(p, data) {
|
57
|
+
this.p = p;
|
58
|
+
this.data = data;
|
59
|
+
};
|
60
|
+
|
61
|
+
|
62
|
+
/**
|
63
|
+
* Returns the X coordinate of the node
|
64
|
+
*
|
65
|
+
* @return {Number} X coordinate of the node.
|
66
|
+
*/
|
67
|
+
jsts.index.kdtree.KdNode.prototype.getX = function() {
|
68
|
+
return this.p.x;
|
69
|
+
};
|
70
|
+
|
71
|
+
|
72
|
+
/**
|
73
|
+
* Returns the Y coordinate of the node
|
74
|
+
*
|
75
|
+
* @return {Number} Y coordinate of the node.
|
76
|
+
*/
|
77
|
+
jsts.index.kdtree.KdNode.prototype.getY = function() {
|
78
|
+
return this.p.y;
|
79
|
+
};
|
80
|
+
|
81
|
+
|
82
|
+
/**
|
83
|
+
* Returns the location of this node
|
84
|
+
*
|
85
|
+
* @return {jsts.geom.Coordinate} location of this node.
|
86
|
+
*/
|
87
|
+
jsts.index.kdtree.KdNode.prototype.getCoordinate = function() {
|
88
|
+
return this.p;
|
89
|
+
};
|
90
|
+
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Gets the user data object associated with this node.
|
94
|
+
*
|
95
|
+
* @return {Object} The data of this node.
|
96
|
+
*/
|
97
|
+
jsts.index.kdtree.KdNode.prototype.getData = function() {
|
98
|
+
return this.data;
|
99
|
+
};
|
100
|
+
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Returns the left node of the tree
|
104
|
+
*
|
105
|
+
* @return {jsts.index.kdtree.KdNode} The left node of the tree.
|
106
|
+
*/
|
107
|
+
jsts.index.kdtree.KdNode.prototype.getLeft = function() {
|
108
|
+
return this.left;
|
109
|
+
};
|
110
|
+
|
111
|
+
|
112
|
+
/**
|
113
|
+
* Returns the right node of the tree
|
114
|
+
*
|
115
|
+
* @return {jsts.index.kdtree.KdNode} The right node of the tree.
|
116
|
+
*/
|
117
|
+
jsts.index.kdtree.KdNode.prototype.getRight = function() {
|
118
|
+
return this.right;
|
119
|
+
};
|
120
|
+
|
121
|
+
|
122
|
+
/**
|
123
|
+
* Increments the count by 1
|
124
|
+
*/
|
125
|
+
jsts.index.kdtree.KdNode.prototype.increment = function() {
|
126
|
+
this.count += 1;
|
127
|
+
};
|
128
|
+
|
129
|
+
|
130
|
+
/**
|
131
|
+
* Returns the number of inserted points that are coincident at this location.
|
132
|
+
*
|
133
|
+
* @return {Number} Number of inserted points that this node represents.
|
134
|
+
*/
|
135
|
+
jsts.index.kdtree.KdNode.prototype.getCount = function() {
|
136
|
+
return this.count;
|
137
|
+
};
|
138
|
+
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Tests whether more than one point with this value have been inserted (up to
|
142
|
+
* the tolerance)
|
143
|
+
*
|
144
|
+
* @return {Boolean} true if more than one point have been inserted with this
|
145
|
+
* value.
|
146
|
+
*/
|
147
|
+
jsts.index.kdtree.KdNode.prototype.isRepeated = function() {
|
148
|
+
return count > 1;
|
149
|
+
};
|
150
|
+
|
151
|
+
|
152
|
+
/**
|
153
|
+
* Sets the left node value
|
154
|
+
*
|
155
|
+
* @param {jsts.index.kdtree.KdNode}
|
156
|
+
* left The node to be inserted as left.
|
157
|
+
*/
|
158
|
+
jsts.index.kdtree.KdNode.prototype.setLeft = function(left) {
|
159
|
+
this.left = left;
|
160
|
+
};
|
161
|
+
|
162
|
+
|
163
|
+
/**
|
164
|
+
* Sets the right node value
|
165
|
+
*
|
166
|
+
* @param {jsts.index.kdtree.KdNode}
|
167
|
+
* right The node to be inserted as right.
|
168
|
+
*/
|
169
|
+
jsts.index.kdtree.KdNode.prototype.setRight = function(right) {
|
170
|
+
this.right = right;
|
171
|
+
};
|
@@ -0,0 +1,218 @@
|
|
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
|
4
|
+
* the license notice.
|
5
|
+
* See /license.txt for the full text of the license.
|
6
|
+
*/
|
7
|
+
|
8
|
+
|
9
|
+
|
10
|
+
/**
|
11
|
+
* An implementation of a 2-D KD-Tree. KD-trees provide fast range searching on
|
12
|
+
* point data.
|
13
|
+
* <p>
|
14
|
+
* This implementation supports detecting and snapping points which are closer
|
15
|
+
* than a given tolerance value. If the same point (up to tolerance) is inserted
|
16
|
+
* more than once a new node is not created but the count of the existing node
|
17
|
+
* is incremented.
|
18
|
+
*
|
19
|
+
* Creates a new instance of a KdTree, specifying a snapping distance tolerance.
|
20
|
+
* Points which lie closer than the tolerance to a point already in the tree
|
21
|
+
* will be treated as identical to the existing point.
|
22
|
+
*
|
23
|
+
* @param {Number}
|
24
|
+
* tolerance (optional) the tolerance distance for considering two
|
25
|
+
* points equal.
|
26
|
+
*
|
27
|
+
* @constructor
|
28
|
+
*/
|
29
|
+
jsts.index.kdtree.KdTree = function(tolerance) {
|
30
|
+
var tol = 0.0;
|
31
|
+
if (tolerance !== undefined) {
|
32
|
+
tol = tolerance;
|
33
|
+
}
|
34
|
+
|
35
|
+
this.root = null;
|
36
|
+
this.last = null;
|
37
|
+
this.numberOfNodes = 0;
|
38
|
+
this.tolerance = tol;
|
39
|
+
};
|
40
|
+
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Inserts a new point in the kd-tree.
|
44
|
+
*
|
45
|
+
* Will call correct *insert function depending on arguments
|
46
|
+
*
|
47
|
+
* @return {jsts.index.kdtree.KdNode} The kd-node containing the point.
|
48
|
+
*/
|
49
|
+
jsts.index.kdtree.KdTree.prototype.insert = function() {
|
50
|
+
if (arguments.length === 1) {
|
51
|
+
return this.insertCoordinate.apply(this, arguments[0]);
|
52
|
+
} else {
|
53
|
+
return this.insertWithData.apply(this, arguments[0], arguments[1]);
|
54
|
+
}
|
55
|
+
};
|
56
|
+
|
57
|
+
|
58
|
+
/**
|
59
|
+
* Inserts a new point in the kd-tree, with no data.
|
60
|
+
*
|
61
|
+
* @param {jsts.geom.Coordinate}
|
62
|
+
* p the point to insert.
|
63
|
+
* @return {jsts.index.kdtree.KdNode} the kdnode containing the point.
|
64
|
+
*/
|
65
|
+
jsts.index.kdtree.KdTree.prototype.insertCoordinate = function(p) {
|
66
|
+
return this.insertWithData(p, null);
|
67
|
+
};
|
68
|
+
|
69
|
+
|
70
|
+
/**
|
71
|
+
* Inserts a new point into the kd-tree.
|
72
|
+
*
|
73
|
+
* @param {jsts.geom.Coordinate}
|
74
|
+
* p the point to insert.
|
75
|
+
* @param {Object}
|
76
|
+
* data a data item for the point.
|
77
|
+
* @return {jsts.index.kdtree.KdNode} returns a new KdNode if a new point is
|
78
|
+
* inserted, else an existing node is returned with its counter
|
79
|
+
* incremented. This can be checked by testing returnedNode.getCount() >
|
80
|
+
* 1.
|
81
|
+
*/
|
82
|
+
jsts.index.kdtree.KdTree.prototype.insertWithData = function(p, data) {
|
83
|
+
if (this.root === null) {
|
84
|
+
this.root = new jsts.index.kdtree.KdNode(p, data);
|
85
|
+
return this.root;
|
86
|
+
}
|
87
|
+
|
88
|
+
var currentNode = this.root, leafNode = this.root, isOddLevel = true, isLessThan = true;
|
89
|
+
|
90
|
+
// traverse the tree first cutting the plane left-right the top-bottom
|
91
|
+
while (currentNode !== last) {
|
92
|
+
if (isOddLevel) {
|
93
|
+
isLessThan = p.x < currentNode.getX();
|
94
|
+
} else {
|
95
|
+
isLessThan = p.y < currentNode.getY();
|
96
|
+
}
|
97
|
+
leafNode = currentNode;
|
98
|
+
if (isLessThan) {
|
99
|
+
currentNode = currentNode.getLeft();
|
100
|
+
} else {
|
101
|
+
currentNode = currentNode.getRight();
|
102
|
+
}
|
103
|
+
|
104
|
+
// test if point is already a node
|
105
|
+
if (currentNode !== null) {
|
106
|
+
var isInTolerance = p.distance(currentNode.getCoordinate()) <= this.tolerance;
|
107
|
+
|
108
|
+
// check if point is already in tree (up to tolerance) and if so simply
|
109
|
+
// return existing node
|
110
|
+
if (isInTolerance) {
|
111
|
+
currentNode.increment();
|
112
|
+
return currentNode;
|
113
|
+
}
|
114
|
+
}
|
115
|
+
isOddLevel = !isOddLevel;
|
116
|
+
}
|
117
|
+
|
118
|
+
// no node found, add new leaf node to tree
|
119
|
+
this.numberOfNodes = numberOfNodes + 1;
|
120
|
+
var node = new jsts.index.kdtree.KdNode(p, data);
|
121
|
+
node.setLeft(this.last);
|
122
|
+
node.setRight(this.last);
|
123
|
+
if (isLessThan) {
|
124
|
+
leafNode.setLeft(node);
|
125
|
+
} else {
|
126
|
+
leafNode.setRight(node);
|
127
|
+
}
|
128
|
+
return node;
|
129
|
+
};
|
130
|
+
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Query's the tree
|
134
|
+
*
|
135
|
+
* @param {jsts.index.kdtree.KdNode}
|
136
|
+
* currentNode the current node.
|
137
|
+
* @param {jsts.index.kdtree.KdNode}
|
138
|
+
* bottomNode the bottom node.
|
139
|
+
* @param {jsts.geom.Envelope}
|
140
|
+
* queryEnv the query-envelope.
|
141
|
+
* @param {Boolean}
|
142
|
+
* odd true if the level is odd.
|
143
|
+
* @param {Array}
|
144
|
+
* result the array to fill the result with.
|
145
|
+
*/
|
146
|
+
jsts.index.kdtree.KdTree.prototype.queryNode = function(currentNode,
|
147
|
+
bottomNode, queryEnv, odd, result) {
|
148
|
+
if (currentNode === bottomNode) {
|
149
|
+
return;
|
150
|
+
}
|
151
|
+
|
152
|
+
var min, max, discriminant;
|
153
|
+
if (odd) {
|
154
|
+
min = queryEnv.getMinX();
|
155
|
+
max = queryEnv.getMaxX();
|
156
|
+
discriminant = currentNode.getX();
|
157
|
+
} else {
|
158
|
+
min = queryEnv.getMinY();
|
159
|
+
max = queryEnv.getMaxY();
|
160
|
+
discriminant = currentNode.getY();
|
161
|
+
}
|
162
|
+
|
163
|
+
var searchLeft = min < discriminant;
|
164
|
+
var searchRight = discriminant <= max;
|
165
|
+
|
166
|
+
if (searchLeft) {
|
167
|
+
this.queryNode(currentNode.getLeft(), bottomNode, queryEnv, !odd, result);
|
168
|
+
}
|
169
|
+
|
170
|
+
if (queryEnv.contains(currentNode.getCoordinate())) {
|
171
|
+
result.add(currentNode);
|
172
|
+
}
|
173
|
+
|
174
|
+
if (searchRight) {
|
175
|
+
this.queryNode(currentNode.getRight(), bottomNode, queryEnv, !odd, result);
|
176
|
+
}
|
177
|
+
};
|
178
|
+
|
179
|
+
|
180
|
+
/**
|
181
|
+
* Will call the correct *query-function depending on arguments
|
182
|
+
*
|
183
|
+
* @return {Array{jsts.index.KdNode}} The found nodes.
|
184
|
+
*/
|
185
|
+
jsts.index.kdtree.KdTree.prototype.query = function() {
|
186
|
+
if (arguments.length === 1) {
|
187
|
+
return this.queryByEnvelope.apply(this, arguments[0]);
|
188
|
+
} else {
|
189
|
+
return this.queryWithArray.apply(this, arguments[0], arguments[1]);
|
190
|
+
}
|
191
|
+
};
|
192
|
+
|
193
|
+
|
194
|
+
/**
|
195
|
+
* Performs a range search of the points in the index.
|
196
|
+
*
|
197
|
+
* @param {jsts.geom.Envelope}
|
198
|
+
* queryEnv the range rectangle to query.
|
199
|
+
* @return {Array} a list of the KdNodes found.
|
200
|
+
*/
|
201
|
+
jsts.index.kdtree.KdTree.prototype.queryByEnvelope = function(queryEnv) {
|
202
|
+
var result = [];
|
203
|
+
this.queryNode(this.root, this.last, queryEnv, true, result);
|
204
|
+
return result;
|
205
|
+
};
|
206
|
+
|
207
|
+
|
208
|
+
/**
|
209
|
+
* Performs a range search of the points in the index.
|
210
|
+
*
|
211
|
+
* @param {jsts.geom.Envelope}
|
212
|
+
* queryEnv the range rectangle to query.
|
213
|
+
* @param {Array}
|
214
|
+
* result a list to accumulate the result nodes into.
|
215
|
+
*/
|
216
|
+
jsts.index.kdtree.KdTree.prototype.queryWithArray = function(queryEnv, result) {
|
217
|
+
this.queryNode(this.root, this.last, queryEnv, true, result);
|
218
|
+
};
|