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.
- checksums.yaml +8 -8
- data/lib/jsts-rails/version.rb +1 -1
- data/vendor/assets/javascripts/javascript.util.js +33 -1
- data/vendor/assets/javascripts/jsts-original.js +164 -1573
- data/vendor/assets/javascripts/jsts.js +197 -0
- data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
- data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
- data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
- data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
- data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
- data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
- data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
- data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
- data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
- data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
- data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
- data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
- data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
- data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
- data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
- data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
- data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
- data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
- data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
- data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
- data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
- data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
- data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
- data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
- data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
- data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
- data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
- data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
- data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
- data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
- data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
- data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
- data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
- data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
- data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
- data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
- data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
- data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
- data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
- data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
- data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
- data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
- data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
- data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
- data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
- data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
- data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
- data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
- data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
- data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
- data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
- data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
- data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
- data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
- data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
- data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
- data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
- data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
- data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
- data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
- data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
- data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
- data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
- data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
- data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
- data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
- data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
- data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
- data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
- data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
- data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
- data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
- data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
- data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
- data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
- data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
- data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
- data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
- data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
- data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
- data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
- data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
- data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
- data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
- data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
- data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
- data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
- data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
- data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
- data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
- data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
- data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
- data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
- data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
- data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
- data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
- data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
- data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
- data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
- data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
- data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
- data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
- data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
- data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
- data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
- 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
|
+
};
|