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,228 @@
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
+
9
+ /**
10
+ * A Quadtree is a spatial index structure for efficient querying of 2D
11
+ * rectangles. If other kinds of spatial objects need to be indexed they can be
12
+ * represented by their envelopes
13
+ * <p>
14
+ * The quadtree structure is used to provide a primary filter for range
15
+ * rectangle queries. The query() method returns a list of all objects which
16
+ * <i>may</i> intersect the query rectangle. Note that it may return objects
17
+ * which do not in fact intersect. A secondary filter is required to test for
18
+ * exact intersection. Of course, this secondary filter may consist of other
19
+ * tests besides intersection, such as testing other kinds of spatial
20
+ * relationships.
21
+ *
22
+ * <p>
23
+ * This implementation does not require specifying the extent of the inserted
24
+ * items beforehand. It will automatically expand to accomodate any extent of
25
+ * dataset.
26
+ * <p>
27
+ * This data structure is also known as an <i>MX-CIF quadtree</i> following the
28
+ * usage of Samet and others.
29
+ *
30
+ * @constructor
31
+ */
32
+ jsts.index.quadtree.Quadtree = function() {
33
+ this.root = new jsts.index.quadtree.Root();
34
+
35
+ /**
36
+ * minExtent is the minimum envelope extent of all items inserted into the
37
+ * tree so far. It is used as a heuristic value to construct non-zero
38
+ * envelopes for features with zero X and/or Y extent. Start with a non-zero
39
+ * extent, in case the first feature inserted has a zero extent in both
40
+ * directions. This value may be non-optimal, but only one feature will be
41
+ * inserted with this value.
42
+ */
43
+ this.minExtent = 1.0;
44
+ };
45
+
46
+ /**
47
+ * Ensure that the envelope for the inserted item has non-zero extents. Use the
48
+ * current minExtent to pad the envelope, if necessary
49
+ */
50
+
51
+
52
+ /**
53
+ * Ensures an extent is not zero.
54
+ *
55
+ * @param {jsts.geom.Envelope}
56
+ * itemEnv The envelope to check.
57
+ * @param {Number}
58
+ * minExtent the minimum width/height to expand the extent with if it
59
+ * is zero.
60
+ * @return {jsts.geom.Envelope} A valid extent.
61
+ */
62
+ jsts.index.quadtree.Quadtree.ensureExtent = function(itemEnv, minExtent) {
63
+ var minx, maxx, miny, maxy;
64
+
65
+ minx = itemEnv.getMinX();
66
+ maxx = itemEnv.getMaxX();
67
+ miny = itemEnv.getMinY();
68
+ maxy = itemEnv.getMaxY();
69
+
70
+ // has a non-zero extent
71
+ if (minx !== maxx && miny !== maxy) {
72
+ return itemEnv;
73
+ }
74
+
75
+ // pad one or both extents
76
+ if (minx === maxx) {
77
+ minx = minx - (minExtent / 2.0);
78
+ maxx = minx + (minExtent / 2.0);
79
+ }
80
+
81
+ if (miny === maxy) {
82
+ miny = miny - (minExtent / 2.0);
83
+ maxy = miny + (minExtent / 2.0);
84
+ }
85
+
86
+ return new jsts.geom.Envelope(minx, maxx, miny, maxy);
87
+ };
88
+
89
+
90
+ /**
91
+ * Returns the depth of the tree.
92
+ *
93
+ * @return {Number} the depth.
94
+ */
95
+ jsts.index.quadtree.Quadtree.prototype.depth = function() {
96
+ return this.root.depth();
97
+ };
98
+
99
+
100
+ /**
101
+ * Returns the number of items in the tree.
102
+ *
103
+ * @return {Number} the number of items in the tree.
104
+ */
105
+ jsts.index.quadtree.Quadtree.prototype.size = function() {
106
+ return this.root.size();
107
+ };
108
+
109
+
110
+ /**
111
+ * Inserts an item to the tree
112
+ *
113
+ * @param {jsts.geom.Envelope}
114
+ * itemEnv The envelope.
115
+ * @param {Object}
116
+ * item The item.
117
+ */
118
+ jsts.index.quadtree.Quadtree.prototype.insert = function(itemEnv, item) {
119
+ this.collectStats(itemEnv);
120
+ var insertEnv = jsts.index.quadtree.Quadtree.ensureExtent(itemEnv,
121
+ this.minExtent);
122
+ this.root.insert(insertEnv, item);
123
+ };
124
+
125
+
126
+ /**
127
+ * Removes a single item from the tree
128
+ *
129
+ * @param {jsts.geom.Envelope}
130
+ * itemEnv the envelope of the item to be removed.
131
+ * @param {Object}
132
+ * item the item to remove.
133
+ * @return {Boolean} <code>true</true> if the item was found (and removed).
134
+ */
135
+ jsts.index.quadtree.Quadtree.prototype.remove = function(itemEnv, item) {
136
+ var posEnv = jsts.index.quadtree.Quadtree.ensureExtent(itemEnv,
137
+ this.minExtent);
138
+ return this.root.remove(posEnv, item);
139
+ };
140
+
141
+
142
+ /**
143
+ * Querys the quadtree.
144
+ *
145
+ * Calls appropriate function depending on arguments
146
+ */
147
+ jsts.index.quadtree.Quadtree.prototype.query = function() {
148
+ if (arguments.length === 1) {
149
+ return jsts.index.quadtree.Quadtree.prototype.queryByEnvelope.apply(this,
150
+ arguments);
151
+ } else {
152
+ jsts.index.quadtree.Quadtree.prototype.queryWithVisitor.apply(this,
153
+ arguments);
154
+ }
155
+ };
156
+
157
+
158
+ /**
159
+ * Queries the tree and returns items which may lie in the given search
160
+ * envelope. Precisely, the items that are returned are all items in the tree
161
+ * whose envelope <b>may</b> intersect the search Envelope. Note that some
162
+ * items with non-intersecting envelopes may be returned as well; the client is
163
+ * responsible for filtering these out. In most situations there will be many
164
+ * items in the tree which do not intersect the search envelope and which are
165
+ * not returned - thus providing improved performance over a simple linear scan.
166
+ *
167
+ * @param {jsts.geom.Envelope}
168
+ * searchEnv the envelope of the desired query area.
169
+ * @return {Array} an array of items which may intersect the search envelope.
170
+ */
171
+ jsts.index.quadtree.Quadtree.prototype.queryByEnvelope = function(searchEnv) {
172
+ var visitor = new jsts.index.ArrayListVisitor();
173
+ this.query(searchEnv, visitor);
174
+
175
+ return visitor.getItems();
176
+ };
177
+
178
+
179
+ /**
180
+ * Queries the tree and visits items which may lie in the given search envelope.
181
+ * Precisely, the items that are visited are all items in the tree whose
182
+ * envelope <b>may</b> intersect the search Envelope. Note that some items with
183
+ * non-intersecting envelopes may be visited as well; the client is responsible
184
+ * for filtering these out. In most situations there will be many items in the
185
+ * tree which do not intersect the search envelope and which are not visited -
186
+ * thus providing improved performance over a simple linear scan.
187
+ *
188
+ * @param {jsts.geom.Envelope}
189
+ * searchEnv the envelope of the desired query area.
190
+ * @param {jsts.index.Visitor}
191
+ * visitor a visitor object which is passed the visited items.
192
+ */
193
+ jsts.index.quadtree.Quadtree.prototype.queryWithVisitor = function(searchEnv,
194
+ visitor) {
195
+ this.root.visit(searchEnv, visitor);
196
+ };
197
+
198
+
199
+ /**
200
+ * Returns an array of all items in the quadtree.
201
+ *
202
+ * @return {Array} An array of all items in the quadtree.
203
+ */
204
+ jsts.index.quadtree.Quadtree.prototype.queryAll = function() {
205
+ var foundItems = [];
206
+ foundItems = this.root.addAllItems(foundItems);
207
+ return foundItems;
208
+ };
209
+
210
+
211
+ /**
212
+ * Checks wheter a width and height of an envelope is above zero and sets
213
+ * minExtent if the widht or height is less than the current min extent
214
+ *
215
+ * @param {jsts.geom.Envelope}
216
+ * itemEnv The envelope.
217
+ */
218
+ jsts.index.quadtree.Quadtree.prototype.collectStats = function(itemEnv) {
219
+ var delX = itemEnv.getWidth();
220
+ if (delX < this.minExtent && delX > 0.0) {
221
+ this.minExtent = delX;
222
+ }
223
+
224
+ var delY = itemEnv.getHeight();
225
+ if (delY < this.minExtent && delY > 0.0) {
226
+ this.minExtent = delY;
227
+ }
228
+ };
@@ -0,0 +1,105 @@
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
+
9
+ /**
10
+ * QuadRoot is the root of a single Quadtree. It is centred at the origin, and
11
+ * does not have a defined extent.
12
+ *
13
+ * @constructor
14
+ */
15
+ jsts.index.quadtree.Root = function() {
16
+ jsts.index.quadtree.NodeBase.prototype.constructor.apply(this, arguments);
17
+
18
+ // the root quad is centred at the origin.
19
+ this.origin = new jsts.geom.Coordinate(0.0, 0.0);
20
+ };
21
+
22
+ jsts.index.quadtree.Root.prototype = new jsts.index.quadtree.NodeBase();
23
+
24
+
25
+ /**
26
+ * Insert an item into the quadtree this is the root of.
27
+ *
28
+ * @param {jsts.geom.Envelope}
29
+ * itemEnv the item envelope.
30
+ * @param {Object}
31
+ * item the item to insert.
32
+ */
33
+ jsts.index.quadtree.Root.prototype.insert = function(itemEnv, item) {
34
+ var index = this.getSubnodeIndex(itemEnv, this.origin);
35
+
36
+ // if index is -1, itemEnv must cross the X or Y axis.
37
+ if (index === -1) {
38
+ this.add(item);
39
+ return;
40
+ }
41
+ /**
42
+ * the item must be contained in one quadrant, so insert it into the tree for
43
+ * that quadrant (which may not yet exist)
44
+ */
45
+ var node = this.subnode[index];
46
+ /**
47
+ * If the subquad doesn't exist or this item is not contained in it, have to
48
+ * expand the tree upward to contain the item.
49
+ */
50
+
51
+ if (node === null || !node.getEnvelope().contains(itemEnv)) {
52
+ var largerNode = jsts.index.quadtree.Node.createExpanded(node, itemEnv);
53
+ this.subnode[index] = largerNode;
54
+ }
55
+ /**
56
+ * At this point we have a subquad which exists and must contain contains the
57
+ * env for the item. Insert the item into the tree.
58
+ */
59
+ this.insertContained(this.subnode[index], itemEnv, item);
60
+ };
61
+
62
+
63
+ /**
64
+ * insert an item which is known to be contained in the tree rooted at the given
65
+ * QuadNode root. Lower levels of the tree will be created if necessary to hold
66
+ * the item.
67
+ *
68
+ * @param {jsts.index.quadtree.Node}
69
+ * tree the root-node of the tree.
70
+ * @param {jsts.geom.Envelope}
71
+ * itemEnv the envelope.
72
+ * @param {Object}
73
+ * item the item to insert.
74
+ */
75
+ jsts.index.quadtree.Root.prototype.insertContained = function(tree, itemEnv,
76
+ item) {
77
+ /**
78
+ * Do NOT create a new quad for zero-area envelopes - this would lead to
79
+ * infinite recursion. Instead, use a heuristic of simply returning the
80
+ * smallest existing quad containing the query
81
+ */
82
+ var isZeroX, isZeroY, node;
83
+ isZeroX = jsts.index.IntervalSize.isZeroWidth(itemEnv.getMinX(),
84
+ itemEnv.getMaxX());
85
+ isZeroY = jsts.index.IntervalSize.isZeroWidth(itemEnv.getMinY(),
86
+ itemEnv.getMaxY());
87
+
88
+ if (isZeroX || isZeroY) {
89
+ node = tree.find(itemEnv);
90
+ } else {
91
+ node = tree.getNode(itemEnv);
92
+ }
93
+ node.add(item);
94
+ };
95
+
96
+
97
+ /**
98
+ * Checks if the root is a search match.
99
+ *
100
+ * @param {jsts.geom.Envelope} searchEnv the envelope.
101
+ * @return {Boolean} Always returns true for a root node.
102
+ */
103
+ jsts.index.quadtree.Root.prototype.isSearchMatch = function(searchEnv) {
104
+ return true;
105
+ };
@@ -0,0 +1,107 @@
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
+ * A node of the STR tree. The children of this node are either more nodes
9
+ * (AbstractNodes) or real data (ItemBoundables). If this node contains real data
10
+ * (rather than nodes), then we say that this node is a "leaf node".
11
+ *
12
+ * @requires jsts/index/strtree/Boundable.js
13
+ */
14
+
15
+
16
+
17
+ /**
18
+ * Constructs an AbstractNode at the given level in the tree
19
+ * @param {Integer} level 0 if this node is a leaf, 1 if a parent of a leaf, and so on; the
20
+ * root node will have the highest level.
21
+ *
22
+ * @extends {Boundable}
23
+ * @constructor
24
+ * @interface
25
+ */
26
+ jsts.index.strtree.AbstractNode = function(level) {
27
+ this.level = level;
28
+ this.childBoundables = [];
29
+ };
30
+
31
+ jsts.index.strtree.AbstractNode.prototype = new jsts.index.strtree.Boundable();
32
+ jsts.index.strtree.AbstractNode.constructor = jsts.index.strtree.AbstractNode;
33
+
34
+ /**
35
+ * @type {Array}
36
+ * @private
37
+ */
38
+ jsts.index.strtree.AbstractNode.prototype.childBoundables = null;
39
+
40
+
41
+ /**
42
+ * @type {Object}
43
+ * @private
44
+ */
45
+ jsts.index.strtree.AbstractNode.prototype.bounds = null;
46
+
47
+
48
+ /**
49
+ * @type {number}
50
+ * @private
51
+ */
52
+ jsts.index.strtree.AbstractNode.prototype.level = null;
53
+
54
+
55
+ /**
56
+ * Returns either child {@link AbstractNodes}, or if this is a leaf node, real data (wrapped
57
+ * in {@link ItemBoundables}).
58
+ *
59
+ * @return {Array}
60
+ */
61
+ jsts.index.strtree.AbstractNode.prototype.getChildBoundables = function() {
62
+ return this.childBoundables;
63
+ };
64
+
65
+
66
+ /**
67
+ * Returns a representation of space that encloses this Boundable,
68
+ * preferably not much bigger than this Boundable's boundary yet fast to
69
+ * test for intersection with the bounds of other Boundables. The class of
70
+ * object returned depends on the subclass of AbstractSTRtree.
71
+ *
72
+ * @return an Envelope (for STRtrees), an Interval (for SIRtrees), or other
73
+ * object (for other subclasses of AbstractSTRtree).
74
+ * @see AbstractSTRtree.IntersectsOp
75
+ */
76
+ jsts.index.strtree.AbstractNode.prototype.computeBounds = function() {
77
+ throw new jsts.error.AbstractMethodInvocationError();
78
+ };
79
+
80
+ jsts.index.strtree.AbstractNode.prototype.getBounds = function() {
81
+ if (this.bounds === null) {
82
+ this.bounds = this.computeBounds();
83
+ }
84
+ return this.bounds;
85
+ };
86
+
87
+
88
+ /**
89
+ * Returns 0 if this node is a leaf, 1 if a parent of a leaf, and so on; the
90
+ * root node will have the highest level
91
+ *
92
+ * @return {number}
93
+ */
94
+ jsts.index.strtree.AbstractNode.prototype.getLevel = function() {
95
+ return this.level;
96
+ };
97
+
98
+
99
+ /**
100
+ * Adds either an AbstractNode, or if this is a leaf node, a data object
101
+ * (wrapped in an ItemBoundable)
102
+ *
103
+ * @param {jsts.index.strtree.Boundable} childBoundable
104
+ */
105
+ jsts.index.strtree.AbstractNode.prototype.addChildBoundable = function(childBoundable) {
106
+ this.childBoundables.push(childBoundable);
107
+ };
@@ -0,0 +1,594 @@
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
+ * Base class for STRtree and SIRtree. STR-packed R-trees are described in:
9
+ * P. Rigaux, Michel Scholl and Agnes Voisard. Spatial Databases With
10
+ * Application To GIS. Morgan Kaufmann, San Francisco, 2002.
11
+ * <p>
12
+ * This implementation is based on Boundables rather than just AbstractNodes,
13
+ * because the STR algorithm operates on both nodes and
14
+ * data, both of which are treated here as Boundables.
15
+ *
16
+ * @see STRtree
17
+ * @see SIRtree
18
+ */
19
+
20
+
21
+
22
+ /**
23
+ * Constructs an AbstractSTRtree with the specified maximum number of child
24
+ * nodes that a node may have
25
+ *
26
+ * @param {Integer}
27
+ * nodeCapacity
28
+ *
29
+ * @constuctor
30
+ */
31
+ jsts.index.strtree.AbstractSTRtree = function(nodeCapacity) {
32
+ if (nodeCapacity === undefined)
33
+ return;
34
+
35
+ this.itemBoundables = [];
36
+
37
+ jsts.util.Assert.isTrue(nodeCapacity > 1, 'Node capacity must be greater than 1');
38
+ this.nodeCapacity = nodeCapacity;
39
+ };
40
+
41
+
42
+
43
+ /**
44
+ * A test for intersection between two bounds, necessary because subclasses of
45
+ * AbstractSTRtree have different implementations of bounds.
46
+ *
47
+ * @interface
48
+ * @constructor
49
+ * @public
50
+ */
51
+ jsts.index.strtree.AbstractSTRtree.IntersectsOp = function() {
52
+
53
+ };
54
+
55
+
56
+ /**
57
+ * For STRtrees, the bounds will be Envelopes; for SIRtrees, Intervals; for
58
+ * other subclasses of AbstractSTRtree, some other class.
59
+ *
60
+ * @param {Object}
61
+ * aBounds the bounds of one spatial object.
62
+ * @param {Object}
63
+ * bBounds the bounds of another spatial object.
64
+ * @return {boolean} whether the two bounds intersect.
65
+ */
66
+ jsts.index.strtree.AbstractSTRtree.IntersectsOp.prototype.intersects = function(
67
+ aBounds, bBounds) {
68
+ throw new jsts.error.AbstractMethodInvocationError();
69
+ };
70
+
71
+
72
+ /**
73
+ * @type {jsts.index.strtree.AbstractNode}
74
+ * @protected
75
+ */
76
+ jsts.index.strtree.AbstractSTRtree.prototype.root = null;
77
+
78
+
79
+ /**
80
+ * @type {boolean}
81
+ * @private
82
+ */
83
+ jsts.index.strtree.AbstractSTRtree.prototype.built = false;
84
+
85
+
86
+ /**
87
+ * @type {Array}
88
+ * @private
89
+ */
90
+ jsts.index.strtree.AbstractSTRtree.prototype.itemBoundables = null;
91
+
92
+
93
+ /**
94
+ * @type {number}
95
+ * @private
96
+ */
97
+ jsts.index.strtree.AbstractSTRtree.prototype.nodeCapacity = null;
98
+
99
+
100
+ /**
101
+ * Creates parent nodes, grandparent nodes, and so forth up to the root node,
102
+ * for the data that has been inserted into the tree. Can only be called once,
103
+ * and thus can be called only after all of the data has been inserted into the
104
+ * tree.
105
+ */
106
+ jsts.index.strtree.AbstractSTRtree.prototype.build = function() {
107
+ jsts.util.Assert.isTrue(!this.built);
108
+ this.root = this.itemBoundables.length === 0 ? this.createNode(0) : this
109
+ .createHigherLevels(this.itemBoundables, -1);
110
+ this.built = true;
111
+ };
112
+
113
+
114
+ /**
115
+ * @param {number}
116
+ * level
117
+ * @return {jsts.index.strtree.AbstractNode}
118
+ */
119
+ jsts.index.strtree.AbstractSTRtree.prototype.createNode = function(level) {
120
+ throw new jsts.error.AbstractMethodInvocationError();
121
+ };
122
+
123
+
124
+ /**
125
+ * Sorts the childBoundables then divides them into groups of size M, where M is
126
+ * the node capacity.
127
+ */
128
+ jsts.index.strtree.AbstractSTRtree.prototype.createParentBoundables = function(
129
+ childBoundables, newLevel) {
130
+ jsts.util.Assert.isTrue(!(childBoundables.length === 0));
131
+ var parentBoundables = [];
132
+ parentBoundables.push(this.createNode(newLevel));
133
+ var sortedChildBoundables = [];
134
+ for (var i = 0; i < childBoundables.length; i++) {
135
+ sortedChildBoundables.push(childBoundables[i]);
136
+ }
137
+ sortedChildBoundables.sort(this.getComparator());
138
+ for (var i = 0; i < sortedChildBoundables.length; i++) {
139
+ var childBoundable = sortedChildBoundables[i];
140
+ if (this.lastNode(parentBoundables).getChildBoundables().length === this
141
+ .getNodeCapacity()) {
142
+ parentBoundables.push(this.createNode(newLevel));
143
+ }
144
+ this.lastNode(parentBoundables).addChildBoundable(childBoundable);
145
+ }
146
+ return parentBoundables;
147
+ };
148
+
149
+
150
+ /**
151
+ * @param {Array}
152
+ * nodes
153
+ * @return {jsts.index.strtree.AbstractNode}
154
+ */
155
+ jsts.index.strtree.AbstractSTRtree.prototype.lastNode = function(nodes) {
156
+ return nodes[nodes.length - 1];
157
+ };
158
+
159
+
160
+ /**
161
+ * @param {number}
162
+ * a
163
+ * @param {number}
164
+ * b
165
+ * @return {number}
166
+ */
167
+ jsts.index.strtree.AbstractSTRtree.prototype.compareDoubles = function(a, b) {
168
+ return a > b ? 1 : a < b ? -1 : 0;
169
+ };
170
+
171
+
172
+ /**
173
+ * Creates the levels higher than the given level
174
+ *
175
+ * @param {Array}
176
+ * boundablesOfALevel the level to build on.
177
+ * @param {number}
178
+ * level the level of the Boundables, or -1 if the boundables are item
179
+ * boundables (that is, below level 0).
180
+ * @return {jsts.index.strtree.AbstractNode} the root, which may be a ParentNode
181
+ * or a LeafNode.
182
+ * @private
183
+ */
184
+ jsts.index.strtree.AbstractSTRtree.prototype.createHigherLevels = function(
185
+ boundablesOfALevel, level) {
186
+ jsts.util.Assert.isTrue(!(boundablesOfALevel.length === 0));
187
+ var parentBoundables = this.createParentBoundables(boundablesOfALevel,
188
+ level + 1);
189
+ if (parentBoundables.length === 1) {
190
+ return parentBoundables[0];
191
+ }
192
+ return this.createHigherLevels(parentBoundables, level + 1);
193
+ };
194
+
195
+
196
+ /**
197
+ * @return {jsts.index.strtree.AbstractNode}
198
+ */
199
+ jsts.index.strtree.AbstractSTRtree.prototype.getRoot = function() {
200
+ if (!this.built)
201
+ this.build();
202
+ return this.root;
203
+ };
204
+
205
+
206
+ /**
207
+ * Returns the maximum number of child nodes that a node may have
208
+ *
209
+ * return {number}
210
+ */
211
+ jsts.index.strtree.AbstractSTRtree.prototype.getNodeCapacity = function() {
212
+ return this.nodeCapacity;
213
+ };
214
+
215
+
216
+ /**
217
+ * @return {number}
218
+ */
219
+ jsts.index.strtree.AbstractSTRtree.prototype.size = function() {
220
+ if (arguments.length === 1) {
221
+ return this.size2(arguments[0]);
222
+ }
223
+
224
+ if (!this.built) {
225
+ this.build();
226
+ }
227
+ if (this.itemBoundables.length === 0) {
228
+ return 0;
229
+ }
230
+ return this.size2(root);
231
+ };
232
+
233
+ /**
234
+ * @param {jsts.index.strtree.AbstractNode=}
235
+ * [node].
236
+ * @return {number}
237
+ */
238
+ jsts.index.strtree.AbstractSTRtree.prototype.size2 = function(node) {
239
+ var size = 0;
240
+ var childBoundables = node.getChildBoundables();
241
+ for (var i = 0; i < childBoundables.length; i++) {
242
+ var childBoundable = childBoundables[i];
243
+ if (childBoundable instanceof jsts.index.strtree.AbstractNode) {
244
+ size += this.size(childBoundable);
245
+ } else if (childBoundable instanceof jsts.index.strtree.ItemBoundable) {
246
+ size += 1;
247
+ }
248
+ }
249
+ return size;
250
+ };
251
+
252
+
253
+ /**
254
+ * @return {number}
255
+ */
256
+ jsts.index.strtree.AbstractSTRtree.prototype.depth = function() {
257
+ if (arguments.length === 1) {
258
+ return this.depth2(arguments[0]);
259
+ }
260
+
261
+ if (!this.built) {
262
+ this.build();
263
+ }
264
+ if (this.itemBoundables.length === 0) {
265
+ return 0;
266
+ }
267
+ return this.depth2(root);
268
+ };
269
+
270
+ /**
271
+ * @param {jsts.index.strtree.AbstractNode}
272
+ * [node].
273
+ * @return {number}
274
+ */
275
+ jsts.index.strtree.AbstractSTRtree.prototype.depth2 = function() {
276
+ var maxChildDepth = 0;
277
+ var childBoundables = node.getChildBoundables();
278
+ for (var i = 0; i < childBoundables.length; i++) {
279
+ var childBoundable = childBoundables[i];
280
+ if (childBoundable instanceof jsts.index.strtree.AbstractNode) {
281
+ var childDepth = this.depth(childBoundable);
282
+ if (childDepth > maxChildDepth)
283
+ maxChildDepth = childDepth;
284
+ }
285
+ }
286
+ return maxChildDepth + 1;
287
+ };
288
+
289
+
290
+ /**
291
+ *
292
+ * @param {Object}
293
+ * bounds
294
+ * @param {Object}
295
+ * item
296
+ */
297
+ jsts.index.strtree.AbstractSTRtree.prototype.insert = function(bounds, item) {
298
+ jsts.util.Assert.isTrue(!this.built, 'Cannot insert items into an STR packed R-tree after it has been built.');
299
+ this.itemBoundables.push(new jsts.index.strtree.ItemBoundable(bounds, item));
300
+ };
301
+
302
+ /**
303
+ * Also builds the tree, if necessary.
304
+ *
305
+ * @param {Object}
306
+ * searchBounds
307
+ * @param {jsts.index.ItemVisitor}
308
+ * [visitor].
309
+ * @param {jsts.index.strtree.AbstractNode}
310
+ * [node].
311
+ * @param {Array}
312
+ * [matches].
313
+ * @return {Array}
314
+ */
315
+ jsts.index.strtree.AbstractSTRtree.prototype.query = function(searchBounds) {
316
+ if (arguments.length > 1) {
317
+ this.query2.apply(this, arguments);
318
+ }
319
+
320
+ if (!this.built) {
321
+ this.build();
322
+ }
323
+ var matches = [];
324
+ if (this.itemBoundables.length === 0) {
325
+ jsts.util.Assert.isTrue(this.root.getBounds() === null);
326
+ return matches;
327
+ }
328
+ if (this.getIntersectsOp().intersects(this.root.getBounds(), searchBounds)) {
329
+ this.query3(searchBounds, this.root, matches);
330
+ }
331
+ return matches;
332
+ };
333
+
334
+ jsts.index.strtree.AbstractSTRtree.prototype.query2 = function(searchBounds,
335
+ visitor) {
336
+ if (arguments.length > 2) {
337
+ this.query3.apply(this, arguments);
338
+ }
339
+
340
+ if (!this.built) {
341
+ this.build();
342
+ }
343
+ if (this.itemBoundables.length === 0) {
344
+ jsts.util.Assert.isTrue(this.root.getBounds() === null);
345
+ }
346
+ if (this.getIntersectsOp().intersects(this.root.getBounds(), searchBounds)) {
347
+ this.query4(searchBounds, this.root, visitor);
348
+ }
349
+ };
350
+
351
+ /**
352
+ * @private
353
+ */
354
+ jsts.index.strtree.AbstractSTRtree.prototype.query3 = function(searchBounds,
355
+ node, matches) {
356
+ if (!(arguments[2] instanceof Array)) {
357
+ this.query4.apply(this, arguments);
358
+ }
359
+
360
+ var childBoundables = node.getChildBoundables();
361
+ for (var i = 0; i < childBoundables.length; i++) {
362
+ var childBoundable = childBoundables[i];
363
+ if (!this.getIntersectsOp().intersects(childBoundable.getBounds(),
364
+ searchBounds)) {
365
+ continue;
366
+ }
367
+ if (childBoundable instanceof jsts.index.strtree.AbstractNode) {
368
+ this.query3(searchBounds, childBoundable, matches);
369
+ } else if (childBoundable instanceof jsts.index.strtree.ItemBoundable) {
370
+ matches.push(childBoundable.getItem());
371
+ } else {
372
+ jsts.util.Assert.shouldNeverReachHere();
373
+ }
374
+ }
375
+ };
376
+
377
+ /**
378
+ * @private
379
+ */
380
+ jsts.index.strtree.AbstractSTRtree.prototype.query4 = function(searchBounds,
381
+ node, visitor) {
382
+ var childBoundables = node.getChildBoundables();
383
+ for (var i = 0; i < childBoundables.length; i++) {
384
+ var childBoundable = childBoundables[i];
385
+ if (!this.getIntersectsOp().intersects(childBoundable.getBounds(),
386
+ searchBounds)) {
387
+ continue;
388
+ }
389
+ if (childBoundable instanceof jsts.index.strtree.AbstractNode) {
390
+ this.query4(searchBounds, childBoundable, visitor);
391
+ } else if (childBoundable instanceof jsts.index.strtree.ItemBoundable) {
392
+ visitor.visitItem(childBoundable.getItem());
393
+ } else {
394
+ jsts.util.Assert.shouldNeverReachHere();
395
+ }
396
+ }
397
+ };
398
+
399
+ /**
400
+ * @return {jsts.index.strtree.AbstractSTRtree.IntersectOp}
401
+ */
402
+ jsts.index.strtree.AbstractSTRtree.prototype.getIntersectsOp = function() {
403
+ throw new jsts.error.AbstractMethodInvocationError();
404
+ };
405
+
406
+ // TODO: port rest
407
+
408
+ /**
409
+ * Gets a tree structure (as a nested list) corresponding to the structure of
410
+ * the items and nodes in this tree.
411
+ * <p>
412
+ * The returned {@link List}s contain either {@link Object} items, or Lists
413
+ * which correspond to subtrees of the tree Subtrees which do not contain any
414
+ * items are not included.
415
+ * <p>
416
+ * Builds the tree if necessary.
417
+ *
418
+ * @return {Array} a List of items and/or Lists.
419
+ */
420
+ jsts.index.strtree.AbstractSTRtree.prototype.itemsTree = function() {
421
+ if (arguments.length === 1) {
422
+ return this.itemsTree2.apply(this, arguments);
423
+ }
424
+
425
+ if (!this.built) {
426
+ this.build();
427
+ }
428
+
429
+ var valuesTree = this.itemsTree2(this.root);
430
+ if (valuesTree === null)
431
+ return [];
432
+ return valuesTree;
433
+ };
434
+
435
+ jsts.index.strtree.AbstractSTRtree.prototype.itemsTree2 = function(node) {
436
+ var valuesTreeForNode = [];
437
+ var childBoundables = node.getChildBoundables();
438
+ for (var i = 0; i < childBoundables.length; i++) {
439
+ var childBoundable = childBoundables[i];
440
+ if (childBoundable instanceof jsts.index.strtree.AbstractNode) {
441
+ var valuesTreeForChild = this.itemsTree(childBoundable);
442
+ // only add if not null (which indicates an item somewhere in this tree
443
+ if (valuesTreeForChild != null)
444
+ valuesTreeForNode.push(valuesTreeForChild);
445
+ } else if (childBoundable instanceof jsts.index.strtree.ItemBoundable) {
446
+ valuesTreeForNode.push(childBoundable.getItem());
447
+ } else {
448
+ jsts.util.Assert.shouldNeverReachHere();
449
+ }
450
+ }
451
+ if (valuesTreeForNode.length <= 0)
452
+ return null;
453
+ return valuesTreeForNode;
454
+ };
455
+
456
+ /**
457
+ * Removes an item from the tree. (Builds the tree, if necessary.)
458
+ *
459
+ * @param {Object}
460
+ * searchBounds
461
+ * @param {jsts.index.strtree.AbstractNode}
462
+ * [node].
463
+ * @param {Object]
464
+ * item}
465
+ * @return {boolean}
466
+ */
467
+ jsts.index.strtree.AbstractSTRtree.prototype.remove = function(searchBounds,
468
+ item) {
469
+ // TODO: argument switch
470
+
471
+
472
+ if (!this.built) {
473
+ this.build();
474
+ }
475
+ if (this.itemBoundables.length === 0) {
476
+ jsts.util.Assert.isTrue(this.root.getBounds() == null);
477
+ }
478
+ if (this.getIntersectsOp().intersects(this.root.getBounds(), searchBounds)) {
479
+ return this.remove2(searchBounds, this.root, item);
480
+ }
481
+ return false;
482
+ };
483
+
484
+ jsts.index.strtree.AbstractSTRtree.prototype.remove2 = function(searchBounds,
485
+ node, item) {
486
+ // first try removing item from this node
487
+ var found = this.removeItem(node, item);
488
+ if (found)
489
+ return true;
490
+
491
+ var childToPrune = null;
492
+ // next try removing item from lower nodes
493
+ var childBoundables = node.getChildBoundables();
494
+ for (var i = 0; i < childBoundables.length; i++) {
495
+ var childBoundable = childBoundables[i];
496
+ if (!this.getIntersectsOp().intersects(childBoundable.getBounds(),
497
+ searchBounds)) {
498
+ continue;
499
+ }
500
+ if (childBoundable instanceof jsts.index.strtree.AbstractNode) {
501
+ found = this.remove(searchBounds, childBoundable, item);
502
+ // if found, record child for pruning and exit
503
+ if (found) {
504
+ childToPrune = childBoundable;
505
+ break;
506
+ }
507
+ }
508
+ }
509
+ // prune child if possible
510
+ if (childToPrune != null) {
511
+ if (childToPrune.getChildBoundables().length === 0) {
512
+ childBoundables.splice(childBoundables.indexOf(childToPrune), 1);
513
+ }
514
+ }
515
+ return found;
516
+ };
517
+
518
+
519
+
520
+ /**
521
+ *
522
+ * @param {jsts.index.strtree.AbstractNode}
523
+ * node
524
+ * @param {Object}
525
+ * item
526
+ * @return {boolean}
527
+ */
528
+ jsts.index.strtree.AbstractSTRtree.prototype.removeItem = function(node, item) {
529
+ var childToRemove = null;
530
+ var childBoundables = node.getChildBoundables();
531
+ for (var i = 0; i < childBoundables.length; i++) {
532
+ var childBoundable = childBoundables[i];
533
+ if (childBoundable instanceof jsts.index.strtree.ItemBoundable) {
534
+ if (childBoundable.getItem() === item)
535
+ childToRemove = childBoundable;
536
+ }
537
+ }
538
+ if (childToRemove !== null) {
539
+ childBoundables.splice(childBoundables.indexOf(childToRemove), 1);
540
+ return true;
541
+ }
542
+ return false;
543
+ };
544
+
545
+
546
+ jsts.index.strtree.AbstractSTRtree.prototype.boundablesAtLevel = function(level) {
547
+ if (arguments.length > 1) {
548
+ this.boundablesAtLevel2.apply(this, arguments);
549
+ return;
550
+ }
551
+
552
+ var boundables = [];
553
+ this.boundablesAtLevel2(level, this.root, boundables);
554
+ return boundables;
555
+ };
556
+
557
+ /**
558
+ * @param {number}
559
+ * level
560
+ * @param {jsts.index.strtree.AbstractNode}
561
+ * [top].
562
+ * @param {Array}
563
+ * [boundables].
564
+ * @return {?Array}
565
+ */
566
+ jsts.index.strtree.AbstractSTRtree.prototype.boundablesAtLevel2 = function(
567
+ level, top, boundables) {
568
+ jsts.util.Assert.isTrue(level > -2);
569
+ if (top.getLevel() === level) {
570
+ boundables.add(top);
571
+ return;
572
+ }
573
+ var childBoundables = node.getChildBoundables();
574
+ for (var i = 0; i < childBoundables.length; i++) {
575
+ var boundable = childBoundables[i];
576
+ if (boundable instanceof jsts.index.strtree.AbstractNode) {
577
+ this.boundablesAtLevel(level, boundable, boundables);
578
+ } else {
579
+ jsts.util.Assert.isTrue(boundable instanceof jsts.index.strtree.ItemBoundable);
580
+ if (level === -1) {
581
+ boundables.add(boundable);
582
+ }
583
+ }
584
+ }
585
+ return;
586
+ };
587
+
588
+
589
+ /**
590
+ * @return {Comparator}
591
+ */
592
+ jsts.index.strtree.AbstractSTRtree.prototype.getComparator = function() {
593
+ throw new jsts.error.AbstractMethodInvocationError();
594
+ };