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,270 @@
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/EdgeEnd.js
13
+ */
14
+
15
+ var Location = jsts.geom.Location;
16
+ var Position = jsts.geomgraph.Position;
17
+ var EdgeEnd = jsts.geomgraph.EdgeEnd;
18
+
19
+
20
+ /**
21
+ * @constructor
22
+ * @extends jsts.geomgraph.EdgeEnd
23
+ */
24
+ jsts.geomgraph.DirectedEdge = function(edge, isForward) {
25
+ EdgeEnd.call(this, edge);
26
+
27
+ this.depth = [0, -999, -999];
28
+
29
+ this._isForward = isForward;
30
+ if (isForward) {
31
+ this.init(edge.getCoordinate(0), edge.getCoordinate(1));
32
+ } else {
33
+ var n = edge.getNumPoints() - 1;
34
+ this.init(edge.getCoordinate(n), edge.getCoordinate(n - 1));
35
+ }
36
+ this.computeDirectedLabel();
37
+
38
+ };
39
+ jsts.geomgraph.DirectedEdge.prototype = new EdgeEnd();
40
+ jsts.geomgraph.DirectedEdge.constructor = jsts.geomgraph.DirectedEdge;
41
+
42
+
43
+ /**
44
+ * Computes the factor for the change in depth when moving from one location
45
+ * to another. E.g. if crossing from the INTERIOR to the EXTERIOR the depth
46
+ * decreases, so the factor is -1
47
+ */
48
+ jsts.geomgraph.DirectedEdge.depthFactor = function(currLocation, nextLocation) {
49
+ if (currLocation === Location.EXTERIOR &&
50
+ nextLocation === Location.INTERIOR)
51
+ return 1;
52
+ else if (currLocation === Location.INTERIOR &&
53
+ nextLocation === Location.EXTERIOR)
54
+ return -1;
55
+ return 0;
56
+ };
57
+
58
+ /**
59
+ * @type {boolean}
60
+ * @protected
61
+ */
62
+ jsts.geomgraph.DirectedEdge.prototype._isForward = null;
63
+ /**
64
+ * @type {boolean}
65
+ * @private
66
+ */
67
+ jsts.geomgraph.DirectedEdge.prototype._isInResult = false;
68
+ /**
69
+ * @type {boolean}
70
+ * @private
71
+ */
72
+ jsts.geomgraph.DirectedEdge.prototype._isVisited = false;
73
+
74
+ /**
75
+ * the symmetric edge
76
+ *
77
+ * @type {DirectedEdge}
78
+ * @private
79
+ */
80
+ jsts.geomgraph.DirectedEdge.prototype.sym = null;
81
+ /**
82
+ * the next edge in the edge ring for the polygon containing this edge
83
+ *
84
+ * @type {DirectedEdge}
85
+ * @private
86
+ */
87
+ jsts.geomgraph.DirectedEdge.prototype.next = null;
88
+ /**
89
+ * the next edge in the MinimalEdgeRing that contains this edge
90
+ *
91
+ * @type {DirectedEdge}
92
+ * @private
93
+ */
94
+ jsts.geomgraph.DirectedEdge.prototype.nextMin = null;
95
+ /**
96
+ * the EdgeRing that this edge is part of
97
+ *
98
+ * @type {EdgeRing}
99
+ * @private
100
+ */
101
+ jsts.geomgraph.DirectedEdge.prototype.edgeRing = null;
102
+ /**
103
+ * the MinimalEdgeRing that this edge is part of
104
+ *
105
+ * @type {EdgeRing}
106
+ * @private
107
+ */
108
+ jsts.geomgraph.DirectedEdge.prototype.minEdgeRing = null;
109
+ /**
110
+ * The depth of each side (position) of this edge. The 0 element of the array
111
+ * is never used.
112
+ *
113
+ * @type {Array.<number>}
114
+ */
115
+ jsts.geomgraph.DirectedEdge.prototype.depth = null;
116
+
117
+ jsts.geomgraph.DirectedEdge.prototype.getEdge = function() {
118
+ return this.edge;
119
+ };
120
+ jsts.geomgraph.DirectedEdge.prototype.setInResult = function(isInResult) {
121
+ this._isInResult = isInResult;
122
+ };
123
+ jsts.geomgraph.DirectedEdge.prototype.isInResult = function() {
124
+ return this._isInResult;
125
+ };
126
+ jsts.geomgraph.DirectedEdge.prototype.isVisited = function() {
127
+ return this._isVisited;
128
+ };
129
+ jsts.geomgraph.DirectedEdge.prototype.setVisited = function(isVisited) {
130
+ this._isVisited = isVisited;
131
+ };
132
+ jsts.geomgraph.DirectedEdge.prototype.setEdgeRing = function(edgeRing) {
133
+ this.edgeRing = edgeRing;
134
+ };
135
+ jsts.geomgraph.DirectedEdge.prototype.getEdgeRing = function() {
136
+ return this.edgeRing;
137
+ };
138
+ jsts.geomgraph.DirectedEdge.prototype.setMinEdgeRing = function(minEdgeRing) {
139
+ this.minEdgeRing = minEdgeRing;
140
+ };
141
+ jsts.geomgraph.DirectedEdge.prototype.getMinEdgeRing = function() { return this.minEdgeRing; };
142
+ jsts.geomgraph.DirectedEdge.prototype.getDepth = function(position) {
143
+ return this.depth[position];
144
+ };
145
+
146
+ jsts.geomgraph.DirectedEdge.prototype.setDepth = function(position, depthVal) {
147
+ if (this.depth[position] !== -999) {
148
+ if (this.depth[position] !== depthVal)
149
+ throw new jsts.error.TopologyError('assigned depths do not match', this
150
+ .getCoordinate());
151
+ }
152
+ this.depth[position] = depthVal;
153
+ };
154
+
155
+ jsts.geomgraph.DirectedEdge.prototype.getDepthDelta = function() {
156
+ var depthDelta = this.edge.getDepthDelta();
157
+ if (!this._isForward)
158
+ depthDelta = -depthDelta;
159
+ return depthDelta;
160
+ };
161
+
162
+ /**
163
+ * setVisitedEdge marks both DirectedEdges attached to a given Edge. This is
164
+ * used for edges corresponding to lines, which will only appear oriented in a
165
+ * single direction in the result.
166
+ */
167
+ jsts.geomgraph.DirectedEdge.prototype.setVisitedEdge = function(isVisited) {
168
+ this.setVisited(isVisited);
169
+ this.sym.setVisited(isVisited);
170
+ };
171
+ /**
172
+ * Each Edge gives rise to a pair of symmetric DirectedEdges, in opposite
173
+ * directions.
174
+ *
175
+ * @return the DirectedEdge for the same Edge but in the opposite direction.
176
+ */
177
+ jsts.geomgraph.DirectedEdge.prototype.getSym = function() {
178
+ return this.sym;
179
+ };
180
+ jsts.geomgraph.DirectedEdge.prototype.isForward = function() {
181
+ return this._isForward;
182
+ };
183
+ jsts.geomgraph.DirectedEdge.prototype.setSym = function(de) {
184
+ this.sym = de;
185
+ };
186
+ jsts.geomgraph.DirectedEdge.prototype.getNext = function() {
187
+ return this.next;
188
+ };
189
+ jsts.geomgraph.DirectedEdge.prototype.setNext = function(next) {
190
+ this.next = next;
191
+ };
192
+ jsts.geomgraph.DirectedEdge.prototype.getNextMin = function() {
193
+ return this.nextMin;
194
+ };
195
+ jsts.geomgraph.DirectedEdge.prototype.setNextMin = function(nextMin) {
196
+ this.nextMin = nextMin;
197
+ };
198
+
199
+ /**
200
+ * This edge is a line edge if
201
+ * <ul>
202
+ * <li> at least one of the labels is a line label
203
+ * <li> any labels which are not line labels have all Locations = EXTERIOR
204
+ * </ul>
205
+ */
206
+ jsts.geomgraph.DirectedEdge.prototype.isLineEdge = function() {
207
+ var isLine = this.label.isLine(0) || this.label.isLine(1);
208
+ var isExteriorIfArea0 = !this.label.isArea(0) ||
209
+ this.label.allPositionsEqual(0, Location.EXTERIOR);
210
+ var isExteriorIfArea1 = !this.label.isArea(1) ||
211
+ this.label.allPositionsEqual(1, Location.EXTERIOR);
212
+
213
+ return isLine && isExteriorIfArea0 && isExteriorIfArea1;
214
+ };
215
+ /**
216
+ * This is an interior Area edge if
217
+ * <ul>
218
+ * <li> its label is an Area label for both Geometries
219
+ * <li> and for each Geometry both sides are in the interior.
220
+ * </ul>
221
+ *
222
+ * @return true if this is an interior Area edge.
223
+ */
224
+ jsts.geomgraph.DirectedEdge.prototype.isInteriorAreaEdge = function() {
225
+ var isInteriorAreaEdge = true;
226
+ for (var i = 0; i < 2; i++) {
227
+ if (!(this.label.isArea(i) &&
228
+ this.label.getLocation(i, Position.LEFT) === Location.INTERIOR && this.label
229
+ .getLocation(i, Position.RIGHT) === Location.INTERIOR)) {
230
+ isInteriorAreaEdge = false;
231
+ }
232
+ }
233
+ return isInteriorAreaEdge;
234
+ };
235
+
236
+ /**
237
+ * Compute the label in the appropriate orientation for this DirEdge
238
+ *
239
+ * @private
240
+ */
241
+ jsts.geomgraph.DirectedEdge.prototype.computeDirectedLabel = function() {
242
+ this.label = new jsts.geomgraph.Label(this.edge.getLabel());
243
+ if (!this._isForward)
244
+ this.label.flip();
245
+ };
246
+
247
+ /**
248
+ * Set both edge depths. One depth for a given side is provided. The other is
249
+ * computed depending on the Location transition and the depthDelta of the
250
+ * edge.
251
+ */
252
+ jsts.geomgraph.DirectedEdge.prototype.setEdgeDepths = function(position, depth) {
253
+ // get the depth transition delta from R to L for this directed Edge
254
+ var depthDelta = this.getEdge().getDepthDelta();
255
+ if (!this._isForward)
256
+ depthDelta = -depthDelta;
257
+
258
+ // if moving from L to R instead of R to L must change sign of delta
259
+ var directionFactor = 1;
260
+ if (position === Position.LEFT)
261
+ directionFactor = -1;
262
+
263
+ var oppositePos = Position.opposite(position);
264
+ var delta = depthDelta * directionFactor;
265
+ var oppositeDepth = depth + delta;
266
+ this.setDepth(position, depth);
267
+ this.setDepth(oppositePos, oppositeDepth);
268
+ };
269
+
270
+ })();
@@ -0,0 +1,388 @@
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/EdgeEndStar.js
13
+ * @requires jsts/util/Assert.js
14
+ */
15
+
16
+ var Location = jsts.geom.Location;
17
+ var Position = jsts.geomgraph.Position;
18
+ var EdgeEndStar = jsts.geomgraph.EdgeEndStar;
19
+ var Assert = jsts.util.Assert;
20
+
21
+
22
+ /**
23
+ * A DirectedEdgeStar is an ordered list of <b>outgoing</b> DirectedEdges
24
+ * around a node. It supports labelling the edges as well as linking the edges
25
+ * to form both MaximalEdgeRings and MinimalEdgeRings.
26
+ *
27
+ * @constructor
28
+ * @extends jsts.geomgraph.EdgeEnd
29
+ */
30
+ jsts.geomgraph.DirectedEdgeStar = function() {
31
+ jsts.geomgraph.EdgeEndStar.call(this);
32
+ };
33
+ jsts.geomgraph.DirectedEdgeStar.prototype = new EdgeEndStar();
34
+ jsts.geomgraph.DirectedEdgeStar.constructor = jsts.geomgraph.DirectedEdgeStar;
35
+
36
+
37
+ /**
38
+ * A list of all outgoing edges in the result, in CCW order
39
+ *
40
+ * @private
41
+ */
42
+ jsts.geomgraph.DirectedEdgeStar.prototype.resultAreaEdgeList = null;
43
+ jsts.geomgraph.DirectedEdgeStar.prototype.label = null;
44
+
45
+ /**
46
+ * Insert a directed edge in the list
47
+ */
48
+ jsts.geomgraph.DirectedEdgeStar.prototype.insert = function(ee) {
49
+ var de = ee;
50
+ this.insertEdgeEnd(de, de);
51
+ };
52
+
53
+ jsts.geomgraph.DirectedEdgeStar.prototype.getLabel = function() {
54
+ return this.label;
55
+ };
56
+
57
+ jsts.geomgraph.DirectedEdgeStar.prototype.getOutgoingDegree = function() {
58
+ var degree = 0;
59
+ for (var it = this.iterator(); it.hasNext();) {
60
+ var de = it.next();
61
+ if (de.isInResult())
62
+ degree++;
63
+ }
64
+ return degree;
65
+ };
66
+ jsts.geomgraph.DirectedEdgeStar.prototype.getOutgoingDegree = function(er) {
67
+ var degree = 0;
68
+ for (var it = this.iterator(); it.hasNext();) {
69
+ var de = it.next();
70
+ if (de.getEdgeRing() === er)
71
+ degree++;
72
+ }
73
+ return degree;
74
+ };
75
+
76
+ jsts.geomgraph.DirectedEdgeStar.prototype.getRightmostEdge = function() {
77
+ var edges = this.getEdges();
78
+ var size = edges.size();
79
+ if (size < 1)
80
+ return null;
81
+ var de0 = edges.get(0);
82
+ if (size == 1)
83
+ return de0;
84
+ var deLast = edges.get(size - 1);
85
+
86
+ var quad0 = de0.getQuadrant();
87
+ var quad1 = deLast.getQuadrant();
88
+ if (jsts.geomgraph.Quadrant.isNorthern(quad0) &&
89
+ jsts.geomgraph.Quadrant.isNorthern(quad1))
90
+ return de0;
91
+ else if (!jsts.geomgraph.Quadrant.isNorthern(quad0) &&
92
+ !jsts.geomgraph.Quadrant.isNorthern(quad1))
93
+ return deLast;
94
+ else {
95
+ // edges are in different hemispheres - make sure we return one that is
96
+ // non-horizontal
97
+ var nonHorizontalEdge = null;
98
+ if (de0.getDy() != 0)
99
+ return de0;
100
+ else if (deLast.getDy() != 0)
101
+ return deLast;
102
+ }
103
+ Assert.shouldNeverReachHere('found two horizontal edges incident on node');
104
+ return null;
105
+ };
106
+ /**
107
+ * Compute the labelling for all dirEdges in this star, as well as the overall
108
+ * labelling
109
+ */
110
+ jsts.geomgraph.DirectedEdgeStar.prototype.computeLabelling = function(geom) {
111
+ EdgeEndStar.prototype.computeLabelling.call(this, geom);
112
+
113
+ // determine the overall labelling for this DirectedEdgeStar
114
+ // (i.e. for the node it is based at)
115
+ this.label = new jsts.geomgraph.Label(Location.NONE);
116
+ for (var it = this.iterator(); it.hasNext();) {
117
+ var ee = it.next();
118
+ var e = ee.getEdge();
119
+ var eLabel = e.getLabel();
120
+ for (var i = 0; i < 2; i++) {
121
+ var eLoc = eLabel.getLocation(i);
122
+ if (eLoc === Location.INTERIOR || eLoc === Location.BOUNDARY)
123
+ this.label.setLocation(i, Location.INTERIOR);
124
+ }
125
+ }
126
+ };
127
+
128
+ /**
129
+ * For each dirEdge in the star, merge the label from the sym dirEdge into the
130
+ * label
131
+ */
132
+ jsts.geomgraph.DirectedEdgeStar.prototype.mergeSymLabels = function() {
133
+ for (var it = this.iterator(); it.hasNext();) {
134
+ var de = it.next();
135
+ var label = de.getLabel();
136
+ label.merge(de.getSym().getLabel());
137
+ }
138
+ };
139
+
140
+ /**
141
+ * Update incomplete dirEdge labels from the labelling for the node
142
+ */
143
+ jsts.geomgraph.DirectedEdgeStar.prototype.updateLabelling = function(nodeLabel) {
144
+ for (var it = this.iterator(); it.hasNext();) {
145
+ var de = it.next();
146
+ var label = de.getLabel();
147
+ label.setAllLocationsIfNull(0, nodeLabel.getLocation(0));
148
+ label.setAllLocationsIfNull(1, nodeLabel.getLocation(1));
149
+ }
150
+ };
151
+
152
+ /**
153
+ * @private
154
+ */
155
+ jsts.geomgraph.DirectedEdgeStar.prototype.getResultAreaEdges = function() {
156
+ if (this.resultAreaEdgeList !== null)
157
+ return this.resultAreaEdgeList;
158
+ this.resultAreaEdgeList = new javascript.util.ArrayList();
159
+ for (var it = this.iterator(); it.hasNext();) {
160
+ var de = it.next();
161
+ if (de.isInResult() || de.getSym().isInResult())
162
+ this.resultAreaEdgeList.add(de);
163
+ }
164
+ return this.resultAreaEdgeList;
165
+
166
+ };
167
+
168
+ /**
169
+ * @private
170
+ */
171
+ jsts.geomgraph.DirectedEdgeStar.prototype.SCANNING_FOR_INCOMING = 1;
172
+ /**
173
+ * @private
174
+ */
175
+ jsts.geomgraph.DirectedEdgeStar.prototype.LINKING_TO_OUTGOING = 2;
176
+ /**
177
+ * Traverse the star of DirectedEdges, linking the included edges together. To
178
+ * link two dirEdges, the <next> pointer for an incoming dirEdge is set to the
179
+ * next outgoing edge.
180
+ * <p>
181
+ * DirEdges are only linked if:
182
+ * <ul>
183
+ * <li>they belong to an area (i.e. they have sides)
184
+ * <li>they are marked as being in the result
185
+ * </ul>
186
+ * <p>
187
+ * Edges are linked in CCW order (the order they are stored). This means that
188
+ * rings have their face on the Right (in other words, the topological
189
+ * location of the face is given by the RHS label of the DirectedEdge)
190
+ * <p>
191
+ * PRECONDITION: No pair of dirEdges are both marked as being in the result
192
+ */
193
+ jsts.geomgraph.DirectedEdgeStar.prototype.linkResultDirectedEdges = function() {
194
+ // make sure edges are copied to resultAreaEdges list
195
+ this.getResultAreaEdges();
196
+ // find first area edge (if any) to start linking at
197
+ var firstOut = null;
198
+ var incoming = null;
199
+ var state = this.SCANNING_FOR_INCOMING;
200
+ // link edges in CCW order
201
+ for (var i = 0; i < this.resultAreaEdgeList.size(); i++) {
202
+ var nextOut = this.resultAreaEdgeList.get(i);
203
+ var nextIn = nextOut.getSym();
204
+
205
+ // skip de's that we're not interested in
206
+ if (!nextOut.getLabel().isArea())
207
+ continue;
208
+
209
+ // record first outgoing edge, in order to link the last incoming edge
210
+ if (firstOut === null && nextOut.isInResult())
211
+ firstOut = nextOut;
212
+ // assert: sym.isInResult() == false, since pairs of dirEdges should have
213
+ // been removed already
214
+
215
+ switch (state) {
216
+ case this.SCANNING_FOR_INCOMING:
217
+ if (!nextIn.isInResult())
218
+ continue;
219
+ incoming = nextIn;
220
+ state = this.LINKING_TO_OUTGOING;
221
+ break;
222
+ case this.LINKING_TO_OUTGOING:
223
+ if (!nextOut.isInResult())
224
+ continue;
225
+ incoming.setNext(nextOut);
226
+ state = this.SCANNING_FOR_INCOMING;
227
+ break;
228
+ }
229
+ }
230
+ if (state === this.LINKING_TO_OUTGOING) {
231
+ if (firstOut === null)
232
+ throw new jsts.error.TopologyError('no outgoing dirEdge found', this
233
+ .getCoordinate());
234
+ Assert.isTrue(firstOut.isInResult(),
235
+ 'unable to link last incoming dirEdge');
236
+ incoming.setNext(firstOut);
237
+ }
238
+ };
239
+ jsts.geomgraph.DirectedEdgeStar.prototype.linkMinimalDirectedEdges = function(er) {
240
+ // find first area edge (if any) to start linking at
241
+ var firstOut = null;
242
+ var incoming = null;
243
+ var state = this.SCANNING_FOR_INCOMING;
244
+ // link edges in CW order
245
+ for (var i = this.resultAreaEdgeList.size() - 1; i >= 0; i--) {
246
+ var nextOut = this.resultAreaEdgeList.get(i);
247
+ var nextIn = nextOut.getSym();
248
+
249
+ // record first outgoing edge, in order to link the last incoming edge
250
+ if (firstOut === null && nextOut.getEdgeRing() === er)
251
+ firstOut = nextOut;
252
+
253
+ switch (state) {
254
+ case this.SCANNING_FOR_INCOMING:
255
+ if (nextIn.getEdgeRing() != er)
256
+ continue;
257
+ incoming = nextIn;
258
+ state = this.LINKING_TO_OUTGOING;
259
+ break;
260
+ case this.LINKING_TO_OUTGOING:
261
+ if (nextOut.getEdgeRing() !== er)
262
+ continue;
263
+ incoming.setNextMin(nextOut);
264
+ state = this.SCANNING_FOR_INCOMING;
265
+ break;
266
+ }
267
+ }
268
+ if (state === this.LINKING_TO_OUTGOING) {
269
+ Assert.isTrue(firstOut !== null, 'found null for first outgoing dirEdge');
270
+ Assert.isTrue(firstOut.getEdgeRing() === er,
271
+ 'unable to link last incoming dirEdge');
272
+ incoming.setNextMin(firstOut);
273
+ }
274
+ };
275
+ jsts.geomgraph.DirectedEdgeStar.prototype.linkAllDirectedEdges = function() {
276
+ this.getEdges();
277
+ // find first area edge (if any) to start linking at
278
+ var prevOut = null;
279
+ var firstIn = null;
280
+ // link edges in CW order
281
+ for (var i = this.edgeList.size() - 1; i >= 0; i--) {
282
+ var nextOut = this.edgeList.get(i);
283
+ var nextIn = nextOut.getSym();
284
+ if (firstIn === null)
285
+ firstIn = nextIn;
286
+ if (prevOut !== null)
287
+ nextIn.setNext(prevOut);
288
+ // record outgoing edge, in order to link the last incoming edge
289
+ prevOut = nextOut;
290
+ }
291
+ firstIn.setNext(prevOut);
292
+ };
293
+
294
+ /**
295
+ * Traverse the star of edges, maintaing the current location in the result
296
+ * area at this node (if any). If any L edges are found in the interior of the
297
+ * result, mark them as covered.
298
+ */
299
+ jsts.geomgraph.DirectedEdgeStar.prototype.findCoveredLineEdges = function() {
300
+ // Since edges are stored in CCW order around the node,
301
+ // as we move around the ring we move from the right to the left side of the
302
+ // edge
303
+
304
+ /**
305
+ * Find first DirectedEdge of result area (if any). The interior of the
306
+ * result is on the RHS of the edge, so the start location will be: -
307
+ * INTERIOR if the edge is outgoing - EXTERIOR if the edge is incoming
308
+ */
309
+ var startLoc = Location.NONE;
310
+ for (var it = this.iterator(); it.hasNext();) {
311
+ var nextOut = it.next();
312
+ var nextIn = nextOut.getSym();
313
+ if (!nextOut.isLineEdge()) {
314
+ if (nextOut.isInResult()) {
315
+ startLoc = Location.INTERIOR;
316
+ break;
317
+ }
318
+ if (nextIn.isInResult()) {
319
+ startLoc = Location.EXTERIOR;
320
+ break;
321
+ }
322
+ }
323
+ }
324
+ // no A edges found, so can't determine if L edges are covered or not
325
+ if (startLoc === Location.NONE)
326
+ return;
327
+
328
+ /**
329
+ * move around ring, keeping track of the current location (Interior or
330
+ * Exterior) for the result area. If L edges are found, mark them as covered
331
+ * if they are in the interior
332
+ */
333
+ var currLoc = startLoc;
334
+
335
+ for (var it = this.iterator(); it.hasNext();) {
336
+ var nextOut = it.next();
337
+ var nextIn = nextOut.getSym();
338
+ if (nextOut.isLineEdge()) {
339
+ nextOut.getEdge().setCovered(currLoc === Location.INTERIOR);
340
+ } else { // edge is an Area edge
341
+ if (nextOut.isInResult())
342
+ currLoc = Location.EXTERIOR;
343
+ if (nextIn.isInResult())
344
+ currLoc = Location.INTERIOR;
345
+ }
346
+ }
347
+ };
348
+
349
+ jsts.geomgraph.DirectedEdgeStar.prototype.computeDepths = function(de) {
350
+ if (arguments.length === 2) {
351
+ this.computeDepths2.apply(this, arguments);
352
+ // NOTE: intentional, this function returns void
353
+ return;
354
+ }
355
+
356
+ var edgeIndex = this.findIndex(de);
357
+ var label = de.getLabel();
358
+ var startDepth = de.getDepth(Position.LEFT);
359
+ var targetLastDepth = de.getDepth(Position.RIGHT);
360
+ // compute the depths from this edge up to the end of the edge array
361
+ var nextDepth = this.computeDepths2(edgeIndex + 1, this.edgeList.size(),
362
+ startDepth);
363
+ // compute the depths for the initial part of the array
364
+ var lastDepth = this.computeDepths2(0, edgeIndex, nextDepth);
365
+ if (lastDepth != targetLastDepth)
366
+ throw new jsts.error.TopologyError('depth mismatch at ' +
367
+ de.getCoordinate());
368
+ };
369
+
370
+ /**
371
+ * Compute the DirectedEdge depths for a subsequence of the edge array.
372
+ *
373
+ * @return the last depth assigned (from the R side of the last edge visited).
374
+ * @private
375
+ */
376
+ jsts.geomgraph.DirectedEdgeStar.prototype.computeDepths2 = function(startIndex, endIndex,
377
+ startDepth) {
378
+ var currDepth = startDepth;
379
+ for (var i = startIndex; i < endIndex; i++) {
380
+ var nextDe = this.edgeList.get(i);
381
+ var label = nextDe.getLabel();
382
+ nextDe.setEdgeDepths(Position.RIGHT, currDepth);
383
+ currDepth = nextDe.getDepth(Position.LEFT);
384
+ }
385
+ return currDepth;
386
+ };
387
+
388
+ })();