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,134 @@
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 Key is a unique identifier for a node in a quadtree. It contains a
11
+ * lower-left point and a level number. The level number is the power of two for
12
+ * the size of the node envelope.
13
+ *
14
+ * @param {jsts.geom.Envelope}
15
+ * itemEnv the envelope of the key.
16
+ *
17
+ * @constructor
18
+ */
19
+ jsts.index.quadtree.Key = function(itemEnv) {
20
+ // the fields which make up the key
21
+ this.pt = new jsts.geom.Coordinate();
22
+ this.level = 0;
23
+ // auxiliary data which is derived from the key for use in computation
24
+ this.env = null;
25
+
26
+ this.computeKey(itemEnv);
27
+ };
28
+
29
+
30
+ /**
31
+ * Computes the quad-level for specified envelope
32
+ *
33
+ * @param {jsts.geom.Envelope}
34
+ * env the envelope to calculate level for.
35
+ * @return {Number} The calculated level.
36
+ */
37
+ jsts.index.quadtree.Key.computeQuadLevel = function(env) {
38
+ var dx, dy, dMax, level;
39
+
40
+ dx = env.getWidth();
41
+ dy = env.getHeight();
42
+ dMax = dx > dy ? dx : dy;
43
+ level = jsts.index.DoubleBits.exponent(dMax) + 1;
44
+ return level;
45
+ };
46
+
47
+
48
+ /**
49
+ * Gets the point of this key.
50
+ *
51
+ * @return {jsts.geom.Coordinate} The point.
52
+ */
53
+ jsts.index.quadtree.Key.prototype.getPoint = function() {
54
+ return this.pt;
55
+ };
56
+
57
+
58
+ /**
59
+ * Gets the level of this key
60
+ *
61
+ * @return {Number} The level.
62
+ */
63
+ jsts.index.quadtree.Key.prototype.getLevel = function() {
64
+ return this.level;
65
+ };
66
+
67
+
68
+ /**
69
+ * Gets the envelope of this key
70
+ *
71
+ * @return {jsts.geom.Envelope} The envelope.
72
+ */
73
+ jsts.index.quadtree.Key.prototype.getEnvelope = function() {
74
+ return this.env;
75
+ };
76
+
77
+
78
+ /**
79
+ * Gets the centre of this key
80
+ *
81
+ * @return {jsts.geom.Coordinate} the center-point.
82
+ */
83
+ jsts.index.quadtree.Key.prototype.getCentre = function() {
84
+ var x, y;
85
+ x = (this.env.getMinX() + this.env.getMaxX()) / 2;
86
+ y = (this.env.getMinY() + this.env.getMaxY()) / 2;
87
+ return new jsts.geom.Coordinate(x, y);
88
+ };
89
+
90
+
91
+ /**
92
+ * Will call appropriate computeKey* method depending on arguments.
93
+ */
94
+ jsts.index.quadtree.Key.prototype.computeKey = function() {
95
+ if (arguments[0] instanceof jsts.geom.Envelope) {
96
+ this.computeKeyFromEnvelope(arguments[0]);
97
+ } else {
98
+ this.computeKeyFromLevel(arguments[0], arguments[1]);
99
+ }
100
+ };
101
+
102
+
103
+ /**
104
+ * Computes the key from specified envlope.
105
+ *
106
+ * @param {jsts.geom.Envelope}
107
+ * env the envelope.
108
+ */
109
+ jsts.index.quadtree.Key.prototype.computeKeyFromEnvelope = function(env) {
110
+ this.level = jsts.index.quadtree.Key.computeQuadLevel(env);
111
+ this.env = new jsts.geom.Envelope();
112
+ this.computeKey(this.level, env);
113
+ while (!this.env.contains(env)) {
114
+ this.level += 1;
115
+ this.computeKey(this.level, env);
116
+ }
117
+ };
118
+
119
+
120
+ /**
121
+ * Computes a key from a level and an envelope
122
+ *
123
+ * @param {Number}
124
+ * level the level.
125
+ * @param {jsts.geom.Envelope}
126
+ * env the envelope.
127
+ */
128
+ jsts.index.quadtree.Key.prototype.computeKeyFromLevel = function(level, env) {
129
+ var quadSize = jsts.index.DoubleBits.powerOf2(level);
130
+ this.pt.x = Math.floor(env.getMinX() / quadSize) * quadSize;
131
+ this.pt.y = Math.floor(env.getMinY() / quadSize) * quadSize;
132
+ this.env.init(this.pt.x, this.pt.x + quadSize, this.pt.y, this.pt.y +
133
+ quadSize);
134
+ };
@@ -0,0 +1,220 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+
8
+
9
+ /**
10
+ * Represents a node of a {@link Quadtree}. Nodes contain items which have a
11
+ * spatial extent corresponding to the node's position in the quadtree.
12
+ *
13
+ * @param {jsts.geom.Envelope}
14
+ * env Envelope to initialize from.
15
+ * @param {Number}
16
+ * level The level.
17
+ *
18
+ * @constructor
19
+ * @requires jsts/index/quadtree/NodeBase.js
20
+ */
21
+ jsts.index.quadtree.Node = function(env, level) {
22
+ jsts.index.quadtree.NodeBase.prototype.constructor.apply(this, arguments);
23
+
24
+ this.env = env;
25
+ this.level = level;
26
+ this.centre = new jsts.geom.Coordinate();
27
+ this.centre.x = (env.getMinX() + env.getMaxX()) / 2;
28
+ this.centre.y = (env.getMinY() + env.getMaxY()) / 2;
29
+ };
30
+
31
+ jsts.index.quadtree.Node.prototype = new jsts.index.quadtree.NodeBase();
32
+
33
+
34
+ /**
35
+ * Creates a node from specified envelope
36
+ *
37
+ * @param {jsts.geom.Envelope}
38
+ * env the envelope.
39
+ * @return {jsts.index.quadtree.Node} the created node.
40
+ */
41
+ jsts.index.quadtree.Node.createNode = function(env) {
42
+ var key, node;
43
+ key = new jsts.index.quadtree.Key(env);
44
+ node = new jsts.index.quadtree.Node(key.getEnvelope(), key.getLevel());
45
+
46
+ return node;
47
+ };
48
+
49
+
50
+ /**
51
+ * Creates an expanded node.
52
+ *
53
+ * @param {jsts.index.quadtree.Node}
54
+ * node the node to create a new node from.
55
+ * @param {jsts.geom.Envelope}
56
+ * addEnv the envelope.
57
+ * @return {jsts.index.quadtree.Node} the created node.
58
+ */
59
+ jsts.index.quadtree.Node.createExpanded = function(node, addEnv) {
60
+ var expandEnv = new jsts.geom.Envelope(addEnv), largerNode;
61
+
62
+ if (node !== null) {
63
+ expandEnv.expandToInclude(node.env);
64
+ }
65
+
66
+ largerNode = jsts.index.quadtree.Node.createNode(expandEnv);
67
+ if (node !== null) {
68
+ largerNode.insertNode(node);
69
+ }
70
+
71
+ return largerNode;
72
+ };
73
+
74
+
75
+ /**
76
+ * Gets the envelope for this node
77
+ *
78
+ * @return {jsts.geom.Envelope} the envelope.
79
+ */
80
+ jsts.index.quadtree.Node.prototype.getEnvelope = function() {
81
+ return this.env;
82
+ };
83
+
84
+
85
+ /**
86
+ * Checks wheter the provided envelope intersects this nodes envelope.
87
+ *
88
+ * @param {jsts.geom.Envelope}
89
+ * searchEnv the envelope to search.
90
+ * @return {Boolean} True if searchEnv intersects this nodes envelope.
91
+ */
92
+ jsts.index.quadtree.Node.prototype.isSearchMatch = function(searchEnv) {
93
+ return this.env.intersects(searchEnv);
94
+ };
95
+
96
+
97
+ /**
98
+ * Returns the subquad containing the envelope. Creates the subquad if it does
99
+ * not already exist.
100
+ *
101
+ * @param {jsts.geom.Envelope}
102
+ * searchEnv the input envelope.
103
+ * @return {jsts.index.quadtree.Node} the node containing the searchEnv.
104
+ */
105
+ jsts.index.quadtree.Node.prototype.getNode = function(searchEnv) {
106
+ var subnodeIndex = this.getSubnodeIndex(searchEnv, this.centre), node;
107
+
108
+ // if subquadIndex is -1 searchEnv is not contained in a subquad
109
+ if (subnodeIndex !== -1) {
110
+ // create the quad if it does not exist
111
+ node = this.getSubnode(subnodeIndex);
112
+ // recursively search the found/created quad
113
+ return node.getNode(searchEnv);
114
+ } else {
115
+ return this;
116
+ }
117
+ };
118
+
119
+
120
+ /**
121
+ * Returns the smallest <i>existing</i> node containing the envelope.
122
+ *
123
+ * @param {jsts.geom.Envelope}
124
+ * searchEnv input Envelope.
125
+ * @return {jsts.index.quadtree.Node} the smallest node containing searchEnv.
126
+ */
127
+ jsts.index.quadtree.Node.prototype.find = function(searchEnv) {
128
+ var subnodeIndex = this.getSubnodeIndex(searchEnv, this.centre), node;
129
+ if (subnodeIndex === -1) {
130
+ return this;
131
+ }
132
+
133
+ if (this.subnode[subnodeIndex] !== null) {
134
+ // query lies in subquad, so search it
135
+ node = this.subnode[subnodeIndex];
136
+ return node.find(searchEnv);
137
+ }
138
+
139
+ // no existing subquad, so return this one anyway
140
+ return this;
141
+ };
142
+
143
+
144
+ /**
145
+ * Inserts a child-node
146
+ *
147
+ * @param {jsts.index.quadtree.Node}
148
+ * node to insert.
149
+ */
150
+ jsts.index.quadtree.Node.prototype.insertNode = function(node) {
151
+ var index = this.getSubnodeIndex(node.env, this.centre), childNode;
152
+ if (node.level === this.level - 1) {
153
+ this.subnode[index] = node;
154
+ } else {
155
+ // the quad is not a direct child, so make a new child quad to contain it
156
+ // and recursively insert the quad
157
+ childNode = this.createSubnode(index);
158
+ childNode.insertNode(node);
159
+ this.subnode[index] = childNode;
160
+ }
161
+ };
162
+
163
+
164
+ /**
165
+ * get the subquad for the index. If it doesn't exist, create it
166
+ *
167
+ * @param {Number}
168
+ * index the index of the subnode to get.
169
+ * @return {jsts.index.quadtree.Node} the specified subnode.
170
+ */
171
+ jsts.index.quadtree.Node.prototype.getSubnode = function(index) {
172
+ if (this.subnode[index] === null) {
173
+ this.subnode[index] = this.createSubnode(index);
174
+ }
175
+ return this.subnode[index];
176
+ };
177
+
178
+
179
+ /**
180
+ * Creates a subnode
181
+ *
182
+ * @param {Number}
183
+ * index The index (0-4) on where to create a subnode.
184
+ * @return {jsts.index.quadtree.Node} the created node.
185
+ */
186
+ jsts.index.quadtree.Node.prototype.createSubnode = function(index) {
187
+ var minx = 0.0, maxx = 0.0, miny = 0.0, maxy = 0.0, sqEnv, node;
188
+ // create a new subquad in the appropriate quadrant
189
+ switch (index) {
190
+ case 0:
191
+ minx = this.env.getMinX();
192
+ maxx = this.centre.x;
193
+ miny = this.env.getMinY();
194
+ maxy = this.centre.y;
195
+ break;
196
+ case 1:
197
+ minx = this.centre.x;
198
+ maxx = this.env.getMaxX();
199
+ miny = this.env.getMinY();
200
+ maxy = this.centre.y;
201
+ break;
202
+ case 2:
203
+ minx = this.env.getMinX();
204
+ maxx = this.centre.x;
205
+ miny = this.centre.y;
206
+ maxy = this.env.getMaxY();
207
+ break;
208
+ case 3:
209
+ minx = this.centre.x;
210
+ maxx = this.env.getMaxX();
211
+ miny = this.centre.y;
212
+ maxy = this.env.getMaxY();
213
+ break;
214
+ }
215
+
216
+ sqEnv = new jsts.geom.Envelope(minx, maxx, miny, maxy);
217
+ node = new jsts.index.quadtree.Node(sqEnv, this.level - 1);
218
+
219
+ return node;
220
+ };
@@ -0,0 +1,330 @@
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
+ * The base class for nodes in a {@link Quadtree}.
11
+ *
12
+ * @constructor
13
+ */
14
+ jsts.index.quadtree.NodeBase = function() {
15
+ /**
16
+ * subquads are numbered as follows:
17
+ *
18
+ * <pre>
19
+ * 2 | 3
20
+ * --+--
21
+ * 0 | 1
22
+ * </pre>
23
+ */
24
+ this.subnode = new Array(4);
25
+ this.subnode[0] = null;
26
+ this.subnode[1] = null;
27
+ this.subnode[2] = null;
28
+ this.subnode[3] = null;
29
+
30
+ this.items = [];
31
+ };
32
+
33
+
34
+ /**
35
+ * Returns the index of the subquad that wholly contains the given envelope. If
36
+ * none does, returns -1.
37
+ *
38
+ * @param {jsts.geom.Envelope}
39
+ * env The envelope to check.
40
+ * @param {jsts.geom.Coordinate}
41
+ * centre The coordinate.
42
+ * @return {Number} The sub-index or -1.
43
+ */
44
+ jsts.index.quadtree.NodeBase.prototype.getSubnodeIndex = function(env, centre) {
45
+ var subnodeIndex = -1;
46
+ if (env.getMinX() >= centre.x) {
47
+ if (env.getMinY() >= centre.y) {
48
+ subnodeIndex = 3;
49
+ }
50
+ if (env.getMaxY() <= centre.y) {
51
+ subnodeIndex = 1;
52
+ }
53
+ }
54
+ if (env.getMaxX() <= centre.x) {
55
+ if (env.getMinY() >= centre.y) {
56
+ subnodeIndex = 2;
57
+ }
58
+ if (env.getMaxY() <= centre.y) {
59
+ subnodeIndex = 0;
60
+ }
61
+ }
62
+ return subnodeIndex;
63
+ };
64
+
65
+
66
+ /**
67
+ * Returns the nodes items
68
+ *
69
+ * @return {Array} the items-array.
70
+ */
71
+ jsts.index.quadtree.NodeBase.prototype.getItems = function() {
72
+ return this.items;
73
+ };
74
+
75
+
76
+ /**
77
+ * Checks if the node has any items
78
+ *
79
+ * @return {Boolean} true if the node has any items.
80
+ */
81
+ jsts.index.quadtree.NodeBase.prototype.hasItems = function() {
82
+ return (this.items.length > 0);
83
+ };
84
+
85
+
86
+ /**
87
+ * Adds an item to the node
88
+ *
89
+ * @param {Object}
90
+ * item the item to add.
91
+ */
92
+ jsts.index.quadtree.NodeBase.prototype.add = function(item) {
93
+ this.items.push(item);
94
+ };
95
+
96
+
97
+ /**
98
+ * Removes a single item from this subtree.
99
+ *
100
+ * @param {jsts.geom.Envelope}
101
+ * itemEnv the envelope containing the item.
102
+ * @param {Object}
103
+ * item the item to remove.
104
+ * @return {Boolean} <code>true</code> if the item was found and removed.
105
+ */
106
+ jsts.index.quadtree.NodeBase.prototype.remove = function(itemEnv, item) {
107
+ // use envelope to restrict nodes scanned
108
+ if (!this.isSearchMatch(itemEnv)) {
109
+ return false;
110
+ }
111
+
112
+ var found = false, i = 0;
113
+ for (i; i < 4; i++) {
114
+ if (this.subnode[i] !== null) {
115
+ found = this.subnode[i].remove(itemEnv, item);
116
+ if (found) {
117
+ // trim subtree if empty
118
+ if (this.subnode[i].isPrunable()) {
119
+ this.subnode[i] = null;
120
+ }
121
+ break;
122
+ }
123
+ }
124
+ }
125
+ // if item was found lower down, don't need to search for it here
126
+ if (found) {
127
+ return found;
128
+ }
129
+ // otherwise, try and remove the item from the list of items in this node
130
+
131
+ if (this.items.indexOf(item) !== -1) {
132
+ for (var i = this.items.length - 1; i >= 0; i--) {
133
+ if (this.items[i] === item) {
134
+ this.items.splice(i, 1);
135
+ // break;more than once??
136
+ }
137
+ }
138
+
139
+ found = true;
140
+ }
141
+ return found;
142
+ };
143
+
144
+
145
+ /**
146
+ * @return {Boolean} <code>true</code> if the node is prunable.
147
+ */
148
+ jsts.index.quadtree.NodeBase.prototype.isPrunable = function() {
149
+ return !(this.hasChildren() || this.hasItems());
150
+ };
151
+
152
+
153
+ /**
154
+ * @return {Boolean} <code>true</code> if the node has any children.
155
+ */
156
+ jsts.index.quadtree.NodeBase.prototype.hasChildren = function() {
157
+ var i = 0;
158
+ for (i; i < 4; i++) {
159
+ if (this.subnode[i] !== null) {
160
+ return true;
161
+ }
162
+ }
163
+ return false;
164
+ };
165
+
166
+
167
+ /**
168
+ * @return {Boolean} <code>true</code> if the node or any subnode does not
169
+ * have any items.
170
+ */
171
+ jsts.index.quadtree.NodeBase.prototype.isEmpty = function() {
172
+ var isEmpty = true;
173
+ if (this.items.length > 0) {
174
+ isEmpty = false;
175
+ }
176
+ var i = 0;
177
+ for (i; i < 4; i++) {
178
+ if (this.subnode[i] !== null) {
179
+ if (!this.subnode[i].isEmpty()) {
180
+ isEmpty = false;
181
+ }
182
+ }
183
+ }
184
+ return isEmpty;
185
+ };
186
+
187
+
188
+ /**
189
+ * Adds all the items of the node and any subnodes
190
+ *
191
+ * @param {Array}
192
+ * resultItems the array to add items to.
193
+ * @return {Array} a new array with original and added items.
194
+ */
195
+ jsts.index.quadtree.NodeBase.prototype.addAllItems = function(resultItems) {
196
+ // this node may have items as well as subnodes (since items may not
197
+ // be wholely contained in any single subnode
198
+ resultItems = resultItems.concat(this.items);
199
+ var i = 0;
200
+ for (i; i < 4; i++) {
201
+ if (this.subnode[i] !== null) {
202
+ resultItems = this.subnode[i].addAllItems(resultItems);
203
+ // resultItems = resultItems.concat(this.subnode[i]);
204
+ }
205
+ }
206
+
207
+ return resultItems;
208
+ };
209
+
210
+
211
+ /**
212
+ *
213
+ * @param {jsts.geom.Envelope}
214
+ * searchEnv the search-envelope.
215
+ * @param {Array}
216
+ * resultItems the array containing original and added items.
217
+ */
218
+ jsts.index.quadtree.NodeBase.prototype.addAllItemsFromOverlapping = function(
219
+ searchEnv, resultItems) {
220
+ if (!this.isSearchMatch(searchEnv)) {
221
+ return;
222
+ }
223
+
224
+ // this node may have items as well as subnodes (since items may not
225
+ // be wholely contained in any single subnode
226
+
227
+ resultItems = resultItems.concat(this.items);
228
+
229
+ var i = 0;
230
+ for (i; i < 4; i++) {
231
+ if (this.subnode[i] !== null) {
232
+ resultItems = this.subnode[i].addAllItemsFromOverlapping(searchEnv,
233
+ resultItems);
234
+ }
235
+ }
236
+ };
237
+
238
+
239
+ /**
240
+ * Visits the node
241
+ *
242
+ * @param {jsts.geom.Envelope}
243
+ * searchEnv the search-envelope.
244
+ * @param {Object}
245
+ * visitor the visitor.
246
+ */
247
+ jsts.index.quadtree.NodeBase.prototype.visit = function(searchEnv, visitor) {
248
+ if (!this.isSearchMatch(searchEnv)) {
249
+ return;
250
+ }
251
+
252
+ // this node may have items as well as subnodes (since items may not
253
+ // be wholely contained in any single subnode
254
+ this.visitItems(searchEnv, visitor);
255
+
256
+ var i = 0;
257
+ for (i; i < 4; i++) {
258
+ if (this.subnode[i] !== null) {
259
+ this.subnode[i].visit(searchEnv, visitor);
260
+ }
261
+ }
262
+ };
263
+
264
+
265
+ /**
266
+ * Visits the items
267
+ *
268
+ * @param {jsts.geom.Envelope}
269
+ * env the search envelope.
270
+ * @param {Object}
271
+ * visitor the visitor.
272
+ */
273
+ jsts.index.quadtree.NodeBase.prototype.visitItems = function(env, visitor) {
274
+ var i = 0, il = this.items.length;
275
+
276
+ for (i; i < il; i++) {
277
+ visitor.visitItem(this.items[i]);
278
+ }
279
+ };
280
+
281
+
282
+ /**
283
+ * Calculates the depth
284
+ *
285
+ * @return {Number} the calculated depth.
286
+ */
287
+ jsts.index.quadtree.NodeBase.prototype.depth = function() {
288
+ var maxSubDepth = 0, i = 0, sqd;
289
+ for (i; i < 4; i++) {
290
+ if (this.subnode[i] !== null) {
291
+ sqd = this.subnode[i].depth();
292
+ if (sqd > maxSubDepth) {
293
+ maxSubDepth = sqd;
294
+ }
295
+ }
296
+ }
297
+ return maxSubDepth + 1;
298
+ };
299
+
300
+
301
+ /**
302
+ * Calculates the size
303
+ *
304
+ * @return {Number} the calculated size.
305
+ */
306
+ jsts.index.quadtree.NodeBase.prototype.size = function() {
307
+ var subSize = 0, i = 0;
308
+ for (i; i < 4; i++) {
309
+ if (this.subnode[i] !== null) {
310
+ subSize += this.subnode[i].size();
311
+ }
312
+ }
313
+ return subSize + this.items.length;
314
+ };
315
+
316
+
317
+ /**
318
+ * Counts the nodes
319
+ *
320
+ * @return {Number} the size of this node.
321
+ */
322
+ jsts.index.quadtree.NodeBase.prototype.getNodeCount = function() {
323
+ var subSize = 0, i = 0;
324
+ for (i; i < 4; i++) {
325
+ if (this.subnode[i] !== null) {
326
+ subSize += this.subnode[i].size();
327
+ }
328
+ }
329
+ return subSize + 1;
330
+ };