jsts-rails 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (209) hide show
  1. checksums.yaml +8 -8
  2. data/lib/jsts-rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/javascript.util.js +33 -1
  4. data/vendor/assets/javascripts/jsts-original.js +164 -1573
  5. data/vendor/assets/javascripts/jsts.js +197 -0
  6. data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
  7. data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
  8. data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
  9. data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
  10. data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
  11. data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
  12. data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
  13. data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
  14. data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
  15. data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
  16. data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
  17. data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
  18. data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
  19. data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
  20. data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
  21. data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
  22. data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
  23. data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
  24. data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
  25. data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
  26. data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
  27. data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
  28. data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
  29. data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
  30. data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
  31. data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
  32. data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
  33. data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
  34. data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
  35. data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
  36. data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
  37. data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
  38. data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
  39. data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
  40. data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
  41. data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
  42. data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
  43. data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
  44. data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
  45. data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
  46. data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
  47. data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
  48. data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
  49. data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
  50. data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
  51. data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
  52. data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
  53. data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
  54. data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
  55. data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
  56. data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
  57. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
  58. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
  59. data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
  60. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
  61. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
  62. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
  63. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
  64. data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
  65. data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
  66. data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
  67. data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
  68. data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
  69. data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
  70. data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
  71. data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
  72. data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
  73. data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
  74. data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
  75. data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
  76. data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
  77. data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
  78. data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
  79. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
  80. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
  81. data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
  82. data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
  83. data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
  84. data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
  85. data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
  86. data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
  87. data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
  88. data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
  89. data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
  90. data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
  91. data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
  92. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
  93. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
  94. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
  95. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
  96. data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
  97. data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
  98. data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
  99. data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
  100. data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
  101. data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
  102. data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
  103. data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
  104. data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
  105. data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
  106. data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
  107. data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
  108. data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
  109. data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
  110. data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
  111. data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
  112. data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
  113. data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
  114. data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
  115. data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
  116. data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
  117. data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
  118. data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
  119. data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
  120. data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
  121. data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
  122. data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
  123. data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
  124. data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
  125. data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
  126. data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
  127. data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
  128. data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
  129. data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
  130. data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
  131. data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
  132. data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
  133. data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
  134. data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
  135. data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
  136. data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
  137. data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
  138. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
  139. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
  140. data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
  141. data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
  142. data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
  143. data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
  144. data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
  145. data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
  146. data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
  147. data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
  148. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
  149. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
  150. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
  151. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
  152. data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
  153. data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
  154. data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
  155. data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
  156. data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
  157. data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
  158. data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
  159. data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
  160. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
  161. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
  162. data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
  163. data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
  164. data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
  165. data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
  166. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
  167. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
  168. data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
  169. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
  170. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
  171. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
  172. data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
  173. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
  174. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
  175. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
  176. data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
  177. data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
  178. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
  179. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
  180. data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
  181. data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
  182. data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
  183. data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
  184. data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
  185. data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
  186. data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
  187. data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
  188. data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
  189. data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
  190. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
  191. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
  192. data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
  193. data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
  194. data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
  195. data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
  196. data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
  197. data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
  198. data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
  199. data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
  200. data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
  201. data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
  202. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
  203. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
  204. data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
  205. data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
  206. data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
  207. data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
  208. data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
  209. metadata +204 -1
