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,124 @@
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/index/chain/MonotoneChainSelectAction.js
9
+ */
10
+
11
+ /**
12
+ * Implements {@link PointInRing} using {@link MonotoneChain}s and a
13
+ * {@link Bintree} index to increase performance.
14
+ *
15
+ * @see IndexedPointInAreaLocator for more general functionality
16
+ */
17
+ jsts.algorithm.MCPointInRing = function(ring) {
18
+ this.ring = ring;
19
+ this.tree = null;
20
+ this.crossings = 0;
21
+ this.interval = new jsts.index.bintree.Interval();
22
+ this.buildIndex();
23
+ };
24
+
25
+ /**
26
+ *
27
+ * @param {jsts.geom.Coordinate}
28
+ * p the input coordinate.
29
+ * @return {jsts.algorithm.MCPointInRing.MCSelecter}
30
+ * @constructor
31
+ */
32
+ jsts.algorithm.MCPointInRing.MCSelecter = function(p,parent) {
33
+ this.parent = parent; //To be used instead of inner-class function calls
34
+ this.p = p;
35
+ };
36
+
37
+ jsts.algorithm.MCPointInRing.MCSelecter.prototype = new jsts.index.chain.MonotoneChainSelectAction;
38
+ jsts.algorithm.MCPointInRing.MCSelecter.prototype.constructor = jsts.algorithm.MCPointInRing.MCSelecter;
39
+
40
+ jsts.algorithm.MCPointInRing.MCSelecter.prototype.select2 = function(ls) {
41
+ this.parent.testLineSegment.apply(this.parent, [this.p, ls]);
42
+ //this.testLineSegment(this.p, ls);
43
+ };
44
+
45
+ jsts.algorithm.MCPointInRing.prototype.buildIndex = function() {
46
+ this.tree = new jsts.index.bintree.Bintree();
47
+
48
+ var pts = jsts.geom.CoordinateArrays.removeRepeatedPoints(this.ring
49
+ .getCoordinates());
50
+
51
+ var mcList = jsts.index.chain.MonotoneChainBuilder.getChains(pts);
52
+
53
+ for (var i = 0; i < mcList.length; i++) {
54
+ var mc = mcList[i];
55
+ var mcEnv = mc.getEnvelope();
56
+ this.interval.min = mcEnv.getMinY();
57
+ this.interval.max = mcEnv.getMaxY();
58
+ this.tree.insert(this.interval, mc);
59
+ }
60
+ };
61
+
62
+ jsts.algorithm.MCPointInRing.prototype.isInside = function(pt) {
63
+ this.crossings = 0;
64
+
65
+ // test all segments intersected by ray from pt in positive x direction
66
+ var rayEnv = new jsts.geom.Envelope(-Number.MAX_VALUE, Number.MAX_VALUE, pt.y,
67
+ pt.y);
68
+
69
+ this.interval.min = pt.y;
70
+ this.interval.max = pt.y;
71
+
72
+ var segs = this.tree.query(this.interval);
73
+
74
+ var mcSelecter = new jsts.algorithm.MCPointInRing.MCSelecter(pt, this);
75
+
76
+ for (var i = segs.iterator(); i.hasNext();) {
77
+ var mc = i.next();
78
+ this.testMonotoneChain(rayEnv, mcSelecter, mc);
79
+ }
80
+
81
+ /*
82
+ * p is inside if number of crossings is odd.
83
+ */
84
+ if ((this.crossings % 2) == 1) {
85
+ return true;
86
+ }
87
+ return false;
88
+
89
+ };
90
+
91
+ jsts.algorithm.MCPointInRing.prototype.testMonotoneChain = function(rayEnv,
92
+ mcSelecter, mc) {
93
+ mc.select(rayEnv, mcSelecter);
94
+ };
95
+
96
+ jsts.algorithm.MCPointInRing.prototype.testLineSegment = function(p, seg) {
97
+ var xInt, x1, y1, x2, y2, p1, p2;
98
+
99
+ /*
100
+ * Test if segment crosses ray from test point in positive x direction.
101
+ */
102
+ p1 = seg.p0;
103
+ p2 = seg.p1;
104
+
105
+ x1 = p1.x - p.x;
106
+ y1 = p1.y - p.y;
107
+ x2 = p2.x - p.x;
108
+ y2 = p2.y - p.y;
109
+
110
+ if (((y1 > 0) && (y2 <= 0)) || ((y2 > 0) && (y1 <= 0))) {
111
+ /*
112
+ * segment straddles x axis, so compute intersection.
113
+ */
114
+ xInt = jsts.algorithm.RobustDeterminant.signOfDet2x2(x1, y1, x2, y2) /
115
+ (y2 - y1);
116
+ // xsave = xInt;
117
+ /*
118
+ * crosses ray if strictly positive intersection.
119
+ */
120
+ if (0.0 < xInt) {
121
+ this.crossings++;
122
+ }
123
+ }
124
+ };
@@ -0,0 +1,247 @@
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
+ * Computes the topological ({@link Location}) of a single point to a
11
+ * {@link Geometry}. A {@link BoundaryNodeRule} may be specified to control the
12
+ * evaluation of whether the point lies on the boundary or not The default rule
13
+ * is to use the the <i>SFS Boundary Determination Rule</i>
14
+ * <p>
15
+ * Notes:
16
+ * <ul>
17
+ * <li>{@link LinearRing}s do not enclose any area - points inside the ring
18
+ * are still in the EXTERIOR of the ring.
19
+ * </ul>
20
+ * Instances of this class are not reentrant.
21
+ *
22
+ * @constructor
23
+ */
24
+ jsts.algorithm.PointLocator = function(boundaryRule) {
25
+ this.boundaryRule = boundaryRule ? boundaryRule
26
+ : jsts.algorithm.BoundaryNodeRule.OGC_SFS_BOUNDARY_RULE;
27
+ };
28
+
29
+
30
+ /**
31
+ * default is to use OGC SFS rule
32
+ *
33
+ * @type {BoundaryNodeRule}
34
+ * @private
35
+ */
36
+ jsts.algorithm.PointLocator.prototype.boundaryRule = null;
37
+
38
+
39
+ /**
40
+ * true if the point lies in or on any Geometry element
41
+ *
42
+ * @type {boolean}
43
+ * @private
44
+ */
45
+ jsts.algorithm.PointLocator.prototype.isIn = null;
46
+
47
+
48
+ /**
49
+ * the number of sub-elements whose boundaries the point lies in
50
+ *
51
+ * @type {int}
52
+ * @private
53
+ */
54
+ jsts.algorithm.PointLocator.prototype.numBoundaries = null;
55
+
56
+
57
+ /**
58
+ * Convenience method to test a point for intersection with a Geometry
59
+ *
60
+ * @param {Coordinate}
61
+ * p the coordinate to test.
62
+ * @param {Geometry}
63
+ * geom the Geometry to test.
64
+ * @return {boolean} <code>true</code> if the point is in the interior or
65
+ * boundary of the Geometry.
66
+ */
67
+ jsts.algorithm.PointLocator.prototype.intersects = function(p, geom) {
68
+ return this.locate(p, geom) !== jsts.geom.Location.EXTERIOR;
69
+ };
70
+
71
+
72
+ /**
73
+ * Computes the topological relationship ({@link Location}) of a single point
74
+ * to a Geometry. It handles both single-element and multi-element Geometries.
75
+ * The algorithm for multi-part Geometries takes into account the SFS Boundary
76
+ * Determination Rule.
77
+ *
78
+ * @param {Coordinate}
79
+ * p the coordinate to test.
80
+ * @param {Geometry}
81
+ * geom the Geometry to test.
82
+ * @return {int} the {@link Location} of the point relative to the input
83
+ * Geometry.
84
+ */
85
+ jsts.algorithm.PointLocator.prototype.locate = function(p, geom) {
86
+ if (geom.isEmpty())
87
+ return jsts.geom.Location.EXTERIOR;
88
+
89
+ if (geom instanceof jsts.geom.Point) {
90
+ return this.locate2(p, geom);
91
+ } else if (geom instanceof jsts.geom.LineString) {
92
+ return this.locate3(p, geom);
93
+ } else if (geom instanceof jsts.geom.Polygon) {
94
+ return this.locate4(p, geom);
95
+ }
96
+
97
+ this.isIn = false;
98
+ this.numBoundaries = 0;
99
+ this.computeLocation(p, geom);
100
+ if (this.boundaryRule.isInBoundary(this.numBoundaries))
101
+ return jsts.geom.Location.BOUNDARY;
102
+ if (this.numBoundaries > 0 || this.isIn)
103
+ return jsts.geom.Location.INTERIOR;
104
+
105
+ return jsts.geom.Location.EXTERIOR;
106
+ };
107
+
108
+
109
+ /**
110
+ * @param {Coordinate}
111
+ * p the coordinate to test.
112
+ * @param {Geometry}
113
+ * geom the Geometry to test.
114
+ * @private
115
+ */
116
+ jsts.algorithm.PointLocator.prototype.computeLocation = function(p, geom) {
117
+ if (geom instanceof jsts.geom.Point || geom instanceof jsts.geom.LineString ||
118
+ geom instanceof jsts.geom.Polygon) {
119
+ this.updateLocationInfo(this.locate(p, geom));
120
+ } else if (geom instanceof jsts.geom.MultiLineString) {
121
+ var ml = geom;
122
+ for (var i = 0; i < ml.getNumGeometries(); i++) {
123
+ var l = ml.getGeometryN(i);
124
+ this.updateLocationInfo(this.locate(p, l));
125
+ }
126
+ } else if (geom instanceof jsts.geom.MultiPolygon) {
127
+ var mpoly = geom;
128
+ for (var i = 0; i < mpoly.getNumGeometries(); i++) {
129
+ var poly = mpoly.getGeometryN(i);
130
+ this.updateLocationInfo(this.locate(p, poly));
131
+ }
132
+ } else if (geom instanceof jsts.geom.MultiPoint || geom instanceof jsts.geom.GeometryCollection) {
133
+ for (var i = 0; i < geom.getNumGeometries(); i++) {
134
+ var part = geom.getGeometryN(i);
135
+ if (part !== geom) {
136
+ this.computeLocation(p, part);
137
+ }
138
+ }
139
+ }
140
+ };
141
+
142
+
143
+ /**
144
+ * @param {int}
145
+ * loc
146
+ * @return {int}
147
+ * @private
148
+ */
149
+ jsts.algorithm.PointLocator.prototype.updateLocationInfo = function(loc) {
150
+ if (loc === jsts.geom.Location.INTERIOR)
151
+ this.isIn = true;
152
+ if (loc === jsts.geom.Location.BOUNDARY)
153
+ this.numBoundaries++;
154
+ };
155
+
156
+
157
+ /**
158
+ * @param {Coordinate}
159
+ * p the coordinate to test.
160
+ * @param {Point}
161
+ * pt the Point to test.
162
+ * @return {int}
163
+ * @private
164
+ */
165
+ jsts.algorithm.PointLocator.prototype.locate2 = function(p, pt) {
166
+ // no point in doing envelope test, since equality test is just as fast
167
+
168
+ var ptCoord = pt.getCoordinate();
169
+ if (ptCoord.equals2D(p))
170
+ return jsts.geom.Location.INTERIOR;
171
+ return jsts.geom.Location.EXTERIOR;
172
+ };
173
+
174
+
175
+ /**
176
+ * @param {Coordinate}
177
+ * p the coordinate to test.
178
+ * @param {LineString}
179
+ * l the LineString to test.
180
+ * @return {int}
181
+ * @private
182
+ */
183
+ jsts.algorithm.PointLocator.prototype.locate3 = function(p, l) {
184
+ // bounding-box check
185
+ if (!l.getEnvelopeInternal().intersects(p))
186
+ return jsts.geom.Location.EXTERIOR;
187
+
188
+ var pt = l.getCoordinates();
189
+ if (!l.isClosed()) {
190
+ if (p.equals(pt[0]) || p.equals(pt[pt.length - 1])) {
191
+ return jsts.geom.Location.BOUNDARY;
192
+ }
193
+ }
194
+ if (jsts.algorithm.CGAlgorithms.isOnLine(p, pt))
195
+ return jsts.geom.Location.INTERIOR;
196
+ return jsts.geom.Location.EXTERIOR;
197
+ };
198
+
199
+
200
+ /**
201
+ * @param {Coordinate}
202
+ * p the coordinate to test.
203
+ * @param {LinearRing}
204
+ * ring the LinearRing to test.
205
+ * @return {int}
206
+ * @private
207
+ */
208
+ jsts.algorithm.PointLocator.prototype.locateInPolygonRing = function(p, ring) {
209
+ // bounding-box check
210
+ if (!ring.getEnvelopeInternal().intersects(p))
211
+ return jsts.geom.Location.EXTERIOR;
212
+
213
+ return jsts.algorithm.CGAlgorithms
214
+ .locatePointInRing(p, ring.getCoordinates());
215
+ };
216
+
217
+
218
+ /**
219
+ * @param {Coordinate}
220
+ * p the coordinate to test.
221
+ * @param {Polygon}
222
+ * poly the LinearRing to test.
223
+ * @return {int}
224
+ * @private
225
+ */
226
+ jsts.algorithm.PointLocator.prototype.locate4 = function(p, poly) {
227
+ if (poly.isEmpty())
228
+ return jsts.geom.Location.EXTERIOR;
229
+
230
+ var shell = poly.getExteriorRing();
231
+
232
+ var shellLoc = this.locateInPolygonRing(p, shell);
233
+ if (shellLoc === jsts.geom.Location.EXTERIOR)
234
+ return jsts.geom.Location.EXTERIOR;
235
+ if (shellLoc === jsts.geom.Location.BOUNDARY)
236
+ return jsts.geom.Location.BOUNDARY;
237
+ // now test if the point lies in or on the holes
238
+ for (var i = 0; i < poly.getNumInteriorRing(); i++) {
239
+ var hole = poly.getInteriorRingN(i);
240
+ var holeLoc = this.locateInPolygonRing(p, hole);
241
+ if (holeLoc === jsts.geom.Location.INTERIOR)
242
+ return jsts.geom.Location.EXTERIOR;
243
+ if (holeLoc === jsts.geom.Location.BOUNDARY)
244
+ return jsts.geom.Location.BOUNDARY;
245
+ }
246
+ return jsts.geom.Location.INTERIOR;
247
+ };
@@ -0,0 +1,215 @@
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
+ * Counts the number of segments crossed by a horizontal ray extending to the
11
+ * right from a given point, in an incremental fashion. This can be used to
12
+ * determine whether a point lies in a {@link Polygonal} geometry. The class
13
+ * determines the situation where the point lies exactly on a segment. When
14
+ * being used for Point-In-Polygon determination, this case allows
15
+ * short-circuiting the evaluation.
16
+ * <p>
17
+ * This class handles polygonal geometries with any number of shells and holes.
18
+ * The orientation of the shell and hole rings is unimportant. In order to
19
+ * compute a correct location for a given polygonal geometry, it is essential
20
+ * that <b>all</b> segments are counted which
21
+ * <ul>
22
+ * <li>touch the ray
23
+ * <li>lie in in any ring which may contain the point
24
+ * </ul>
25
+ * The only exception is when the point-on-segment situation is detected, in
26
+ * which case no further processing is required. The implication of the above
27
+ * rule is that segments which can be a priori determined to <i>not</i> touch
28
+ * the ray (i.e. by a test of their bounding box or Y-extent) do not need to be
29
+ * counted. This allows for optimization by indexing.
30
+ *
31
+ * @constructor
32
+ */
33
+ jsts.algorithm.RayCrossingCounter = function(p) {
34
+ this.p = p;
35
+ };
36
+
37
+
38
+ /**
39
+ * Determines the {@link Location} of a point in a ring. This method is an
40
+ * exemplar of how to use this class.
41
+ *
42
+ * @param {Coordinate}
43
+ * p the point to test.
44
+ * @param {Coordinate[]}
45
+ * ring an array of Coordinates forming a ring.
46
+ * @return {int} the location of the point in the ring.
47
+ */
48
+ jsts.algorithm.RayCrossingCounter.locatePointInRing = function(p, ring) {
49
+ var counter = new jsts.algorithm.RayCrossingCounter(p);
50
+
51
+ for (var i = 1; i < ring.length; i++) {
52
+ var p1 = ring[i];
53
+ var p2 = ring[i - 1];
54
+ counter.countSegment(p1, p2);
55
+ if (counter.isOnSegment())
56
+ return counter.getLocation();
57
+ }
58
+ return counter.getLocation();
59
+ };
60
+
61
+
62
+ /**
63
+ * @type {Coordinate}
64
+ * @private
65
+ */
66
+ jsts.algorithm.RayCrossingCounter.prototype.p = null;
67
+
68
+
69
+ /**
70
+ * @type {int}
71
+ * @private
72
+ */
73
+ jsts.algorithm.RayCrossingCounter.prototype.crossingCount = 0;
74
+
75
+
76
+ /**
77
+ * true if the test point lies on an input segment
78
+ *
79
+ * @type {boolean}
80
+ * @private
81
+ */
82
+ jsts.algorithm.RayCrossingCounter.prototype.isPointOnSegment = false;
83
+
84
+
85
+ /**
86
+ * Counts a segment
87
+ *
88
+ * @param {Coordinate}
89
+ * p1 an endpoint of the segment.
90
+ * @param {Coordinate}
91
+ * p2 another endpoint of the segment.
92
+ */
93
+ jsts.algorithm.RayCrossingCounter.prototype.countSegment = function(p1, p2) {
94
+ /**
95
+ * For each segment, check if it crosses a horizontal ray running from the
96
+ * test point in the positive x direction.
97
+ */
98
+
99
+ // check if the segment is strictly to the left of the test point
100
+ if (p1.x < this.p.x && p2.x < this.p.x)
101
+ return;
102
+
103
+ // check if the point is equal to the current ring vertex
104
+ if (this.p.x == p2.x && this.p.y === p2.y) {
105
+ this.isPointOnSegment = true;
106
+ return;
107
+ }
108
+ /**
109
+ * For horizontal segments, check if the point is on the segment. Otherwise,
110
+ * horizontal segments are not counted.
111
+ */
112
+ if (p1.y === this.p.y && p2.y === this.p.y) {
113
+ var minx = p1.x;
114
+ var maxx = p2.x;
115
+ if (minx > maxx) {
116
+ minx = p2.x;
117
+ maxx = p1.x;
118
+ }
119
+ if (this.p.x >= minx && this.p.x <= maxx) {
120
+ this.isPointOnSegment = true;
121
+ }
122
+ return;
123
+ }
124
+ /**
125
+ * Evaluate all non-horizontal segments which cross a horizontal ray to the
126
+ * right of the test pt. To avoid double-counting shared vertices, we use the
127
+ * convention that
128
+ * <ul>
129
+ * <li>an upward edge includes its starting endpoint, and excludes its final
130
+ * endpoint
131
+ * <li>a downward edge excludes its starting endpoint, and includes its final
132
+ * endpoint
133
+ * </ul>
134
+ */
135
+ if (((p1.y > this.p.y) && (p2.y <= this.p.y)) || ((p2.y > this.p.y) && (p1.y <= this.p.y))) {
136
+ // translate the segment so that the test point lies on the origin
137
+ var x1 = p1.x - this.p.x;
138
+ var y1 = p1.y - this.p.y;
139
+ var x2 = p2.x - this.p.x;
140
+ var y2 = p2.y - this.p.y;
141
+
142
+ /**
143
+ * The translated segment straddles the x-axis. Compute the sign of the
144
+ * ordinate of intersection with the x-axis. (y2 != y1, so denominator will
145
+ * never be 0.0)
146
+ */
147
+ // double xIntSign = RobustDeterminant.signOfDet2x2(x1, y1, x2, y2) / (y2
148
+ // - y1);
149
+ // MD - faster & more robust computation?
150
+ var xIntSign = jsts.algorithm.RobustDeterminant.signOfDet2x2(x1, y1, x2, y2);
151
+ if (xIntSign === 0.0) {
152
+ this.isPointOnSegment = true;
153
+ return;
154
+ }
155
+ if (y2 < y1)
156
+ xIntSign = -xIntSign;
157
+ // xsave = xInt;
158
+
159
+ // System.out.println("xIntSign(" + x1 + ", " + y1 + ", " + x2 + ", " + y2
160
+ // + " = " + xIntSign);
161
+ // The segment crosses the ray if the sign is strictly positive.
162
+ if (xIntSign > 0.0) {
163
+ this.crossingCount++;
164
+ }
165
+ }
166
+ };
167
+
168
+
169
+ /**
170
+ * Reports whether the point lies exactly on one of the supplied segments. This
171
+ * method may be called at any time as segments are processed. If the result of
172
+ * this method is <tt>true</tt>, no further segments need be supplied, since
173
+ * the result will never change again.
174
+ *
175
+ * @return {boolean} true if the point lies exactly on a segment.
176
+ */
177
+ jsts.algorithm.RayCrossingCounter.prototype.isOnSegment = function() {
178
+ return jsts.geom.isPointOnSegment;
179
+ };
180
+
181
+
182
+ /**
183
+ * Gets the {@link Location} of the point relative to the ring, polygon or
184
+ * multipolygon from which the processed segments were provided.
185
+ * <p>
186
+ * This method only determines the correct location if <b>all</b> relevant
187
+ * segments must have been processed.
188
+ *
189
+ * @return {int} the Location of the point.
190
+ */
191
+ jsts.algorithm.RayCrossingCounter.prototype.getLocation = function() {
192
+ if (this.isPointOnSegment)
193
+ return jsts.geom.Location.BOUNDARY;
194
+
195
+ // The point is in the interior of the ring if the number of X-crossings is
196
+ // odd.
197
+ if ((this.crossingCount % 2) === 1) {
198
+ return jsts.geom.Location.INTERIOR;
199
+ }
200
+ return jsts.geom.Location.EXTERIOR;
201
+ };
202
+
203
+
204
+ /**
205
+ * Tests whether the point lies in or on the ring, polygon or multipolygon from
206
+ * which the processed segments were provided.
207
+ * <p>
208
+ * This method only determines the correct location if <b>all</b> relevant
209
+ * segments must have been processed.
210
+ *
211
+ * @return {boolean} true if the point lies in or on the supplied polygon.
212
+ */
213
+ jsts.algorithm.RayCrossingCounter.prototype.isPointInPolygon = function() {
214
+ return this.getLocation() !== jsts.geom.Location.EXTERIOR;
215
+ };