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,160 @@
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
+ * Represents an (1-dimensional) closed interval on the Real number line.
9
+ *
10
+ */
11
+ (function() {
12
+ /**
13
+ * Constructs a new Interval and initializes it if arguments is provided
14
+ *
15
+ * @constructor
16
+ * @param {None}
17
+ * If no argument is specified, it will be initialized with 0.0, 0.0.
18
+ * @param {Number},
19
+ * { Number } min, max It can be initialized with min <-> max.
20
+ * @param {jsts.index.bintree.Interval}
21
+ * It can also be initialized with another interval.
22
+ */
23
+ var Interval = function() {
24
+ this.min = 0.0;
25
+ this.max = 0.0;
26
+
27
+ if (arguments.length === 1) {
28
+ var interval = arguments[0];
29
+ this.init(interval.min, interval.max);
30
+ }else if (arguments.length === 2) {
31
+ this.init(arguments[0], arguments[1]);
32
+ }
33
+ };
34
+
35
+ /**
36
+ * Initializes the interval
37
+ *
38
+ * @param {Number}
39
+ * min
40
+ * @param {Number}
41
+ * max
42
+ */
43
+ Interval.prototype.init = function(min, max) {
44
+ this.min = min;
45
+ this.max = max;
46
+ if (min > max) {
47
+ this.min = max;
48
+ this.max = min;
49
+ }
50
+ };
51
+
52
+ Interval.prototype.getMin = function() {
53
+ return this.min;
54
+ };
55
+
56
+ Interval.prototype.getMax = function() {
57
+ return this.max;
58
+ };
59
+
60
+ Interval.prototype.getWidth = function() {
61
+ return (this.max - this.min);
62
+ };
63
+
64
+ /**
65
+ * Expands this interval to include another interval
66
+ *
67
+ * @param {jsts.index.bintree.Interval}
68
+ * interval the interval to include.
69
+ */
70
+ Interval.prototype.expandToInclude = function(interval) {
71
+ if (interval.max > this.max) {
72
+ this.max = interval.max;
73
+ }
74
+ if (interval.min < this.min) {
75
+ this.min = interval.min;
76
+ }
77
+ };
78
+
79
+ /**
80
+ * Checks if this interval overlaps. Calls correct overlaps- function based on
81
+ * arguments
82
+ *
83
+ * @return {Boolean} true if the interval overlaps.
84
+ */
85
+ Interval.prototype.overlaps = function() {
86
+ if (arguments.length === 1) {
87
+ return this.overlapsInterval.apply(this, arguments);
88
+ }else {
89
+ return this.overlapsMinMax.apply(this, arguments);
90
+ }
91
+ };
92
+
93
+ /**
94
+ * Checks if this inteval overlaps another interval
95
+ *
96
+ * @param {jsts.index.bintree.Interval}
97
+ * interval the interval to check.
98
+ * @return {Boolean} true if the interval overlaps.
99
+ */
100
+ Interval.prototype.overlapsInterval = function(interval) {
101
+ return this.overlaps(interval.min, interval.max);
102
+ };
103
+
104
+ /**
105
+ * Checks if this inteval overlaps the specified min/max values
106
+ *
107
+ * @param {Number}
108
+ * min minimum.
109
+ * @param {Number}
110
+ * max maximum.
111
+ * @return {Boolean} true if the interval overlaps.
112
+ */
113
+ Interval.prototype.overlapsMinMax = function(min, max) {
114
+ if (this.min > max || this.max < min) {
115
+ return false;
116
+ }
117
+ return true;
118
+ };
119
+
120
+ /**
121
+ * Checks if this interval contains an interval, min -max pair or a point
122
+ *
123
+ * @return {Boolean} true if this interval contains the specified argument.
124
+ */
125
+ Interval.prototype.contains = function() {
126
+ var interval;
127
+ if (arguments[0] instanceof jsts.index.bintree.Interval) {
128
+ interval = arguments[0];
129
+ return this.containsMinMax(interval.min, interval.max);
130
+ }else if (arguments.length === 1) {
131
+ return this.containsPoint(arguments[0]);
132
+ }else {
133
+ return this.containsMinMax(arguments[0], arguments[1]);
134
+ }
135
+ };
136
+
137
+ /**
138
+ * Checks if this interval contains the min- and max-point provided
139
+ *
140
+ * @param {Number}
141
+ * min the minpoint.
142
+ * @param {Number}
143
+ * max the maxpoint.
144
+ */
145
+ Interval.prototype.containsMinMax = function(min, max) {
146
+ return (min >= this.min && max <= this.max);
147
+ };
148
+
149
+ /**
150
+ * Checks if this interval contains the specified point
151
+ *
152
+ * @param {Number}
153
+ * p the point to check.
154
+ */
155
+ Interval.prototype.containsPoint = function(p) {
156
+ return (p >= this.min && p <= this.max);
157
+ };
158
+
159
+ jsts.index.bintree.Interval = Interval;
160
+ })();
@@ -0,0 +1,110 @@
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 Key is a unique identifier for a node in a tree. It contains a lower-left
9
+ * point and a level number. The level number is the power of two for the size
10
+ * of the node envelope
11
+ */
12
+ (function() {
13
+
14
+ /**
15
+ * @requires jsts/index/bintree/Interval.js
16
+ * @requires jsts/index/DoubleBits.js
17
+ */
18
+
19
+ var DoubleBits = jsts.index.DoubleBits;
20
+ var Interval = jsts.index.bintree.Interval;
21
+
22
+ /**
23
+ * Constructs a new Key
24
+ *
25
+ * @constructor
26
+ * @param {jsts.index.bintree.Interval}
27
+ * interval the interval to compute the key from.
28
+ */
29
+ var Key = function(interval) {
30
+ this.pt = 0.0;
31
+ this.level = 0;
32
+
33
+ this.computeKey(interval);
34
+ };
35
+
36
+ /**
37
+ * Computes the level for an interval
38
+ *
39
+ * @param {jsts.index.bintree.Interval}
40
+ * interval the interval.
41
+ * @results {Number} the calculated level
42
+ */
43
+ Key.computeLevel = function(interval) {
44
+ var dx = interval.getWidth(), level;
45
+
46
+ level = DoubleBits.exponent(dx) + 1;
47
+ return level;
48
+ };
49
+
50
+ /**
51
+ * Returns the point
52
+ *
53
+ * @return {Number} point.
54
+ */
55
+ Key.prototype.getPoint = function() {
56
+ return this.pt;
57
+ };
58
+
59
+ /**
60
+ * Returns the level
61
+ *
62
+ * @return {Number} level.
63
+ */
64
+ Key.prototype.getLevel = function() {
65
+ return this.level;
66
+ };
67
+
68
+ /**
69
+ * Returns the interval
70
+ *
71
+ * @return {jsts.index.bintree.Interval}
72
+ */
73
+ Key.prototype.getInterval = function() {
74
+ return this.interval;
75
+ };
76
+
77
+ /**
78
+ * Calculates the key
79
+ *
80
+ * @param {jsts.index.bintree.Interval}
81
+ * itemInterval the interval.
82
+ */
83
+ Key.prototype.computeKey = function(itemInterval) {
84
+ this.level = Key.computeLevel(itemInterval);
85
+ this.interval = new Interval();
86
+ this.computeInterval(this.level, itemInterval);
87
+ // MD - would be nice to have a non-iterative form of this algorithm
88
+ while (!this.interval.contains(itemInterval)) {
89
+ this.level += 1;
90
+ this.computeInterval(this.level, itemInterval);
91
+ }
92
+ };
93
+
94
+ /**
95
+ * Computes the interval
96
+ *
97
+ * @param {Number}
98
+ * level the level.
99
+ * @param {jsts.index.bintree.Interval}
100
+ * itemInterval an interval.
101
+ */
102
+ Key.prototype.computeInterval = function(level, itemInterval) {
103
+ var size = DoubleBits.powerOf2(level);
104
+
105
+ this.pt = Math.floor(itemInterval.getMin() / size) * size;
106
+ this.interval.init(this.pt, this.pt + size);
107
+ };
108
+
109
+ jsts.index.bintree.Key = Key;
110
+ })();
@@ -0,0 +1,204 @@
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 a {@link Bintree}.
9
+ */
10
+ (function() {
11
+
12
+ /**
13
+ * @requires jsts/index/bintree/NodeBase.js
14
+ * @requires jsts/index/bintree/Interval.js
15
+ * @requires jsts/index/bintree/Key.js
16
+ */
17
+
18
+ var NodeBase = jsts.index.bintree.NodeBase;
19
+ var Key = jsts.index.bintree.Key;
20
+ var Interval = jsts.index.bintree.Interval;
21
+
22
+ /**
23
+ * Constructs a new Node
24
+ *
25
+ * @constructor
26
+ */
27
+ var Node = function(interval, level) {
28
+ /**
29
+ * subnodes are numbered as follows:
30
+ *
31
+ * 0 | 1
32
+ */
33
+ this.items = new javascript.util.ArrayList();
34
+ this.subnode = [null, null];
35
+ this.interval = interval;
36
+ this.level = level;
37
+ this.centre = (interval.getMin() + interval.getMax()) / 2;
38
+ };
39
+ Node.prototype = new NodeBase();
40
+ Node.constructor = Node;
41
+
42
+ /**
43
+ * Creates a node from a specified interval
44
+ *
45
+ * @param {jsts.index.bintree.Interval}
46
+ * itemInterval the interval.
47
+ * @return {jsts.index.bintree.Node} the created node.
48
+ */
49
+ Node.createNode = function(itemInterval) {
50
+ var key, node;
51
+
52
+ key = new Key(itemInterval);
53
+ node = new Node(key.getInterval(), key.getLevel());
54
+ return node;
55
+ };
56
+
57
+ /**
58
+ * Creates an expanded node
59
+ *
60
+ * @param {jsts.index.bintree.Node}
61
+ * node the node.
62
+ * @param {jsts.index.bintree.Interval}
63
+ * addInterval the interval to add.
64
+ * @return {jsts.index.bintree.Node} the expanded node.
65
+ */
66
+ Node.createExpanded = function(node, addInterval) {
67
+ var expandInt, largerNode;
68
+ expandInt = new Interval(addInterval);
69
+ if (node !== null) {
70
+ expandInt.expandToInclude(node.interval);
71
+ }
72
+
73
+ largerNode = Node.createNode(expandInt);
74
+
75
+ if (node !== null) {
76
+ largerNode.insert(node);
77
+ }
78
+
79
+ return largerNode;
80
+ };
81
+
82
+ Node.prototype.getInterval = function() {
83
+ return this.interval;
84
+ };
85
+
86
+ /**
87
+ * Checks if the input interval matches any items in this node
88
+ *
89
+ * @return {Boolean} true if there is a search match.
90
+ */
91
+ Node.prototype.isSearchMatch = function(itemInterval) {
92
+ return itemInterval.overlaps(this.interval);
93
+ };
94
+
95
+ /**
96
+ * Returns the subnode containing the envelope. Creates the node if it does
97
+ * not already exist.
98
+ *
99
+ * @param {jsts.index.bintree.Interval}
100
+ * serachInterval the interval.
101
+ * @return {jsts.index.bintree.Node} the node.
102
+ */
103
+ Node.prototype.getNode = function(searchInterval) {
104
+ var subnodeIndex = NodeBase.getSubnodeIndex(searchInterval, this.centre), node;
105
+ // if index is -1 searchEnv is not contained in a subnode
106
+ if (subnodeIndex != -1) {
107
+ // create the node if it does not exist
108
+ node = this.getSubnode(subnodeIndex);
109
+ // recursively search the found/created node
110
+ return node.getNode(searchInterval);
111
+ } else {
112
+ return this;
113
+ }
114
+ };
115
+
116
+ /**
117
+ * Returns the smallest <i>existing</i> node containing the envelope.
118
+ *
119
+ * @param {jsts.index.bintree.Interval}
120
+ * searchInterval the interval.
121
+ * @return {jsts.index.bintree.Node} the smallest node contained.
122
+ */
123
+ Node.prototype.find = function(searchInterval) {
124
+ var subnodeIndex = NodeBase.getSubnodeIndex(searchInterval, this.centre), node;
125
+ if (subnodeIndex === -1) {
126
+ return this;
127
+ }
128
+
129
+ if (this.subnode[subnodeIndex] !== null) {
130
+ // query lies in subnode, so search it
131
+ node = this.subnode[subnodeIndex];
132
+ return node.find(searchInterval);
133
+ }
134
+ // no existing subnode, so return this one anyway
135
+ return this;
136
+ };
137
+
138
+ /**
139
+ * Inserts a node as a child node (at some level) in this node
140
+ *
141
+ * @param {jsts.index.bintree.Node}
142
+ * node the node to insert.
143
+ */
144
+ Node.prototype.insert = function(node) {
145
+ //Assert.isTrue(interval == null || interval.contains(node.interval));
146
+
147
+ var index = NodeBase.getSubnodeIndex(node.interval, this.centre), childNode;
148
+ if (node.level === this.level - 1) {
149
+ this.subnode[index] = node;
150
+ } else {
151
+ // the node is not a direct child, so make a new child node to contain it
152
+ // and recursively insert the node
153
+ childNode = this.createSubnode(index);
154
+ childNode.insert(node);
155
+ this.subnode[index] = childNode;
156
+ }
157
+ };
158
+
159
+ /**
160
+ * get the subnode for the index. If it doesn't exist, create it
161
+ *
162
+ * @param {Number}
163
+ * index
164
+ * @return {jsts.index.bintree.Node} the found or created node.
165
+ */
166
+ Node.prototype.getSubnode = function(index) {
167
+ if (this.subnode[index] === null) {
168
+ this.subnode[index] = this.createSubnode(index);
169
+ }
170
+ return this.subnode[index];
171
+ };
172
+
173
+ /**
174
+ * Creates a subnode
175
+ *
176
+ * @param {Number}
177
+ * index the index to create the subnode at.
178
+ * @return {jsts.index.bintree.Node} the created node.
179
+ */
180
+ Node.prototype.createSubnode = function(index) {
181
+ // create a new subnode in the appropriate interval
182
+
183
+ var min, max, subInt, node;
184
+
185
+ min = 0.0;
186
+ max = 0.0;
187
+
188
+ switch (index) {
189
+ case 0:
190
+ min = this.interval.getMin();
191
+ max = this.centre;
192
+ break;
193
+ case 1:
194
+ min = this.centre;
195
+ max = this.interval.getMax();
196
+ break;
197
+ }
198
+ subInt = new Interval(min, max);
199
+ node = new Node(subInt, this.level - 1);
200
+ return node;
201
+ };
202
+
203
+ jsts.index.bintree.Node = Node;
204
+ })();