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,275 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ /**
8
+ * @requires jsts/geom/Coordinate.js
9
+ */
10
+
11
+ /**
12
+ * Represents a line segment defined by two {@link Coordinate}s. Provides
13
+ * methods to compute various geometric properties and relationships of line
14
+ * segments.
15
+ * <p>
16
+ * This class is designed to be easily mutable (to the extent of having its
17
+ * contained points public). This supports a common pattern of reusing a single
18
+ * LineSegment object as a way of computing segment properties on the segments
19
+ * defined by arrays or lists of {@link Coordinate}s.
20
+ *
21
+ * @param {Coordinate}
22
+ * p0
23
+ * @param {Coordinate}
24
+ * p1
25
+ * @constructor
26
+ */
27
+ jsts.geom.LineSegment = function(p0, p1) {
28
+ if (p0 === undefined) {
29
+ this.p0 = new jsts.geom.Coordinate();
30
+ this.p1 = new jsts.geom.Coordinate();
31
+ return;
32
+ }
33
+
34
+ this.p0 = p0;
35
+ this.p1 = p1;
36
+ };
37
+
38
+
39
+ /**
40
+ * @type {Coordinate}
41
+ */
42
+ jsts.geom.LineSegment.prototype.p0 = null;
43
+
44
+
45
+ /**
46
+ * @type {Coordinate}
47
+ */
48
+ jsts.geom.LineSegment.prototype.p1 = null;
49
+
50
+ /**
51
+ * Computes the length of the line segment.
52
+ *
53
+ * @return {number} the length of the line segment.
54
+ */
55
+ jsts.geom.LineSegment.prototype.getLength = function() {
56
+ return this.p0.distance(this.p1);
57
+ };
58
+
59
+ /**
60
+ * Tests whether the segment is horizontal.
61
+ *
62
+ * @return {boolean} <code>true</code> if the segment is horizontal.
63
+ */
64
+ jsts.geom.LineSegment.prototype.isHorizontal = function() {
65
+ return this.p0.y === this.p1.y;
66
+ };
67
+ /**
68
+ * Tests whether the segment is vertical.
69
+ *
70
+ * @return {boolean} <code>true</code> if the segment is vertical.
71
+ */
72
+ jsts.geom.LineSegment.prototype.isVertical = function() {
73
+ return this.p0.x === this.p1.x;
74
+ };
75
+
76
+
77
+ /**
78
+ * Reverses the direction of the line segment.
79
+ */
80
+ jsts.geom.LineSegment.prototype.reverse = function()
81
+ {
82
+ var temp = this.p0;
83
+ this.p0 = this.p1;
84
+ this.p1 = temp;
85
+ };
86
+
87
+ /**
88
+ * Computes the Projection Factor for the projection of the point p onto this
89
+ * LineSegment. The Projection Factor is the constant r by which the vector for
90
+ * this segment must be multiplied to equal the vector for the projection of
91
+ * <tt>p<//t> on the line
92
+ * defined by this segment.
93
+ * <p>
94
+ * The projection factor returned will be in the range <tt>(-inf, +inf)</tt>.
95
+ *
96
+ * @param {Coordinate} p the point to compute the factor for.
97
+ * @return {double} the projection factor for the point.
98
+ */
99
+ jsts.geom.LineSegment.prototype.projectionFactor = function(p) {
100
+ if (p.equals(this.p0))
101
+ return 0.0;
102
+ if (p.equals(this.p1))
103
+ return 1.0;
104
+ // Otherwise, use comp.graphics.algorithms Frequently Asked Questions method
105
+ /* AC dot AB
106
+ r = ---------
107
+ ||AB||^2
108
+ r has the following meaning:
109
+ r=0 P = A
110
+ r=1 P = B
111
+ r<0 P is on the backward extension of AB
112
+ r>1 P is on the forward extension of AB
113
+ 0<r<1 P is interior to AB
114
+ */
115
+ var dx = this.p1.x - this.p0.x;
116
+ var dy = this.p1.y - this.p0.y;
117
+ var len2 = dx * dx + dy * dy;
118
+ var r = ((p.x - this.p0.x) * dx + (p.y - this.p0.y) * dy) / len2;
119
+ return r;
120
+ };
121
+
122
+
123
+ /**
124
+ * Computes the closest point on this line segment to another point.
125
+ *
126
+ * @param {Coordinate}
127
+ * p the point to find the closest point to.
128
+ * @return {Coordinate} a Coordinate which is the closest point on the line
129
+ * segment to the point p.
130
+ */
131
+ jsts.geom.LineSegment.prototype.closestPoint = function(p) {
132
+ var factor = this.projectionFactor(p);
133
+ if (factor > 0 && factor < 1) {
134
+ return this.project(p);
135
+ }
136
+ var dist0 = this.p0.distance(p);
137
+ var dist1 = this.p1.distance(p);
138
+ if (dist0 < dist1)
139
+ return this.p0;
140
+ return this.p1;
141
+ };
142
+
143
+
144
+ /**
145
+ * Computes the closest points on two line segments.
146
+ *
147
+ * @param {LineSegment}
148
+ * line the segment to find the closest point to.
149
+ * @return {[]} a pair of Coordinates which are the closest points on the line
150
+ * segments.
151
+ */
152
+ jsts.geom.LineSegment.prototype.closestPoints = function(line) {
153
+ // test for intersection
154
+ var intPt = this.intersection(line);
155
+ if (intPt !== null) {
156
+ return [intPt, intPt];
157
+ }
158
+
159
+ /**
160
+ * if no intersection closest pair contains at least one endpoint. Test each
161
+ * endpoint in turn.
162
+ */
163
+ var closestPt = [];
164
+ var minDistance = Number.MAX_VALUE;
165
+ var dist;
166
+
167
+ var close00 = this.closestPoint(line.p0);
168
+ minDistance = close00.distance(line.p0);
169
+ closestPt[0] = close00;
170
+ closestPt[1] = line.p0;
171
+
172
+ var close01 = this.closestPoint(line.p1);
173
+ dist = close01.distance(line.p1);
174
+ if (dist < minDistance) {
175
+ minDistance = dist;
176
+ closestPt[0] = close01;
177
+ closestPt[1] = line.p1;
178
+ }
179
+
180
+ var close10 = line.closestPoint(this.p0);
181
+ dist = close10.distance(this.p0);
182
+ if (dist < minDistance) {
183
+ minDistance = dist;
184
+ closestPt[0] = this.p0;
185
+ closestPt[1] = close10;
186
+ }
187
+
188
+ var close11 = line.closestPoint(this.p1);
189
+ dist = close11.distance(this.p1);
190
+ if (dist < minDistance) {
191
+ minDistance = dist;
192
+ closestPt[0] = this.p1;
193
+ closestPt[1] = close11;
194
+ }
195
+
196
+ return closestPt;
197
+ };
198
+
199
+
200
+ /**
201
+ * Computes an intersection point between two line segments, if there is one.
202
+ * There may be 0, 1 or many intersection points between two segments. If there
203
+ * are 0, null is returned. If there is 1 or more, exactly one of them is
204
+ * returned (chosen at the discretion of the algorithm). If more information is
205
+ * required about the details of the intersection, the
206
+ * {@link RobustLineIntersector} class should be used.
207
+ *
208
+ * @param {LineSegment}
209
+ * line a line segment.
210
+ * @return {Coordinate} an intersection point, or <code>null</code> if there
211
+ * is none.
212
+ *
213
+ * @see RobustLineIntersector
214
+ */
215
+ jsts.geom.LineSegment.prototype.intersection = function(line) {
216
+ var li = new jsts.algorithm.RobustLineIntersector();
217
+ li.computeIntersection(this.p0, this.p1, line.p0, line.p1);
218
+ if (li.hasIntersection())
219
+ return li.getIntersection(0);
220
+ return null;
221
+ };
222
+
223
+
224
+ /**
225
+ * Compute the projection of a point onto the line determined by this line
226
+ * segment.
227
+ * <p>
228
+ * Note that the projected point may lie outside the line segment. If this is
229
+ * the case, the projection factor will lie outside the range [0.0, 1.0].
230
+ *
231
+ * @param {Coordinate}
232
+ * p
233
+ * @return {Coordinate}
234
+ */
235
+ jsts.geom.LineSegment.prototype.project = function(p) {
236
+ if (p.equals(this.p0) || p.equals(this.p1))
237
+ return new jsts.geom.Coordinate(p);
238
+
239
+ var r = this.projectionFactor(p);
240
+ var coord = new jsts.geom.Coordinate();
241
+ coord.x = this.p0.x + r * (this.p1.x - this.p0.x);
242
+ coord.y = this.p0.y + r * (this.p1.y - this.p0.y);
243
+ return coord;
244
+ };
245
+
246
+ jsts.geom.LineSegment.prototype.setCoordinates = function(ls) {
247
+ if (ls instanceof jsts.geom.Coordinate) {
248
+ this.setCoordinates2.apply(this, arguments);
249
+ return;
250
+ }
251
+
252
+ this.setCoordinates2(ls.p0, ls.p1);
253
+ };
254
+
255
+ jsts.geom.LineSegment.prototype.setCoordinates2 = function(p0, p1) {
256
+ this.p0.x = p0.x;
257
+ this.p0.y = p0.y;
258
+ this.p1.x = p1.x;
259
+ this.p1.y = p1.y;
260
+ };
261
+
262
+ /**
263
+ * Computes the distance between this line segment and a given point.
264
+ *
265
+ * @param {jsts.geom.Coordinate}
266
+ * p the coordinate.
267
+ * @return {number}
268
+ * the distance from this segment to the given point.
269
+ */
270
+ jsts.geom.LineSegment.prototype.distance = function(p)
271
+ {
272
+ return jsts.algorithm.CGAlgorithms.distancePointLine(p, this.p0, this.p1);
273
+ };
274
+
275
+ // TODO: port rest
@@ -0,0 +1,299 @@
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/Geometry.js
11
+ * @requires jsts/geom/Dimension.js
12
+ */
13
+
14
+ var Dimension = jsts.geom.Dimension;
15
+
16
+ /**
17
+ * @extends jsts.geom.Geometry
18
+ * @constructor
19
+ */
20
+ jsts.geom.LineString = function(points, factory) {
21
+ this.factory = factory;
22
+ this.points = points || [];
23
+ };
24
+
25
+ jsts.geom.LineString.prototype = new jsts.geom.Geometry();
26
+ jsts.geom.LineString.constructor = jsts.geom.LineString;
27
+
28
+ /**
29
+ * @type {jsts.geom.Coordinate[]}
30
+ * @private
31
+ */
32
+ jsts.geom.LineString.prototype.points = null;
33
+
34
+ /**
35
+ * @return {jsts.geom.Coordinate[]} this LineString's internal coordinate
36
+ * array.
37
+ */
38
+ jsts.geom.LineString.prototype.getCoordinates = function() {
39
+ return this.points;
40
+ };
41
+
42
+ jsts.geom.LineString.prototype.getCoordinateSequence = function() {
43
+ return this.points;
44
+ };
45
+
46
+
47
+ /**
48
+ * @return {jsts.geom.Coordinate} The n'th coordinate of this
49
+ * jsts.geom.LineString.
50
+ * @param {int}
51
+ * n index.
52
+ */
53
+ jsts.geom.LineString.prototype.getCoordinateN = function(n) {
54
+ return this.points[n];
55
+ };
56
+
57
+
58
+ /**
59
+ * @return {jsts.geom.Coordinate} The first coordinate of this LineString or
60
+ * null if empty.
61
+ */
62
+ jsts.geom.LineString.prototype.getCoordinate = function() {
63
+ if (this.isEmpty()) {
64
+ return null;
65
+ }
66
+ return this.getCoordinateN(0);
67
+ };
68
+
69
+
70
+ /**
71
+ * @return {number} LineStrings are always 1-dimensional.
72
+ */
73
+ jsts.geom.LineString.prototype.getDimension = function() {
74
+ return 1;
75
+ };
76
+
77
+
78
+ /**
79
+ * @return {number} dimension of the boundary of this jsts.geom.LineString.
80
+ */
81
+ jsts.geom.LineString.prototype.getBoundaryDimension = function() {
82
+ if (this.isClosed()) {
83
+ return Dimension.FALSE;
84
+ }
85
+ return 0;
86
+ };
87
+
88
+
89
+ /**
90
+ * @return {Boolean} true if empty.
91
+ */
92
+ jsts.geom.LineString.prototype.isEmpty = function() {
93
+ return this.points.length === 0;
94
+ };
95
+
96
+ jsts.geom.LineString.prototype.getNumPoints = function() {
97
+ return this.points.length;
98
+ };
99
+
100
+ jsts.geom.LineString.prototype.getPointN = function(n) {
101
+ return this.getFactory().createPoint(this.points[n]);
102
+ };
103
+
104
+
105
+ jsts.geom.LineString.prototype.getStartPoint = function() {
106
+ if (this.isEmpty()) {
107
+ return null;
108
+ }
109
+ return this.getPointN(0);
110
+ };
111
+
112
+ jsts.geom.LineString.prototype.getEndPoint = function() {
113
+ if (this.isEmpty()) {
114
+ return null;
115
+ }
116
+ return this.getPointN(this.getNumPoints() - 1);
117
+ };
118
+
119
+
120
+ /**
121
+ * @return {Boolean} true if LineString is Closed.
122
+ */
123
+ jsts.geom.LineString.prototype.isClosed = function() {
124
+ if (this.isEmpty()) {
125
+ return false;
126
+ }
127
+ return this.getCoordinateN(0).equals2D(
128
+ this.getCoordinateN(this.points.length - 1));
129
+ };
130
+
131
+
132
+ /**
133
+ * @return {Boolean} true if LineString is a Ring.
134
+ */
135
+ jsts.geom.LineString.prototype.isRing = function() {
136
+ return this.isClosed() && this.isSimple();
137
+ };
138
+
139
+
140
+ /**
141
+ * @return {String} String representation of LineString type.
142
+ */
143
+ jsts.geom.LineString.prototype.getGeometryType = function() {
144
+ return 'LineString';
145
+ };
146
+
147
+
148
+ /**
149
+ * Returns the length of this <code>LineString</code>
150
+ *
151
+ * @return the length of the linestring.
152
+ */
153
+ jsts.geom.LineString.prototype.getLength = function() {
154
+ return jsts.algorithm.CGAlgorithms.computeLength(this.points);
155
+ };
156
+
157
+ /**
158
+ * Gets the boundary of this geometry. The boundary of a lineal geometry is
159
+ * always a zero-dimensional geometry (which may be empty).
160
+ *
161
+ * @return {Geometry} the boundary geometry.
162
+ * @see Geometry#getBoundary
163
+ */
164
+ jsts.geom.LineString.prototype.getBoundary = function() {
165
+ return (new jsts.operation.BoundaryOp(this)).getBoundary();
166
+ };
167
+
168
+
169
+ jsts.geom.LineString.prototype.computeEnvelopeInternal = function() {
170
+ if (this.isEmpty()) {
171
+ return new jsts.geom.Envelope();
172
+ }
173
+
174
+ var env = new jsts.geom.Envelope();
175
+ this.points.forEach(function(component) {
176
+ env.expandToInclude(component);
177
+ });
178
+
179
+ return env;
180
+ };
181
+
182
+
183
+ /**
184
+ * @param {Geometry}
185
+ * other Geometry to compare this LineString to.
186
+ * @param {double}
187
+ * tolerance Tolerance.
188
+ * @return {Boolean} true if equal.
189
+ */
190
+ jsts.geom.LineString.prototype.equalsExact = function(other, tolerance) {
191
+ if (!this.isEquivalentClass(other)) {
192
+ return false;
193
+ }
194
+
195
+ if (this.points.length !== other.points.length) {
196
+ return false;
197
+ }
198
+
199
+ if (this.isEmpty() && other.isEmpty()) {
200
+ return true;
201
+ }
202
+
203
+ return this.points
204
+ .reduce(function(equal, point, i) {
205
+ return equal &&
206
+ jsts.geom.Geometry.prototype.equal(point, other.points[i],
207
+ tolerance);
208
+ });
209
+ };
210
+
211
+ jsts.geom.LineString.prototype.isEquivalentClass = function(other) {
212
+ return other instanceof jsts.geom.LineString;
213
+ };
214
+
215
+ jsts.geom.LineString.prototype.compareToSameClass = function(o) {
216
+ var line = o;
217
+ // MD - optimized implementation
218
+ var i = 0, il = this.points.length;
219
+ var j = 0, jl = line.points.length;
220
+ while (i < il && j < jl) {
221
+ var comparison = this.points[i].compareTo(line.points[j]);
222
+ if (comparison !== 0) {
223
+ return comparison;
224
+ }
225
+ i++;
226
+ j++;
227
+ }
228
+ if (i < il) {
229
+ return 1;
230
+ }
231
+ if (j < jl) {
232
+ return -1;
233
+ }
234
+ return 0;
235
+ };
236
+
237
+ jsts.geom.LineString.prototype.apply = function(filter) {
238
+ if (filter instanceof jsts.geom.GeometryFilter ||
239
+ filter instanceof jsts.geom.GeometryComponentFilter) {
240
+ filter.filter(this);
241
+ } else if (filter instanceof jsts.geom.CoordinateFilter) {
242
+ for (var i = 0, len = this.points.length; i < len; i++) {
243
+ filter.filter(this.points[i]);
244
+ }
245
+ } else if (filter instanceof jsts.geom.CoordinateSequenceFilter) {
246
+ this.apply2.apply(this, arguments);
247
+ }
248
+ };
249
+
250
+ jsts.geom.LineString.prototype.apply2 = function(filter) {
251
+ if (this.points.length === 0)
252
+ return;
253
+ for (var i = 0; i < this.points.length; i++) {
254
+ filter.filter(this.points, i);
255
+ if (filter.isDone())
256
+ break;
257
+ }
258
+ if (filter.isGeometryChanged()) {
259
+ // TODO: call geometryChanged(); when ported
260
+ }
261
+ };
262
+
263
+ jsts.geom.LineString.prototype.clone = function() {
264
+ var points = [];
265
+
266
+ for (var i = 0, len = this.points.length; i < len; i++) {
267
+ points.push(this.points[i].clone());
268
+ }
269
+
270
+ return this.factory.createLineString(points);
271
+ };
272
+
273
+ /**
274
+ * Normalizes a LineString. A normalized linestring has the first point which
275
+ * is not equal to it's reflected point less than the reflected point.
276
+ */
277
+ jsts.geom.LineString.prototype.normalize = function() {
278
+ var i, il, j, ci, cj, len;
279
+
280
+ len = this.points.length;
281
+ il = parseInt(len / 2);
282
+
283
+ for (i = 0; i < il; i++) {
284
+ j = len - 1 - i;
285
+ // skip equal points on both ends
286
+ ci = this.points[i];
287
+ cj = this.points[j];
288
+ if (!ci.equals(cj)) {
289
+ if (ci.compareTo(cj) > 0) {
290
+ this.points.reverse();
291
+ }
292
+ return;
293
+ }
294
+ }
295
+ };
296
+
297
+ jsts.geom.LineString.prototype.CLASS_NAME = 'jsts.geom.LineString';
298
+
299
+ })();