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.
Files changed (209) hide show
  1. checksums.yaml +8 -8
  2. data/lib/jsts-rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/javascript.util.js +33 -1
  4. data/vendor/assets/javascripts/jsts-original.js +164 -1573
  5. data/vendor/assets/javascripts/jsts.js +197 -0
  6. data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
  7. data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
  8. data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
  9. data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
  10. data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
  11. data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
  12. data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
  13. data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
  14. data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
  15. data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
  16. data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
  17. data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
  18. data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
  19. data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
  20. data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
  21. data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
  22. data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
  23. data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
  24. data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
  25. data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
  26. data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
  27. data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
  28. data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
  29. data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
  30. data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
  31. data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
  32. data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
  33. data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
  34. data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
  35. data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
  36. data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
  37. data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
  38. data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
  39. data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
  40. data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
  41. data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
  42. data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
  43. data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
  44. data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
  45. data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
  46. data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
  47. data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
  48. data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
  49. data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
  50. data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
  51. data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
  52. data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
  53. data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
  54. data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
  55. data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
  56. data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
  57. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
  58. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
  59. data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
  60. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
  61. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
  62. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
  63. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
  64. data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
  65. data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
  66. data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
  67. data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
  68. data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
  69. data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
  70. data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
  71. data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
  72. data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
  73. data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
  74. data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
  75. data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
  76. data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
  77. data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
  78. data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
  79. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
  80. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
  81. data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
  82. data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
  83. data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
  84. data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
  85. data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
  86. data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
  87. data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
  88. data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
  89. data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
  90. data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
  91. data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
  92. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
  93. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
  94. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
  95. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
  96. data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
  97. data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
  98. data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
  99. data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
  100. data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
  101. data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
  102. data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
  103. data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
  104. data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
  105. data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
  106. data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
  107. data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
  108. data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
  109. data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
  110. data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
  111. data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
  112. data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
  113. data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
  114. data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
  115. data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
  116. data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
  117. data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
  118. data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
  119. data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
  120. data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
  121. data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
  122. data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
  123. data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
  124. data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
  125. data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
  126. data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
  127. data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
  128. data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
  129. data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
  130. data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
  131. data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
  132. data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
  133. data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
  134. data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
  135. data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
  136. data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
  137. data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
  138. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
  139. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
  140. data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
  141. data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
  142. data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
  143. data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
  144. data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
  145. data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
  146. data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
  147. data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
  148. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
  149. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
  150. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
  151. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
  152. data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
  153. data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
  154. data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
  155. data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
  156. data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
  157. data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
  158. data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
  159. data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
  160. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
  161. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
  162. data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
  163. data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
  164. data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
  165. data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
  166. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
  167. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
  168. data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
  169. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
  170. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
  171. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
  172. data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
  173. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
  174. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
  175. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
  176. data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
  177. data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
  178. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
  179. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
  180. data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
  181. data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
  182. data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
  183. data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
  184. data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
  185. data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
  186. data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
  187. data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
  188. data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
  189. data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
  190. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
  191. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
  192. data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
  193. data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
  194. data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
  195. data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
  196. data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
  197. data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
  198. data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
  199. data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
  200. data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
  201. data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
  202. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
  203. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
  204. data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
  205. data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
  206. data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
  207. data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
  208. data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
  209. 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
+ };