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,118 @@
|
|
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
|
+
* @param {Coordinate}
|
11
|
+
* p00
|
12
|
+
* @param {Coordinate}
|
13
|
+
* p01
|
14
|
+
* @param {Coordinate}
|
15
|
+
* p10
|
16
|
+
* @param {Coordinate}
|
17
|
+
* p11
|
18
|
+
* @constructor
|
19
|
+
*/
|
20
|
+
jsts.algorithm.CentralEndpointIntersector = function(p00, p01, p10, p11) {
|
21
|
+
this.pts = [p00, p01, p10, p11];
|
22
|
+
this.compute();
|
23
|
+
};
|
24
|
+
|
25
|
+
|
26
|
+
/**
|
27
|
+
* @param {Coordinate}
|
28
|
+
* p00
|
29
|
+
* @param {Coordinate}
|
30
|
+
* p01
|
31
|
+
* @param {Coordinate}
|
32
|
+
* p10
|
33
|
+
* @param {Coordinate}
|
34
|
+
* p11
|
35
|
+
* @return {Coordinate}
|
36
|
+
*/
|
37
|
+
jsts.algorithm.CentralEndpointIntersector.getIntersection = function(p00, p01,
|
38
|
+
p10, p11) {
|
39
|
+
var intor = new jsts.algorithm.CentralEndpointIntersector(p00, p01, p10, p11);
|
40
|
+
return intor.getIntersection();
|
41
|
+
};
|
42
|
+
|
43
|
+
|
44
|
+
/**
|
45
|
+
* @type {Coordinate[]}
|
46
|
+
* @private
|
47
|
+
*/
|
48
|
+
jsts.algorithm.CentralEndpointIntersector.prototype.pts = null;
|
49
|
+
|
50
|
+
|
51
|
+
/**
|
52
|
+
* @type {Coordinate}
|
53
|
+
* @private
|
54
|
+
*/
|
55
|
+
jsts.algorithm.CentralEndpointIntersector.prototype.intPt = null;
|
56
|
+
|
57
|
+
|
58
|
+
/**
|
59
|
+
* @private
|
60
|
+
*/
|
61
|
+
jsts.algorithm.CentralEndpointIntersector.prototype.compute = function() {
|
62
|
+
var centroid = jsts.algorithm.CentralEndpointIntersector.average(this.pts);
|
63
|
+
this.intPt = this.findNearestPoint(centroid, this.pts);
|
64
|
+
};
|
65
|
+
|
66
|
+
|
67
|
+
/**
|
68
|
+
* @return {Coordinate}
|
69
|
+
*/
|
70
|
+
jsts.algorithm.CentralEndpointIntersector.prototype.getIntersection = function() {
|
71
|
+
return this.intPt;
|
72
|
+
};
|
73
|
+
|
74
|
+
|
75
|
+
/**
|
76
|
+
* @param {Coordinate[]}
|
77
|
+
* pts
|
78
|
+
* @return {Coordinate}
|
79
|
+
* @private
|
80
|
+
*/
|
81
|
+
jsts.algorithm.CentralEndpointIntersector.average = function(pts) {
|
82
|
+
var avg = new jsts.geom.Coordinate();
|
83
|
+
var i, n = pts.length;
|
84
|
+
for (i = 0; i < n; i++) {
|
85
|
+
avg.x += pts[i].x;
|
86
|
+
avg.y += pts[i].y;
|
87
|
+
}
|
88
|
+
if (n > 0) {
|
89
|
+
avg.x /= n;
|
90
|
+
avg.y /= n;
|
91
|
+
}
|
92
|
+
return avg;
|
93
|
+
};
|
94
|
+
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Determines a point closest to the given point.
|
98
|
+
*
|
99
|
+
* @param {Coordinate}
|
100
|
+
* p the point to compare against.
|
101
|
+
* @param {Coordinate[]}
|
102
|
+
* pts
|
103
|
+
* @return {Coordinate} the point closest to the input point p.
|
104
|
+
* @private
|
105
|
+
*/
|
106
|
+
jsts.algorithm.CentralEndpointIntersector.prototype.findNearestPoint = function(
|
107
|
+
p, pts) {
|
108
|
+
var minDist = Number.MAX_VALUE;
|
109
|
+
var i, result = null, dist;
|
110
|
+
for (i = 0; i < pts.length; i++) {
|
111
|
+
dist = p.distance(pts[i]);
|
112
|
+
if (dist < minDist) {
|
113
|
+
minDist = dist;
|
114
|
+
result = pts[i];
|
115
|
+
}
|
116
|
+
}
|
117
|
+
return result;
|
118
|
+
};
|
@@ -0,0 +1,225 @@
|
|
1
|
+
/**
|
2
|
+
* Computes the centroid of an area geometry.
|
3
|
+
* <h2>Algorithm</h2>
|
4
|
+
* Based on the usual algorithm for calculating the centroid as a weighted sum
|
5
|
+
* of the centroids of a decomposition of the area into (possibly overlapping)
|
6
|
+
* triangles. The algorithm has been extended to handle holes and
|
7
|
+
* multi-polygons. See
|
8
|
+
* <code>http://www.faqs.org/faqs/graphics/algorithms-faq/</code> for further
|
9
|
+
* details of the basic approach. The code has also be extended to handle
|
10
|
+
* degenerate (zero-area) polygons. In this case, the centroid of the line
|
11
|
+
* segments in the polygon will be returned.
|
12
|
+
*
|
13
|
+
* @version 1.7
|
14
|
+
*/
|
15
|
+
jsts.algorithm.CentroidArea = function() {
|
16
|
+
this.basePt = null;
|
17
|
+
this.triangleCent3 = new jsts.geom.Coordinate();
|
18
|
+
this.centSum = new jsts.geom.Coordinate();
|
19
|
+
this.cg3 = new jsts.geom.Coordinate();
|
20
|
+
};
|
21
|
+
|
22
|
+
|
23
|
+
/**
|
24
|
+
* the point all triangles are based at
|
25
|
+
*
|
26
|
+
* @type {jsts.geom.Coordinate}
|
27
|
+
* @private
|
28
|
+
*/
|
29
|
+
jsts.algorithm.CentroidArea.prototype.basePt = null;
|
30
|
+
|
31
|
+
|
32
|
+
/**
|
33
|
+
* temporary variable to hold centroid of triangle
|
34
|
+
*
|
35
|
+
* @type {jsts.geom.Coordinate}
|
36
|
+
* @private
|
37
|
+
*/
|
38
|
+
jsts.algorithm.CentroidArea.prototype.triangleCent3 = null;
|
39
|
+
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Partial area sum
|
43
|
+
*
|
44
|
+
* @type {double}
|
45
|
+
* @private
|
46
|
+
*/
|
47
|
+
jsts.algorithm.CentroidArea.prototype.areasum2 = 0;
|
48
|
+
|
49
|
+
|
50
|
+
/**
|
51
|
+
* partial centroid sum
|
52
|
+
*
|
53
|
+
* @type {jsts.geom.Coordinate}
|
54
|
+
* @private
|
55
|
+
*/
|
56
|
+
jsts.algorithm.CentroidArea.prototype.cg3 = null;
|
57
|
+
|
58
|
+
|
59
|
+
/**
|
60
|
+
* // data for linear centroid computation, if needed
|
61
|
+
*
|
62
|
+
* @type {jsts.geom.Coordinate}
|
63
|
+
* @private
|
64
|
+
*/
|
65
|
+
jsts.algorithm.CentroidArea.prototype.centSum = null;
|
66
|
+
|
67
|
+
|
68
|
+
/**
|
69
|
+
* @type {double}
|
70
|
+
* @private
|
71
|
+
*/
|
72
|
+
jsts.algorithm.CentroidArea.prototype.totalLength = 0.0;
|
73
|
+
|
74
|
+
|
75
|
+
/**
|
76
|
+
* Adds the area defined by a Geometry to the centroid total. If the geometry
|
77
|
+
* has no area it does not contribute to the centroid.
|
78
|
+
*
|
79
|
+
* @param geom
|
80
|
+
* the geometry to add.
|
81
|
+
*/
|
82
|
+
jsts.algorithm.CentroidArea.prototype.add = function(geom) {
|
83
|
+
if (geom instanceof jsts.geom.Polygon) {
|
84
|
+
var poly = geom;
|
85
|
+
this.setBasePoint(poly.getExteriorRing().getCoordinateN(0));
|
86
|
+
this.add3(poly);
|
87
|
+
} else if (geom instanceof jsts.geom.GeometryCollection || geom instanceof jsts.geom.MultiPolygon) {
|
88
|
+
var gc = geom;
|
89
|
+
for (var i = 0; i < gc.getNumGeometries(); i++) {
|
90
|
+
this.add(gc.getGeometryN(i));
|
91
|
+
}
|
92
|
+
} else if (geom instanceof Array) {
|
93
|
+
this.add2(geom);
|
94
|
+
}
|
95
|
+
};
|
96
|
+
|
97
|
+
|
98
|
+
/**
|
99
|
+
* Adds the area defined by an array of coordinates. The array must be a ring;
|
100
|
+
* i.e. end with the same coordinate as it starts with.
|
101
|
+
*
|
102
|
+
* @param ring
|
103
|
+
* an array of {@link Coordinate} s.
|
104
|
+
*/
|
105
|
+
jsts.algorithm.CentroidArea.prototype.add2 = function(ring) {
|
106
|
+
this.setBasePoint(ring[0]);
|
107
|
+
this.addShell(ring);
|
108
|
+
};
|
109
|
+
|
110
|
+
jsts.algorithm.CentroidArea.prototype.getCentroid = function() {
|
111
|
+
var cent = new jsts.geom.Coordinate();
|
112
|
+
if (Math.abs(this.areasum2) > 0.0) {
|
113
|
+
cent.x = this.cg3.x / 3 / this.areasum2;
|
114
|
+
cent.y = this.cg3.y / 3 / this.areasum2;
|
115
|
+
} else {
|
116
|
+
// if polygon was degenerate, compute linear centroid instead
|
117
|
+
cent.x = this.centSum.x / this.totalLength;
|
118
|
+
cent.y = this.centSum.y / this.totalLength;
|
119
|
+
}
|
120
|
+
return cent;
|
121
|
+
};
|
122
|
+
|
123
|
+
|
124
|
+
/**
|
125
|
+
* @private
|
126
|
+
*/
|
127
|
+
jsts.algorithm.CentroidArea.prototype.setBasePoint = function(basePt) {
|
128
|
+
if (this.basePt == null)
|
129
|
+
this.basePt = basePt;
|
130
|
+
};
|
131
|
+
|
132
|
+
|
133
|
+
/**
|
134
|
+
* @private
|
135
|
+
*/
|
136
|
+
jsts.algorithm.CentroidArea.prototype.add3 = function(poly) {
|
137
|
+
this.addShell(poly.getExteriorRing().getCoordinates());
|
138
|
+
for (var i = 0; i < poly.getNumInteriorRing(); i++) {
|
139
|
+
this.addHole(poly.getInteriorRingN(i).getCoordinates());
|
140
|
+
}
|
141
|
+
};
|
142
|
+
|
143
|
+
|
144
|
+
/**
|
145
|
+
* @private
|
146
|
+
*/
|
147
|
+
jsts.algorithm.CentroidArea.prototype.addShell = function(pts) {
|
148
|
+
var isPositiveArea = !jsts.algorithm.CGAlgorithms.isCCW(pts);
|
149
|
+
for (var i = 0; i < pts.length - 1; i++) {
|
150
|
+
this.addTriangle(this.basePt, pts[i], pts[i + 1], isPositiveArea);
|
151
|
+
}
|
152
|
+
this.addLinearSegments(pts);
|
153
|
+
};
|
154
|
+
|
155
|
+
|
156
|
+
/**
|
157
|
+
* @private
|
158
|
+
*/
|
159
|
+
jsts.algorithm.CentroidArea.prototype.addHole = function(pts) {
|
160
|
+
var isPositiveArea = jsts.algorithm.CGAlgorithms.isCCW(pts);
|
161
|
+
for (var i = 0; i < pts.length - 1; i++) {
|
162
|
+
this.addTriangle(this.basePt, pts[i], pts[i + 1], isPositiveArea);
|
163
|
+
}
|
164
|
+
this.addLinearSegments(pts);
|
165
|
+
};
|
166
|
+
|
167
|
+
|
168
|
+
/**
|
169
|
+
* @private
|
170
|
+
*/
|
171
|
+
jsts.algorithm.CentroidArea.prototype.addTriangle = function(p0, p1, p2,
|
172
|
+
isPositiveArea) {
|
173
|
+
var sign = (isPositiveArea) ? 1.0 : -1.0;
|
174
|
+
jsts.algorithm.CentroidArea.centroid3(p0, p1, p2, this.triangleCent3);
|
175
|
+
var area2 = jsts.algorithm.CentroidArea.area2(p0, p1, p2);
|
176
|
+
this.cg3.x += sign * area2 * this.triangleCent3.x;
|
177
|
+
this.cg3.y += sign * area2 * this.triangleCent3.y;
|
178
|
+
this.areasum2 += sign * area2;
|
179
|
+
};
|
180
|
+
|
181
|
+
|
182
|
+
/**
|
183
|
+
* Returns three times the centroid of the triangle p1-p2-p3. The factor of 3 is
|
184
|
+
* left in to permit division to be avoided until later.
|
185
|
+
*
|
186
|
+
* @private
|
187
|
+
*/
|
188
|
+
jsts.algorithm.CentroidArea.centroid3 = function(p1, p2, p3, c) {
|
189
|
+
c.x = p1.x + p2.x + p3.x;
|
190
|
+
c.y = p1.y + p2.y + p3.y;
|
191
|
+
return;
|
192
|
+
};
|
193
|
+
|
194
|
+
|
195
|
+
/**
|
196
|
+
* Returns twice the signed area of the triangle p1-p2-p3, positive if a,b,c are
|
197
|
+
* oriented ccw, and negative if cw.
|
198
|
+
*
|
199
|
+
* @private
|
200
|
+
*/
|
201
|
+
jsts.algorithm.CentroidArea.area2 = function(p1, p2, p3) {
|
202
|
+
return (p2.x - p1.x) * (p3.y - p1.y) - (p3.x - p1.x) * (p2.y - p1.y);
|
203
|
+
};
|
204
|
+
|
205
|
+
|
206
|
+
/**
|
207
|
+
* Adds the linear segments defined by an array of coordinates to the linear
|
208
|
+
* centroid accumulators. This is done in case the polygon(s) have zero-area, in
|
209
|
+
* which case the linear centroid is computed instead.
|
210
|
+
*
|
211
|
+
* @param pts
|
212
|
+
* an array of {@link Coordinate} s.
|
213
|
+
* @private
|
214
|
+
*/
|
215
|
+
jsts.algorithm.CentroidArea.prototype.addLinearSegments = function(pts) {
|
216
|
+
for (var i = 0; i < pts.length - 1; i++) {
|
217
|
+
var segmentLen = pts[i].distance(pts[i + 1]);
|
218
|
+
this.totalLength += segmentLen;
|
219
|
+
|
220
|
+
var midx = (pts[i].x + pts[i + 1].x) / 2;
|
221
|
+
this.centSum.x += segmentLen * midx;
|
222
|
+
var midy = (pts[i].y + pts[i + 1].y) / 2;
|
223
|
+
this.centSum.y += segmentLen * midy;
|
224
|
+
}
|
225
|
+
};
|
@@ -0,0 +1,85 @@
|
|
1
|
+
/**
|
2
|
+
* Computes the centroid of a linear geometry.
|
3
|
+
* <h2>Algorithm</h2>
|
4
|
+
* Compute the average of the midpoints of all line segments weighted by the
|
5
|
+
* segment length.
|
6
|
+
*
|
7
|
+
* @version 1.7
|
8
|
+
*/
|
9
|
+
jsts.algorithm.CentroidLine = function() {
|
10
|
+
this.centSum = new jsts.geom.Coordinate();
|
11
|
+
};
|
12
|
+
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @type {jsts.geom.Coordinate}
|
16
|
+
* @private
|
17
|
+
*/
|
18
|
+
jsts.algorithm.CentroidLine.prototype.centSum = null;
|
19
|
+
|
20
|
+
|
21
|
+
/**
|
22
|
+
* @type {double}
|
23
|
+
* @private
|
24
|
+
*/
|
25
|
+
jsts.algorithm.CentroidLine.prototype.totalLength = 0.0;
|
26
|
+
|
27
|
+
|
28
|
+
/**
|
29
|
+
* Adds the linear components of by a Geometry to the centroid total. If the
|
30
|
+
* geometry has no linear components it does not contribute to the centroid,
|
31
|
+
*
|
32
|
+
* @param geom
|
33
|
+
* the geometry to add.
|
34
|
+
*/
|
35
|
+
jsts.algorithm.CentroidLine.prototype.add = function(geom) {
|
36
|
+
if (geom instanceof Array) {
|
37
|
+
this.add2.apply(this, arguments);
|
38
|
+
return;
|
39
|
+
}
|
40
|
+
|
41
|
+
if (geom instanceof jsts.geom.LineString) {
|
42
|
+
this.add(geom.getCoordinates());
|
43
|
+
} else if (geom instanceof jsts.geom.Polygon) {
|
44
|
+
var poly = geom;
|
45
|
+
// add linear components of a polygon
|
46
|
+
this.add(poly.getExteriorRing().getCoordinates());
|
47
|
+
for (var i = 0; i < poly.getNumInteriorRing(); i++) {
|
48
|
+
this.add(poly.getInteriorRingN(i).getCoordinates());
|
49
|
+
}
|
50
|
+
} else if (geom instanceof jsts.geom.GeometryCollection ||
|
51
|
+
geom instanceof jsts.geom.MultiPoint ||
|
52
|
+
geom instanceof jsts.geom.MultiLineString ||
|
53
|
+
geom instanceof jsts.geom.MultiPolygon) {
|
54
|
+
var gc = geom;
|
55
|
+
for (var i = 0; i < gc.getNumGeometries(); i++) {
|
56
|
+
this.add(gc.getGeometryN(i));
|
57
|
+
}
|
58
|
+
}
|
59
|
+
};
|
60
|
+
|
61
|
+
jsts.algorithm.CentroidLine.prototype.getCentroid = function() {
|
62
|
+
var cent = new jsts.geom.Coordinate();
|
63
|
+
cent.x = this.centSum.x / this.totalLength;
|
64
|
+
cent.y = this.centSum.y / this.totalLength;
|
65
|
+
return cent;
|
66
|
+
};
|
67
|
+
|
68
|
+
|
69
|
+
/**
|
70
|
+
* Adds the length defined by an array of coordinates.
|
71
|
+
*
|
72
|
+
* @param pts
|
73
|
+
* an array of {@link Coordinate} s.
|
74
|
+
*/
|
75
|
+
jsts.algorithm.CentroidLine.prototype.add2 = function(pts) {
|
76
|
+
for (var i = 0; i < pts.length - 1; i++) {
|
77
|
+
var segmentLen = pts[i].distance(pts[i + 1]);
|
78
|
+
this.totalLength += segmentLen;
|
79
|
+
|
80
|
+
var midx = (pts[i].x + pts[i + 1].x) / 2;
|
81
|
+
this.centSum.x += segmentLen * midx;
|
82
|
+
var midy = (pts[i].y + pts[i + 1].y) / 2;
|
83
|
+
this.centSum.y += segmentLen * midy;
|
84
|
+
}
|
85
|
+
};
|
@@ -0,0 +1,77 @@
|
|
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
|
+
* Computes the centroid of a point geometry.
|
10
|
+
* <h2>Algorithm</h2>
|
11
|
+
* Compute the average of all points.
|
12
|
+
*
|
13
|
+
* @version 1.7
|
14
|
+
*/
|
15
|
+
jsts.algorithm.CentroidPoint = function() {
|
16
|
+
this.centSum = new jsts.geom.Coordinate();
|
17
|
+
};
|
18
|
+
|
19
|
+
|
20
|
+
/**
|
21
|
+
* @type {int}
|
22
|
+
* @private
|
23
|
+
*/
|
24
|
+
jsts.algorithm.CentroidPoint.prototype.ptCount = 0;
|
25
|
+
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @type {jsts.geom.Coordinate}
|
29
|
+
* @private
|
30
|
+
*/
|
31
|
+
jsts.algorithm.CentroidPoint.prototype.centSum = null;
|
32
|
+
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Adds the point(s) defined by a Geometry to the centroid total. If the
|
36
|
+
* geometry is not of dimension 0 it does not contribute to the centroid.
|
37
|
+
*
|
38
|
+
* @param {Geometry}
|
39
|
+
* geom the geometry to add.
|
40
|
+
*/
|
41
|
+
jsts.algorithm.CentroidPoint.prototype.add = function(geom) {
|
42
|
+
if (geom instanceof jsts.geom.Point) {
|
43
|
+
this.add2(geom.getCoordinate());
|
44
|
+
} else if (geom instanceof jsts.geom.GeometryCollection ||
|
45
|
+
geom instanceof jsts.geom.MultiPoint ||
|
46
|
+
geom instanceof jsts.geom.MultiLineString ||
|
47
|
+
geom instanceof jsts.geom.MultiPolygon) {
|
48
|
+
var gc = geom;
|
49
|
+
for (var i = 0; i < gc.getNumGeometries(); i++) {
|
50
|
+
this.add(gc.getGeometryN(i));
|
51
|
+
}
|
52
|
+
}
|
53
|
+
};
|
54
|
+
|
55
|
+
|
56
|
+
/**
|
57
|
+
* Adds the length defined by an array of coordinates.
|
58
|
+
*
|
59
|
+
* @param {jsts.geom.Coordinate}
|
60
|
+
* pts an array of {@link Coordinate}s.
|
61
|
+
*/
|
62
|
+
jsts.algorithm.CentroidPoint.prototype.add2 = function(pt) {
|
63
|
+
this.ptCount += 1;
|
64
|
+
this.centSum.x += pt.x;
|
65
|
+
this.centSum.y += pt.y;
|
66
|
+
};
|
67
|
+
|
68
|
+
|
69
|
+
/**
|
70
|
+
* @return {jsts.geom.Coordinate}
|
71
|
+
*/
|
72
|
+
jsts.algorithm.CentroidPoint.prototype.getCentroid = function() {
|
73
|
+
var cent = new jsts.geom.Coordinate();
|
74
|
+
cent.x = this.centSum.x / this.ptCount;
|
75
|
+
cent.y = this.centSum.y / this.ptCount;
|
76
|
+
return cent;
|
77
|
+
};
|