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,369 @@
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 raw offset curve for a single {@link Geometry} component (ring,
11
+ * line or point). A raw offset curve line is not noded - it may contain
12
+ * self-intersections (and usually will). The final buffer polygon is computed
13
+ * by forming a topological graph of all the noded raw curves and tracing
14
+ * outside contours. The points in the raw curve are rounded to a given
15
+ * {@link PrecisionModel}.
16
+ *
17
+ * @constructor
18
+ */
19
+ jsts.operation.buffer.OffsetCurveBuilder = function(precisionModel, bufParams) {
20
+ this.precisionModel = precisionModel;
21
+ this.bufParams = bufParams;
22
+ };
23
+
24
+
25
+ /**
26
+ * @type {double}
27
+ * @private
28
+ */
29
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.distance = 0.0;
30
+
31
+
32
+ /**
33
+ * @type {PrecisionModel}
34
+ * @private
35
+ */
36
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.precisionModel = null;
37
+
38
+
39
+ /**
40
+ * @type {BufferParameters}
41
+ * @private
42
+ */
43
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.bufParams = null;
44
+
45
+
46
+ /**
47
+ * Gets the buffer parameters being used to generate the curve.
48
+ *
49
+ * @return the buffer parameters being used.
50
+ */
51
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.getBufferParameters = function() {
52
+ return this.bufParams;
53
+ };
54
+
55
+
56
+ /**
57
+ * This method handles single points as well as LineStrings. LineStrings are
58
+ * assumed <b>not</b> to be closed (the function will not fail for closed
59
+ * lines, but will generate superfluous line caps).
60
+ *
61
+ * @param inputPts
62
+ * the vertices of the line to offset.
63
+ * @param distance
64
+ * the offset distance.
65
+ *
66
+ * @return a Coordinate array representing the curve.
67
+ * @return null if the curve is empty.
68
+ */
69
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.getLineCurve = function(
70
+ inputPts, distance) {
71
+ this.distance = distance;
72
+
73
+ // a zero or negative width buffer of a line/point is empty
74
+ if (this.distance < 0.0 && !this.bufParams.isSingleSided())
75
+ return null;
76
+ if (this.distance == 0.0)
77
+ return null;
78
+
79
+ var posDistance = Math.abs(this.distance);
80
+ var segGen = this.getSegGen(posDistance);
81
+ if (inputPts.length <= 1) {
82
+ this.computePointCurve(inputPts[0], segGen);
83
+ } else {
84
+ if (this.bufParams.isSingleSided()) {
85
+ var isRightSide = distance < 0.0;
86
+ this.computeSingleSidedBufferCurve(inputPts, isRightSide, segGen);
87
+ } else
88
+ this.computeLineBufferCurve(inputPts, segGen);
89
+ }
90
+
91
+ var lineCoord = segGen.getCoordinates();
92
+ return lineCoord;
93
+ };
94
+
95
+
96
+ /**
97
+ * This method handles the degenerate cases of single points and lines, as well
98
+ * as rings.
99
+ *
100
+ * @return a Coordinate array representing the curve.
101
+ * @return null if the curve is empty.
102
+ */
103
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.getRingCurve = function(
104
+ inputPts, side, distance) {
105
+ this.distance = distance;
106
+ if (inputPts.length <= 2)
107
+ return this.getLineCurve(inputPts, distance);
108
+
109
+ // optimize creating ring for for zero distance
110
+ if (this.distance == 0.0) {
111
+ return jsts.operation.buffer.OffsetCurveBuilder.copyCoordinates(inputPts);
112
+ }
113
+ var segGen = this.getSegGen(this.distance);
114
+ this.computeRingBufferCurve(inputPts, side, segGen);
115
+ return segGen.getCoordinates();
116
+ };
117
+
118
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.getOffsetCurve = function(
119
+ inputPts, distance) {
120
+ this.distance = distance;
121
+
122
+ // a zero width offset curve is empty
123
+ if (this.distance === 0.0)
124
+ return null;
125
+
126
+ var isRightSide = this.distance < 0.0;
127
+ var posDistance = Math.abs(this.distance);
128
+ var segGen = this.getSegGen(posDistance);
129
+ if (inputPts.length <= 1) {
130
+ this.computePointCurve(inputPts[0], segGen);
131
+ } else {
132
+ this.computeOffsetCurve(inputPts, isRightSide, segGen);
133
+ }
134
+ var curvePts = segGen.getCoordinates();
135
+ // for right side line is traversed in reverse direction, so have to reverse
136
+ // generated line
137
+ if (isRightSide)
138
+ curvePts.reverse();
139
+ return curvePts;
140
+ };
141
+
142
+
143
+ /**
144
+ * @private
145
+ */
146
+ jsts.operation.buffer.OffsetCurveBuilder.copyCoordinates = function(pts) {
147
+ var copy = [];
148
+ for (var i = 0; i < pts.length; i++) {
149
+ copy.push(pts[i].clone());
150
+ }
151
+ return copy;
152
+ };
153
+
154
+
155
+ /**
156
+ * @private
157
+ */
158
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.getSegGen = function(
159
+ distance) {
160
+ return new jsts.operation.buffer.OffsetSegmentGenerator(this.precisionModel,
161
+ this.bufParams, distance);
162
+ };
163
+
164
+
165
+ /**
166
+ * Use a value which results in a potential distance error which is
167
+ * significantly less than the error due to the quadrant segment discretization.
168
+ * For QS = 8 a value of 100 is reasonable. This should produce a maximum of 1%
169
+ * distance error.
170
+ *
171
+ * @private
172
+ */
173
+ jsts.operation.buffer.OffsetCurveBuilder.SIMPLIFY_FACTOR = 100.0;
174
+
175
+
176
+ /**
177
+ * Computes the distance tolerance to use during input line simplification.
178
+ *
179
+ * @param distance
180
+ * the buffer distance.
181
+ * @return the simplification tolerance.
182
+ * @private
183
+ */
184
+ jsts.operation.buffer.OffsetCurveBuilder.simplifyTolerance = function(
185
+ bufDistance) {
186
+ return bufDistance / jsts.operation.buffer.OffsetCurveBuilder.SIMPLIFY_FACTOR;
187
+ };
188
+
189
+
190
+ /**
191
+ * @private
192
+ */
193
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.computePointCurve = function(
194
+ pt, segGen) {
195
+ switch (this.bufParams.getEndCapStyle()) {
196
+ case jsts.operation.buffer.BufferParameters.CAP_ROUND:
197
+ segGen.createCircle(pt);
198
+ break;
199
+ case jsts.operation.buffer.BufferParameters.CAP_SQUARE:
200
+ segGen.createSquare(pt);
201
+ break;
202
+ // otherwise curve is empty (e.g. for a butt cap);
203
+ }
204
+ };
205
+
206
+
207
+ /**
208
+ * @private
209
+ */
210
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.computeLineBufferCurve = function(
211
+ inputPts, segGen) {
212
+ var distTol = jsts.operation.buffer.OffsetCurveBuilder
213
+ .simplifyTolerance(this.distance);
214
+
215
+ // --------- compute points for left side of line
216
+ // Simplify the appropriate side of the line before generating
217
+ var simp1 = jsts.operation.buffer.BufferInputLineSimplifier.simplify(
218
+ inputPts, distTol);
219
+ // MD - used for testing only (to eliminate simplification)
220
+ // Coordinate[] simp1 = inputPts;
221
+
222
+ var n1 = simp1.length - 1;
223
+ segGen.initSideSegments(simp1[0], simp1[1], jsts.geomgraph.Position.LEFT);
224
+ for (var i = 2; i <= n1; i++) {
225
+ segGen.addNextSegment(simp1[i], true);
226
+ }
227
+ segGen.addLastSegment();
228
+ // add line cap for end of line
229
+ segGen.addLineEndCap(simp1[n1 - 1], simp1[n1]);
230
+
231
+ // ---------- compute points for right side of line
232
+ // Simplify the appropriate side of the line before generating
233
+ var simp2 = jsts.operation.buffer.BufferInputLineSimplifier.simplify(
234
+ inputPts, -distTol);
235
+ // MD - used for testing only (to eliminate simplification)
236
+ // Coordinate[] simp2 = inputPts;
237
+ var n2 = simp2.length - 1;
238
+
239
+ // since we are traversing line in opposite order, offset position is still
240
+ // LEFT
241
+ segGen.initSideSegments(simp2[n2], simp2[n2 - 1], jsts.geomgraph.Position.LEFT);
242
+ for (var i = n2 - 2; i >= 0; i--) {
243
+ segGen.addNextSegment(simp2[i], true);
244
+ }
245
+ segGen.addLastSegment();
246
+ // add line cap for start of line
247
+ segGen.addLineEndCap(simp2[1], simp2[0]);
248
+
249
+ segGen.closeRing();
250
+ };
251
+
252
+
253
+ /**
254
+ * @private
255
+ */
256
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.computeSingleSidedBufferCurve = function(
257
+ inputPts, isRightSide, segGen) {
258
+ var distTol = jsts.operation.buffer.OffsetCurveBuilder
259
+ .simplifyTolerance(this.distance);
260
+
261
+ if (isRightSide) {
262
+ // add original line
263
+ segGen.addSegments(inputPts, true);
264
+
265
+ // ---------- compute points for right side of line
266
+ // Simplify the appropriate side of the line before generating
267
+ var simp2 = jsts.operation.buffer.BufferInputLineSimplifier.simplify(
268
+ inputPts, -distTol);
269
+ // MD - used for testing only (to eliminate simplification)
270
+ // Coordinate[] simp2 = inputPts;
271
+ var n2 = simp2.length - 1;
272
+
273
+ // since we are traversing line in opposite order, offset position is still
274
+ // LEFT
275
+ segGen.initSideSegments(simp2[n2], simp2[n2 - 1],
276
+ jsts.geomgraph.Position.LEFT);
277
+ segGen.addFirstSegment();
278
+ for (var i = n2 - 2; i >= 0; i--) {
279
+ segGen.addNextSegment(simp2[i], true);
280
+ }
281
+ } else {
282
+ // add original line
283
+ segGen.addSegments(inputPts, false);
284
+
285
+ // --------- compute points for left side of line
286
+ // Simplify the appropriate side of the line before generating
287
+ var simp1 = jsts.operation.buffer.BufferInputLineSimplifier.simplify(
288
+ inputPts, distTol);
289
+ // MD - used for testing only (to eliminate simplification)
290
+ // Coordinate[] simp1 = inputPts;
291
+
292
+ var n1 = simp1.length - 1;
293
+ segGen.initSideSegments(simp1[0], simp1[1], jsts.geomgraph.Position.LEFT);
294
+ segGen.addFirstSegment();
295
+ for (var i = 2; i <= n1; i++) {
296
+ segGen.addNextSegment(simp1[i], true);
297
+ }
298
+ }
299
+ segGen.addLastSegment();
300
+ segGen.closeRing();
301
+ };
302
+
303
+
304
+ /**
305
+ * @private
306
+ */
307
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.computeOffsetCurve = function(
308
+ inputPts, isRightSide, segGen) {
309
+ var distTol = jsts.operation.buffer.OffsetCurveBuilder
310
+ .simplifyTolerance(this.distance);
311
+
312
+ if (isRightSide) {
313
+ // ---------- compute points for right side of line
314
+ // Simplify the appropriate side of the line before generating
315
+ var simp2 = jsts.operation.buffer.BufferInputLineSimplifier.simplify(
316
+ inputPts, -distTol);
317
+ // MD - used for testing only (to eliminate simplification)
318
+ // Coordinate[] simp2 = inputPts;
319
+ var n2 = simp2.length - 1;
320
+
321
+ // since we are traversing line in opposite order, offset position is still
322
+ // LEFT
323
+ segGen.initSideSegments(simp2[n2], simp2[n2 - 1],
324
+ jsts.geomgraph.Position.LEFT);
325
+ segGen.addFirstSegment();
326
+ for (var i = n2 - 2; i >= 0; i--) {
327
+ segGen.addNextSegment(simp2[i], true);
328
+ }
329
+ } else {
330
+ // --------- compute points for left side of line
331
+ // Simplify the appropriate side of the line before generating
332
+ var simp1 = jsts.operation.buffer.BufferInputLineSimplifier.simplify(
333
+ inputPts, distTol);
334
+ // MD - used for testing only (to eliminate simplification)
335
+ // Coordinate[] simp1 = inputPts;
336
+
337
+ var n1 = simp1.length - 1;
338
+ segGen.initSideSegments(simp1[0], simp1[1], jsts.geomgraph.Position.LEFT);
339
+ segGen.addFirstSegment();
340
+ for (var i = 2; i <= n1; i++) {
341
+ segGen.addNextSegment(simp1[i], true);
342
+ }
343
+ }
344
+ segGen.addLastSegment();
345
+ };
346
+
347
+
348
+ /**
349
+ * @private
350
+ */
351
+ jsts.operation.buffer.OffsetCurveBuilder.prototype.computeRingBufferCurve = function(
352
+ inputPts, side, segGen) {
353
+ // simplify input line to improve performance
354
+ var distTol = jsts.operation.buffer.OffsetCurveBuilder
355
+ .simplifyTolerance(this.distance);
356
+ // ensure that correct side is simplified
357
+ if (side === jsts.geomgraph.Position.RIGHT)
358
+ distTol = -distTol;
359
+ var simp = jsts.operation.buffer.BufferInputLineSimplifier.simplify(inputPts,
360
+ distTol);
361
+
362
+ var n = simp.length - 1;
363
+ segGen.initSideSegments(simp[n - 1], simp[0], side);
364
+ for (var i = 1; i <= n; i++) {
365
+ var addStartPoint = i !== 1;
366
+ segGen.addNextSegment(simp[i], addStartPoint);
367
+ }
368
+ segGen.closeRing();
369
+ };
@@ -0,0 +1,301 @@
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
+ * Creates all the raw offset curves for a buffer of a {@link Geometry}. Raw
10
+ * curves need to be noded together and polygonized to form the final buffer
11
+ * area.
12
+ *
13
+ * @constructor
14
+ */
15
+ jsts.operation.buffer.OffsetCurveSetBuilder = function(inputGeom, distance,
16
+ curveBuilder) {
17
+ this.inputGeom = inputGeom;
18
+ this.distance = distance;
19
+ this.curveBuilder = curveBuilder;
20
+
21
+ this.curveList = new javascript.util.ArrayList();
22
+ };
23
+
24
+
25
+ /**
26
+ * @private
27
+ */
28
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.inputGeom = null;
29
+
30
+
31
+ /**
32
+ * @private
33
+ */
34
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.distance = null;
35
+
36
+
37
+ /**
38
+ * @private
39
+ */
40
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.curveBuilder = null;
41
+
42
+
43
+ /**
44
+ * @private
45
+ */
46
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.curveList = null;
47
+
48
+
49
+ /**
50
+ * Computes the set of raw offset curves for the buffer. Each offset curve has
51
+ * an attached {@link Label} indicating its left and right location.
52
+ *
53
+ * @return a Collection of SegmentStrings representing the raw buffer curves.
54
+ */
55
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.getCurves = function() {
56
+ this.add(this.inputGeom);
57
+ return this.curveList;
58
+ };
59
+
60
+
61
+ /**
62
+ * Creates a {@link SegmentString} for a coordinate list which is a raw offset
63
+ * curve, and adds it to the list of buffer curves. The SegmentString is tagged
64
+ * with a Label giving the topology of the curve. The curve may be oriented in
65
+ * either direction. If the curve is oriented CW, the locations will be: <br>
66
+ * Left: Location.EXTERIOR <br>
67
+ * Right: Location.INTERIOR
68
+ *
69
+ * @private
70
+ */
71
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.addCurve = function(
72
+ coord, leftLoc, rightLoc) {
73
+ // don't add null or trivial curves
74
+ if (coord == null || coord.length < 2)
75
+ return;
76
+ // add the edge for a coordinate list which is a raw offset curve
77
+ var e = new jsts.noding.NodedSegmentString(coord, new jsts.geomgraph.Label(0,
78
+ jsts.geom.Location.BOUNDARY, leftLoc, rightLoc));
79
+ this.curveList.add(e);
80
+ };
81
+
82
+
83
+ /**
84
+ * @private
85
+ */
86
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.add = function(g) {
87
+ if (g.isEmpty())
88
+ return;
89
+
90
+ if (g instanceof jsts.geom.Polygon)
91
+ this.addPolygon(g);
92
+ // LineString also handles LinearRings
93
+ else if (g instanceof jsts.geom.LineString)
94
+ this.addLineString(g);
95
+ else if (g instanceof jsts.geom.Point)
96
+ this.addPoint(g);
97
+ else if (g instanceof jsts.geom.MultiPoint)
98
+ this.addCollection(g);
99
+ else if (g instanceof jsts.geom.MultiLineString)
100
+ this.addCollection(g);
101
+ else if (g instanceof jsts.geom.MultiPolygon)
102
+ this.addCollection(g);
103
+ else if (g instanceof jsts.geom.GeometryCollection)
104
+ this.addCollection(g);
105
+ else
106
+ throw new jsts.error.IllegalArgumentError();
107
+ };
108
+
109
+
110
+ /**
111
+ * @private
112
+ */
113
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.addCollection = function(
114
+ gc) {
115
+ for (var i = 0; i < gc.getNumGeometries(); i++) {
116
+ var g = gc.getGeometryN(i);
117
+ this.add(g);
118
+ }
119
+ };
120
+
121
+
122
+ /**
123
+ * Add a Point to the graph.
124
+ *
125
+ * @private
126
+ */
127
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.addPoint = function(p) {
128
+ // a zero or negative width buffer of a line/point is empty
129
+ if (this.distance <= 0.0)
130
+ return;
131
+ var coord = p.getCoordinates();
132
+ var curve = this.curveBuilder.getLineCurve(coord, this.distance);
133
+ this
134
+ .addCurve(curve, jsts.geom.Location.EXTERIOR, jsts.geom.Location.INTERIOR);
135
+ };
136
+
137
+
138
+ /**
139
+ * @private
140
+ */
141
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.addLineString = function(
142
+ line) {
143
+ // a zero or negative width buffer of a line/point is empty
144
+ if (this.distance <= 0.0 &&
145
+ !this.curveBuilder.getBufferParameters().isSingleSided())
146
+ return;
147
+ var coord = jsts.geom.CoordinateArrays.removeRepeatedPoints(line
148
+ .getCoordinates());
149
+ var curve = this.curveBuilder.getLineCurve(coord, this.distance);
150
+ this
151
+ .addCurve(curve, jsts.geom.Location.EXTERIOR, jsts.geom.Location.INTERIOR);
152
+ };
153
+
154
+
155
+ /**
156
+ * @private
157
+ */
158
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.addPolygon = function(p) {
159
+ var offsetDistance = this.distance;
160
+ var offsetSide = jsts.geomgraph.Position.LEFT;
161
+ if (this.distance < 0.0) {
162
+ offsetDistance = -this.distance;
163
+ offsetSide = jsts.geomgraph.Position.RIGHT;
164
+ }
165
+
166
+ var shell = p.getExteriorRing();
167
+ var shellCoord = jsts.geom.CoordinateArrays.removeRepeatedPoints(shell
168
+ .getCoordinates());
169
+ // optimization - don't bother computing buffer
170
+ // if the polygon would be completely eroded
171
+ if (this.distance < 0.0 && this.isErodedCompletely(shell, this.distance))
172
+ return;
173
+ // don't attemtp to buffer a polygon with too few distinct vertices
174
+ if (this.distance <= 0.0 && shellCoord.length < 3)
175
+ return;
176
+
177
+ this.addPolygonRing(shellCoord, offsetDistance, offsetSide,
178
+ jsts.geom.Location.EXTERIOR, jsts.geom.Location.INTERIOR);
179
+
180
+ for (var i = 0; i < p.getNumInteriorRing(); i++) {
181
+
182
+ var hole = p.getInteriorRingN(i);
183
+ var holeCoord = jsts.geom.CoordinateArrays.removeRepeatedPoints(hole
184
+ .getCoordinates());
185
+
186
+ // optimization - don't bother computing buffer for this hole
187
+ // if the hole would be completely covered
188
+ if (this.distance > 0.0 && this.isErodedCompletely(hole, -this.distance))
189
+ continue;
190
+
191
+ // Holes are topologically labelled opposite to the shell, since
192
+ // the interior of the polygon lies on their opposite side
193
+ // (on the left, if the hole is oriented CCW)
194
+ this.addPolygonRing(holeCoord, offsetDistance, jsts.geomgraph.Position
195
+ .opposite(offsetSide), jsts.geom.Location.INTERIOR,
196
+ jsts.geom.Location.EXTERIOR);
197
+ }
198
+ };
199
+
200
+
201
+ /**
202
+ * Adds an offset curve for a polygon ring. The side and left and right
203
+ * topological location arguments assume that the ring is oriented CW. If the
204
+ * ring is in the opposite orientation, the left and right locations must be
205
+ * interchanged and the side flipped.
206
+ *
207
+ * @param coord
208
+ * the coordinates of the ring (must not contain repeated points).
209
+ * @param offsetDistance
210
+ * the distance at which to create the buffer.
211
+ * @param side
212
+ * the side of the ring on which to construct the buffer line.
213
+ * @param cwLeftLoc
214
+ * the location on the L side of the ring (if it is CW).
215
+ * @param cwRightLoc
216
+ * the location on the R side of the ring (if it is CW).
217
+ */
218
+ /**
219
+ * @private
220
+ */
221
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.addPolygonRing = function(
222
+ coord, offsetDistance, side, cwLeftLoc, cwRightLoc) {
223
+ // don't bother adding ring if it is "flat" and will disappear in the output
224
+ if (offsetDistance == 0.0 &&
225
+ coord.length < jsts.geom.LinearRing.MINIMUM_VALID_SIZE)
226
+ return;
227
+
228
+ var leftLoc = cwLeftLoc;
229
+ var rightLoc = cwRightLoc;
230
+ if (coord.length >= jsts.geom.LinearRing.MINIMUM_VALID_SIZE &&
231
+ jsts.algorithm.CGAlgorithms.isCCW(coord)) {
232
+ leftLoc = cwRightLoc;
233
+ rightLoc = cwLeftLoc;
234
+ side = jsts.geomgraph.Position.opposite(side);
235
+ }
236
+ var curve = this.curveBuilder.getRingCurve(coord, side, offsetDistance);
237
+ this.addCurve(curve, leftLoc, rightLoc);
238
+ };
239
+
240
+
241
+ /**
242
+ * The ringCoord is assumed to contain no repeated points. It may be degenerate
243
+ * (i.e. contain only 1, 2, or 3 points). In this case it has no area, and hence
244
+ * has a minimum diameter of 0.
245
+ *
246
+ * @param ringCoord
247
+ * @param offsetDistance
248
+ * @return
249
+ */
250
+ /**
251
+ * @private
252
+ */
253
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.isErodedCompletely = function(
254
+ ring, bufferDistance) {
255
+ var ringCoord = ring.getCoordinates();
256
+ var minDiam = 0.0;
257
+ // degenerate ring has no area
258
+ if (ringCoord.length < 4)
259
+ return bufferDistance < 0;
260
+
261
+ // important test to eliminate inverted triangle bug
262
+ // also optimizes erosion test for triangles
263
+ if (ringCoord.length == 4)
264
+ return this.isTriangleErodedCompletely(ringCoord, bufferDistance);
265
+
266
+ // if envelope is narrower than twice the buffer distance, ring is eroded
267
+ var env = ring.getEnvelopeInternal();
268
+ var envMinDimension = Math.min(env.getHeight(), env.getWidth());
269
+ if (bufferDistance < 0.0 && 2 * Math.abs(bufferDistance) > envMinDimension)
270
+ return true;
271
+
272
+ return false;
273
+ };
274
+
275
+
276
+ /**
277
+ * Tests whether a triangular ring would be eroded completely by the given
278
+ * buffer distance. This is a precise test. It uses the fact that the inner
279
+ * buffer of a triangle converges on the inCentre of the triangle (the point
280
+ * equidistant from all sides). If the buffer distance is greater than the
281
+ * distance of the inCentre from a side, the triangle will be eroded completely.
282
+ *
283
+ * This test is important, since it removes a problematic case where the buffer
284
+ * distance is slightly larger than the inCentre distance. In this case the
285
+ * triangle buffer curve "inverts" with incorrect topology, producing an
286
+ * incorrect hole in the buffer.
287
+ *
288
+ * @param triangleCoord
289
+ * @param bufferDistance
290
+ * @return
291
+ *
292
+ * @private
293
+ */
294
+ jsts.operation.buffer.OffsetCurveSetBuilder.prototype.isTriangleErodedCompletely = function(
295
+ triangleCoord, bufferDistance) {
296
+ var tri = new jsts.geom.Triangle(triangleCoord[0], triangleCoord[1], triangleCoord[2]);
297
+ var inCentre = tri.inCentre();
298
+ var distToCentre = jsts.algorithm.CGAlgorithms.distancePointLine(inCentre,
299
+ tri.p0, tri.p1);
300
+ return distToCentre < Math.abs(bufferDistance);
301
+ };