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,502 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+
8
+
9
+ /**
10
+ * A LineIntersector is an algorithm that can both test whether two line
11
+ * segments intersect and compute the intersection point if they do. The
12
+ * intersection point may be computed in a precise or non-precise manner.
13
+ * Computing it precisely involves rounding it to an integer. (This assumes that
14
+ * the input coordinates have been made precise by scaling them to an integer
15
+ * grid.)
16
+ *
17
+ * @constructor
18
+ */
19
+ jsts.algorithm.LineIntersector = function() {
20
+ this.inputLines = [[], []];
21
+ this.intPt = [null, null];
22
+ // alias the intersection points for ease of reference
23
+ this.pa = this.intPt[0];
24
+ this.pb = this.intPt[1];
25
+ this.result = jsts.algorithm.LineIntersector.NO_INTERSECTION;
26
+ };
27
+
28
+
29
+ /**
30
+ * Indicates that line segments do not intersect
31
+ *
32
+ * @type {int}
33
+ */
34
+ jsts.algorithm.LineIntersector.NO_INTERSECTION = 0;
35
+
36
+
37
+ /**
38
+ * Indicates that line segments intersect in a single point
39
+ *
40
+ * @type {int}
41
+ */
42
+ jsts.algorithm.LineIntersector.POINT_INTERSECTION = 1;
43
+
44
+
45
+ /**
46
+ * Indicates that line segments intersect in a line segment
47
+ *
48
+ * @type {int}
49
+ */
50
+ jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION = 2;
51
+
52
+
53
+ /**
54
+ * Force computed intersection to be rounded to a given precision model. No
55
+ * getter is provided, because the precision model is not required to be
56
+ * specified.
57
+ *
58
+ * @param precisionModel
59
+ */
60
+ jsts.algorithm.LineIntersector.prototype.setPrecisionModel = function(
61
+ precisionModel) {
62
+ this.precisionModel = precisionModel;
63
+ };
64
+
65
+
66
+ /**
67
+ * Gets an endpoint of an input segment.
68
+ *
69
+ * @param segmentIndex
70
+ * the index of the input segment (0 or 1).
71
+ * @param ptIndex
72
+ * the index of the endpoint (0 or 1).
73
+ * @return the specified endpoint.
74
+ */
75
+ jsts.algorithm.LineIntersector.prototype.getEndpoint = function(segmentIndex,
76
+ ptIndex) {
77
+ return this.inputLines[segmentIndex][ptIndex];
78
+ };
79
+
80
+
81
+ /**
82
+ * Computes the "edge distance" of an intersection point p along a segment. The
83
+ * edge distance is a metric of the point along the edge. The metric used is a
84
+ * robust and easy to compute metric function. It is <b>not</b> equivalent to
85
+ * the usual Euclidean metric. It relies on the fact that either the x or the y
86
+ * ordinates of the points in the edge are unique, depending on whether the edge
87
+ * is longer in the horizontal or vertical direction.
88
+ * <p>
89
+ * NOTE: This function may produce incorrect distances for inputs where p is not
90
+ * precisely on p1-p2 (E.g. p = (139,9) p1 = (139,10), p2 = (280,1) produces
91
+ * distanct 0.0, which is incorrect.
92
+ * <p>
93
+ * My hypothesis is that the function is safe to use for points which are the
94
+ * result of <b>rounding</b> points which lie on the line, but not safe to use
95
+ * for <b>truncated</b> points.
96
+ *
97
+ * @param {Coordinate}
98
+ * p
99
+ * @param {Coordinate}
100
+ * p0
101
+ * @param {Coordinate}
102
+ * p1
103
+ * @return {double}
104
+ */
105
+ jsts.algorithm.LineIntersector.computeEdgeDistance = function(p, p0, p1) {
106
+ var dx = Math.abs(p1.x - p0.x);
107
+ var dy = Math.abs(p1.y - p0.y);
108
+
109
+ var dist = -1.0; // sentinel value
110
+ if (p.equals(p0)) {
111
+ dist = 0.0;
112
+ } else if (p.equals(p1)) {
113
+ if (dx > dy) {
114
+ dist = dx;
115
+ } else {
116
+ dist = dy;
117
+ }
118
+ } else {
119
+ var pdx = Math.abs(p.x - p0.x);
120
+ var pdy = Math.abs(p.y - p0.y);
121
+ if (dx > dy) {
122
+ dist = pdx;
123
+ } else {
124
+ dist = pdy;
125
+ }
126
+ // <FIX>
127
+ // hack to ensure that non-endpoints always have a non-zero distance
128
+ if (dist === 0.0 && !p.equals(p0)) {
129
+ dist = Math.max(pdx, pdy);
130
+ }
131
+ }
132
+ if (dist === 0.0 && !p.equals(p0)) {
133
+ throw new jsts.error.IllegalArgumentError('Bad distance calculation');
134
+ }
135
+ return dist;
136
+ };
137
+
138
+
139
+ /**
140
+ * This function is non-robust, since it may compute the square of large
141
+ * numbers. Currently not sure how to improve this.
142
+ *
143
+ * @param {Coordinate}
144
+ * p
145
+ * @param {Coordinate}
146
+ * p0
147
+ * @param {Coordinate}
148
+ * p1
149
+ * @return {double}
150
+ */
151
+ jsts.algorithm.LineIntersector.nonRobustComputeEdgeDistance = function(p, p1,
152
+ p2) {
153
+ var dx = p.x - p1.x;
154
+ var dy = p.y - p1.y;
155
+ var dist = Math.sqrt(dx * dx + dy * dy); // dummy value
156
+ if (!(dist === 0.0 && !p.equals(p1))) {
157
+ throw new jsts.error.IllegalArgumentError('Invalid distance calculation');
158
+ }
159
+ return dist;
160
+ };
161
+
162
+
163
+ /**
164
+ * @protected
165
+ * @type {int}
166
+ */
167
+ jsts.algorithm.LineIntersector.prototype.result = null;
168
+
169
+
170
+ /**
171
+ * @protected
172
+ * @type {Coordinate[][] }
173
+ */
174
+ jsts.algorithm.LineIntersector.prototype.inputLines = null;
175
+
176
+
177
+ /**
178
+ * @protected
179
+ * @type {Coordinate[]}
180
+ */
181
+ jsts.algorithm.LineIntersector.prototype.intPt = null;
182
+
183
+
184
+ /**
185
+ * The indexes of the endpoints of the intersection lines, in order along the
186
+ * corresponding line
187
+ */
188
+ /**
189
+ * @protected
190
+ * @type {int[][]}
191
+ */
192
+ jsts.algorithm.LineIntersector.prototype.intLineIndex = null;
193
+
194
+
195
+ /**
196
+ * @protected
197
+ * @type {boolean}
198
+ */
199
+ jsts.algorithm.LineIntersector.prototype._isProper = null;
200
+
201
+
202
+ /**
203
+ * @protected
204
+ * @type {Coordinate}
205
+ */
206
+ jsts.algorithm.LineIntersector.prototype.pa = null;
207
+
208
+
209
+ /**
210
+ * @protected
211
+ * @type {Coordinate}
212
+ */
213
+ jsts.algorithm.LineIntersector.prototype.pb = null;
214
+
215
+
216
+ /**
217
+ * @protected
218
+ * @type {PrecisionModel}
219
+ */
220
+ jsts.algorithm.LineIntersector.prototype.precisionModel = null;
221
+
222
+
223
+ /**
224
+ * Compute the intersection of a point p and the line p1-p2. This function
225
+ * computes the boolean value of the hasIntersection test. The actual value of
226
+ * the intersection (if there is one) is equal to the value of <code>p</code>.
227
+ *
228
+ * @param {Coordinate}
229
+ * p
230
+ * @param {Coordinate}
231
+ * p1
232
+ * @param {Coordinate}
233
+ * p2
234
+ */
235
+ jsts.algorithm.LineIntersector.prototype.computeIntersection = function(p, p1,
236
+ p2) {
237
+ throw new jsts.error.AbstractMethodInvocationError();
238
+ };
239
+
240
+
241
+ /**
242
+ * @return {boolean}
243
+ * @protected
244
+ */
245
+ jsts.algorithm.LineIntersector.prototype.isCollinear = function() {
246
+ return this.result === jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION;
247
+ };
248
+
249
+
250
+ /**
251
+ * Computes the intersection of the lines p1-p2 and p3-p4. This function
252
+ * computes both the boolean value of the hasIntersection test and the
253
+ * (approximate) value of the intersection point itself (if there is one).
254
+ *
255
+ * @param {Coordinate}
256
+ * p1
257
+ * @param {Coordinate}
258
+ * p2
259
+ * @param {Coordinate}
260
+ * p3
261
+ * @param {Coordinate}
262
+ * p4
263
+ */
264
+ jsts.algorithm.LineIntersector.prototype.computeIntersection = function(p1, p2,
265
+ p3, p4) {
266
+ this.inputLines[0][0] = p1;
267
+ this.inputLines[0][1] = p2;
268
+ this.inputLines[1][0] = p3;
269
+ this.inputLines[1][1] = p4;
270
+ this.result = this.computeIntersect(p1, p2, p3, p4);
271
+ };
272
+
273
+
274
+ /**
275
+ * @param {Coordinate}
276
+ * p1
277
+ * @param {Coordinate}
278
+ * p2
279
+ * @param {Coordinate}
280
+ * q1
281
+ * @param {Coordinate}
282
+ * q2
283
+ * @return {int}
284
+ * @protected
285
+ */
286
+ jsts.algorithm.LineIntersector.prototype.computeIntersect = function(p1, p2,
287
+ q1, q2) {
288
+ throw new jsts.error.AbstractMethodInvocationError();
289
+ };
290
+
291
+
292
+ /**
293
+ * @return {boolean}
294
+ * @protected
295
+ */
296
+ jsts.algorithm.LineIntersector.prototype.isEndPoint = function() {
297
+ return this.hasIntersection() && !this._isProper;
298
+ };
299
+
300
+
301
+ /**
302
+ * Tests whether the input geometries intersect.
303
+ *
304
+ * @return {boolean} true if the input geometries intersect.
305
+ */
306
+ jsts.algorithm.LineIntersector.prototype.hasIntersection = function() {
307
+ return this.result !== jsts.algorithm.LineIntersector.NO_INTERSECTION;
308
+ };
309
+
310
+
311
+ /**
312
+ * Returns the number of intersection points found. This will be either 0, 1 or
313
+ * 2.
314
+ *
315
+ * @return {int}
316
+ */
317
+ jsts.algorithm.LineIntersector.prototype.getIntersectionNum = function() {
318
+ return this.result;
319
+ };
320
+
321
+
322
+ /**
323
+ * Returns the intIndex'th intersection point
324
+ *
325
+ * @param {int}
326
+ * intIndex is 0 or 1.
327
+ *
328
+ * @return {Coordinate} the intIndex'th intersection point.
329
+ */
330
+ jsts.algorithm.LineIntersector.prototype.getIntersection = function(intIndex) {
331
+ return this.intPt[intIndex];
332
+ };
333
+
334
+
335
+ /**
336
+ * @protected
337
+ */
338
+ jsts.algorithm.LineIntersector.prototype.computeIntLineIndex = function() {
339
+ if (this.intLineIndex === null) {
340
+ this.intLineIndex = [[], []];
341
+ this.computeIntLineIndex(0);
342
+ this.computeIntLineIndex(1);
343
+ }
344
+ };
345
+
346
+
347
+ /**
348
+ * Test whether a point is a intersection point of two line segments. Note that
349
+ * if the intersection is a line segment, this method only tests for equality
350
+ * with the endpoints of the intersection segment. It does <b>not</b> return
351
+ * true if the input point is internal to the intersection segment.
352
+ *
353
+ * @param {Coordinate}
354
+ * pt
355
+ * @return {boolean} true if the input point is one of the intersection points.
356
+ */
357
+ jsts.algorithm.LineIntersector.prototype.isIntersection = function(pt) {
358
+ var i;
359
+ for (i = 0; i < this.result; i++) {
360
+ if (this.intPt[i].equals2D(pt)) {
361
+ return true;
362
+ }
363
+ }
364
+ return false;
365
+ };
366
+
367
+
368
+ /**
369
+ * Tests whether either intersection point is an interior point of one of the
370
+ * input segments.
371
+ *
372
+ * @return {boolean} <code>true</code> if either intersection point is in the
373
+ * interior of one of the input segments.
374
+ */
375
+ jsts.algorithm.LineIntersector.prototype.isInteriorIntersection = function() {
376
+ if (arguments.length === 1) {
377
+ return this.isInteriorIntersection2.apply(this, arguments);
378
+ }
379
+
380
+ if (this.isInteriorIntersection(0)) {
381
+ return true;
382
+ }
383
+ if (this.isInteriorIntersection(1)) {
384
+ return true;
385
+ }
386
+ return false;
387
+ };
388
+
389
+
390
+ /**
391
+ * Tests whether either intersection point is an interior point of the specified
392
+ * input segment.
393
+ *
394
+ * @param {[]} inputLineIndex
395
+ * @return {boolean} <code>true</code> if either intersection point is in the
396
+ * interior of the input segment.
397
+ */
398
+ jsts.algorithm.LineIntersector.prototype.isInteriorIntersection2 = function(
399
+ inputLineIndex) {
400
+ var i;
401
+ for (i = 0; i < this.result; i++) {
402
+ if (!(this.intPt[i].equals2D(this.inputLines[inputLineIndex][0]) || this.intPt[i]
403
+ .equals2D(this.inputLines[inputLineIndex][1]))) {
404
+ return true;
405
+ }
406
+ }
407
+ return false;
408
+ };
409
+
410
+
411
+ /**
412
+ * Tests whether an intersection is proper. <br>
413
+ * The intersection between two line segments is considered proper if they
414
+ * intersect in a single point in the interior of both segments (e.g. the
415
+ * intersection is a single point and is not equal to any of the endpoints).
416
+ * <p>
417
+ * The intersection between a point and a line segment is considered proper if
418
+ * the point lies in the interior of the segment (e.g. is not equal to either of
419
+ * the endpoints).
420
+ *
421
+ * @return {boolean} true if the intersection is proper.
422
+ */
423
+ jsts.algorithm.LineIntersector.prototype.isProper = function() {
424
+ return this.hasIntersection() && this._isProper;
425
+ };
426
+
427
+
428
+ /**
429
+ * Computes the intIndex'th intersection point in the direction of a specified
430
+ * input line segment
431
+ *
432
+ * @param {int}
433
+ * segmentIndex is 0 or 1.
434
+ * @param {int}
435
+ * intIndex is 0 or 1.
436
+ *
437
+ * @return {Coordinate} the intIndex'th intersection point in the direction of
438
+ * the specified input line segment.
439
+ */
440
+ jsts.algorithm.LineIntersector.prototype.getIntersectionAlongSegment = function(
441
+ segmentIndex, intIndex) {
442
+ // lazily compute int line array
443
+ this.computeIntLineIndex();
444
+ return this.intPt[intLineIndex[segmentIndex][intIndex]];
445
+ };
446
+
447
+
448
+ /**
449
+ * Computes the index of the intIndex'th intersection point in the direction of
450
+ * a specified input line segment
451
+ *
452
+ * @param {int}
453
+ * segmentIndex is 0 or 1.
454
+ * @param {int}
455
+ * intIndex is 0 or 1.
456
+ *
457
+ * @return {int} the index of the intersection point along the segment (0 or 1).
458
+ */
459
+ jsts.algorithm.LineIntersector.prototype.getIndexAlongSegment = function(
460
+ segmentIndex, intIndex) {
461
+ this.computeIntLineIndex();
462
+ return this.intLineIndex[segmentIndex][intIndex];
463
+ };
464
+
465
+
466
+ /**
467
+ * @param {int}
468
+ * segmentIndex
469
+ * @protected
470
+ */
471
+ jsts.algorithm.LineIntersector.prototype.computeIntLineIndex = function(
472
+ segmentIndex) {
473
+ var dist0 = this.getEdgeDistance(segmentIndex, 0);
474
+ var dist1 = this.getEdgeDistance(segmentIndex, 1);
475
+ if (dist0 > dist1) {
476
+ this.intLineIndex[segmentIndex][0] = 0;
477
+ this.intLineIndex[segmentIndex][1] = 1;
478
+ } else {
479
+ this.intLineIndex[segmentIndex][0] = 1;
480
+ this.intLineIndex[segmentIndex][1] = 0;
481
+ }
482
+ };
483
+
484
+
485
+ /**
486
+ * Computes the "edge distance" of an intersection point along the specified
487
+ * input line segment.
488
+ *
489
+ * @param {int}
490
+ * segmentIndex is 0 or 1.
491
+ * @param {int}
492
+ * intIndex is 0 or 1.
493
+ *
494
+ * @return {double} the edge distance of the intersection point.
495
+ */
496
+ jsts.algorithm.LineIntersector.prototype.getEdgeDistance = function(
497
+ segmentIndex, intIndex) {
498
+ var dist = jsts.algorithm.LineIntersector.computeEdgeDistance(
499
+ this.intPt[intIndex], this.inputLines[segmentIndex][0],
500
+ this.inputLines[segmentIndex][1]);
501
+ return dist;
502
+ };