jsts-rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +8 -8
  2. data/lib/jsts-rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/javascript.util.js +33 -1
  4. data/vendor/assets/javascripts/jsts-original.js +164 -1573
  5. data/vendor/assets/javascripts/jsts.js +197 -0
  6. data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
  7. data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
  8. data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
  9. data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
  10. data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
  11. data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
  12. data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
  13. data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
  14. data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
  15. data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
  16. data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
  17. data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
  18. data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
  19. data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
  20. data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
  21. data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
  22. data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
  23. data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
  24. data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
  25. data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
  26. data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
  27. data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
  28. data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
  29. data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
  30. data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
  31. data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
  32. data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
  33. data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
  34. data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
  35. data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
  36. data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
  37. data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
  38. data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
  39. data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
  40. data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
  41. data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
  42. data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
  43. data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
  44. data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
  45. data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
  46. data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
  47. data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
  48. data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
  49. data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
  50. data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
  51. data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
  52. data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
  53. data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
  54. data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
  55. data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
  56. data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
  57. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
  58. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
  59. data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
  60. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
  61. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
  62. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
  63. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
  64. data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
  65. data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
  66. data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
  67. data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
  68. data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
  69. data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
  70. data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
  71. data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
  72. data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
  73. data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
  74. data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
  75. data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
  76. data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
  77. data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
  78. data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
  79. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
  80. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
  81. data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
  82. data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
  83. data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
  84. data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
  85. data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
  86. data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
  87. data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
  88. data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
  89. data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
  90. data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
  91. data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
  92. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
  93. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
  94. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
  95. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
  96. data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
  97. data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
  98. data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
  99. data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
  100. data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
  101. data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
  102. data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
  103. data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
  104. data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
  105. data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
  106. data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
  107. data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
  108. data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
  109. data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
  110. data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
  111. data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
  112. data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
  113. data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
  114. data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
  115. data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
  116. data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
  117. data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
  118. data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
  119. data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
  120. data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
  121. data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
  122. data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
  123. data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
  124. data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
  125. data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
  126. data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
  127. data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
  128. data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
  129. data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
  130. data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
  131. data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
  132. data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
  133. data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
  134. data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
  135. data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
  136. data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
  137. data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
  138. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
  139. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
  140. data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
  141. data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
  142. data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
  143. data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
  144. data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
  145. data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
  146. data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
  147. data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
  148. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
  149. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
  150. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
  151. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
  152. data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
  153. data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
  154. data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
  155. data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
  156. data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
  157. data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
  158. data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
  159. data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
  160. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
  161. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
  162. data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
  163. data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
  164. data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
  165. data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
  166. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
  167. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
  168. data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
  169. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
  170. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
  171. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
  172. data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
  173. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
  174. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
  175. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
  176. data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
  177. data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
  178. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
  179. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
  180. data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
  181. data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
  182. data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
  183. data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
  184. data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
  185. data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
  186. data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
  187. data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
  188. data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
  189. data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
  190. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
  191. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
  192. data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
  193. data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
  194. data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
  195. data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
  196. data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
  197. data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
  198. data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
  199. data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
  200. data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
  201. data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
  202. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
  203. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
  204. data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
  205. data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
  206. data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
  207. data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
  208. data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
  209. metadata +204 -1