@@ -0,0 +1,228 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+
8
+ /**
9
+ * Snaps the vertices and segments of a {@link LineString} to a set of target
10
+ * snap vertices. A snap distance tolerance is used to control where snapping is
11
+ * performed.
12
+ * <p>
13
+ * The implementation handles empty geometry and empty snap vertex sets.
14
+ *
15
+ */
16
+
17
+ (function() {
18
+ /**
19
+ * Constructs a new LineStringSnapper based on provided arguments
20
+ *
21
+ * @constructor
22
+ */
23
+ var LineStringSnapper = function() {
24
+ this.snapTolerance = 0.0;
25
+ this.seg = new jsts.geom.LineSegment();
26
+ this.allowSnappingToSourceVertices = false;
27
+ this.isClosed = false;
28
+ this.srcPts = [];
29
+
30
+ if (arguments[0] instanceof jsts.geom.LineString) {
31
+ this.initFromLine.apply(this, arguments);
32
+ } else {
33
+ this.initFromPoints.apply(this, arguments);
34
+ }
35
+ };
36
+
37
+ /**
38
+ * Creates a new snapper using the points in the given {@link LineString} as
39
+ * source snap points.
40
+ *
41
+ * @param {jsts.geom.LineString}
42
+ * srcLine a LineString to snap (may be empty).
43
+ * @param {Number}
44
+ * snapTolerance the snap tolerance to use.
45
+ */
46
+ LineStringSnapper.prototype.initFromLine = function(srcLine, snapTolerance) {
47
+ this.initFromPoints(srcLine.getCoordinates(), snapTolerance);
48
+ };
49
+
50
+ /**
51
+ * Creates a new snapper using the given points as source points to be
52
+ * snapped.
53
+ *
54
+ * @param {Array{jsts.geom.Coordinate}}
55
+ * srcPts the points to snap
56
+ * @param {Number}
57
+ * snapTolerance the snap tolerance to use.
58
+ */
59
+ LineStringSnapper.prototype.initFromPoints = function(srcPts, snapTolerance) {
60
+ this.srcPts = srcPts;
61
+ this.isClosed = this.calcIsClosed(srcPts);
62
+ this.snapTolerance = snapTolerance;
63
+ };
64
+
65
+ LineStringSnapper.prototype.setAllowSnappingToSourceVertices = function(
66
+ allowSnappingToSourceVertices) {
67
+ this.allowSnappingToSourceVertices = allowSnappingToSourceVertices;
68
+ };
69
+
70
+ LineStringSnapper.prototype.calcIsClosed = function(pts) {
71
+ if (pts.length <= 1) {
72
+ return false;
73
+ }
74
+
75
+ return pts[0].equals(pts[pts.length - 1]);
76
+ };
77
+
78
+ /**
79
+ * Snaps the vertices and segments of the source LineString to the given set
80
+ * of snap vertices.
81
+ *
82
+ * @param {Array{Coordinate}}
83
+ * snapPts the vertices to snap to
84
+ * @return {Array{Coordinate}} a list of the snapped points
85
+ */
86
+ LineStringSnapper.prototype.snapTo = function(snapPts) {
87
+ var coordList = new jsts.geom.CoordinateList(this.srcPts);
88
+ this.snapVertices(coordList, snapPts);
89
+ this.snapSegments(coordList, snapPts);
90
+
91
+ return coordList.toCoordinateArray();
92
+ };
93
+
94
+ /**
95
+ * Snap source vertices to vertices in the target.
96
+ *
97
+ * @param {jsts.geom.CoordinateList}
98
+ * srcCoords the points to snap.
99
+ * @param {Array{Coordinate}}
100
+ * snapPts the points to snap to
101
+ */
102
+ LineStringSnapper.prototype.snapVertices = function(srcCoords, snapPts) {
103
+ // try snapping vertices
104
+ // if src is a ring then don't snap final vertex
105
+ var end = this.isClosed ? srcCoords.size() - 1 : srcCoords.size(), i = 0, srcPt, snapVert;
106
+ for (i; i < end; i++) {
107
+ srcPt = srcCoords.get(i);
108
+ snapVert = this.findSnapForVertex(srcPt, snapPts);
109
+ if (snapVert !== null) {
110
+ // update src with snap pt
111
+ srcCoords.set(i, new jsts.geom.Coordinate(snapVert));
112
+ // keep final closing point in synch (rings only)
113
+ if (i === 0 && this.isClosed)
114
+ srcCoords.set(srcCoords.size() - 1, new jsts.geom.Coordinate(snapVert));
115
+ }
116
+ }
117
+ };
118
+
119
+ LineStringSnapper.prototype.findSnapForVertex = function(pt, snapPts) {
120
+ var i = 0, il = snapPts.length;
121
+ for (i = 0; i < il; i++) {
122
+ // if point is already equal to a src pt, don't snap
123
+ if (pt.equals(snapPts[i])) {
124
+ return null;
125
+ }
126
+
127
+ if (pt.distance(snapPts[i]) < this.snapTolerance) {
128
+ return snapPts[i];
129
+ }
130
+ }
131
+ return null;
132
+ };
133
+
134
+ /**
135
+ * Snap segments of the source to nearby snap vertices. Source segments are
136
+ * "cracked" at a snap vertex. A single input segment may be snapped several
137
+ * times to different snap vertices.
138
+ * <p>
139
+ * For each distinct snap vertex, at most one source segment is snapped to.
140
+ * This prevents "cracking" multiple segments at the same point, which would
141
+ * likely cause topology collapse when being used on polygonal linework.
142
+ *
143
+ * @param {jsts.geom.CoordinateList}
144
+ * srcCoords the coordinates of the source linestring to be snapped.
145
+ * @param {Array{jsts.geom.Coordinate}}
146
+ * snapPts the target snap vertices
147
+ */
148
+ LineStringSnapper.prototype.snapSegments = function(srcCoords, snapPts) {
149
+ // guard against empty input
150
+ if (snapPts.length === 0) {
151
+ return;
152
+ }
153
+
154
+ var distinctPtCount = snapPts.length, i, snapPt, index;
155
+
156
+ // check for duplicate snap pts when they are sourced from a linear ring.
157
+ // TODO: Need to do this better - need to check *all* snap points for dups
158
+ // (using a Set?)
159
+ if (snapPts.length>1 && snapPts[0].equals2D(snapPts[snapPts.length - 1])) {
160
+ distinctPtCount = snapPts.length - 1;
161
+ }
162
+
163
+ i = 0;
164
+ for (i; i < distinctPtCount; i++) {
165
+ snapPt = snapPts[i];
166
+ index = this.findSegmentIndexToSnap(snapPt, srcCoords);
167
+ /**
168
+ * If a segment to snap to was found, "crack" it at the snap pt. The new
169
+ * pt is inserted immediately into the src segment list, so that
170
+ * subsequent snapping will take place on the modified segments. Duplicate
171
+ * points are not added.
172
+ */
173
+ if (index >= 0) {
174
+ srcCoords.add(index + 1, new jsts.geom.Coordinate(snapPt), false);
175
+ }
176
+ }
177
+ };
178
+
179
+ /**
180
+ * Finds a src segment which snaps to (is close to) the given snap point.
181
+ * <p>
182
+ * Only a single segment is selected for snapping. This prevents multiple
183
+ * segments snapping to the same snap vertex, which would almost certainly
184
+ * cause invalid geometry to be created. (The heuristic approach to snapping
185
+ * used here is really only appropriate when snap pts snap to a unique spot on
186
+ * the src geometry.)
187
+ * <p>
188
+ * Also, if the snap vertex occurs as a vertex in the src coordinate list, no
189
+ * snapping is performed.
190
+ *
191
+ * @param {jsts.geom.Coordinate}
192
+ * snapPt the point to snap to.
193
+ * @param {jsts.geom.CoordinateList}
194
+ * srcCoords the source segment coordinates.
195
+ * @return {Number} the index of the snapped segment.
196
+ * @return {Number} -1 if no segment snaps to the snap point.
197
+ */
198
+ LineStringSnapper.prototype.findSegmentIndexToSnap = function(snapPt,
199
+ srcCoords) {
200
+ var minDist = Number.MAX_VALUE, snapIndex = -1, i = 0, dist;
201
+ for (i; i < srcCoords.size() - 1; i++) {
202
+ this.seg.p0 = srcCoords.get(i);
203
+ this.seg.p1 = srcCoords.get(i + 1);
204
+
205
+ /**
206
+ * Check if the snap pt is equal to one of the segment endpoints.
207
+ *
208
+ * If the snap pt is already in the src list, don't snap at all.
209
+ */
210
+ if (this.seg.p0.equals(snapPt) || this.seg.p1.equals(snapPt)) {
211
+ if (this.allowSnappingToSourceVertices) {
212
+ continue;
213
+ } else {
214
+ return -1;
215
+ }
216
+ }
217
+
218
+ dist = this.seg.distance(snapPt);
219
+ if (dist < this.snapTolerance && dist < minDist) {
220
+ minDist = dist;
221
+ snapIndex = i;
222
+ }
223
+ }
224
+ return snapIndex;
225
+ };
226
+
227
+ jsts.operation.overlay.snap.LineStringSnapper = LineStringSnapper;
228
+ })();
@@ -0,0 +1,85 @@
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
+ (function() {
8
+
9
+ /**
10
+ * @requires jsts/operation/overlay/OverlayOp.js
11
+ * @requires jsts/operation/overlay/snap/SnapOverlayOp.js
12
+ */
13
+
14
+ var OverlayOp = jsts.operation.overlay.OverlayOp;
15
+ var SnapOverlayOp = jsts.operation.overlay.snap.SnapOverlayOp;
16
+
17
+ /**
18
+ * Performs an overlay operation using snapping and enhanced precision to
19
+ * improve the robustness of the result. This class only uses snapping if an
20
+ * error is detected when running the standard JTS overlay code. Errors
21
+ * detected include thrown exceptions (in particular,
22
+ * {@link TopologyException}) and invalid overlay computations.
23
+ */
24
+ var SnapIfNeededOverlayOp = function(g1, g2) {
25
+ this.geom = [];
26
+ this.geom[0] = g1;
27
+ this.geom[1] = g2;
28
+ };
29
+
30
+ SnapIfNeededOverlayOp.overlayOp = function(g0, g1, opCode) {
31
+ var op = new SnapIfNeededOverlayOp(g0, g1);
32
+ return op.getResultGeometry(opCode);
33
+ };
34
+
35
+ SnapIfNeededOverlayOp.intersection = function(g0, g1) {
36
+ return overlayOp(g0, g1, OverlayOp.INTERSECTION);
37
+ };
38
+
39
+ SnapIfNeededOverlayOp.union = function(g0, g1) {
40
+ return overlayOp(g0, g1, OverlayOp.UNION);
41
+ };
42
+
43
+ SnapIfNeededOverlayOp.difference = function(g0, g1) {
44
+ return overlayOp(g0, g1, OverlayOp.DIFFERENCE);
45
+ };
46
+
47
+ SnapIfNeededOverlayOp.symDifference = function(g0, g1) {
48
+ return overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE);
49
+ };
50
+
51
+ /**
52
+ * @private
53
+ * @type {Array.<jsts.geom.Geometry}
54
+ */
55
+ SnapIfNeededOverlayOp.prototype.geom = null;
56
+
57
+
58
+ SnapIfNeededOverlayOp.prototype.getResultGeometry = function(opCode) {
59
+ var result = null;
60
+ var isSuccess = false;
61
+ var savedException = null;
62
+ try {
63
+ result = OverlayOp.overlayOp(this.geom[0], this.geom[1], opCode);
64
+ var isValid = true;
65
+ if (isValid)
66
+ isSuccess = true;
67
+
68
+ } catch (ex) {
69
+ savedException = ex;
70
+ }
71
+ if (!isSuccess) {
72
+ // this may still throw an exception
73
+ // if so, throw the original exception since it has the input coordinates
74
+ try {
75
+ result = SnapOverlayOp.overlayOp(this.geom[0], this.geom[1], opCode);
76
+ } catch (ex) {
77
+ throw savedException;
78
+ }
79
+ }
80
+ return result;
81
+ };
82
+
83
+ jsts.operation.overlay.snap.SnapIfNeededOverlayOp = SnapIfNeededOverlayOp;
84
+
85
+ })();
@@ -0,0 +1,134 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ /**
8
+ * Port source:
9
+ * /jts/jts/java/src/com/vividsolutions/jts/operation/overlay/snap/SnapOverlayOp.java
10
+ * Revision: 150
11
+ */
12
+
13
+ /**
14
+ * @requires jsts/operation/overlay/snap/GeometrySnapper.js
15
+ * @requires jsts/operation/overlay/OverlayOp.js
16
+ * TODO: reenable when ported: requires jsts/precision/CommonBitsRemover.js
17
+ */
18
+
19
+ /**
20
+ * Performs an overlay operation using snapping and enhanced precision to
21
+ * improve the robustness of the result. This class <i>always</i> uses
22
+ * snapping. This is less performant than the standard JTS overlay code, and may
23
+ * even introduce errors which were not present in the original data. For this
24
+ * reason, this class should only be used if the standard overlay code fails to
25
+ * produce a correct result.
26
+ */
27
+
28
+ (function() {
29
+
30
+ var OverlayOp = jsts.operation.overlay.OverlayOp;
31
+ var GeometrySnapper = jsts.operation.overlay.snap.GeometrySnapper;
32
+
33
+ /**
34
+ * @constructor
35
+ */
36
+ var SnapOverlayOp = function(g1, g2) {
37
+ this.geom = [];
38
+ this.geom[0] = g1;
39
+ this.geom[1] = g2;
40
+ this.computeSnapTolerance();
41
+ };
42
+
43
+ SnapOverlayOp.overlayOp = function(g0, g1, opCode) {
44
+ var op = new SnapOverlayOp(g0, g1);
45
+ return op.getResultGeometry(opCode);
46
+ };
47
+
48
+ SnapOverlayOp.intersection = function(g0, g1) {
49
+ return this.overlayOp(g0, g1, OverlayOp.INTERSECTION);
50
+ };
51
+
52
+ SnapOverlayOp.union = function(g0, g1) {
53
+ return this.overlayOp(g0, g1, OverlayOp.UNION);
54
+ };
55
+
56
+ SnapOverlayOp.difference = function(g0, g1) {
57
+ return overlayOp(g0, g1, OverlayOp.DIFFERENCE);
58
+ };
59
+
60
+ SnapOverlayOp.symDifference = function(g0, g1) {
61
+ return overlayOp(g0, g1, OverlayOp.SYMDIFFERENCE);
62
+ };
63
+
64
+
65
+ SnapOverlayOp.prototype.geom = null;
66
+ SnapOverlayOp.prototype.snapTolerance = null;
67
+
68
+ /**
69
+ * @private
70
+ */
71
+ SnapOverlayOp.prototype.computeSnapTolerance = function() {
72
+ this.snapTolerance = GeometrySnapper.computeOverlaySnapTolerance(
73
+ this.geom[0], this.geom[1]);
74
+ };
75
+
76
+ SnapOverlayOp.prototype.getResultGeometry = function(opCode) {
77
+ var prepGeom = this.snap(this.geom);
78
+ var result = OverlayOp.overlayOp(prepGeom[0], prepGeom[1], opCode);
79
+ return this.prepareResult(result);
80
+ };
81
+
82
+ /**
83
+ * @private
84
+ */
85
+ SnapOverlayOp.prototype.selfSnap = function(geom) {
86
+ var snapper0 = new GeometrySnapper(geom);
87
+ var snapGeom = snapper0.snapTo(geom, this.snapTolerance);
88
+ return snapGeom;
89
+ };
90
+
91
+ /**
92
+ * @private
93
+ */
94
+ SnapOverlayOp.prototype.snap = function(geom) {
95
+ // TODO: CommonBitsRemover isn't ported yet...
96
+ var remGeom = geom;//this.removeCommonBits(geom);
97
+
98
+ var snapGeom = GeometrySnapper.snap(remGeom[0], remGeom[1],
99
+ this.snapTolerance);
100
+
101
+ return snapGeom;
102
+ };
103
+
104
+ /**
105
+ * @private
106
+ */
107
+ SnapOverlayOp.prototype.prepareResult = function(geom) {
108
+ // TODO: CommonBitsRemover isn't ported yet...
109
+ //this.cbr.addCommonBits(geom);
110
+ return geom;
111
+ };
112
+
113
+ /**
114
+ * @private
115
+ * @type {CommonBitsRemover}
116
+ */
117
+ SnapOverlayOp.prototype.cbr = null;
118
+
119
+ /**
120
+ * @private
121
+ */
122
+ SnapOverlayOp.prototype.removeCommonBits = function(geom) {
123
+ this.cbr = new jsts.precision.CommonBitsRemover();
124
+ this.cbr.add(this.geom[0]);
125
+ this.cbr.add(this.geom[1]);
126
+ var remGeom = [];
127
+ remGeom[0] = cbr.removeCommonBits(this.geom[0].clone());
128
+ remGeom[1] = cbr.removeCommonBits(this.geom[1].clone());
129
+ return remGeom;
130
+ };
131
+
132
+ jsts.operation.overlay.snap.SnapOverlayOp = SnapOverlayOp;
133
+
134
+ })();
@@ -0,0 +1,259 @@
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/operation/polygonize/EdgeRing.java
10
+ * Revision: 109
11
+ */
12
+
13
+ (function() {
14
+
15
+ /**
16
+ * Represents a ring of {@link PolygonizeDirectedEdge}s which form a ring of
17
+ * a polygon. The ring may be either an outer shell or a hole.
18
+ */
19
+ var EdgeRing = function(factory) {
20
+ this.deList = new javascript.util.ArrayList();
21
+
22
+ this.factory = factory;
23
+ };
24
+
25
+
26
+
27
+ /**
28
+ * Find the innermost enclosing shell EdgeRing containing the argument
29
+ * EdgeRing, if any. The innermost enclosing ring is the <i>smallest</i>
30
+ * enclosing ring. The algorithm used depends on the fact that: <br>
31
+ * ring A contains ring B iff envelope(ring A) contains envelope(ring B) <br>
32
+ * This routine is only safe to use if the chosen point of the hole is known
33
+ * to be properly contained in a shell (which is guaranteed to be the case if
34
+ * the hole does not touch its shell)
35
+ *
36
+ * @param {EdgeRing}
37
+ * testEr
38
+ * @param {List}
39
+ * shellList
40
+ *
41
+ * @return containing EdgeRing, if there is one.
42
+ * @return null if no containing EdgeRing is found.
43
+ */
44
+ EdgeRing.findEdgeRingContaining = function(testEr, shellList) {
45
+ var testRing = testEr.getRing();
46
+ var testEnv = testRing.getEnvelopeInternal();
47
+ var testPt = testRing.getCoordinateN(0);
48
+
49
+ var minShell = null;
50
+ var minEnv = null;
51
+ for (var it = shellList.iterator(); it.hasNext();) {
52
+ var tryShell = it.next();
53
+ var tryRing = tryShell.getRing();
54
+ var tryEnv = tryRing.getEnvelopeInternal();
55
+ if (minShell != null)
56
+ minEnv = minShell.getRing().getEnvelopeInternal();
57
+ var isContained = false;
58
+ // the hole envelope cannot equal the shell envelope
59
+ if (tryEnv.equals(testEnv))
60
+ continue;
61
+
62
+ testPt = jsts.geom.CoordinateArrays.ptNotInList(
63
+ testRing.getCoordinates(), tryRing.getCoordinates());
64
+ if (tryEnv.contains(testEnv) &&
65
+ jsts.algorithm.CGAlgorithms.isPointInRing(testPt, tryRing
66
+ .getCoordinates()))
67
+ isContained = true;
68
+ // check if this new containing ring is smaller than the current minimum
69
+ // ring
70
+ if (isContained) {
71
+ if (minShell == null || minEnv.contains(tryEnv)) {
72
+ minShell = tryShell;
73
+ }
74
+ }
75
+ }
76
+ return minShell;
77
+ };
78
+
79
+ /**
80
+ * Finds a point in a list of points which is not contained in another list of
81
+ * points
82
+ *
83
+ * @param {Coordinate[]}
84
+ * testPts the {@link Coordinate}s to test.
85
+ * @param {Coordinate[]}
86
+ * pts an array of {@link Coordinate}s to test the input points
87
+ * against.
88
+ * @return a {@link Coordinate} from <code>testPts</code> which is not in
89
+ * <code>pts</code>,.
90
+ * @return null if there is no coordinate not in the list.
91
+ */
92
+ EdgeRing.ptNotInList = function(testPts, pts) {
93
+ for (var i = 0; i < testPts.length; i++) {
94
+ var testPt = testPts[i];
95
+ if (!isInList(testPt, pts))
96
+ return testPt;
97
+ }
98
+ return null;
99
+ };
100
+
101
+ /**
102
+ * Tests whether a given point is in an array of points. Uses a value-based
103
+ * test.
104
+ *
105
+ * @param {Coordinate}
106
+ * pt a {@link Coordinate} for the test point.
107
+ * @param {Coordinate[]}
108
+ * pts an array of {@link Coordinate}s to test.
109
+ * @return <code>true</code> if the point is in the array.
110
+ */
111
+ EdgeRing.isInList = function(pt, pts) {
112
+ for (var i = 0; i < pts.length; i++) {
113
+ if (pt.equals(pts[i]))
114
+ return true;
115
+ }
116
+ return false;
117
+ }
118
+
119
+ EdgeRing.prototype.factory = null;
120
+
121
+ EdgeRing.prototype.deList = null;
122
+
123
+ // cache the following data for efficiency
124
+ EdgeRing.prototype.ring = null;
125
+
126
+ EdgeRing.prototype.ringPts = null;
127
+ EdgeRing.prototype.holes = null;
128
+
129
+ /**
130
+ * Adds a {@link DirectedEdge} which is known to form part of this ring.
131
+ *
132
+ * @param de
133
+ * the {@link DirectedEdge} to add.
134
+ */
135
+ EdgeRing.prototype.add = function(de) {
136
+ this.deList.add(de);
137
+ };
138
+
139
+ /**
140
+ * Tests whether this ring is a hole. Due to the way the edges in the
141
+ * polyongization graph are linked, a ring is a hole if it is oriented
142
+ * counter-clockwise.
143
+ *
144
+ * @return <code>true</code> if this ring is a hole.
145
+ */
146
+ EdgeRing.prototype.isHole = function() {
147
+ var ring = this.getRing();
148
+ return jsts.algorithm.CGAlgorithms.isCCW(ring.getCoordinates());
149
+ };
150
+
151
+ /**
152
+ * Adds a hole to the polygon formed by this ring.
153
+ *
154
+ * @param hole
155
+ * the {@link LinearRing} forming the hole.
156
+ */
157
+ EdgeRing.prototype.addHole = function(hole) {
158
+ if (this.holes == null)
159
+ this.holes = new javascript.util.ArrayList();
160
+ this.holes.add(hole);
161
+ };
162
+
163
+ /**
164
+ * Computes the {@link Polygon} formed by this ring and any contained holes.
165
+ *
166
+ * @return the {@link Polygon} formed by this ring and its holes.
167
+ */
168
+ EdgeRing.prototype.getPolygon = function() {
169
+ var holeLR = null;
170
+ if (this.holes != null) {
171
+ holeLR = [];
172
+ for (var i = 0; i < this.holes.size(); i++) {
173
+ holeLR[i] = this.holes.get(i);
174
+ }
175
+ }
176
+ var poly = this.factory.createPolygon(this.ring, holeLR);
177
+ return poly;
178
+ };
179
+
180
+ /**
181
+ * Tests if the {@link LinearRing} ring formed by this edge ring is
182
+ * topologically valid.
183
+ *
184
+ * @return true if the ring is valid.
185
+ */
186
+ EdgeRing.prototype.isValid = function() {
187
+ this.getCoordinates();
188
+ if (this.ringPts.length <= 3)
189
+ return false;
190
+ this.getRing();
191
+ return this.ring.isValid();
192
+ };
193
+
194
+ /**
195
+ * Computes the list of coordinates which are contained in this ring. The
196
+ * coordinatea are computed once only and cached.
197
+ *
198
+ * @return an array of the {@link Coordinate} s in this ring.
199
+ */
200
+ EdgeRing.prototype.getCoordinates = function() {
201
+ if (this.ringPts == null) {
202
+ var coordList = new jsts.geom.CoordinateList();
203
+ for (var i = this.deList.iterator(); i.hasNext();) {
204
+ var de = i.next();
205
+ var edge = de.getEdge();
206
+ EdgeRing.addEdge(edge.getLine().getCoordinates(), de.getEdgeDirection(),
207
+ coordList);
208
+ }
209
+ this.ringPts = coordList.toCoordinateArray();
210
+ }
211
+ return this.ringPts;
212
+ };
213
+
214
+ /**
215
+ * Gets the coordinates for this ring as a {@link LineString}. Used to return
216
+ * the coordinates in this ring as a valid geometry, when it has been detected
217
+ * that the ring is topologically invalid.
218
+ *
219
+ * @return a {@link LineString} containing the coordinates in this ring.
220
+ */
221
+ EdgeRing.prototype.getLineString = function() {
222
+ this.getCoordinates();
223
+ return this.factory.createLineString(this.ringPts);
224
+ };
225
+
226
+ /**
227
+ * Returns this ring as a {@link LinearRing}, or null if an Exception occurs
228
+ * while creating it (such as a topology problem). Details of problems are
229
+ * written to standard output.
230
+ */
231
+ EdgeRing.prototype.getRing = function() {
232
+ if (this.ring != null)
233
+ return this.ring;
234
+ this.getCoordinates();
235
+ if (this.ringPts.length < 3)
236
+ console.log(this.ringPts);
237
+ try {
238
+ this.ring = this.factory.createLinearRing(this.ringPts);
239
+ } catch (ex) {
240
+ console.log(this.ringPts);
241
+ }
242
+ return this.ring;
243
+ };
244
+
245
+ EdgeRing.addEdge = function(coords, isForward, coordList) {
246
+ if (isForward) {
247
+ for (var i = 0; i < coords.length; i++) {
248
+ coordList.add(coords[i], false);
249
+ }
250
+ } else {
251
+ for (var i = coords.length - 1; i >= 0; i--) {
252
+ coordList.add(coords[i], false);
253
+ }
254
+ }
255
+ };
256
+
257
+ jsts.operation.polygonize.EdgeRing = EdgeRing;
258
+
259
+ })();