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,246 @@
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/planargraph/PlanarGraph.java
10
+ * Revision: 107
11
+ */
12
+
13
+ /**
14
+ * @requires jsts/planargraph/NodeMap.js
15
+ */
16
+
17
+ (function() {
18
+
19
+ var ArrayList = javascript.util.ArrayList;
20
+
21
+
22
+ /**
23
+ * Represents a directed graph which is embeddable in a planar surface.
24
+ * <p>
25
+ * This class and the other classes in this package serve as a framework for
26
+ * building planar graphs for specific algorithms. This class must be
27
+ * subclassed to expose appropriate methods to construct the graph. This
28
+ * allows controlling the types of graph components ({@link DirectedEdge}s,
29
+ * {@link Edge}s and {@link Node}s) which can be added to the graph. An
30
+ * application which uses the graph framework will almost always provide
31
+ * subclasses for one or more graph components, which hold
32
+ * application-specific data and graph algorithms.
33
+ *
34
+ * Constructs a empty graph.
35
+ */
36
+ var PlanarGraph = function() {
37
+ this.edges = new javascript.util.HashSet();
38
+ this.dirEdges = new javascript.util.HashSet();
39
+ this.nodeMap = new jsts.planargraph.NodeMap();
40
+ };
41
+
42
+
43
+ PlanarGraph.prototype.edges = null;
44
+ PlanarGraph.prototype.dirEdges = null;
45
+ PlanarGraph.prototype.nodeMap = null;
46
+
47
+
48
+ /**
49
+ * Returns the {@link Node} at the given location, or null if no {@link Node}
50
+ * was there.
51
+ *
52
+ * @param pt
53
+ * the location to query.
54
+ * @return the node found.
55
+ * @return <code>null</code> if this graph contains no node at the location.
56
+ */
57
+ PlanarGraph.prototype.findNode = function(pt) {
58
+ return this.nodeMap.find(pt);
59
+ };
60
+
61
+ /**
62
+ * Adds a node to the map, replacing any that is already at that location.
63
+ * Only subclasses can add Nodes, to ensure Nodes are of the right type.
64
+ *
65
+ * @param node
66
+ * the node to add.
67
+ */
68
+ PlanarGraph.prototype.add = function(node) {
69
+ if (node instanceof jsts.planargraph.Edge) {
70
+ return this.add2(node);
71
+ } else if (node instanceof jsts.planargraph.DirectedEdge) {
72
+ return this.add3(node);
73
+ }
74
+
75
+ this.nodeMap.add(node);
76
+ };
77
+
78
+ /**
79
+ * Adds the Edge and its DirectedEdges with this PlanarGraph. Assumes that the
80
+ * Edge has already been created with its associated DirectEdges. Only
81
+ * subclasses can add Edges, to ensure the edges added are of the right class.
82
+ */
83
+ PlanarGraph.prototype.add2 = function(edge) {
84
+ this.edges.add(edge);
85
+ this.add(edge.getDirEdge(0));
86
+ this.add(edge.getDirEdge(1));
87
+ };
88
+
89
+ /**
90
+ * Adds the Edge to this PlanarGraph; only subclasses can add DirectedEdges,
91
+ * to ensure the edges added are of the right class.
92
+ */
93
+ PlanarGraph.prototype.add3 = function(dirEdge) {
94
+ this.dirEdges.add(dirEdge);
95
+ };
96
+
97
+ /**
98
+ * Returns an Iterator over the Nodes in this PlanarGraph.
99
+ */
100
+ PlanarGraph.prototype.nodeIterator = function() {
101
+ return this.nodeMap.iterator();
102
+ };
103
+
104
+ /**
105
+ * Returns the Nodes in this PlanarGraph.
106
+ */
107
+
108
+ /**
109
+ * Tests whether this graph contains the given {@link Edge}
110
+ *
111
+ * @param e
112
+ * the edge to query.
113
+ * @return <code>true</code> if the graph contains the edge.
114
+ */
115
+ PlanarGraph.prototype.contains = function(e) {
116
+ if (e instanceof jsts.planargraph.DirectedEdge) {
117
+ return this.contains2(e);
118
+ }
119
+
120
+ return this.edges.contains(e);
121
+ };
122
+
123
+ /**
124
+ * Tests whether this graph contains the given {@link DirectedEdge}
125
+ *
126
+ * @param de
127
+ * the directed edge to query.
128
+ * @return <code>true</code> if the graph contains the directed edge.
129
+ */
130
+ PlanarGraph.prototype.contains2 = function(de) {
131
+ return this.dirEdges.contains(de);
132
+ };
133
+
134
+ PlanarGraph.prototype.getNodes = function() {
135
+ return this.nodeMap.values();
136
+ };
137
+
138
+ /**
139
+ * Returns an Iterator over the DirectedEdges in this PlanarGraph, in the
140
+ * order in which they were added.
141
+ *
142
+ * @see #add(Edge)
143
+ * @see #add(DirectedEdge)
144
+ */
145
+ PlanarGraph.prototype.dirEdgeIterator = function() {
146
+ return this.dirEdges.iterator();
147
+ };
148
+ /**
149
+ * Returns an Iterator over the Edges in this PlanarGraph, in the order in
150
+ * which they were added.
151
+ *
152
+ * @see #add(Edge)
153
+ */
154
+ PlanarGraph.prototype.edgeIterator = function() {
155
+ return this.edges.iterator();
156
+ };
157
+
158
+ /**
159
+ * Returns the Edges that have been added to this PlanarGraph
160
+ *
161
+ * @see #add(Edge)
162
+ */
163
+ PlanarGraph.prototype.getEdges = function() {
164
+ return this.edges;
165
+ };
166
+
167
+ /**
168
+ * Removes an {@link Edge} and its associated {@link DirectedEdge}s from
169
+ * their from-Nodes and from the graph. Note: This method does not remove the
170
+ * {@link Node}s associated with the {@link Edge}, even if the removal of
171
+ * the {@link Edge} reduces the degree of a {@link Node} to zero.
172
+ */
173
+ PlanarGraph.prototype.remove = function(edge) {
174
+ if (edge instanceof jsts.planargraph.DirectedEdge) {
175
+ return this.remove2(edge);
176
+ }
177
+
178
+ this.remove(edge.getDirEdge(0));
179
+ this.remove(edge.getDirEdge(1));
180
+ this.edges.remove(edge);
181
+ this.edge.remove();
182
+ };
183
+
184
+ /**
185
+ * Removes a {@link DirectedEdge} from its from-{@link Node} and from this
186
+ * graph. This method does not remove the {@link Node}s associated with the
187
+ * DirectedEdge, even if the removal of the DirectedEdge reduces the degree of
188
+ * a Node to zero.
189
+ */
190
+ PlanarGraph.prototype.remove2 = function(de) {
191
+ if (de instanceof jsts.planargraph.Node) {
192
+ return this.remove3(de);
193
+ }
194
+
195
+ var sym = de.getSym();
196
+ if (sym != null)
197
+ sym.setSym(null);
198
+
199
+ de.getFromNode().remove(de);
200
+ de.remove();
201
+ this.dirEdges.remove(de);
202
+ };
203
+
204
+ /**
205
+ * Removes a node from the graph, along with any associated DirectedEdges and
206
+ * Edges.
207
+ */
208
+ PlanarGraph.prototype.remove3 = function(node) {
209
+ // unhook all directed edges
210
+ var outEdges = node.getOutEdges().getEdges();
211
+ for (var i = outEdges.iterator(); i.hasNext();) {
212
+ var de = i.next();
213
+ var sym = de.getSym();
214
+ // remove the diredge that points to this node
215
+ if (sym != null)
216
+ this.remove(sym);
217
+ // remove this diredge from the graph collection
218
+ this.dirEdges.remove(de);
219
+
220
+ var edge = de.getEdge();
221
+ if (edge != null) {
222
+ this.edges.remove(edge);
223
+ }
224
+
225
+ }
226
+ // remove the node from the graph
227
+ this.nodeMap.remove(node.getCoordinate());
228
+ node.remove();
229
+ };
230
+
231
+ /**
232
+ * Returns all Nodes with the given number of Edges around it.
233
+ */
234
+ PlanarGraph.prototype.findNodesOfDegree = function(degree) {
235
+ var nodesFound = new ArrayList();
236
+ for (var i = this.nodeIterator(); i.hasNext();) {
237
+ var node = i.next();
238
+ if (node.getDegree() == degree)
239
+ nodesFound.add(node);
240
+ }
241
+ return nodesFound;
242
+ };
243
+
244
+ jsts.planargraph.PlanarGraph = PlanarGraph;
245
+
246
+ })();
@@ -0,0 +1,101 @@
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
+ * An spatial index on a set of {@link LineSegment}s. Supports adding and
10
+ * removing items.
11
+ *
12
+ * @author Martin Davis
13
+ */
14
+ jsts.simplify.LineSegmentIndex = function() {
15
+ this.index = new jsts.index.quadtree.Quadtree();
16
+ };
17
+
18
+ /**
19
+ * @private
20
+ */
21
+ jsts.simplify.LineSegmentIndex.prototype.index = null;
22
+
23
+ /**
24
+ * @param {TaggedLineString}
25
+ * line
26
+ */
27
+ jsts.simplify.LineSegmentIndex.prototype.add = function(line) {
28
+ if (line instanceof jsts.geom.LineSegment) {
29
+ this.add2(line);
30
+ return;
31
+ }
32
+
33
+ var segs = line.getSegments();
34
+ for (var i = 0; i < segs.length; i++) {
35
+ var seg = segs[i];
36
+ this.add2(seg);
37
+ }
38
+ };
39
+
40
+ /**
41
+ * @param {LineSegment}
42
+ * seg
43
+ */
44
+ jsts.simplify.LineSegmentIndex.prototype.add2 = function(seg) {
45
+ this.index.insert(new jsts.geom.Envelope(seg.p0, seg.p1), seg);
46
+ };
47
+ /**
48
+ * @param {LineSegment}
49
+ * seg
50
+ */
51
+ jsts.simplify.LineSegmentIndex.prototype.remove = function(seg) {
52
+ this.index.remove(new jsts.geom.Envelope(seg.p0, seg.p1), seg);
53
+ };
54
+
55
+ /**
56
+ * @param {LineSegment}
57
+ * querySeg
58
+ * @return {Array}
59
+ */
60
+ jsts.simplify.LineSegmentIndex.prototype.query = function(querySeg) {
61
+ var env = new jsts.geom.Envelope(querySeg.p0, querySeg.p1);
62
+
63
+ var visitor = new jsts.simplify.LineSegmentIndex.LineSegmentVisitor(querySeg);
64
+ this.index.query(env, visitor);
65
+ var itemsFound = visitor.getItems();
66
+
67
+ return itemsFound;
68
+ };
69
+
70
+
71
+ /**
72
+ * @requires jsts/index/ItemVisitor.js
73
+ */
74
+ /**
75
+ * ItemVisitor subclass to reduce volume of query results.
76
+ *
77
+ * @implements {jsts.index.ItemVisitor}
78
+ */
79
+ jsts.simplify.LineSegmentIndex.LineSegmentVisitor = function(querySeg) {
80
+ this.items = [];
81
+
82
+ this.querySeg = querySeg;
83
+ };
84
+
85
+
86
+ jsts.simplify.LineSegmentIndex.LineSegmentVisitor.prototype = new jsts.index.ItemVisitor();
87
+
88
+ // MD - only seems to make about a 10% difference in overall time.
89
+ jsts.simplify.LineSegmentIndex.LineSegmentVisitor.prototype.querySeg = null;
90
+ jsts.simplify.LineSegmentIndex.LineSegmentVisitor.prototype.items = null;
91
+
92
+ jsts.simplify.LineSegmentIndex.LineSegmentVisitor.prototype.visitItem = function(
93
+ item) {
94
+ var seg = item;
95
+ if (jsts.geom.Envelope.intersects(seg.p0, seg.p1, this.querySeg.p0, this.querySeg.p1))
96
+ this.items.push(item);
97
+ };
98
+
99
+ jsts.simplify.LineSegmentIndex.LineSegmentVisitor.prototype.getItems = function() {
100
+ return this.items;
101
+ };
@@ -0,0 +1,224 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+
8
+
9
+ /**
10
+ * A utility class which creates Delaunay Trianglulations from collections of
11
+ * points and extract the resulting triangulation edges or triangles as
12
+ * geometries.
13
+ *
14
+ * Initializes a new DelaunayTriangulationBuilder
15
+ *
16
+ * @constructor
17
+ */
18
+ jsts.triangulate.DelaunayTriangulationBuilder = function() {
19
+
20
+ this.siteCoords = null;
21
+ this.tolerance = 0.0;
22
+ this.subdiv = null;
23
+ };
24
+
25
+
26
+ /**
27
+ * Extracts the unique {@link Coordinate}s from the given {@link Geometry}.
28
+ *
29
+ * @param {jsts.geom.Geometry}
30
+ * geom the geometry to extract from.
31
+ * @return {Array{jsts.geom.Coordinate}} An array of the unique Coordinates
32
+ */
33
+ jsts.triangulate.DelaunayTriangulationBuilder.extractUniqueCoordinates = function(
34
+ geom) {
35
+ if (geom === undefined || geom === null) {
36
+ return new jsts.geom.CoordinateList([], false).toArray();
37
+ }
38
+
39
+ var coords = geom.getCoordinates();
40
+ return jsts.triangulate.DelaunayTriangulationBuilder.unique(coords);
41
+ };
42
+
43
+
44
+ /**
45
+ * Removes any duplicates in the passed array.
46
+ *
47
+ * @param {Array{jsts.geom.Coordinate}}
48
+ * coords The input coordinates
49
+ * @return {Array{jsts.geom.Coordinate}} An array stripped out of any duplicates
50
+ */
51
+ jsts.triangulate.DelaunayTriangulationBuilder.unique = function(coords) {
52
+ // Sort the coordinates by their compareTo-function
53
+ coords.sort(function(a, b) {
54
+ return a.compareTo(b);
55
+ });
56
+
57
+ var coordList = new jsts.geom.CoordinateList(coords, false);
58
+ return coordList.toArray();
59
+ };
60
+
61
+
62
+ /**
63
+ * Converts an array of coordinates to an array of vertexes
64
+ *
65
+ * @param {Array{jsts.geom.Coordinate}}
66
+ * coords the input coordinates
67
+ * @return {Array{jsts.triangulate.quadedge.Vertex}} The created vertexes
68
+ */
69
+ jsts.triangulate.DelaunayTriangulationBuilder.toVertices = function(coords) {
70
+ var verts = new Array(coords.length), i = 0, il = coords.length, coord;
71
+
72
+ for (i; i < il; i++) {
73
+ coord = coords[i];
74
+ verts[i] = new jsts.triangulate.quadedge.Vertex(coord);
75
+ }
76
+
77
+ return verts;
78
+ };
79
+
80
+
81
+ /**
82
+ * Computes the {jsts.geom.Envelope} of an array of {jsts.geom.Coordinate}s
83
+ *
84
+ * @param {Array{jsts.geom.Coordinate}}
85
+ * coords the input coordinates
86
+ * @return {jsts.geom.Envelope} The created envelope.
87
+ *
88
+ */
89
+ jsts.triangulate.DelaunayTriangulationBuilder.envelope = function(coords) {
90
+ var env = new jsts.geom.Envelope(), i = 0, il = coords.length;
91
+
92
+ for (i; i < il; i++) {
93
+ env.expandToInclude(coords[i]);
94
+ }
95
+
96
+ return env;
97
+ };
98
+
99
+
100
+ /**
101
+ * Sets the sites which will be triangulated. Calls the correct setSites*
102
+ * function after argument-checking
103
+ */
104
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.setSites = function() {
105
+ var arg = arguments[0];
106
+
107
+ if (arg instanceof jsts.geom.Geometry ||
108
+ arg instanceof jsts.geom.Coordinate || arg instanceof jsts.geom.Point ||
109
+ arg instanceof jsts.geom.MultiPoint ||
110
+ arg instanceof jsts.geom.LineString ||
111
+ arg instanceof jsts.geom.MultiLineString ||
112
+ arg instanceof jsts.geom.LinearRing || arg instanceof jsts.geom.Polygon ||
113
+ arg instanceof jsts.geom.MultiPolygon) {
114
+ this.setSitesFromGeometry(arg);
115
+ } else {
116
+ this.setSitesFromCollection(arg);
117
+ }
118
+ };
119
+
120
+
121
+ /**
122
+ * Sets the sites (point or vertices) which will be triangulated. All vertices
123
+ * of the given geometry will be used as sites.
124
+ *
125
+ * @param {jsts.geom.Geometry}
126
+ * geom the geometry from which the sites will be extracted.
127
+ */
128
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.setSitesFromGeometry = function(
129
+ geom) {
130
+ // remove any duplicate points (they will cause the triangulation to fail)
131
+ this.siteCoords = jsts.triangulate.DelaunayTriangulationBuilder
132
+ .extractUniqueCoordinates(geom);
133
+ };
134
+
135
+
136
+ /**
137
+ * Sets the sites (point or vertices) which will be triangulated from a
138
+ * collection of {@link Coordinate}s.
139
+ *
140
+ * @param {Array{Coordinates}}
141
+ * coords a collection of Coordinates.
142
+ */
143
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.setSitesFromCollection = function(
144
+ coords) {
145
+ // remove any duplicate points (they will cause the triangulation to fail)
146
+ this.siteCoords = jsts.triangulate.DelaunayTriangulationBuilder.unique(coords);
147
+ };
148
+
149
+
150
+ /**
151
+ * Sets the snapping tolerance which will be used to improved the robustness of
152
+ * the triangulation computation. A tolerance of 0.0 specifies that no snapping
153
+ * will take place.
154
+ *
155
+ * @param {Number}
156
+ * tolerance the tolerance distance to use.
157
+ */
158
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.setTolerance = function(
159
+ tolerance) {
160
+ this.tolerance = tolerance;
161
+ };
162
+
163
+
164
+ /**
165
+ * Creates the Delaunay-triangulation.
166
+ *
167
+ */
168
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.create = function() {
169
+ if (this.subdiv === null) {
170
+ var siteEnv, vertices, triangulator;
171
+
172
+ siteEnv = jsts.triangulate.DelaunayTriangulationBuilder
173
+ .envelope(this.siteCoords);
174
+ vertices = jsts.triangulate.DelaunayTriangulationBuilder
175
+ .toVertices(this.siteCoords);
176
+ this.subdiv = new jsts.triangulate.quadedge.QuadEdgeSubdivision(siteEnv,
177
+ this.tolerance);
178
+ triangulator = new jsts.triangulate.IncrementalDelaunayTriangulator(
179
+ this.subdiv);
180
+ triangulator.insertSites(vertices);
181
+ }
182
+ };
183
+
184
+
185
+ /**
186
+ * Gets the {jsts.triangulate.quadedge.QuadEdgeSubdivision} which models the
187
+ * computed triangulation.
188
+ *
189
+ * @return {jsts.triangulate.quadedge.QuadEdgeSubdivision} containing the
190
+ * triangulation.
191
+ */
192
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.getSubdivision = function() {
193
+ this.create();
194
+ return this.subdiv;
195
+ };
196
+
197
+
198
+ /**
199
+ * Gets the edges of the computed triangulation as a {@link MultiLineString}.
200
+ *
201
+ * @param {jsts.geom.GeometryFactory}
202
+ * geomFact the geometry factory to use to create the output.
203
+ * @return {jsts.geom.Geometry} the edges of the triangulation.
204
+ */
205
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.getEdges = function(
206
+ geomFact) {
207
+ this.create();
208
+ return this.subdiv.getEdges(geomFact);
209
+ };
210
+
211
+
212
+ /**
213
+ * Gets the faces of the computed triangulation as a {@link GeometryCollection}
214
+ * of {@link Polygon}.
215
+ *
216
+ * @param {jsts.geom.GeometryFactory}
217
+ * geomFact the geometry factory to use to create the output.
218
+ * @return {jsts.geom.Geometry} the faces of the triangulation.
219
+ */
220
+ jsts.triangulate.DelaunayTriangulationBuilder.prototype.getTriangles = function(
221
+ geomFact) {
222
+ this.create();
223
+ return this.subdiv.getTriangles(geomFact);
224
+ };