@@ -0,0 +1,228 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ /**
8
+ * Port source:
9
+ * /jts/jts/java/src/com/vividsolutions/jts/algorithm/distance/DiscreteHausdorffDistance.java
10
+ * Revision: 6
11
+ */
12
+
13
+ /**
14
+ * @requires jsts/geom/CoordinateFilter.js
15
+ * @requires jsts/geom/CoordinateSequenceFilter.js
16
+ * @requires jsts/algorithm/distance/PointPairDistance.js
17
+ * @requires jsts/algorithm/distance/DistanceToPoint.js
18
+ */
19
+
20
+ (function() {
21
+
22
+ var PointPairDistance = jsts.algorithm.distance.PointPairDistance;
23
+ var DistanceToPoint = jsts.algorithm.distance.DistanceToPoint;
24
+
25
+ var MaxPointDistanceFilter = function(geom) {
26
+ this.maxPtDist = new PointPairDistance();
27
+ this.minPtDist = new PointPairDistance();
28
+ this.euclideanDist = new DistanceToPoint();
29
+
30
+ this.geom = geom;
31
+ };
32
+
33
+ MaxPointDistanceFilter.prototype = new jsts.geom.CoordinateFilter();
34
+
35
+ MaxPointDistanceFilter.prototype.maxPtDist = new PointPairDistance();
36
+ MaxPointDistanceFilter.prototype.minPtDist = new PointPairDistance();
37
+ MaxPointDistanceFilter.prototype.euclideanDist = new DistanceToPoint();
38
+ MaxPointDistanceFilter.prototype.geom;
39
+
40
+ MaxPointDistanceFilter.prototype.filter = function(pt) {
41
+ this.minPtDist.initialize();
42
+ DistanceToPoint.computeDistance(this.geom, pt, this.minPtDist);
43
+ this.maxPtDist.setMaximum(this.minPtDist);
44
+ };
45
+
46
+ MaxPointDistanceFilter.prototype.getMaxPointDistance = function() {
47
+ return this.maxPtDist;
48
+ };
49
+
50
+
51
+ var MaxDensifiedByFractionDistanceFilter = function(geom, fraction) {
52
+ this.maxPtDist = new PointPairDistance();
53
+ this.minPtDist = new PointPairDistance();
54
+
55
+ this.geom = geom;
56
+ // NOTE: Math.rint in JTS changed to Math.round
57
+ this.numSubSegs = Math.round(1.0 / fraction);
58
+ };
59
+
60
+ MaxDensifiedByFractionDistanceFilter.prototype = new jsts.geom.CoordinateSequenceFilter();
61
+
62
+ MaxDensifiedByFractionDistanceFilter.prototype.maxPtDist = new PointPairDistance();
63
+ MaxDensifiedByFractionDistanceFilter.prototype.minPtDist = new PointPairDistance();
64
+ MaxDensifiedByFractionDistanceFilter.prototype.geom;
65
+ MaxDensifiedByFractionDistanceFilter.prototype.numSubSegs = 0;
66
+
67
+ MaxDensifiedByFractionDistanceFilter.prototype.filter = function(seq, index) {
68
+ /**
69
+ * This logic also handles skipping Point geometries
70
+ */
71
+ if (index == 0)
72
+ return;
73
+
74
+ var p0 = seq[index - 1];
75
+ var p1 = seq[index];
76
+
77
+ var delx = (p1.x - p0.x) / this.numSubSegs;
78
+ var dely = (p1.y - p0.y) / this.numSubSegs;
79
+
80
+ for (var i = 0; i < this.numSubSegs; i++) {
81
+ var x = p0.x + i * delx;
82
+ var y = p0.y + i * dely;
83
+ var pt = new jsts.geom.Coordinate(x, y);
84
+ this.minPtDist.initialize();
85
+ DistanceToPoint.computeDistance(this.geom, pt, this.minPtDist);
86
+ this.maxPtDist.setMaximum(this.minPtDist);
87
+ }
88
+ };
89
+
90
+ MaxDensifiedByFractionDistanceFilter.prototype.isGeometryChanged = function() {
91
+ return false;
92
+ };
93
+
94
+ MaxDensifiedByFractionDistanceFilter.prototype.isDone = function() {
95
+ return false;
96
+ };
97
+
98
+ MaxDensifiedByFractionDistanceFilter.prototype.getMaxPointDistance = function() {
99
+ return this.maxPtDist;
100
+ };
101
+
102
+ /**
103
+ * An algorithm for computing a distance metric which is an approximation to
104
+ * the Hausdorff Distance based on a discretization of the input
105
+ * {@link Geometry}. The algorithm computes the Hausdorff distance restricted
106
+ * to discrete points for one of the geometries. The points can be either the
107
+ * vertices of the geometries (the default), or the geometries with line
108
+ * segments densified by a given fraction. Also determines two points of the
109
+ * Geometries which are separated by the computed distance.
110
+ * <p>
111
+ * This algorithm is an approximation to the standard Hausdorff distance.
112
+ * Specifically,
113
+ *
114
+ * <pre>
115
+ * for all geometries a, b: DHD(a, b) &lt;= HD(a, b)
116
+ * </pre>
117
+ *
118
+ * The approximation can be made as close as needed by densifying the input
119
+ * geometries. In the limit, this value will approach the true Hausdorff
120
+ * distance:
121
+ *
122
+ * <pre>
123
+ * DHD(A, B, densifyFactor) -&gt; HD(A, B) as densifyFactor -&gt; 0.0
124
+ * </pre>
125
+ *
126
+ * The default approximation is exact or close enough for a large subset of
127
+ * useful cases. Examples of these are:
128
+ * <ul>
129
+ * <li>computing distance between Linestrings that are roughly parallel to
130
+ * each other, and roughly equal in length. This occurs in matching linear
131
+ * networks.
132
+ * <li>Testing similarity of geometries.
133
+ * </ul>
134
+ * An example where the default approximation is not close is:
135
+ *
136
+ * <pre>
137
+ * A = LINESTRING (0 0, 100 0, 10 100, 10 100)
138
+ * B = LINESTRING (0 100, 0 10, 80 10)
139
+ *
140
+ * DHD(A, B) = 22.360679774997898
141
+ * HD(A, B) &tilde;= 47.8
142
+ * </pre>
143
+ */
144
+ jsts.algorithm.distance.DiscreteHausdorffDistance = function(g0, g1) {
145
+ this.g0 = g0;
146
+ this.g1 = g1;
147
+
148
+ this.ptDist = new jsts.algorithm.distance.PointPairDistance();
149
+ };
150
+
151
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.g0 = null;
152
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.g1 = null;
153
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.ptDist = null;
154
+ /**
155
+ * Value of 0.0 indicates that no densification should take place
156
+ */
157
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.densifyFrac = 0.0;
158
+
159
+ jsts.algorithm.distance.DiscreteHausdorffDistance.distance = function(g0, g1,
160
+ densifyFrac) {
161
+ var dist = new jsts.algorithm.distance.DiscreteHausdorffDistance(g0, g1);
162
+ if (densifyFrac !== undefined)
163
+ dist.setDensifyFraction(densifyFrac);
164
+ return dist.distance();
165
+ };
166
+
167
+
168
+ /**
169
+ * Sets the fraction by which to densify each segment. Each segment will be
170
+ * (virtually) split into a number of equal-length subsegments, whose fraction
171
+ * of the total length is closest to the given fraction.
172
+ *
173
+ * @param densifyPercent
174
+ */
175
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.setDensifyFraction = function(
176
+ densifyFrac) {
177
+ if (densifyFrac > 1.0 || densifyFrac <= 0.0)
178
+ throw new jsts.error.IllegalArgumentError(
179
+ 'Fraction is not in range (0.0 - 1.0]');
180
+
181
+ this.densifyFrac = densifyFrac;
182
+ };
183
+
184
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.distance = function() {
185
+ this.compute(this.g0, this.g1);
186
+ return ptDist.getDistance();
187
+ };
188
+
189
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.orientedDistance = function() {
190
+ this.computeOrientedDistance(this.g0, this.g1, this.ptDist);
191
+ return this.ptDist.getDistance();
192
+ };
193
+
194
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.getCoordinates = function() {
195
+ return ptDist.getCoordinates();
196
+ };
197
+
198
+ /**
199
+ *
200
+ * @private
201
+ */
202
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.compute = function(
203
+ g0, g1) {
204
+ this.computeOrientedDistance(g0, g1, this.ptDist);
205
+ this.computeOrientedDistance(g1, g0, this.ptDist);
206
+ };
207
+
208
+ /**
209
+ *
210
+ * @private
211
+ */
212
+ jsts.algorithm.distance.DiscreteHausdorffDistance.prototype.computeOrientedDistance = function(
213
+ discreteGeom, geom, ptDist) {
214
+ var distFilter = new MaxPointDistanceFilter(geom);
215
+ discreteGeom.apply(distFilter);
216
+ ptDist.setMaximum(distFilter.getMaxPointDistance());
217
+
218
+ if (this.densifyFrac > 0) {
219
+ var fracFilter = new MaxDensifiedByFractionDistanceFilter(geom,
220
+ this.densifyFrac);
221
+ discreteGeom.apply(fracFilter);
222
+ ptDist.setMaximum(fracFilter.getMaxPointDistance());
223
+
224
+ }
225
+ };
226
+
227
+
228
+ })();
@@ -0,0 +1,68 @@
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
+ * Port source: /jts/jts/java/src/com/vividsolutions/jts/algorithm/distance/DistanceToPoint.java
9
+ * Revision: 6
10
+ */
11
+
12
+ /**
13
+ * @requires jsts/geom/Polygon.js
14
+ */
15
+
16
+ /**
17
+ * Computes the Euclidean distance (L2 metric) from a Point to a Geometry. Also
18
+ * computes two points which are separated by the distance.
19
+ */
20
+ jsts.algorithm.distance.DistanceToPoint = function() {
21
+
22
+ };
23
+
24
+ jsts.algorithm.distance.DistanceToPoint.computeDistance = function(geom, pt,
25
+ ptDist) {
26
+ if (geom instanceof jsts.geom.LineString) {
27
+ jsts.algorithm.distance.DistanceToPoint.computeDistance2(geom, pt, ptDist);
28
+ } else if (geom instanceof jsts.geom.Polygon) {
29
+ jsts.algorithm.distance.DistanceToPoint.computeDistance4(geom, pt, ptDist);
30
+ } else if (geom instanceof jsts.geom.GeometryCollection) {
31
+ var gc = geom;
32
+ for (var i = 0; i < gc.getNumGeometries(); i++) {
33
+ var g = gc.getGeometryN(i);
34
+ jsts.algorithm.distance.DistanceToPoint.computeDistance(g, pt, ptDist);
35
+ }
36
+ } else { // assume geom is Point
37
+ ptDist.setMinimum(geom.getCoordinate(), pt);
38
+ }
39
+ };
40
+
41
+ jsts.algorithm.distance.DistanceToPoint.computeDistance2 = function(line, pt,
42
+ ptDist) {
43
+ var tempSegment = new jsts.geom.LineSegment();
44
+
45
+ var coords = line.getCoordinates();
46
+ for (var i = 0; i < coords.length - 1; i++) {
47
+ tempSegment.setCoordinates(coords[i], coords[i + 1]);
48
+ // this is somewhat inefficient - could do better
49
+ var closestPt = tempSegment.closestPoint(pt);
50
+ ptDist.setMinimum(closestPt, pt);
51
+ }
52
+ };
53
+
54
+ jsts.algorithm.distance.DistanceToPoint.computeDistance3 = function(segment,
55
+ pt, ptDist) {
56
+ var closestPt = segment.closestPoint(pt);
57
+ ptDist.setMinimum(closestPt, pt);
58
+ };
59
+
60
+ jsts.algorithm.distance.DistanceToPoint.computeDistance4 = function(poly, pt,
61
+ ptDist) {
62
+ jsts.algorithm.distance.DistanceToPoint.computeDistance2(poly
63
+ .getExteriorRing(), pt, ptDist);
64
+ for (var i = 0; i < poly.getNumInteriorRing(); i++) {
65
+ jsts.algorithm.distance.DistanceToPoint.computeDistance2(poly
66
+ .getInteriorRingN(i), pt, ptDist);
67
+ }
68
+ };
@@ -0,0 +1,104 @@
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
+ * Port source: /jts/jts/java/src/com/vividsolutions/jts/algorithm/distance/PointPairDistance.java
9
+ * Revision: 6
10
+ */
11
+
12
+ /**
13
+ * @requires jsts/geom/Coordinate.js
14
+ */
15
+
16
+
17
+ /**
18
+ * Contains a pair of points and the distance between them. Provides methods to
19
+ * update with a new point pair with either maximum or minimum distance.
20
+ */
21
+ jsts.algorithm.distance.PointPairDistance = function() {
22
+ this.pt = [new jsts.geom.Coordinate(), new jsts.geom.Coordinate()];
23
+ };
24
+
25
+ jsts.algorithm.distance.PointPairDistance.prototype.pt = null;
26
+ jsts.algorithm.distance.PointPairDistance.prototype.distance = NaN;
27
+ jsts.algorithm.distance.PointPairDistance.prototype.isNull = true;
28
+
29
+ /**
30
+ * Initializes the points, avoiding recomputing the distance.
31
+ *
32
+ * @param p0
33
+ * @param p1
34
+ * @param distance
35
+ * the distance between p0 and p1.
36
+ */
37
+ jsts.algorithm.distance.PointPairDistance.prototype.initialize = function(p0,
38
+ p1, distance) {
39
+ if (p0 === undefined) {
40
+ this.isNull = true;
41
+ return;
42
+ }
43
+
44
+ this.pt[0].setCoordinate(p0);
45
+ this.pt[1].setCoordinate(p1);
46
+ this.distance = distance !== undefined ? distance : p0.distance(p1);
47
+ this.isNull = false;
48
+ };
49
+
50
+ jsts.algorithm.distance.PointPairDistance.prototype.getDistance = function() {
51
+ return this.distance;
52
+ };
53
+
54
+ jsts.algorithm.distance.PointPairDistance.prototype.getCoordinates = function() {
55
+ return this.pt;
56
+ };
57
+
58
+ jsts.algorithm.distance.PointPairDistance.prototype.getCoordinate = function(i) {
59
+ return this.pt[i];
60
+ };
61
+
62
+ jsts.algorithm.distance.PointPairDistance.prototype.setMaximum = function(
63
+ ptDist) {
64
+ if (arguments.length === 2) {
65
+ this.setMaximum2.apply(this, arguments);
66
+ return;
67
+ }
68
+
69
+ this.setMaximum(ptDist.pt[0], ptDist.pt[1]);
70
+ };
71
+
72
+ jsts.algorithm.distance.PointPairDistance.prototype.setMaximum2 = function(p0,
73
+ p1) {
74
+ if (this.isNull) {
75
+ this.initialize(p0, p1);
76
+ return;
77
+ }
78
+ var dist = p0.distance(p1);
79
+ if (dist > this.distance)
80
+ this.initialize(p0, p1, dist);
81
+ };
82
+
83
+ jsts.algorithm.distance.PointPairDistance.prototype.setMinimum = function(
84
+ ptDist) {
85
+ if (arguments.length === 2) {
86
+ this.setMinimum2.apply(this, arguments);
87
+ return;
88
+ }
89
+
90
+ this.setMinimum(ptDist.pt[0], ptDist.pt[1]);
91
+ };
92
+
93
+ jsts.algorithm.distance.PointPairDistance.prototype.setMinimum2 = function(p0,
94
+ p1) {
95
+ if (this.isNull) {
96
+ this.initialize(p0, p1);
97
+ return;
98
+ }
99
+ var dist = p0.distance(p1);
100
+ if (dist < this.distance)
101
+ this.initialize(p0, p1, dist);
102
+ };
103
+
104
+ // NOTE: toString not ported
@@ -0,0 +1,7 @@
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
+ // TODO: port!
@@ -0,0 +1,102 @@
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
+ * Computes the location of points relative to a {@link Polygonal}
11
+ * {@link Geometry}, using a simple O(n) algorithm. This algorithm is suitable
12
+ * for use in cases where only one or a few points will be tested against a
13
+ * given area.
14
+ * <p>
15
+ * The algorithm used is only guaranteed to return correct results for points
16
+ * which are <b>not</b> on the boundary of the Geometry.
17
+ *
18
+ * @constructor
19
+ * @augments {PointOnGeometryLocator}
20
+ */
21
+ jsts.algorithm.locate.SimplePointInAreaLocator = function(geom) {
22
+ this.geom = geom;
23
+ };
24
+
25
+
26
+ /**
27
+ * Determines the {@link Location} of a point in an areal {@link Geometry}.
28
+ * Currently this will never return a value of BOUNDARY.
29
+ *
30
+ * @param p
31
+ * the point to test.
32
+ * @param geom
33
+ * the areal geometry to test.
34
+ * @return the Location of the point in the geometry.
35
+ */
36
+ jsts.algorithm.locate.SimplePointInAreaLocator.locate = function(p, geom) {
37
+ if (geom.isEmpty())
38
+ return jsts.geom.Location.EXTERIOR;
39
+
40
+ if (jsts.algorithm.locate.SimplePointInAreaLocator.containsPoint(p, geom))
41
+ return jsts.geom.Location.INTERIOR;
42
+ return jsts.geom.Location.EXTERIOR;
43
+ };
44
+
45
+ jsts.algorithm.locate.SimplePointInAreaLocator.containsPoint = function(p, geom) {
46
+ if (geom instanceof jsts.geom.Polygon) {
47
+ return jsts.algorithm.locate.SimplePointInAreaLocator
48
+ .containsPointInPolygon(p, geom);
49
+ } else if (geom instanceof jsts.geom.GeometryCollection ||
50
+ geom instanceof jsts.geom.MultiPoint ||
51
+ geom instanceof jsts.geom.MultiLineString ||
52
+ geom instanceof jsts.geom.MultiPolygon) {
53
+ for (var i = 0; i < geom.geometries.length; i++) {
54
+ var g2 = geom.geometries[i];
55
+ if (g2 !== geom)
56
+ if (jsts.algorithm.locate.SimplePointInAreaLocator.containsPoint(p, g2))
57
+ return true;
58
+ }
59
+ }
60
+ return false;
61
+ };
62
+
63
+ jsts.algorithm.locate.SimplePointInAreaLocator.containsPointInPolygon = function(
64
+ p, poly) {
65
+ if (poly.isEmpty())
66
+ return false;
67
+ var shell = poly.getExteriorRing();
68
+ if (!jsts.algorithm.locate.SimplePointInAreaLocator.isPointInRing(p, shell))
69
+ return false;
70
+ // now test if the point lies in or on the holes
71
+ for (var i = 0; i < poly.getNumInteriorRing(); i++) {
72
+ var hole = poly.getInteriorRingN(i);
73
+ if (jsts.algorithm.locate.SimplePointInAreaLocator.isPointInRing(p, hole))
74
+ return false;
75
+ }
76
+ return true;
77
+ };
78
+
79
+
80
+ /**
81
+ * Determines whether a point lies in a LinearRing, using the ring envelope to
82
+ * short-circuit if possible.
83
+ *
84
+ * @param p
85
+ * the point to test.
86
+ * @param ring
87
+ * a linear ring.
88
+ * @return true if the point lies inside the ring.
89
+ */
90
+ jsts.algorithm.locate.SimplePointInAreaLocator.isPointInRing = function(p, ring) {
91
+ // short-circuit if point is not in ring envelope
92
+ if (!ring.getEnvelopeInternal().intersects(p))
93
+ return false;
94
+ return jsts.algorithm.CGAlgorithms.isPointInRing(p, ring.getCoordinates());
95
+ };
96
+
97
+ jsts.algorithm.locate.SimplePointInAreaLocator.prototype.geom = null;
98
+
99
+
100
+ jsts.algorithm.locate.SimplePointInAreaLocator.prototype.locate = function(p) {
101
+ return jsts.algorithm.locate.SimplePointInAreaLocator.locate(p, geom);
102
+ };