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,67 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ /**
8
+ * @requires jsts/geom/GeometryFilter.js
9
+ */
10
+
11
+
12
+
13
+ /**
14
+ * A ConnectedElementPointFilter extracts a single point from each connected
15
+ * element in a Geometry (e.g. a polygon, linestring or point) and returns them
16
+ * in a list. The elements of the list are
17
+ * {@link com.vividsolutions.jts.operation.distance.GeometryLocation}s.
18
+ *
19
+ * @param {[]}
20
+ * locations
21
+ * @augments jsts.geom.GeometryFilter
22
+ * @constructor
23
+ */
24
+ jsts.operation.distance.ConnectedElementLocationFilter = function(locations) {
25
+ this.locations = locations;
26
+ };
27
+
28
+ jsts.operation.distance.ConnectedElementLocationFilter.prototype = new jsts.geom.GeometryFilter();
29
+
30
+
31
+ /**
32
+ * @type {[]}
33
+ * @private
34
+ */
35
+ jsts.operation.distance.ConnectedElementLocationFilter.prototype.locations = null;
36
+
37
+
38
+ /**
39
+ * Returns a list containing a point from each Polygon, LineString, and Point
40
+ * found inside the specified geometry. Thus, if the specified geometry is not a
41
+ * GeometryCollection, an empty list will be returned. The elements of the list
42
+ * are {@link com.vividsolutions.jts.operation.distance.GeometryLocation}s.
43
+ *
44
+ * @param {Geometry}
45
+ * geom
46
+ * @return {[]}
47
+ */
48
+ jsts.operation.distance.ConnectedElementLocationFilter.getLocations = function(
49
+ geom) {
50
+ var locations = [];
51
+ geom.apply(new jsts.operation.distance.ConnectedElementLocationFilter(
52
+ locations));
53
+ return locations;
54
+ };
55
+
56
+
57
+ /**
58
+ * @param {Geometry}
59
+ * geom
60
+ */
61
+ jsts.operation.distance.ConnectedElementLocationFilter.prototype.filter = function(
62
+ geom) {
63
+ if (geom instanceof jsts.geom.Point || geom instanceof jsts.geom.LineString ||
64
+ geom instanceof jsts.geom.Polygon)
65
+ this.locations.push(new jsts.operation.distance.GeometryLocation(geom, 0,
66
+ geom.getCoordinate()));
67
+ };
@@ -0,0 +1,506 @@
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
+ * Find two points on two {@link Geometry}s which lie
8
+ * within a given distance, or else are the nearest points
9
+ * on the geometries (in which case this also
10
+ * provides the distance between the geometries).
11
+ * <p>
12
+ * The distance computation also finds a pair of points in the input geometries
13
+ * which have the minimum distance between them.
14
+ * If a point lies in the interior of a line segment,
15
+ * the coordinate computed is a close
16
+ * approximation to the exact point.
17
+ * <p>
18
+ * The algorithms used are straightforward O(n^2)
19
+ * comparisons. This worst-case performance could be improved on
20
+ * by using Voronoi techniques or spatial indexes.
21
+ *
22
+ */
23
+
24
+
25
+
26
+ /**
27
+ * Constructs a DistanceOp that computes the distance and nearest points
28
+ * between the two specified geometries.
29
+ *
30
+ * @param {Geometry}
31
+ * g0 a Geometry.
32
+ * @param {Geometry}
33
+ * g1 a Geometry.
34
+ * @param {double}
35
+ * terminateDistance the distance on which to terminate the search.
36
+ * @constructor
37
+ */
38
+ jsts.operation.distance.DistanceOp = function(g0, g1, terminateDistance) {
39
+ this.ptLocator = new jsts.algorithm.PointLocator();
40
+
41
+ this.geom = [];
42
+ this.geom[0] = g0;
43
+ this.geom[1] = g1;
44
+ this.terminateDistance = terminateDistance;
45
+ };
46
+
47
+
48
+ /**
49
+ * @type {Geometry[]}
50
+ */
51
+ jsts.operation.distance.DistanceOp.prototype.geom = null;
52
+
53
+
54
+ /**
55
+ * @type {double}
56
+ */
57
+ jsts.operation.distance.DistanceOp.prototype.terminateDistance = 0.0;
58
+
59
+
60
+ /**
61
+ * @type {PointLocator}
62
+ */
63
+ jsts.operation.distance.DistanceOp.prototype.ptLocator = null;
64
+
65
+
66
+ /**
67
+ * @type {GeometryLocation[]}
68
+ */
69
+ jsts.operation.distance.DistanceOp.prototype.minDistanceLocation = null;
70
+
71
+
72
+ /**
73
+ * @type {double}
74
+ */
75
+ jsts.operation.distance.DistanceOp.prototype.minDistance = Number.MAX_VALUE;
76
+
77
+
78
+ /**
79
+ * Compute the distance between the nearest points of two geometries.
80
+ *
81
+ * @param {Geometry}
82
+ * g0 a {@link Geometry}.
83
+ * @param {Geometry}
84
+ * g1 another {@link Geometry}.
85
+ * @return {double} the distance between the geometries.
86
+ */
87
+ jsts.operation.distance.DistanceOp.distance = function(g0, g1) {
88
+ var distOp = new jsts.operation.distance.DistanceOp(g0, g1, 0.0);
89
+ return distOp.distance();
90
+ };
91
+
92
+
93
+ /**
94
+ * Test whether two geometries lie within a given distance of each other.
95
+ *
96
+ * @param {Geometry}
97
+ * g0 a {@link Geometry}.
98
+ * @param {Geometry}
99
+ * g1 another {@link Geometry}.
100
+ * @param {double}
101
+ * distance the distance to test.
102
+ * @return {boolean} true if g0.distance(g1) <= distance.
103
+ */
104
+ jsts.operation.distance.DistanceOp.isWithinDistance = function(g0, g1,
105
+ distance) {
106
+ var distOp = new jsts.operation.distance.DistanceOp(g0, g1, distance);
107
+ return distOp.distance() <= distance;
108
+ };
109
+
110
+
111
+ /**
112
+ * Compute the the nearest points of two geometries. The points are presented
113
+ * in the same order as the input Geometries.
114
+ *
115
+ * @param {Geometry}
116
+ * g0 a {@link Geometry}.
117
+ * @param {Geometry}
118
+ * g1 another {@link Geometry}.
119
+ * @return {Coordinate[]} the nearest points in the geometries.
120
+ */
121
+ jsts.operation.distance.DistanceOp.nearestPoints = function(g0, g1) {
122
+ var distOp = new jsts.operation.distance.DistanceOp(g0, g1, 0.0);
123
+ return distOp.nearestPoints();
124
+ };
125
+
126
+
127
+ /**
128
+ * Report the distance between the nearest points on the input geometries.
129
+ *
130
+ * @return {double} the distance between the geometries.
131
+ * @return {double} 0 if either input geometry is empty.
132
+ * @throws IllegalArgumentException
133
+ * if either input geometry is null
134
+ */
135
+ jsts.operation.distance.DistanceOp.prototype.distance = function() {
136
+ if (this.geom[0] === null || this.geom[1] === null)
137
+ throw new jsts.error.IllegalArgumentError('null geometries are not supported');
138
+ if (this.geom[0].isEmpty() || this.geom[1].isEmpty())
139
+ return 0.0;
140
+
141
+ this.computeMinDistance();
142
+ return this.minDistance;
143
+ };
144
+
145
+
146
+ /**
147
+ * Report the coordinates of the nearest points in the input geometries. The
148
+ * points are presented in the same order as the input Geometries.
149
+ *
150
+ * @return {Coordinate[] } a pair of {@link Coordinate} s of the nearest
151
+ * points.
152
+ */
153
+ jsts.operation.distance.DistanceOp.prototype.nearestPoints = function() {
154
+ this.computeMinDistance();
155
+ var nearestPts = [this.minDistanceLocation[0].getCoordinate(),
156
+ this.minDistanceLocation[1].getCoordinate()];
157
+ return nearestPts;
158
+ };
159
+
160
+
161
+ /**
162
+ * Report the locations of the nearest points in the input geometries. The
163
+ * locations are presented in the same order as the input Geometries.
164
+ *
165
+ * @return {GeometryLocation[] } a pair of {@link GeometryLocation} s for the
166
+ * nearest points.
167
+ */
168
+ jsts.operation.distance.DistanceOp.prototype.nearestLocations = function() {
169
+ this.computeMinDistance();
170
+ return this.minDistanceLocation;
171
+ };
172
+
173
+
174
+ /**
175
+ * @param {GeometryLocation[]}
176
+ * locGeom locations.
177
+ * @param {boolean}
178
+ * flip if locations should be flipped.
179
+ * @private
180
+ */
181
+ jsts.operation.distance.DistanceOp.prototype.updateMinDistance = function(
182
+ locGeom, flip) {
183
+ // if not set then don't update
184
+ if (locGeom[0] === null)
185
+ return;
186
+
187
+ if (flip) {
188
+ this.minDistanceLocation[0] = locGeom[1];
189
+ this.minDistanceLocation[1] = locGeom[0];
190
+ } else {
191
+ this.minDistanceLocation[0] = locGeom[0];
192
+ this.minDistanceLocation[1] = locGeom[1];
193
+ }
194
+ };
195
+
196
+
197
+ /**
198
+ * @private
199
+ */
200
+ jsts.operation.distance.DistanceOp.prototype.computeMinDistance = function() {
201
+ // overloaded variant
202
+ if (arguments.length > 0) {
203
+ this.computeMinDistance2.apply(this, arguments);
204
+ return;
205
+ }
206
+
207
+ // only compute once!
208
+ if (this.minDistanceLocation !== null)
209
+ return;
210
+
211
+ this.minDistanceLocation = [];
212
+ this.computeContainmentDistance();
213
+ if (this.minDistance <= this.terminateDistance)
214
+ return;
215
+ this.computeFacetDistance();
216
+ };
217
+
218
+
219
+ /**
220
+ * @private
221
+ */
222
+ jsts.operation.distance.DistanceOp.prototype.computeContainmentDistance = function() {
223
+ if (arguments.length === 2) {
224
+ this.computeContainmentDistance2.apply(this, arguments);
225
+ return;
226
+ } else if (arguments.length === 3 && (!arguments[0] instanceof jsts.operation.distance.GeometryLocation)) {
227
+ this.computeContainmentDistance3.apply(this, arguments);
228
+ return;
229
+ } else if (arguments.length === 3) {
230
+ this.computeContainmentDistance4.apply(this, arguments);
231
+ return;
232
+ }
233
+
234
+ var locPtPoly = [];
235
+ // test if either geometry has a vertex inside the other
236
+ this.computeContainmentDistance2(0, locPtPoly);
237
+ if (this.minDistance <= this.terminateDistance)
238
+ return;
239
+ this.computeContainmentDistance2(1, locPtPoly);
240
+ };
241
+
242
+
243
+ /**
244
+ * @param {int}
245
+ * polyGeomIndex
246
+ * @param {GeometryLocation[]}
247
+ * locPtPoly
248
+ * @private
249
+ */
250
+ jsts.operation.distance.DistanceOp.prototype.computeContainmentDistance2 = function(
251
+ polyGeomIndex, locPtPoly) {
252
+
253
+ var locationsIndex = 1 - polyGeomIndex;
254
+ var polys = jsts.geom.util.PolygonExtracter.getPolygons(this.geom[polyGeomIndex]);
255
+ if (polys.length > 0) {
256
+ var insideLocs = jsts.operation.distance.ConnectedElementLocationFilter
257
+ .getLocations(this.geom[locationsIndex]);
258
+ this.computeContainmentDistance3(insideLocs, polys, locPtPoly);
259
+ if (this.minDistance <= this.terminateDistance) {
260
+ // this assigment is determined by the order of the args in the
261
+ // computeInside call above
262
+ this.minDistanceLocation[locationsIndex] = locPtPoly[0];
263
+ this.minDistanceLocation[polyGeomIndex] = locPtPoly[1];
264
+ return;
265
+ }
266
+ }
267
+ };
268
+
269
+
270
+ /**
271
+ * @param {[]}
272
+ * locs
273
+ * @param {[]}
274
+ * polys
275
+ * @param {GeometryLocation[] }
276
+ * locPtPoly
277
+ * @private
278
+ */
279
+ jsts.operation.distance.DistanceOp.prototype.computeContainmentDistance3 = function(
280
+ locs, polys, locPtPoly) {
281
+
282
+ for (var i = 0; i < locs.length; i++) {
283
+ var loc = locs[i];
284
+ for (var j = 0; j < polys.length; j++) {
285
+ this.computeContainmentDistance4(loc, polys[j], locPtPoly);
286
+ if (this.minDistance <= this.terminateDistance)
287
+ return;
288
+ }
289
+ }
290
+ };
291
+
292
+
293
+ /**
294
+ * @param {GeometryLocation}
295
+ * ptLoc
296
+ * @param {Polygon}
297
+ * poly
298
+ * @param {GeometryLocation[]} locPtPoly
299
+ * @private
300
+ */
301
+ jsts.operation.distance.DistanceOp.prototype.computeContainmentDistance4 = function(
302
+ ptLoc, poly, locPtPoly) {
303
+ var pt = ptLoc.getCoordinate();
304
+ // if pt is not in exterior, distance to geom is 0
305
+ if (jsts.geom.Location.EXTERIOR !== this.ptLocator.locate(pt, poly)) {
306
+ this.minDistance = 0.0;
307
+ locPtPoly[0] = ptLoc;
308
+ locPtPoly[1] = new jsts.operation.distance.GeometryLocation(poly, pt);
309
+ return;
310
+ }
311
+ };
312
+
313
+
314
+ /**
315
+ * Computes distance between facets (lines and points) of input geometries.
316
+ * @private
317
+ */
318
+ jsts.operation.distance.DistanceOp.prototype.computeFacetDistance = function() {
319
+ var locGeom = [];
320
+
321
+ /**
322
+ * Geometries are not wholely inside, so compute distance from lines and
323
+ * points of one to lines and points of the other
324
+ */
325
+ var lines0 = jsts.geom.util.LinearComponentExtracter.getLines(this.geom[0]);
326
+ var lines1 = jsts.geom.util.LinearComponentExtracter.getLines(this.geom[1]);
327
+
328
+ var pts0 = jsts.geom.util.PointExtracter.getPoints(this.geom[0]);
329
+ var pts1 = jsts.geom.util.PointExtracter.getPoints(this.geom[1]);
330
+
331
+ // exit whenever minDistance goes LE than terminateDistance
332
+ this.computeMinDistanceLines(lines0, lines1, locGeom);
333
+ this.updateMinDistance(locGeom, false);
334
+ if (this.minDistance <= this.terminateDistance)
335
+ return;
336
+
337
+ locGeom[0] = null;
338
+ locGeom[1] = null;
339
+ this.computeMinDistanceLinesPoints(lines0, pts1, locGeom);
340
+ this.updateMinDistance(locGeom, false);
341
+ if (this.minDistance <= this.terminateDistance)
342
+ return;
343
+
344
+ locGeom[0] = null;
345
+ locGeom[1] = null;
346
+ this.computeMinDistanceLinesPoints(lines1, pts0, locGeom);
347
+ this.updateMinDistance(locGeom, true);
348
+ if (this.minDistance <= this.terminateDistance)
349
+ return;
350
+
351
+ locGeom[0] = null;
352
+ locGeom[1] = null;
353
+ this.computeMinDistancePoints(pts0, pts1, locGeom);
354
+ this.updateMinDistance(locGeom, false);
355
+ };
356
+
357
+
358
+ /**
359
+ * @param {[]}
360
+ * lines0.
361
+ * @param {[]}
362
+ * lines1
363
+ * @param {GeometryLocation[]}
364
+ * locGeom
365
+ * @private
366
+ */
367
+ jsts.operation.distance.DistanceOp.prototype.computeMinDistanceLines = function(
368
+ lines0, lines1, locGeom) {
369
+ for (var i = 0; i < lines0.length; i++) {
370
+ var line0 = lines0[i];
371
+ for (var j = 0; j < lines1.length; j++) {
372
+ var line1 = lines1[j];
373
+ this.computeMinDistance(line0, line1, locGeom);
374
+ if (this.minDistance <= this.terminateDistance)
375
+ return;
376
+ }
377
+ }
378
+ };
379
+
380
+
381
+ /**
382
+ * @param {[]}
383
+ * points0
384
+ * @param {[]}
385
+ * points1
386
+ * @param {GeometryLocation[]}
387
+ * locGeom
388
+ * @private
389
+ */
390
+ jsts.operation.distance.DistanceOp.prototype.computeMinDistancePoints = function(
391
+ points0, points1, locGeom) {
392
+ for (var i = 0; i < points0.length; i++) {
393
+ var pt0 = points0[i];
394
+ for (var j = 0; j < points1.length; j++) {
395
+ var pt1 = points1[j];
396
+ var dist = pt0.getCoordinate().distance(pt1.getCoordinate());
397
+ if (dist < this.minDistance) {
398
+ this.minDistance = dist;
399
+ locGeom[0] = new jsts.operation.distance.GeometryLocation(pt0, 0, pt0.getCoordinate());
400
+ locGeom[1] = new jsts.operation.distance.GeometryLocation(pt1, 0, pt1.getCoordinate());
401
+ }
402
+ if (this.minDistance <= this.terminateDistance)
403
+ return;
404
+ }
405
+ }
406
+ };
407
+
408
+
409
+ /**
410
+ * @param {[]}
411
+ * lines
412
+ * @param {[]}
413
+ * points
414
+ * @param {GeometryLocation[]}
415
+ * locGeom
416
+ * @private
417
+ */
418
+ jsts.operation.distance.DistanceOp.prototype.computeMinDistanceLinesPoints = function(
419
+ lines, points, locGeom) {
420
+ for (var i = 0; i < lines.length; i++) {
421
+ var line = lines[i];
422
+ for (var j = 0; j < points.length; j++) {
423
+ var pt = points[j];
424
+ this.computeMinDistance(line, pt, locGeom);
425
+ if (this.minDistance <= this.terminateDistance)
426
+ return;
427
+ }
428
+ }
429
+ };
430
+
431
+
432
+ /**
433
+ * @param {LineString}
434
+ * line0
435
+ * @param {Point}
436
+ * line1
437
+ * @param {GeometryLocation[]}
438
+ * locGeom
439
+ * @private
440
+ */
441
+ jsts.operation.distance.DistanceOp.prototype.computeMinDistance2 = function(
442
+ line0, line1, locGeom) {
443
+
444
+ // overloaded variant
445
+ if (line1 instanceof jsts.geom.Point) {
446
+ this.computeMinDistance3(line0, line1, locGeom);
447
+ return;
448
+ }
449
+
450
+ if (line0.getEnvelopeInternal().distance(line1.getEnvelopeInternal()) > this.minDistance) {
451
+ return;
452
+ }
453
+ var coord0 = line0.getCoordinates();
454
+ var coord1 = line1.getCoordinates();
455
+ // brute force approach!
456
+ for (var i = 0; i < coord0.length - 1; i++) {
457
+ for (var j = 0; j < coord1.length - 1; j++) {
458
+ var dist = jsts.algorithm.CGAlgorithms.distanceLineLine(coord0[i], coord0[i + 1],
459
+ coord1[j], coord1[j + 1]);
460
+ if (dist < this.minDistance) {
461
+ this.minDistance = dist;
462
+ var seg0 = new jsts.geom.LineSegment(coord0[i], coord0[i + 1]);
463
+ var seg1 = new jsts.geom.LineSegment(coord1[j], coord1[j + 1]);
464
+ var closestPt = seg0.closestPoints(seg1);
465
+ locGeom[0] = new jsts.operation.distance.GeometryLocation(line0, i, closestPt[0]);
466
+ locGeom[1] = new jsts.operation.distance.GeometryLocation(line1, j, closestPt[1]);
467
+ }
468
+ if (this.minDistance <= this.terminateDistance) {
469
+ return;
470
+ }
471
+ }
472
+ }
473
+ };
474
+
475
+
476
+ /**
477
+ * @param {LineString}
478
+ * line
479
+ * @param {Point}
480
+ * pt
481
+ * @param {GeometryLocation[]}
482
+ * locGeom
483
+ * @private
484
+ */
485
+ jsts.operation.distance.DistanceOp.prototype.computeMinDistance3 = function(
486
+ line, pt, locGeom) {
487
+ if (line.getEnvelopeInternal().distance(pt.getEnvelopeInternal()) > this.minDistance) {
488
+ return;
489
+ }
490
+ var coord0 = line.getCoordinates();
491
+ var coord = pt.getCoordinate();
492
+ // brute force approach!
493
+ for (var i = 0; i < coord0.length - 1; i++) {
494
+ var dist = jsts.algorithm.CGAlgorithms.distancePointLine(coord, coord0[i], coord0[i + 1]);
495
+ if (dist < this.minDistance) {
496
+ this.minDistance = dist;
497
+ var seg = new jsts.geom.LineSegment(coord0[i], coord0[i + 1]);
498
+ var segClosestPoint = seg.closestPoint(coord);
499
+ locGeom[0] = new jsts.operation.distance.GeometryLocation(line, i, segClosestPoint);
500
+ locGeom[1] = new jsts.operation.distance.GeometryLocation(pt, 0, coord);
501
+ }
502
+ if (this.minDistance <= this.terminateDistance) {
503
+ return;
504
+ }
505
+ }
506
+ };