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,67 @@
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
+ * An interface for rules which determine whether node points which are in
11
+ * boundaries of {@link Lineal} geometry components are in the boundary of the
12
+ * parent geometry collection. The SFS specifies a single kind of boundary node
13
+ * rule, the {@link Mod2BoundaryNodeRule} rule. However, other kinds of Boundary
14
+ * Node Rules are appropriate in specific situations (for instance, linear
15
+ * network topology usually follows the {@link EndPointBoundaryNodeRule}.) Some
16
+ * JTS operations allow the BoundaryNodeRule to be specified, and respect this
17
+ * rule when computing the results of the operation.
18
+ *
19
+ * @see RelateOp
20
+ * @see IsSimpleOp
21
+ * @see PointLocator
22
+ * @constructor
23
+ */
24
+ jsts.algorithm.BoundaryNodeRule = function() {
25
+
26
+ };
27
+
28
+
29
+ /**
30
+ * Tests whether a point that lies in <tt>boundaryCount</tt> geometry
31
+ * component boundaries is considered to form part of the boundary of the parent
32
+ * geometry.
33
+ *
34
+ * @param {int}
35
+ * boundaryCount the number of component boundaries that this point
36
+ * occurs in.
37
+ * @return {boolean} true if points in this number of boundaries lie in the
38
+ * parent boundary.
39
+ */
40
+ jsts.algorithm.BoundaryNodeRule.prototype.isInBoundary = function(boundaryCount) {
41
+ throw new jsts.error.AbstractMethodInvocationError();
42
+ };
43
+
44
+
45
+ /**
46
+ * A {@link BoundaryNodeRule} specifies that points are in the boundary of a
47
+ * lineal geometry iff the point lies on the boundary of an odd number of
48
+ * components. Under this rule {@link LinearRing}s and closed
49
+ * {@link LineString}s have an empty boundary.
50
+ * <p>
51
+ * This is the rule specified by the <i>OGC SFS</i>, and is the default rule
52
+ * used in JTS.
53
+ */
54
+ jsts.algorithm.Mod2BoundaryNodeRule = function() {
55
+
56
+ };
57
+
58
+ jsts.algorithm.Mod2BoundaryNodeRule.prototype = new jsts.algorithm.BoundaryNodeRule();
59
+
60
+ jsts.algorithm.Mod2BoundaryNodeRule.prototype.isInBoundary = function(
61
+ boundaryCount) {
62
+ // the "Mod-2 Rule"
63
+ return boundaryCount % 2 === 1;
64
+ };
65
+
66
+ jsts.algorithm.BoundaryNodeRule.MOD2_BOUNDARY_RULE = new jsts.algorithm.Mod2BoundaryNodeRule();
67
+ jsts.algorithm.BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE = jsts.algorithm.BoundaryNodeRule.MOD2_BOUNDARY_RULE;
@@ -0,0 +1,596 @@
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
+ * Specifies and implements various fundamental Computational Geometric
11
+ * algorithms. The algorithms supplied in this class are robust for
12
+ * double-precision floating point.
13
+ *
14
+ * @constructor
15
+ */
16
+ jsts.algorithm.CGAlgorithms = function() {
17
+
18
+ };
19
+
20
+
21
+ /**
22
+ * A value that indicates an orientation of clockwise, or a right turn.
23
+ */
24
+ jsts.algorithm.CGAlgorithms.CLOCKWISE = -1;
25
+
26
+
27
+ /**
28
+ * A value that indicates an orientation of clockwise, or a right turn.
29
+ */
30
+ jsts.algorithm.CGAlgorithms.RIGHT = jsts.algorithm.CGAlgorithms.CLOCKWISE;
31
+
32
+
33
+ /**
34
+ * A value that indicates an orientation of counterclockwise, or a left turn.
35
+ */
36
+ jsts.algorithm.CGAlgorithms.COUNTERCLOCKWISE = 1;
37
+
38
+
39
+ /**
40
+ * A value that indicates an orientation of counterclockwise, or a left turn.
41
+ */
42
+ jsts.algorithm.CGAlgorithms.LEFT = jsts.algorithm.CGAlgorithms.COUNTERCLOCKWISE;
43
+
44
+
45
+ /**
46
+ * A value that indicates an orientation of collinear, or no turn (straight).
47
+ */
48
+ jsts.algorithm.CGAlgorithms.COLLINEAR = 0;
49
+
50
+
51
+ /**
52
+ * A value that indicates an orientation of collinear, or no turn (straight).
53
+ */
54
+ jsts.algorithm.CGAlgorithms.STRAIGHT = jsts.algorithm.CGAlgorithms.COLLINEAR;
55
+
56
+
57
+ /**
58
+ * Returns the index of the direction of the point <code>q</code> relative to
59
+ * a vector specified by <code>p1-p2</code>.
60
+ *
61
+ * @param {jsts.geom.Coordinate}
62
+ * p1 the origin point of the vector.
63
+ * @param {jsts.geom.Coordinate}
64
+ * p2 the final point of the vector.
65
+ * @param {jsts.geom.Coordinate}
66
+ * q the point to compute the direction to.
67
+ *
68
+ * @return {Number} 1 if q is counter-clockwise (left) from p1-p2.
69
+ * @return {Number} -1 if q is clockwise (right) from p1-p2.
70
+ * @return {Number} 0 if q is collinear with p1-p2.
71
+ */
72
+ jsts.algorithm.CGAlgorithms.orientationIndex = function(p1, p2, q) {
73
+ /**
74
+ * MD - 9 Aug 2010 It seems that the basic algorithm is slightly orientation
75
+ * dependent, when computing the orientation of a point very close to a line.
76
+ * This is possibly due to the arithmetic in the translation to the origin.
77
+ *
78
+ * For instance, the following situation produces identical results in spite
79
+ * of the inverse orientation of the line segment:
80
+ *
81
+ * Coordinate p0 = new Coordinate(219.3649559090992, 140.84159161824724);
82
+ * Coordinate p1 = new Coordinate(168.9018919682399, -5.713787599646864);
83
+ *
84
+ * Coordinate p = new Coordinate(186.80814046338352, 46.28973405831556); int
85
+ * orient = orientationIndex(p0, p1, p); int orientInv = orientationIndex(p1,
86
+ * p0, p);
87
+ *
88
+ * A way to force consistent results is to normalize the orientation of the
89
+ * vector using the following code. However, this may make the results of
90
+ * orientationIndex inconsistent through the triangle of points, so it's not
91
+ * clear this is an appropriate patch.
92
+ *
93
+ */
94
+
95
+ var dx1, dy1, dx2, dy2;
96
+ dx1 = p2.x - p1.x;
97
+ dy1 = p2.y - p1.y;
98
+ dx2 = q.x - p2.x;
99
+ dy2 = q.y - p2.y;
100
+
101
+ return jsts.algorithm.RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2);
102
+ };
103
+
104
+
105
+ /**
106
+ * Tests whether a point lies inside or on a ring. The ring may be oriented in
107
+ * either direction. A point lying exactly on the ring boundary is considered to
108
+ * be inside the ring.
109
+ * <p>
110
+ * This method does <i>not</i> first check the point against the envelope of
111
+ * the ring.
112
+ *
113
+ * @param {jsts.geom.Coordinate}
114
+ * p point to check for ring inclusion.
115
+ * @param {Array{jsts.geom.Coordinate}}
116
+ * ring an array of coordinates representing the ring (which must have
117
+ * first point identical to last point)
118
+ * @return {Boolean} true if p is inside ring.
119
+ *
120
+ * @see locatePointInRing
121
+ */
122
+ jsts.algorithm.CGAlgorithms.isPointInRing = function(p, ring) {
123
+ return jsts.algorithm.CGAlgorithms.locatePointInRing(p, ring) !== jsts.geom.Location.EXTERIOR;
124
+ };
125
+
126
+
127
+ /**
128
+ * Determines whether a point lies in the interior, on the boundary, or in the
129
+ * exterior of a ring. The ring may be oriented in either direction.
130
+ * <p>
131
+ * This method does <i>not</i> first check the point against the envelope of
132
+ * the ring.
133
+ *
134
+ * @param {jsts.geom.Coordinate}
135
+ * p point to check for ring inclusion.
136
+ * @param {Array{jsts.geom.Coordinate}}
137
+ * ring an array of coordinates representing the ring (which must have
138
+ * first point identical to last point)
139
+ * @return {jsts.geom.Location} the {@link Location} of p relative to the ring.
140
+ */
141
+ jsts.algorithm.CGAlgorithms.locatePointInRing = function(p, ring) {
142
+ return jsts.algorithm.RayCrossingCounter.locatePointInRing(p, ring);
143
+ };
144
+
145
+
146
+ /**
147
+ * Tests whether a point lies on the line segments defined by a list of
148
+ * coordinates.
149
+ *
150
+ * @param {jsts.geom.Coordinate}
151
+ * p the coordinate to test.
152
+ * @param {Array{jsts.geom.Coordinate}}
153
+ * pt An array of coordinates defining line segments
154
+ * @return {Boolean} true if the point is a vertex of the line or lies in the
155
+ * interior of a line segment in the linestring.
156
+ */
157
+ jsts.algorithm.CGAlgorithms.isOnLine = function(p, pt) {
158
+ var lineIntersector, i, il, p0, p1;
159
+ lineIntersector = new jsts.algorithm.RobustLineIntersector();
160
+
161
+ for (i = 1, il = pt.length; i < il; i++) {
162
+ p0 = pt[i - 1];
163
+ p1 = pt[i];
164
+ lineIntersector.computeIntersection(p, p0, p1);
165
+
166
+ if (lineIntersector.hasIntersection()) {
167
+ return true;
168
+ }
169
+ }
170
+ return false;
171
+ };
172
+
173
+
174
+ /**
175
+ * Computes whether a ring defined by an array of {@link Coordinate}s is
176
+ * oriented counter-clockwise.
177
+ * <ul>
178
+ * <li>The list of points is assumed to have the first and last points equal.
179
+ * <li>This will handle coordinate lists which contain repeated points.
180
+ * </ul>
181
+ * This algorithm is <b>only</b> guaranteed to work with valid rings. If the
182
+ * ring is invalid (e.g. self-crosses or touches), the computed result may not
183
+ * be correct.
184
+ *
185
+ * @param {Array{jsts.geom.Coordinate}}
186
+ * ring an array of Coordinates forming a ring
187
+ * @return {Boolean} true if the ring is oriented counter-clockwise.
188
+ * @throws IllegalArgumentException
189
+ * if there are too few points to determine orientation (< 3)
190
+ */
191
+ jsts.algorithm.CGAlgorithms.isCCW = function(ring) {
192
+ var nPts, hiPt, hiIndex, p, iPrev, iNext, prev, next, i, disc, isCCW;
193
+
194
+ // # of points without closing endpoint
195
+ nPts = ring.length - 1;
196
+
197
+ // sanity check
198
+ if (nPts < 3) {
199
+ throw new jsts.IllegalArgumentError(
200
+ 'Ring has fewer than 3 points, so orientation cannot be determined');
201
+ }
202
+
203
+ // find highets point
204
+ hiPt = ring[0];
205
+ hiIndex = 0;
206
+
207
+ i = 1;
208
+ for (i; i <= nPts; i++) {
209
+ p = ring[i];
210
+ if (p.y > hiPt.y) {
211
+ hiPt = p;
212
+ hiIndex = i;
213
+ }
214
+ }
215
+
216
+ // find distinct point before highest point
217
+ iPrev = hiIndex;
218
+ do {
219
+ iPrev = iPrev - 1;
220
+ if (iPrev < 0) {
221
+ iPrev = nPts;
222
+ }
223
+ } while (ring[iPrev].equals2D(hiPt) && iPrev !== hiIndex);
224
+
225
+ // find distinct point after highest point
226
+ iNext = hiIndex;
227
+ do {
228
+ iNext = (iNext + 1) % nPts;
229
+ } while (ring[iNext].equals2D(hiPt) && iNext !== hiIndex);
230
+
231
+ prev = ring[iPrev];
232
+ next = ring[iNext];
233
+
234
+ /**
235
+ * This check catches cases where the ring contains an A-B-A configuration of
236
+ * points. This can happen if the ring does not contain 3 distinct points
237
+ * (including the case where the input array has fewer than 4 elements), or it
238
+ * contains coincident line segments.
239
+ */
240
+ if (prev.equals2D(hiPt) || next.equals2D(hiPt) || prev.equals2D(next)) {
241
+ return false;
242
+ }
243
+
244
+ disc = jsts.algorithm.CGAlgorithms.computeOrientation(prev, hiPt, next);
245
+
246
+ /**
247
+ * If disc is exactly 0, lines are collinear. There are two possible cases:
248
+ * (1) the lines lie along the x axis in opposite directions (2) the lines lie
249
+ * on top of one another
250
+ *
251
+ * (1) is handled by checking if next is left of prev ==> CCW (2) will never
252
+ * happen if the ring is valid, so don't check for it (Might want to assert
253
+ * this)
254
+ */
255
+ isCCW = false;
256
+ if (disc === 0) {
257
+ // poly is CCW if prev x is right of next x
258
+ isCCW = (prev.x > next.x);
259
+ } else {
260
+ // if area is positive, points are ordered CCW
261
+ isCCW = (disc > 0);
262
+ }
263
+
264
+ return isCCW;
265
+ };
266
+
267
+
268
+ /**
269
+ * Computes the orientation of a point q to the directed line segment p1-p2. The
270
+ * orientation of a point relative to a directed line segment indicates which
271
+ * way you turn to get to q after travelling from p1 to p2.
272
+ *
273
+ * @param {jsts.geom.Coordinate}
274
+ * p1 First coordinate of the linesegment.
275
+ * @param {jsts.geom.Coordinate}
276
+ * p2 Second coordinate of the linesegment.
277
+ * @param {jsts.geom.Coordinate}
278
+ * q The point to calculate orientation of.
279
+ *
280
+ * @return {Number} 1 if q is counter-clockwise from p1-p2.
281
+ * @return {Number} -1 if q is clockwise from p1-p2.
282
+ * @return {Number} 0 if q is collinear with p1-p2.
283
+ */
284
+ jsts.algorithm.CGAlgorithms.computeOrientation = function(p1, p2, q) {
285
+ return jsts.algorithm.CGAlgorithms.orientationIndex(p1, p2, q);
286
+ };
287
+
288
+
289
+ /**
290
+ * Computes the distance from a point p to a line segment AB
291
+ *
292
+ * Note: NON-ROBUST!
293
+ *
294
+ * @param {jsts.geom.Coordinate}
295
+ * p the point to compute the distance for.
296
+ * @param {jsts.geom.Coordinate}
297
+ * A one point of the line.
298
+ * @param {jsts.geom.Coordinate}
299
+ * B another point of the line (must be different to A).
300
+ * @return {Number} the distance from p to line segment AB.
301
+ */
302
+ jsts.algorithm.CGAlgorithms.distancePointLine = function(p, A, B) {
303
+ if (!(A instanceof jsts.geom.Coordinate)) {
304
+ jsts.algorithm.CGAlgorithms.distancePointLine2.apply(this, arguments);
305
+ }
306
+
307
+ // if start = end, then just compute distance to one of the endpoints
308
+ if (A.x === B.x && A.y === B.y) {
309
+ return p.distance(A);
310
+ }
311
+ // otherwise use comp.graphics.algorithms Frequently Asked Questions method
312
+ /*(1) AC dot AB
313
+ r = ---------
314
+ ||AB||^2
315
+ r has the following meaning:
316
+ r=0 P = A
317
+ r=1 P = B
318
+ r<0 P is on the backward extension of AB
319
+ r>1 P is on the forward extension of AB
320
+ 0<r<1 P is interior to AB
321
+ */
322
+ var r, s;
323
+ r = ((p.x - A.x) * (B.x - A.x) + (p.y - A.y) * (B.y - A.y)) /
324
+ ((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
325
+
326
+ if (r <= 0.0) {
327
+ return p.distance(A);
328
+ }
329
+ if (r >= 1.0) {
330
+ return p.distance(B);
331
+ }
332
+
333
+ /*(2)
334
+ (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
335
+ s = -----------------------------
336
+ L^2
337
+
338
+ Then the distance from C to P = |s|*L.
339
+ */
340
+
341
+ s = ((A.y - p.y) * (B.x - A.x) - (A.x - p.x) * (B.y - A.y)) /
342
+ ((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
343
+
344
+ return Math.abs(s) *
345
+ Math.sqrt(((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y)));
346
+ };
347
+
348
+
349
+ /**
350
+ * Computes the perpendicular distance from a point p to the (infinite) line
351
+ * containing the points AB
352
+ *
353
+ * @param {jsts.geom.Coordinate}
354
+ * p the point to compute the distance for.
355
+ * @param {jsts.geom.Coordinate}
356
+ * A one point of the line.
357
+ * @param {jsts.geom.Coordinate}
358
+ * B another point of the line (must be different to A).
359
+ * @return {Number} the distance from p to line AB.
360
+ */
361
+ jsts.algorithm.CGAlgorithms.distancePointLinePerpendicular = function(p, A, B) {
362
+ // use comp.graphics.algorithms Frequently Asked Questions method
363
+ /*(2)
364
+ (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
365
+ s = -----------------------------
366
+ L^2
367
+
368
+ Then the distance from C to P = |s|*L.
369
+ */
370
+ var s = ((A.y - p.y) * (B.x - A.x) - (A.x - p.x) * (B.y - A.y)) /
371
+ ((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y));
372
+
373
+ return Math.abs(s) *
374
+ Math.sqrt(((B.x - A.x) * (B.x - A.x) + (B.y - A.y) * (B.y - A.y)));
375
+ };
376
+
377
+
378
+ /**
379
+ * Computes the distance from a point to a sequence of line segments.
380
+ *
381
+ * @param {jsts.geom.Coordinate}
382
+ * p a point.
383
+ * @param {Array{jsts.geom.Coordinate}}
384
+ * line a sequence of contiguous line segments defined by their
385
+ * vertices
386
+ * @return {Number} the minimum distance between the point and the line
387
+ * segments.
388
+ */
389
+ jsts.algorithm.CGAlgorithms.distancePointLine2 = function(p, line) {
390
+ var minDistance, i, il, dist;
391
+ if (line.length === 0) {
392
+ throw new jsts.error.IllegalArgumentError(
393
+ 'Line array must contain at least one vertex');
394
+ }
395
+ minDistance = p.distance(line[0]);
396
+ for (i = 0, il = line.length - 1; i < il; i++) {
397
+ dist = jsts.algorithm.CGAlgorithms.distancePointLine(p, line[i],
398
+ line[i + 1]);
399
+ if (dist < minDistance) {
400
+ minDistance = dist;
401
+ }
402
+ }
403
+ return minDistance;
404
+ };
405
+
406
+ /**
407
+ * Computes the distance from a line segment AB to a line segment CD
408
+ *
409
+ * Note: NON-ROBUST!
410
+ *
411
+ * @param {jsts.geom.Coordinate}
412
+ * A a point of one line.
413
+ * @param {jsts.geom.Coordinate}
414
+ * B the second point of (must be different to A).
415
+ * @param {jsts.geom.Coordinate}
416
+ * C one point of the line.
417
+ * @param {jsts.geom.Coordinate}
418
+ * D another point of the line (must be different to A).
419
+ * @return {Number} the distance.
420
+ */
421
+
422
+ jsts.algorithm.CGAlgorithms.distanceLineLine = function(A, B, C, D) {
423
+ // check for zero-length segments
424
+ if (A.equals(B)) {
425
+ return jsts.algorithm.CGAlgorithms.distancePointLine(A, C, D);
426
+ }
427
+ if (C.equals(D)) {
428
+ return jsts.algorithm.CGAlgorithms.distancePointLine(D, A, B);
429
+ }
430
+
431
+ // AB and CD are line segments
432
+ /* from comp.graphics.algo
433
+
434
+ Solving the above for r and s yields
435
+ (Ay-Cy)(Dx-Cx)-(Ax-Cx)(Dy-Cy)
436
+ r = ----------------------------- (eqn 1)
437
+ (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
438
+
439
+ (Ay-Cy)(Bx-Ax)-(Ax-Cx)(By-Ay)
440
+ s = ----------------------------- (eqn 2)
441
+ (Bx-Ax)(Dy-Cy)-(By-Ay)(Dx-Cx)
442
+ Let P be the position vector of the intersection point, then
443
+ P=A+r(B-A) or
444
+ Px=Ax+r(Bx-Ax)
445
+ Py=Ay+r(By-Ay)
446
+ By examining the values of r & s, you can also determine some other
447
+ limiting conditions:
448
+ If 0<=r<=1 & 0<=s<=1, intersection exists
449
+ r<0 or r>1 or s<0 or s>1 line segments do not intersect
450
+ If the denominator in eqn 1 is zero, AB & CD are parallel
451
+ If the numerator in eqn 1 is also zero, AB & CD are collinear.
452
+
453
+ */
454
+ var r_top, r_bot, s_top, s_bot, s, r;
455
+ r_top = (A.y - C.y) * (D.x - C.x) - (A.x - C.x) * (D.y - C.y);
456
+ r_bot = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
457
+
458
+ s_top = (A.y - C.y) * (B.x - A.x) - (A.x - C.x) * (B.y - A.y);
459
+ s_bot = (B.x - A.x) * (D.y - C.y) - (B.y - A.y) * (D.x - C.x);
460
+
461
+
462
+ if ((r_bot === 0) || (s_bot === 0)) {
463
+ return Math.min(jsts.algorithm.CGAlgorithms.distancePointLine(A, C, D),
464
+ Math.min(jsts.algorithm.CGAlgorithms.distancePointLine(B, C, D), Math
465
+ .min(jsts.algorithm.CGAlgorithms.distancePointLine(C, A, B),
466
+ jsts.algorithm.CGAlgorithms.distancePointLine(D, A, B))));
467
+ }
468
+
469
+ s = s_top / s_bot;
470
+ r = r_top / r_bot;
471
+ if ((r < 0) || (r > 1) || (s < 0) || (s > 1)) {
472
+ // no intersection
473
+ return Math.min(jsts.algorithm.CGAlgorithms.distancePointLine(A, C, D),
474
+ Math.min(jsts.algorithm.CGAlgorithms.distancePointLine(B, C, D), Math
475
+ .min(jsts.algorithm.CGAlgorithms.distancePointLine(C, A, B),
476
+ jsts.algorithm.CGAlgorithms.distancePointLine(D, A, B))));
477
+ }
478
+
479
+ return 0.0; // intersection exists
480
+ };
481
+
482
+
483
+ /**
484
+ * Computes the signed area for a ring. The signed area is positive if the ring
485
+ * is oriented CW, negative if the ring is oriented CCW, and zero if the ring is
486
+ * degenerate or flat.
487
+ *
488
+ * @param {Array{jsts.geom.Coordinate}}
489
+ * ring the coordinates forming the ring
490
+ * @return {Number} the signed area of the ring.
491
+ */
492
+ jsts.algorithm.CGAlgorithms.signedArea = function(ring) {
493
+ if (ring.length < 3) {
494
+ return 0.0;
495
+ }
496
+ var sum, i, il, bx, by, cx, cy;
497
+
498
+ sum = 0.0;
499
+
500
+ for (i = 0, il = ring.length - 1; i < il; i++) {
501
+ bx = ring[i].x;
502
+ by = ring[i].y;
503
+ cx = ring[i + 1].x;
504
+ cy = ring[i + 1].y;
505
+ sum += (bx + cx) * (cy - by);
506
+ }
507
+
508
+ return -sum / 2.0;
509
+ };
510
+
511
+
512
+ /**
513
+ * Computes the signed area for a ring. The signed area is:
514
+ * <ul>
515
+ * <li>positive if the ring is oriented CW
516
+ * <li>negative if the ring is oriented CCW
517
+ * <li>zero if the ring is degenerate or flat
518
+ * </ul>
519
+ *
520
+ * @param {Array{jsts.geom.Coordinate}}
521
+ * ring the coordinates forming the ring
522
+ * @return {Number} the signed area of the ring.
523
+ */
524
+ jsts.algorithm.CGAlgorithms.signedArea = function(ring) {
525
+ var n, sum, p, bx, by, i, cx, cy;
526
+
527
+ n = ring.length;
528
+ if (n < 3) {
529
+ return 0.0;
530
+ }
531
+
532
+ sum = 0.0;
533
+ p = ring[0];
534
+
535
+ bx = p.x;
536
+ by = p.y;
537
+
538
+ for (i = 1; i < n; i++) {
539
+ p = ring[i];
540
+ cx = p.x;
541
+ cy = p.y;
542
+ sum += (bx + cx) * (cy - by);
543
+ bx = cx;
544
+ by = cy;
545
+ }
546
+
547
+ return -sum / 2.0;
548
+ };
549
+
550
+ /**
551
+ * Computes the length of a linestring specified by a sequence of points.
552
+ *
553
+ * NOTE: This is renamed from length() to computeLength() because 'length' is a
554
+ * reserved keyword in javascript.
555
+ *
556
+ * @param {Array{jsts.geom.Coordinate}}
557
+ * pts the points specifying the linestring
558
+ * @return {Number} the length of the linestring.
559
+ */
560
+ jsts.algorithm.CGAlgorithms.computeLength = function(pts) {
561
+ // optimized for processing CoordinateSequences
562
+ var n = pts.length, len, x0, y0, x1, y1, dx, dy, p, i, il;
563
+ if (n <= 1) {
564
+ return 0.0;
565
+ }
566
+
567
+ len = 0.0;
568
+
569
+ p = pts[0];
570
+
571
+ x0 = p.x;
572
+ y0 = p.y;
573
+
574
+ i = 1, il = n;
575
+ for (i; i < n; i++) {
576
+ p = pts[i];
577
+
578
+ x1 = p.x;
579
+ y1 = p.y;
580
+ dx = x1 - x0;
581
+ dy = y1 - y0;
582
+
583
+ len += Math.sqrt(dx * dx + dy * dy);
584
+
585
+ x0 = x1;
586
+ y0 = y1;
587
+ }
588
+ return len;
589
+ };
590
+
591
+ /**
592
+ * @see {jsts.algorithm.CGAlgorithms.computeLength} Since 'length' is a reserved
593
+ * keyword in javascript this function does not act as a function. Please
594
+ * use 'computeLength' instead.
595
+ */
596
+ jsts.algorithm.CGAlgorithms.length = function() {};