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,111 @@
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
+ (function() {
9
+
10
+ /**
11
+ * @requires jsts/util/Assert.js
12
+ */
13
+
14
+ var ArrayList = javascript.util.ArrayList;
15
+ var TreeMap = javascript.util.TreeMap;
16
+
17
+ /**
18
+ * A EdgeList is a list of Edges. It supports locating edges that are
19
+ * pointwise equals to a target edge.
20
+ *
21
+ * @constructor
22
+ */
23
+ jsts.geomgraph.EdgeList = function() {
24
+ this.edges = new ArrayList();
25
+ this.ocaMap = new TreeMap();
26
+ };
27
+
28
+
29
+ /**
30
+ * @type {javascript.util.ArrayList}
31
+ * @private
32
+ */
33
+ jsts.geomgraph.EdgeList.prototype.edges = null;
34
+
35
+
36
+ /**
37
+ * An index of the edges, for fast lookup.
38
+ *
39
+ * @type {javascript.util.HashMap}
40
+ * @private
41
+ */
42
+ jsts.geomgraph.EdgeList.prototype.ocaMap = null;
43
+
44
+
45
+ /**
46
+ * Insert an edge unless it is already in the list
47
+ */
48
+ jsts.geomgraph.EdgeList.prototype.add = function(e) {
49
+ this.edges.add(e);
50
+ var oca = new jsts.noding.OrientedCoordinateArray(e.getCoordinates());
51
+ this.ocaMap.put(oca, e);
52
+ };
53
+
54
+ jsts.geomgraph.EdgeList.prototype.addAll = function(edgeColl) {
55
+ for (var i = edgeColl.iterator(); i.hasNext();) {
56
+ this.add(i.next());
57
+ }
58
+ };
59
+
60
+
61
+ /**
62
+ * @return {javascript.util.List}
63
+ */
64
+ jsts.geomgraph.EdgeList.prototype.getEdges = function() {
65
+ return this.edges;
66
+ };
67
+
68
+
69
+ /**
70
+ * If there is an edge equal to e already in the list, return it. Otherwise
71
+ * return null.
72
+ *
73
+ * @param {Edge}
74
+ * e
75
+ * @return {Edge} equal edge, if there is one already in the list null
76
+ * otherwise.
77
+ */
78
+ jsts.geomgraph.EdgeList.prototype.findEqualEdge = function(e) {
79
+ var oca = new jsts.noding.OrientedCoordinateArray(e.getCoordinates());
80
+ // will return null if no edge matches
81
+ var matchEdge = this.ocaMap.get(oca);
82
+ return matchEdge;
83
+ };
84
+
85
+ jsts.geomgraph.EdgeList.prototype.getEdges = function() {
86
+ return this.edges;
87
+ };
88
+
89
+ jsts.geomgraph.EdgeList.prototype.iterator = function() {
90
+ return this.edges.iterator();
91
+ };
92
+
93
+ jsts.geomgraph.EdgeList.prototype.get = function(i) {
94
+ return this.edges.get(i);
95
+ };
96
+
97
+
98
+ /**
99
+ * If the edge e is already in the list, return its index.
100
+ *
101
+ * @return {Number} index, if e is already in the list -1 otherwise.
102
+ */
103
+ jsts.geomgraph.EdgeList.prototype.findEdgeIndex = function(e) {
104
+ for (var i = 0; i < this.edges.size(); i++) {
105
+ if (this.edges.get(i).equals(e))
106
+ return i;
107
+ }
108
+ return -1;
109
+ };
110
+
111
+ })();
@@ -0,0 +1,76 @@
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/noding/FastNodingValidator.js
11
+ * @requires jsts/noding/BasicSegmentString.js
12
+ */
13
+
14
+ var FastNodingValidator = jsts.noding.FastNodingValidator;
15
+ var BasicSegmentString = jsts.noding.BasicSegmentString;
16
+ var ArrayList = javascript.util.ArrayList;
17
+
18
+ /**
19
+ * Validates that a collection of {@link Edge}s is correctly noded. Throws an
20
+ * appropriate exception if an noding error is found.
21
+ *
22
+ * Creates a new validator for the given collection of {@link Edge}s.
23
+ *
24
+ * @param edges
25
+ * a collection of Edges.
26
+ */
27
+ jsts.geomgraph.EdgeNodingValidator = function(edges) {
28
+ this.nv = new FastNodingValidator(jsts.geomgraph.EdgeNodingValidator
29
+ .toSegmentStrings(edges));
30
+ };
31
+
32
+ /**
33
+ * Checks whether the supplied {@link Edge}s are correctly noded. Throws a
34
+ * {@link TopologyException} if they are not.
35
+ *
36
+ * @param edges
37
+ * a collection of Edges.
38
+ * @throws TopologyException
39
+ * if the SegmentStrings are not correctly noded
40
+ *
41
+ */
42
+ jsts.geomgraph.EdgeNodingValidator.checkValid = function(edges) {
43
+ var validator = new jsts.geomgraph.EdgeNodingValidator(edges);
44
+ validator.checkValid();
45
+ };
46
+
47
+ jsts.geomgraph.EdgeNodingValidator.toSegmentStrings = function(edges) {
48
+ // convert Edges to SegmentStrings
49
+ var segStrings = new ArrayList();
50
+ for (var i = edges.iterator(); i.hasNext();) {
51
+ var e = i.next();
52
+ segStrings.add(new BasicSegmentString(e.getCoordinates(), e));
53
+ }
54
+ return segStrings;
55
+ };
56
+
57
+ /**
58
+ * @type {jsts.noding.FastNodingValidator}
59
+ * @private
60
+ */
61
+ jsts.geomgraph.EdgeNodingValidator.prototype.nv = null;
62
+
63
+
64
+ /**
65
+ * Checks whether the supplied edges are correctly noded. Throws an exception
66
+ * if they are not.
67
+ *
68
+ * @throws TopologyException
69
+ * if the SegmentStrings are not correctly noded
70
+ *
71
+ */
72
+ jsts.geomgraph.EdgeNodingValidator.prototype.checkValid = function() {
73
+ this.nv.checkValid();
74
+ };
75
+
76
+ })();
@@ -0,0 +1,230 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ /**
8
+ * @requires jsts/geomgraph/Label.js
9
+ */
10
+
11
+ /**
12
+ * Port source: com.vividsolutions.jts.geomgraph.EdgeRing r6
13
+ *
14
+ * @constructor
15
+ */
16
+ jsts.geomgraph.EdgeRing = function(start, geometryFactory) {
17
+ this.edges = [];
18
+ this.pts = [];
19
+ this.holes = [];
20
+ this.label = new jsts.geomgraph.Label(jsts.geom.Location.NONE);
21
+
22
+ this.geometryFactory = geometryFactory;
23
+
24
+ if (start) {
25
+ this.computePoints(start);
26
+ this.computeRing();
27
+ }
28
+ };
29
+
30
+ jsts.geomgraph.EdgeRing.prototype.startDe = null; // the directed edge which
31
+ // starts the list of edges
32
+ // for this EdgeRing
33
+ jsts.geomgraph.EdgeRing.prototype.maxNodeDegree = -1;
34
+ jsts.geomgraph.EdgeRing.prototype.edges = null; // the DirectedEdges making up
35
+ // this EdgeRing
36
+ jsts.geomgraph.EdgeRing.prototype.pts = null;
37
+ jsts.geomgraph.EdgeRing.prototype.label = null; // label stores the locations of
38
+ // each geometry on the face
39
+ // surrounded by this ring
40
+ jsts.geomgraph.EdgeRing.prototype.ring = null; // the ring created for this
41
+ // EdgeRing
42
+ jsts.geomgraph.EdgeRing.prototype._isHole = null;
43
+ jsts.geomgraph.EdgeRing.prototype.shell = null; // if non-null, the ring is a
44
+ // hole and this EdgeRing is its
45
+ // containing shell
46
+ jsts.geomgraph.EdgeRing.prototype.holes = null; // a list of EdgeRings which are
47
+ // holes in this EdgeRing
48
+
49
+ jsts.geomgraph.EdgeRing.prototype.geometryFactory = null;
50
+
51
+ jsts.geomgraph.EdgeRing.prototype.isIsolated = function() {
52
+ return (this.label.getGeometryCount() == 1);
53
+ };
54
+ jsts.geomgraph.EdgeRing.prototype.isHole = function() {
55
+ return this._isHole;
56
+ };
57
+
58
+ jsts.geomgraph.EdgeRing.prototype.getCoordinate = function(i) {
59
+ return this.pts[i];
60
+ };
61
+ jsts.geomgraph.EdgeRing.prototype.getLinearRing = function() { return this.ring; };
62
+ jsts.geomgraph.EdgeRing.prototype.getLabel = function() {
63
+ return this.label;
64
+ };
65
+ jsts.geomgraph.EdgeRing.prototype.isShell = function() {
66
+ return this.shell === null;
67
+ };
68
+ jsts.geomgraph.EdgeRing.prototype.getShell = function() {
69
+ return this.shell;
70
+ };
71
+ jsts.geomgraph.EdgeRing.prototype.setShell = function(shell) {
72
+ this.shell = shell;
73
+ if (shell !== null)
74
+ shell.addHole(this);
75
+ };
76
+ jsts.geomgraph.EdgeRing.prototype.addHole = function(ring) {
77
+ this.holes.push(ring);
78
+ };
79
+
80
+ jsts.geomgraph.EdgeRing.prototype.toPolygon = function(geometryFactory) {
81
+ var holeLR = [];
82
+ for (var i = 0; i < this.holes.length; i++) {
83
+ holeLR[i] = this.holes[i].getLinearRing();
84
+ }
85
+ var poly = this.geometryFactory.createPolygon(this.getLinearRing(), holeLR);
86
+ return poly;
87
+ };
88
+ /**
89
+ * Compute a LinearRing from the point list previously collected. Test if the
90
+ * ring is a hole (i.e. if it is CCW) and set the hole flag accordingly.
91
+ */
92
+ jsts.geomgraph.EdgeRing.prototype.computeRing = function() {
93
+ if (this.ring !== null)
94
+ return; // don't compute more than once
95
+ var coord = [];
96
+ for (var i = 0; i < this.pts.length; i++) {
97
+ coord[i] = this.pts[i];
98
+ }
99
+ this.ring = this.geometryFactory.createLinearRing(coord);
100
+ this._isHole = jsts.algorithm.CGAlgorithms.isCCW(this.ring.getCoordinates());
101
+ };
102
+ jsts.geomgraph.EdgeRing.prototype.getNext = function(de) {
103
+ throw new jsts.error.AbstractInvocationError();
104
+ };
105
+ jsts.geomgraph.EdgeRing.prototype.setEdgeRing = function(de, er) {
106
+ throw new jsts.error.AbstractInvocationError();
107
+ };
108
+ /**
109
+ * Returns the list of DirectedEdges that make up this EdgeRing
110
+ */
111
+ jsts.geomgraph.EdgeRing.prototype.getEdges = function() {
112
+ return this.edges;
113
+ };
114
+
115
+ /**
116
+ * Collect all the points from the DirectedEdges of this ring into a contiguous
117
+ * list
118
+ */
119
+ jsts.geomgraph.EdgeRing.prototype.computePoints = function(start) {
120
+ this.startDe = start;
121
+ var de = start;
122
+ var isFirstEdge = true;
123
+ do {
124
+ if (de === null)
125
+ throw new jsts.error.TopologyError('Found null DirectedEdge');
126
+ if (de.getEdgeRing() === this)
127
+ throw new jsts.error.TopologyError(
128
+ 'Directed Edge visited twice during ring-building at ' +
129
+ de.getCoordinate());
130
+
131
+ this.edges.push(de);
132
+ var label = de.getLabel();
133
+ jsts.util.Assert.isTrue(label.isArea());
134
+ this.mergeLabel(label);
135
+ this.addPoints(de.getEdge(), de.isForward(), isFirstEdge);
136
+ isFirstEdge = false;
137
+ this.setEdgeRing(de, this);
138
+ de = this.getNext(de);
139
+ } while (de !== this.startDe);
140
+ };
141
+
142
+ jsts.geomgraph.EdgeRing.prototype.getMaxNodeDegree = function() {
143
+ if (this.maxNodeDegree < 0)
144
+ this.computeMaxNodeDegree();
145
+ return this.maxNodeDegree;
146
+ };
147
+
148
+ jsts.geomgraph.EdgeRing.prototype.computeMaxNodeDegree = function() {
149
+ this.maxNodeDegree = 0;
150
+ var de = this.startDe;
151
+ do {
152
+ var node = de.getNode();
153
+ var degree = node.getEdges().getOutgoingDegree(this);
154
+ if (degree > this.maxNodeDegree)
155
+ this.maxNodeDegree = degree;
156
+ de = this.getNext(de);
157
+ } while (de !== this.startDe);
158
+ this.maxNodeDegree *= 2;
159
+ };
160
+
161
+
162
+ jsts.geomgraph.EdgeRing.prototype.setInResult = function() {
163
+ var de = this.startDe;
164
+ do {
165
+ de.getEdge().setInResult(true);
166
+ de = de.getNext();
167
+ } while (de != this.startDe);
168
+ };
169
+
170
+ jsts.geomgraph.EdgeRing.prototype.mergeLabel = function(deLabel) {
171
+ this.mergeLabel2(deLabel, 0);
172
+ this.mergeLabel2(deLabel, 1);
173
+ };
174
+ /**
175
+ * Merge the RHS label from a DirectedEdge into the label for this EdgeRing. The
176
+ * DirectedEdge label may be null. This is acceptable - it results from a node
177
+ * which is NOT an intersection node between the Geometries (e.g. the end node
178
+ * of a LinearRing). In this case the DirectedEdge label does not contribute any
179
+ * information to the overall labelling, and is simply skipped.
180
+ */
181
+ jsts.geomgraph.EdgeRing.prototype.mergeLabel2 = function(deLabel, geomIndex) {
182
+ var loc = deLabel.getLocation(geomIndex, jsts.geomgraph.Position.RIGHT);
183
+ // no information to be had from this label
184
+ if (loc == jsts.geom.Location.NONE)
185
+ return;
186
+ // if there is no current RHS value, set it
187
+ if (this.label.getLocation(geomIndex) === jsts.geom.Location.NONE) {
188
+ this.label.setLocation(geomIndex, loc);
189
+ return;
190
+ }
191
+ };
192
+ jsts.geomgraph.EdgeRing.prototype.addPoints = function(edge, isForward,
193
+ isFirstEdge) {
194
+ var edgePts = edge.getCoordinates();
195
+ if (isForward) {
196
+ var startIndex = 1;
197
+ if (isFirstEdge)
198
+ startIndex = 0;
199
+ for (var i = startIndex; i < edgePts.length; i++) {
200
+ this.pts.push(edgePts[i]);
201
+ }
202
+ } else { // is backward
203
+ var startIndex = edgePts.length - 2;
204
+ if (isFirstEdge)
205
+ startIndex = edgePts.length - 1;
206
+ for (var i = startIndex; i >= 0; i--) {
207
+ this.pts.push(edgePts[i]);
208
+ }
209
+ }
210
+ };
211
+
212
+ /**
213
+ * This method will cause the ring to be computed. It will also check any holes,
214
+ * if they have been assigned.
215
+ */
216
+ jsts.geomgraph.EdgeRing.prototype.containsPoint = function(p) {
217
+ var shell = this.getLinearRing();
218
+ var env = shell.getEnvelopeInternal();
219
+ if (!env.contains(p))
220
+ return false;
221
+ if (!jsts.algorithm.CGAlgorithms.isPointInRing(p, shell.getCoordinates()))
222
+ return false;
223
+
224
+ for (var i = 0; i < this.holes.length; i++) {
225
+ var hole = this.holes[i];
226
+ if (hole.containsPoint(p))
227
+ return false;
228
+ }
229
+ return true;
230
+ };
@@ -0,0 +1,469 @@
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/geom/Location.js
11
+ * @requires jsts/geomgraph/Position.js
12
+ * @requires jsts/geomgraph/PlanarGraph.js
13
+ * @requires jsts/util/Assert.js
14
+ */
15
+
16
+ var Location = jsts.geom.Location;
17
+ var Position = jsts.geomgraph.Position;
18
+ var Assert = jsts.util.Assert;
19
+
20
+
21
+
22
+ /**
23
+ * A GeometryGraph is a graph that models a given Geometry
24
+ *
25
+ * @param {int}
26
+ * argIndex
27
+ * @param {Geometry}
28
+ * parentGeom
29
+ * @param {BoundaryNodeRule}
30
+ * boundaryNodeRule
31
+ * @augments jsts.planargraph.PlanarGraph
32
+ */
33
+ jsts.geomgraph.GeometryGraph = function(argIndex, parentGeom,
34
+ boundaryNodeRule) {
35
+ jsts.geomgraph.PlanarGraph.call(this);
36
+
37
+ this.lineEdgeMap = new javascript.util.HashMap();
38
+
39
+ this.ptLocator = new jsts.algorithm.PointLocator();
40
+
41
+ this.argIndex = argIndex;
42
+ this.parentGeom = parentGeom;
43
+ this.boundaryNodeRule = boundaryNodeRule ||
44
+ jsts.algorithm.BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
45
+ if (parentGeom !== null) {
46
+ this.add(parentGeom);
47
+ }
48
+ };
49
+
50
+ jsts.geomgraph.GeometryGraph.prototype = new jsts.geomgraph.PlanarGraph();
51
+ jsts.geomgraph.GeometryGraph.constructor = jsts.geomgraph.GeometryGraph;
52
+
53
+ /**
54
+ * @return {EdgeSetIntersector}
55
+ * @private
56
+ */
57
+ jsts.geomgraph.GeometryGraph.prototype.createEdgeSetIntersector = function() {
58
+ return new jsts.geomgraph.index.SimpleEdgeSetIntersector();
59
+ // TODO: use optimized version when ported
60
+ // return new jsts.geomgraph.index.SimpleMCSweepLineIntersector();
61
+ };
62
+
63
+ /**
64
+ * @param {BoundaryNodeRule}
65
+ * boundaryNodeRule
66
+ * @param {int}
67
+ * boundaryCount
68
+ * @return {int}
69
+ */
70
+ jsts.geomgraph.GeometryGraph.determineBoundary = function(boundaryNodeRule,
71
+ boundaryCount) {
72
+ return boundaryNodeRule.isInBoundary(boundaryCount) ? Location.BOUNDARY
73
+ : Location.INTERIOR;
74
+ };
75
+
76
+
77
+ /**
78
+ * @type {Geometry}
79
+ */
80
+ jsts.geomgraph.GeometryGraph.prototype.parentGeom = null;
81
+
82
+
83
+ /**
84
+ * The lineEdgeMap is a map of the linestring components of the parentGeometry
85
+ * to the edges which are derived from them. This is used to efficiently
86
+ * perform findEdge queries
87
+ *
88
+ * @type {Object}
89
+ * @private
90
+ */
91
+ jsts.geomgraph.GeometryGraph.prototype.lineEdgeMap = null;
92
+
93
+
94
+ /**
95
+ * @type {BoundaryNodeRule}
96
+ */
97
+ jsts.geomgraph.GeometryGraph.prototype.boundaryNodeRule = null;
98
+
99
+
100
+ /**
101
+ * If this flag is true, the Boundary Determination Rule will used when
102
+ * deciding whether nodes are in the boundary or not
103
+ */
104
+ /**
105
+ * @type {boolean}
106
+ * @private
107
+ */
108
+ jsts.geomgraph.GeometryGraph.prototype.useBoundaryDeterminationRule = true;
109
+
110
+
111
+ /**
112
+ * the index of this geometry as an argument to a spatial function (used for
113
+ * labelling)
114
+ *
115
+ * @type {number}
116
+ * @private
117
+ */
118
+ jsts.geomgraph.GeometryGraph.prototype.argIndex = null;
119
+
120
+
121
+ /**
122
+ * @type {javascript.util.Collection}
123
+ * @private
124
+ */
125
+ jsts.geomgraph.GeometryGraph.prototype.boundaryNodes = null;
126
+
127
+
128
+ /**
129
+ * @type {Coordinate}
130
+ * @private
131
+ */
132
+ jsts.geomgraph.GeometryGraph.prototype.hasTooFewPoints = false;
133
+
134
+
135
+ /**
136
+ * @type {Coordinate}
137
+ * @private
138
+ */
139
+ jsts.geomgraph.GeometryGraph.prototype.invalidPoint = null;
140
+
141
+
142
+ /**
143
+ * @type {PointOnGeometryLocator}
144
+ * @private
145
+ */
146
+ jsts.geomgraph.GeometryGraph.prototype.areaPtLocator = null;
147
+
148
+
149
+ /**
150
+ * for use if geometry is not Polygonal
151
+ *
152
+ * @type {PointLocator}
153
+ * @private
154
+ */
155
+ jsts.geomgraph.GeometryGraph.prototype.ptLocator = null;
156
+
157
+
158
+ jsts.geomgraph.GeometryGraph.prototype.getGeometry = function() {
159
+ return this.parentGeom;
160
+ };
161
+
162
+ jsts.geomgraph.GeometryGraph.prototype.getBoundaryNodes = function() {
163
+ if (this.boundaryNodes === null)
164
+ this.boundaryNodes = this.nodes.getBoundaryNodes(this.argIndex);
165
+ return this.boundaryNodes;
166
+ };
167
+
168
+ jsts.geomgraph.GeometryGraph.prototype.getBoundaryNodeRule = function() {
169
+ return this.boundaryNodeRule;
170
+ };
171
+
172
+
173
+
174
+ jsts.geomgraph.GeometryGraph.prototype.findEdge = function(line) {
175
+ return this.lineEdgeMap.get(line);
176
+ };
177
+
178
+ jsts.geomgraph.GeometryGraph.prototype.computeSplitEdges = function(edgelist) {
179
+ for (var i = this.edges.iterator(); i.hasNext();) {
180
+ var e = i.next();
181
+ e.eiList.addSplitEdges(edgelist);
182
+ }
183
+ }
184
+
185
+ /**
186
+ * @param {Geometry}
187
+ * g
188
+ */
189
+ jsts.geomgraph.GeometryGraph.prototype.add = function(g) {
190
+ if (g.isEmpty()) {
191
+ return;
192
+ }
193
+
194
+ // check if this Geometry should obey the Boundary Determination Rule
195
+ // all collections except MultiPolygons obey the rule
196
+ if (g instanceof jsts.geom.MultiPolygon)
197
+ this.useBoundaryDeterminationRule = false;
198
+
199
+ if (g instanceof jsts.geom.Polygon)
200
+ this.addPolygon(g);
201
+ // LineString also handles LinearRings
202
+ else if (g instanceof jsts.geom.LineString)
203
+ this.addLineString(g);
204
+ else if (g instanceof jsts.geom.Point)
205
+ this.addPoint(g);
206
+ else if (g instanceof jsts.geom.MultiPoint)
207
+ this.addCollection(g);
208
+ else if (g instanceof jsts.geom.MultiLineString)
209
+ this.addCollection(g);
210
+ else if (g instanceof jsts.geom.MultiPolygon)
211
+ this.addCollection(g);
212
+ else if (g instanceof jsts.geom.GeometryCollection)
213
+ this.addCollection(g);
214
+ else
215
+ throw new jsts.error.IllegalArgumentError('Geometry type not supported.');
216
+ };
217
+
218
+
219
+ /**
220
+ * @private
221
+ */
222
+ jsts.geomgraph.GeometryGraph.prototype.addCollection = function(gc) {
223
+ for (var i = 0; i < gc.getNumGeometries(); i++) {
224
+ var g = gc.getGeometryN(i);
225
+ this.add(g);
226
+ }
227
+ };
228
+
229
+
230
+ /**
231
+ * Add an Edge computed externally. The label on the Edge is assumed to be
232
+ * correct.
233
+ */
234
+ jsts.geomgraph.GeometryGraph.prototype.addEdge = function(e) {
235
+ this.insertEdge(e);
236
+ var coord = e.getCoordinates();
237
+ // insert the endpoint as a node, to mark that it is on the boundary
238
+ this.insertPoint(this.argIndex, coord[0], Location.BOUNDARY);
239
+ this.insertPoint(this.argIndex, coord[coord.length - 1], Location.BOUNDARY);
240
+ };
241
+
242
+
243
+ /**
244
+ * Add a Point to the graph.
245
+ */
246
+ jsts.geomgraph.GeometryGraph.prototype.addPoint = function(p) {
247
+ var coord = p.getCoordinate();
248
+ this.insertPoint(this.argIndex, coord, Location.INTERIOR);
249
+ };
250
+
251
+
252
+ /**
253
+ * @param {LineString}
254
+ * line
255
+ * @private
256
+ */
257
+ jsts.geomgraph.GeometryGraph.prototype.addLineString = function(line) {
258
+ var coord = jsts.geom.CoordinateArrays.removeRepeatedPoints(line
259
+ .getCoordinates());
260
+
261
+ if (coord.length < 2) {
262
+ this.hasTooFewPoints = true;
263
+ this.invalidPoint = coords[0];
264
+ return;
265
+ }
266
+
267
+ // add the edge for the LineString
268
+ // line edges do not have locations for their left and right sides
269
+ var e = new jsts.geomgraph.Edge(coord, new jsts.geomgraph.Label(
270
+ this.argIndex, Location.INTERIOR));
271
+ this.lineEdgeMap.put(line, e);
272
+ this.insertEdge(e);
273
+ /**
274
+ * Add the boundary points of the LineString, if any. Even if the LineString
275
+ * is closed, add both points as if they were endpoints. This allows for the
276
+ * case that the node already exists and is a boundary point.
277
+ */
278
+ Assert.isTrue(coord.length >= 2, 'found LineString with single point');
279
+ this.insertBoundaryPoint(this.argIndex, coord[0]);
280
+ this.insertBoundaryPoint(this.argIndex, coord[coord.length - 1]);
281
+ };
282
+
283
+
284
+ /**
285
+ * Adds a polygon ring to the graph. Empty rings are ignored.
286
+ *
287
+ * The left and right topological location arguments assume that the ring is
288
+ * oriented CW. If the ring is in the opposite orientation, the left and right
289
+ * locations must be interchanged.
290
+ *
291
+ * @private
292
+ */
293
+ jsts.geomgraph.GeometryGraph.prototype.addPolygonRing = function(lr, cwLeft,
294
+ cwRight) {
295
+ // don't bother adding empty holes
296
+ if (lr.isEmpty())
297
+ return;
298
+
299
+ var coord = jsts.geom.CoordinateArrays.removeRepeatedPoints(lr
300
+ .getCoordinates());
301
+
302
+ if (coord.length < 4) {
303
+ this.hasTooFewPoints = true;
304
+ this.invalidPoint = coord[0];
305
+ return;
306
+ }
307
+
308
+ var left = cwLeft;
309
+ var right = cwRight;
310
+ if (jsts.algorithm.CGAlgorithms.isCCW(coord)) {
311
+ left = cwRight;
312
+ right = cwLeft;
313
+ }
314
+ var e = new jsts.geomgraph.Edge(coord, new jsts.geomgraph.Label(
315
+ this.argIndex, Location.BOUNDARY, left, right));
316
+ this.lineEdgeMap.put(lr, e);
317
+
318
+ this.insertEdge(e);
319
+ // insert the endpoint as a node, to mark that it is on the boundary
320
+ this.insertPoint(this.argIndex, coord[0], Location.BOUNDARY);
321
+ };
322
+
323
+
324
+ /**
325
+ * @private
326
+ */
327
+ jsts.geomgraph.GeometryGraph.prototype.addPolygon = function(p) {
328
+ this.addPolygonRing(p.getExteriorRing(), Location.EXTERIOR,
329
+ Location.INTERIOR);
330
+
331
+ for (var i = 0; i < p.getNumInteriorRing(); i++) {
332
+ var hole = p.getInteriorRingN(i);
333
+
334
+ // Holes are topologically labelled opposite to the shell, since
335
+ // the interior of the polygon lies on their opposite side
336
+ // (on the left, if the hole is oriented CW)
337
+ this.addPolygonRing(hole, Location.INTERIOR, Location.EXTERIOR);
338
+ }
339
+ };
340
+
341
+
342
+ jsts.geomgraph.GeometryGraph.prototype.computeEdgeIntersections = function(g,
343
+ li, includeProper) {
344
+ var si = new jsts.geomgraph.index.SegmentIntersector(li, includeProper,
345
+ true);
346
+ si.setBoundaryNodes(this.getBoundaryNodes(), g.getBoundaryNodes());
347
+
348
+ var esi = this.createEdgeSetIntersector();
349
+ esi.computeIntersections(this.edges, g.edges, si);
350
+
351
+ return si;
352
+ };
353
+
354
+
355
+ /**
356
+ * Compute self-nodes, taking advantage of the Geometry type to minimize the
357
+ * number of intersection tests. (E.g. rings are not tested for
358
+ * self-intersection, since they are assumed to be valid).
359
+ *
360
+ * @param {LineIntersector}
361
+ * li the LineIntersector to use.
362
+ * @param {boolean}
363
+ * computeRingSelfNodes if <false>, intersection checks are optimized
364
+ * to not test rings for self-intersection.
365
+ * @return {SegmentIntersector} the SegmentIntersector used, containing
366
+ * information about the intersections found.
367
+ */
368
+ jsts.geomgraph.GeometryGraph.prototype.computeSelfNodes = function(li,
369
+ computeRingSelfNodes) {
370
+ var si = new jsts.geomgraph.index.SegmentIntersector(li, true, false);
371
+ var esi = this.createEdgeSetIntersector();
372
+ // optimized test for Polygons and Rings
373
+ if (!computeRingSelfNodes &&
374
+ (this.parentGeom instanceof jsts.geom.LinearRing ||
375
+ this.parentGeom instanceof jsts.geom.Polygon || this.parentGeom instanceof jsts.geom.MultiPolygon)) {
376
+ esi.computeIntersections(this.edges, si, false);
377
+ } else {
378
+ esi.computeIntersections(this.edges, si, true);
379
+ }
380
+ this.addSelfIntersectionNodes(this.argIndex);
381
+ return si;
382
+ };
383
+
384
+
385
+ /**
386
+ * @private
387
+ */
388
+ jsts.geomgraph.GeometryGraph.prototype.insertPoint = function(argIndex,
389
+ coord, onLocation) {
390
+ var n = this.nodes.addNode(coord);
391
+ var lbl = n.getLabel();
392
+ if (lbl == null) {
393
+ n.label = new jsts.geomgraph.Label(argIndex, onLocation);
394
+ } else
395
+ lbl.setLocation(argIndex, onLocation);
396
+ };
397
+
398
+
399
+ /**
400
+ * Adds candidate boundary points using the current {@link BoundaryNodeRule}.
401
+ * This is used to add the boundary points of dim-1 geometries
402
+ * (Curves/MultiCurves).
403
+ */
404
+ jsts.geomgraph.GeometryGraph.prototype.insertBoundaryPoint = function(
405
+ argIndex, coord) {
406
+ var n = this.nodes.addNode(coord);
407
+ var lbl = n.getLabel();
408
+ // the new point to insert is on a boundary
409
+ var boundaryCount = 1;
410
+ // determine the current location for the point (if any)
411
+ var loc = Location.NONE;
412
+ if (lbl !== null)
413
+ loc = lbl.getLocation(argIndex, Position.ON);
414
+ if (loc === Location.BOUNDARY)
415
+ boundaryCount++;
416
+
417
+ // determine the boundary status of the point according to the Boundary
418
+ // Determination Rule
419
+ var newLoc = jsts.geomgraph.GeometryGraph.determineBoundary(
420
+ this.boundaryNodeRule, boundaryCount);
421
+ lbl.setLocation(argIndex, newLoc);
422
+ };
423
+
424
+
425
+ /**
426
+ * add edge intersections as self intersections from each edge intersection
427
+ * list
428
+ *
429
+ * @param argIndex
430
+ * @private
431
+ */
432
+ jsts.geomgraph.GeometryGraph.prototype.addSelfIntersectionNodes = function(
433
+ argIndex) {
434
+ for (var i = this.edges.iterator(); i.hasNext();) {
435
+ var e = i.next();
436
+ var eLoc = e.getLabel().getLocation(argIndex);
437
+ for (var eiIt = e.eiList.iterator(); eiIt.hasNext();) {
438
+ var ei = eiIt.next();
439
+ this.addSelfIntersectionNode(argIndex, ei.coord, eLoc);
440
+ }
441
+ }
442
+ };
443
+
444
+
445
+ /**
446
+ * Add a node for a self-intersection. If the node is a potential boundary
447
+ * node (e.g. came from an edge which is a boundary) then insert it as a
448
+ * potential boundary node. Otherwise, just add it as a regular node.
449
+ *
450
+ * @private
451
+ */
452
+ jsts.geomgraph.GeometryGraph.prototype.addSelfIntersectionNode = function(
453
+ argIndex, coord, loc) {
454
+ // if this node is already a boundary node, don't change it
455
+ if (this.isBoundaryNode(argIndex, coord))
456
+ return;
457
+ if (loc === Location.BOUNDARY && this.useBoundaryDeterminationRule)
458
+ this.insertBoundaryPoint(argIndex, coord);
459
+ else
460
+ this.insertPoint(argIndex, coord, loc);
461
+ };
462
+
463
+ jsts.geomgraph.GeometryGraph.prototype.getInvalidPoint = function() {
464
+ return this.invalidPoint;
465
+ };
466
+
467
+ })();
468
+
469
+ // TODO: port rest of class