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,158 @@
|
|
1
|
+
/* Copyright (c) 2011 by The Authors.
|
2
|
+
* Published under the LGPL 2.1 license.
|
3
|
+
* See /license-notice.txt for the full text of the license notice.
|
4
|
+
* See /license.txt for the full text of the license.
|
5
|
+
*/
|
6
|
+
|
7
|
+
(function() {
|
8
|
+
|
9
|
+
/**
|
10
|
+
* A lightweight class used to store coordinates on the 2-dimensional
|
11
|
+
* Cartesian plane. It is distinct from {@link Point}, which is a subclass of
|
12
|
+
* {@link Geometry}. Unlike objects of type {@link Point} (which contain
|
13
|
+
* additional information such as an envelope, a precision model, and spatial
|
14
|
+
* reference system information), a <code>Coordinate</code> only contains
|
15
|
+
* coordinate values and accessor methods.
|
16
|
+
*
|
17
|
+
* @requires jsts/geom/Geometry.js
|
18
|
+
*/
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
/**
|
23
|
+
* @constructor
|
24
|
+
*/
|
25
|
+
jsts.geom.Coordinate = function(x, y) {
|
26
|
+
if (typeof x === 'number') {
|
27
|
+
this.x = x;
|
28
|
+
this.y = y;
|
29
|
+
} else if (x instanceof jsts.geom.Coordinate) {
|
30
|
+
this.x = parseFloat(x.x);
|
31
|
+
this.y = parseFloat(x.y);
|
32
|
+
} else if (x === undefined || x === null) {
|
33
|
+
this.x = 0;
|
34
|
+
this.y = 0;
|
35
|
+
} else if (typeof x === 'string') {
|
36
|
+
this.x = parseFloat(x);
|
37
|
+
this.y = parseFloat(y);
|
38
|
+
}
|
39
|
+
};
|
40
|
+
|
41
|
+
/**
|
42
|
+
* Sets this <code>Coordinate</code>s (x,y,z) values to that of
|
43
|
+
* <code>other</code>.
|
44
|
+
*
|
45
|
+
* @param {Coordinate}
|
46
|
+
* other the <code>Coordinate</code> to copy.
|
47
|
+
*/
|
48
|
+
jsts.geom.Coordinate.prototype.setCoordinate = function(other) {
|
49
|
+
this.x = other.x;
|
50
|
+
this.y = other.y;
|
51
|
+
};
|
52
|
+
|
53
|
+
|
54
|
+
/**
|
55
|
+
* Clones this instance.
|
56
|
+
*
|
57
|
+
* @return {Coordinate} A point instance cloned from this.
|
58
|
+
*/
|
59
|
+
jsts.geom.Coordinate.prototype.clone = function() {
|
60
|
+
return new jsts.geom.Coordinate(this.x, this.y);
|
61
|
+
};
|
62
|
+
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Computes the 2-dimensional Euclidean distance to another location. The
|
66
|
+
* Z-ordinate is ignored.
|
67
|
+
*
|
68
|
+
* @param {Coordinate}
|
69
|
+
* p a point.
|
70
|
+
* @return {number} the 2-dimensional Euclidean distance between the
|
71
|
+
* locations.
|
72
|
+
*/
|
73
|
+
jsts.geom.Coordinate.prototype.distance = function(p) {
|
74
|
+
var dx = this.x - p.x;
|
75
|
+
var dy = this.y - p.y;
|
76
|
+
|
77
|
+
return Math.sqrt(dx * dx + dy * dy);
|
78
|
+
};
|
79
|
+
|
80
|
+
/**
|
81
|
+
* Returns whether the planar projections of the two <code>Coordinate</code>s
|
82
|
+
* are equal.
|
83
|
+
*
|
84
|
+
* @param {Coordinate}
|
85
|
+
* other a <code>Coordinate</code> with which to do the 2D
|
86
|
+
* comparison.
|
87
|
+
* @return {boolean} <code>true</code> if the x- and y-coordinates are
|
88
|
+
* equal; the z-coordinates do not have to be equal.
|
89
|
+
*/
|
90
|
+
jsts.geom.Coordinate.prototype.equals2D = function(other) {
|
91
|
+
if (this.x !== other.x) {
|
92
|
+
return false;
|
93
|
+
}
|
94
|
+
|
95
|
+
if (this.y !== other.y) {
|
96
|
+
return false;
|
97
|
+
}
|
98
|
+
|
99
|
+
return true;
|
100
|
+
};
|
101
|
+
|
102
|
+
/**
|
103
|
+
* Returns <code>true</code> if <code>other</code> has the same values for
|
104
|
+
* the x and y ordinates. Since Coordinates are 2.5D, this routine ignores the
|
105
|
+
* z value when making the comparison.
|
106
|
+
*
|
107
|
+
* @param {Coordinate}
|
108
|
+
* other a <code>Coordinate</code> with which to do the comparison.
|
109
|
+
* @return {boolean} <code>true</code> if <code>other</code> is a
|
110
|
+
* <code>Coordinate</code> with the same values for the x and y
|
111
|
+
* ordinates.
|
112
|
+
*/
|
113
|
+
jsts.geom.Coordinate.prototype.equals = function(other) {
|
114
|
+
if (!other instanceof jsts.geom.Coordinate || other === undefined) {
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
return this.equals2D(other);
|
118
|
+
};
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Compares this {@link Coordinate} with the specified {@link Coordinate} for
|
122
|
+
* order. This method ignores the z value when making the comparison. Returns:
|
123
|
+
* <UL>
|
124
|
+
* <LI> -1 : this.x < other.x || ((this.x == other.x) && (this.y < other.y))
|
125
|
+
* <LI> 0 : this.x == other.x && this.y = other.y
|
126
|
+
* <LI> 1 : this.x > other.x || ((this.x == other.x) && (this.y > other.y))
|
127
|
+
*
|
128
|
+
* </UL>
|
129
|
+
* Note: This method assumes that ordinate values are valid numbers. NaN
|
130
|
+
* values are not handled correctly.
|
131
|
+
*
|
132
|
+
* @param {Coordinate}
|
133
|
+
* other the <code>Coordinate</code> with which this
|
134
|
+
* <code>Coordinate</code> is being compared.
|
135
|
+
* @return {number} -1, zero, or 1 as explained above.
|
136
|
+
*/
|
137
|
+
jsts.geom.Coordinate.prototype.compareTo = function(other) {
|
138
|
+
if (this.x < other.x) {
|
139
|
+
return -1;
|
140
|
+
}
|
141
|
+
if (this.x > other.x) {
|
142
|
+
return 1;
|
143
|
+
}
|
144
|
+
if (this.y < other.y) {
|
145
|
+
return -1;
|
146
|
+
}
|
147
|
+
if (this.y > other.y) {
|
148
|
+
return 1;
|
149
|
+
}
|
150
|
+
|
151
|
+
return 0;
|
152
|
+
};
|
153
|
+
|
154
|
+
jsts.geom.Coordinate.prototype.toString = function() {
|
155
|
+
return '(' + this.x + ', ' + this.y + ')';
|
156
|
+
};
|
157
|
+
|
158
|
+
})();
|
@@ -0,0 +1,148 @@
|
|
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
|
+
* @constructor
|
11
|
+
*/
|
12
|
+
jsts.geom.CoordinateArrays = function() {
|
13
|
+
throw new jsts.error.AbstractMethodInvocationError();
|
14
|
+
};
|
15
|
+
|
16
|
+
|
17
|
+
/**
|
18
|
+
* If the coordinate array argument has repeated points, constructs a new array
|
19
|
+
* containing no repeated points. Otherwise, returns the argument.
|
20
|
+
*
|
21
|
+
* @return {Coordinate[]}
|
22
|
+
* @see #hasRepeatedPoints(Coordinate[])
|
23
|
+
*/
|
24
|
+
jsts.geom.CoordinateArrays.removeRepeatedPoints = function(coord) {
|
25
|
+
var coordList;
|
26
|
+
if (!this.hasRepeatedPoints(coord)) {
|
27
|
+
return coord;
|
28
|
+
}
|
29
|
+
coordList = new jsts.geom.CoordinateList(coord, false);
|
30
|
+
return coordList.toCoordinateArray();
|
31
|
+
};
|
32
|
+
|
33
|
+
|
34
|
+
/**
|
35
|
+
* Returns whether #equals returns true for any two consecutive Coordinates in
|
36
|
+
* the given array.
|
37
|
+
*
|
38
|
+
* @param {Coordinate[]}
|
39
|
+
* coord
|
40
|
+
* @return {boolean}
|
41
|
+
*/
|
42
|
+
jsts.geom.CoordinateArrays.hasRepeatedPoints = function(coord) {
|
43
|
+
var i;
|
44
|
+
for (i = 1; i < coord.length; i++) {
|
45
|
+
if (coord[i - 1].equals(coord[i])) {
|
46
|
+
return true;
|
47
|
+
}
|
48
|
+
}
|
49
|
+
return false;
|
50
|
+
};
|
51
|
+
|
52
|
+
/**
|
53
|
+
* Finds a point in a list of points which is not contained in another list of points
|
54
|
+
* @param testPts the {@link Coordinate} s to test.
|
55
|
+
* @param pts an array of {@link Coordinate} s to test the input points against.
|
56
|
+
* @return a {@link Coordinate} from <code>testPts</code> which is not in <code>pts</code>, '
|
57
|
+
* or <code>null.</code>
|
58
|
+
*/
|
59
|
+
jsts.geom.CoordinateArrays.ptNotInList = function(testPts, pts) {
|
60
|
+
for (var i = 0; i < testPts.length; i++) {
|
61
|
+
var testPt = testPts[i];
|
62
|
+
if (jsts.geom.CoordinateArrays.indexOf(testPt, pts) < 0)
|
63
|
+
return testPt;
|
64
|
+
}
|
65
|
+
return null;
|
66
|
+
};
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Determines which orientation of the {@link Coordinate} array is (overall)
|
70
|
+
* increasing. In other words, determines which end of the array is "smaller"
|
71
|
+
* (using the standard ordering on {@link Coordinate}). Returns an integer
|
72
|
+
* indicating the increasing direction. If the sequence is a palindrome, it is
|
73
|
+
* defined to be oriented in a positive direction.
|
74
|
+
*
|
75
|
+
* @param pts
|
76
|
+
* the array of Coordinates to test.
|
77
|
+
* @return <code>1</code> if the array is smaller at the start or is a
|
78
|
+
* palindrome, <code>-1</code> if smaller at the end.
|
79
|
+
*/
|
80
|
+
jsts.geom.CoordinateArrays.increasingDirection = function(pts) {
|
81
|
+
for (var i = 0; i < parseInt(pts.length / 2); i++) {
|
82
|
+
var j = pts.length - 1 - i;
|
83
|
+
// skip equal points on both ends
|
84
|
+
var comp = pts[i].compareTo(pts[j]);
|
85
|
+
if (comp != 0)
|
86
|
+
return comp;
|
87
|
+
}
|
88
|
+
// array must be a palindrome - defined to be in positive direction
|
89
|
+
return 1;
|
90
|
+
};
|
91
|
+
|
92
|
+
/**
|
93
|
+
* Returns the minimum coordinate, using the usual lexicographic comparison.
|
94
|
+
*
|
95
|
+
* @param coordinates
|
96
|
+
* the array to search.
|
97
|
+
* @return the minimum coordinate in the array, found using
|
98
|
+
* <code>compareTo.</code>
|
99
|
+
* @see Coordinate#compareTo(Object)
|
100
|
+
*/
|
101
|
+
jsts.geom.CoordinateArrays.minCoordinate = function(coordinates) {
|
102
|
+
var minCoord = null;
|
103
|
+
for (var i = 0; i < coordinates.length; i++) {
|
104
|
+
if (minCoord === null || minCoord.compareTo(coordinates[i]) > 0) {
|
105
|
+
minCoord = coordinates[i];
|
106
|
+
}
|
107
|
+
}
|
108
|
+
return minCoord;
|
109
|
+
};
|
110
|
+
|
111
|
+
/**
|
112
|
+
* Shifts the positions of the coordinates until <code>firstCoordinate</code>
|
113
|
+
* is first.
|
114
|
+
*
|
115
|
+
* @param coordinates
|
116
|
+
* the array to rearrange.
|
117
|
+
* @param firstCoordinate
|
118
|
+
* the coordinate to make first.
|
119
|
+
*/
|
120
|
+
jsts.geom.CoordinateArrays.scroll = function(coordinates, firstCoordinate) {
|
121
|
+
var i = jsts.geom.CoordinateArrays.indexOf(firstCoordinate, coordinates);
|
122
|
+
if (i < 0)
|
123
|
+
return;
|
124
|
+
|
125
|
+
var newCoordinates = coordinates.slice(i).concat(coordinates.slice(0, i));
|
126
|
+
for (i = 0; i < newCoordinates.length; i++) {
|
127
|
+
coordinates[i] = newCoordinates[i];
|
128
|
+
}
|
129
|
+
};
|
130
|
+
|
131
|
+
/**
|
132
|
+
* Returns the index of <code>coordinate</code> in <code>coordinates</code>.
|
133
|
+
* The first position is 0; the second, 1; etc.
|
134
|
+
*
|
135
|
+
* @param coordinate
|
136
|
+
* the <code>Coordinate</code> to search for.
|
137
|
+
* @param coordinates
|
138
|
+
* the array to search.
|
139
|
+
* @return the position of <code>coordinate</code>, or -1 if it is not found.
|
140
|
+
*/
|
141
|
+
jsts.geom.CoordinateArrays.indexOf = function(coordinate, coordinates) {
|
142
|
+
for (var i = 0; i < coordinates.length; i++) {
|
143
|
+
if (coordinate.equals(coordinates[i])) {
|
144
|
+
return i;
|
145
|
+
}
|
146
|
+
}
|
147
|
+
return -1;
|
148
|
+
};
|
@@ -0,0 +1,29 @@
|
|
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
|
+
* <code>Geometry</code> classes support the concept of applying a coordinate
|
10
|
+
* filter to every coordinate in the <code>Geometry</code>. A coordinate
|
11
|
+
* filter can either record information about each coordinate or change the
|
12
|
+
* coordinate in some way. Coordinate filters implement the interface
|
13
|
+
* <code>CoordinateFilter</code>. (<code>CoordinateFilter</code> is an
|
14
|
+
* example of the Gang-of-Four Visitor pattern). Coordinate filters can be used
|
15
|
+
* to implement such things as coordinate transformations, centroid and envelope
|
16
|
+
* computation, and many other functions.
|
17
|
+
*
|
18
|
+
* @interface
|
19
|
+
*/
|
20
|
+
jsts.geom.CoordinateFilter = function() {};
|
21
|
+
/**
|
22
|
+
* Performs an operation with or on <code>coord</code>.
|
23
|
+
*
|
24
|
+
* @param coord
|
25
|
+
* a <code>Coordinate</code> to which the filter is applied.
|
26
|
+
*/
|
27
|
+
jsts.geom.CoordinateFilter.prototype.filter = function(coord) {
|
28
|
+
throw new jsts.error.AbstractMethodInvocationError();
|
29
|
+
};
|
@@ -0,0 +1,157 @@
|
|
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
|
+
* Constructs a new list from an array of Coordinates, allowing caller to
|
11
|
+
* specify if repeated points are to be removed.
|
12
|
+
*
|
13
|
+
* @param {Array.<jsts.geom.Coordinate>}
|
14
|
+
* coord the array of coordinates to load into the list.
|
15
|
+
* @param {boolean}
|
16
|
+
* allowRepeated if <code>false</code>, repeated points are removed.
|
17
|
+
*
|
18
|
+
* @constructor
|
19
|
+
*/
|
20
|
+
jsts.geom.CoordinateList = function(coord, allowRepeated) {
|
21
|
+
javascript.util.ArrayList.apply(this, arguments);
|
22
|
+
|
23
|
+
allowRepeated = (allowRepeated === undefined) ? true : allowRepeated;
|
24
|
+
|
25
|
+
if (coord !== undefined) {
|
26
|
+
this.add(coord, allowRepeated);
|
27
|
+
}
|
28
|
+
};
|
29
|
+
|
30
|
+
jsts.geom.CoordinateList.prototype = new javascript.util.ArrayList();
|
31
|
+
|
32
|
+
|
33
|
+
// simulate overloaded methods...
|
34
|
+
jsts.geom.CoordinateList.prototype.add = function() {
|
35
|
+
if (arguments.length>1) {
|
36
|
+
return this.addCoordinates.apply(this, arguments);
|
37
|
+
} else {
|
38
|
+
return javascript.util.ArrayList.prototype.add.apply(this, arguments);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Adds an array of coordinates to the list.
|
44
|
+
*
|
45
|
+
* @param {Array.<jsts.geom.Coordinate>}
|
46
|
+
* coord The coordinates.
|
47
|
+
* @param {boolean}
|
48
|
+
* allowRepeated if set to false, repeated coordinates are collapsed.
|
49
|
+
* @param {boolean}
|
50
|
+
* direction if false, the array is added in reverse order.
|
51
|
+
* @return {boolean} true (as by general collection contract).
|
52
|
+
*/
|
53
|
+
jsts.geom.CoordinateList.prototype.addCoordinates = function(coord, allowRepeated,
|
54
|
+
direction) {
|
55
|
+
if (coord instanceof jsts.geom.Coordinate) {
|
56
|
+
return this.addCoordinate.apply(this, arguments);
|
57
|
+
} else if (typeof coord === 'number') {
|
58
|
+
return this.insertCoordinate.apply(this, arguments);
|
59
|
+
}
|
60
|
+
|
61
|
+
direction = direction || true;
|
62
|
+
|
63
|
+
if (direction) {
|
64
|
+
for (var i = 0; i < coord.length; i++) {
|
65
|
+
this.addCoordinate(coord[i], allowRepeated);
|
66
|
+
}
|
67
|
+
} else {
|
68
|
+
for (var i = coord.length - 1; i >= 0; i--) {
|
69
|
+
this.addCoordinate(coord[i], allowRepeated);
|
70
|
+
}
|
71
|
+
}
|
72
|
+
return true;
|
73
|
+
};
|
74
|
+
|
75
|
+
|
76
|
+
/**
|
77
|
+
* Adds a coordinate to the end of the list.
|
78
|
+
*
|
79
|
+
* @param {Coordinate}
|
80
|
+
* coord The coordinates.
|
81
|
+
* @param {boolean}
|
82
|
+
* allowRepeated if set to false, repeated coordinates are collapsed.
|
83
|
+
*/
|
84
|
+
jsts.geom.CoordinateList.prototype.addCoordinate = function(coord,
|
85
|
+
allowRepeated) {
|
86
|
+
// don't add duplicate coordinates
|
87
|
+
if (!allowRepeated) {
|
88
|
+
if (this.size() >= 1) {
|
89
|
+
var last = this.get(this.size() - 1);
|
90
|
+
if (last.equals2D(coord)) return;
|
91
|
+
}
|
92
|
+
}
|
93
|
+
this.add(coord);
|
94
|
+
};
|
95
|
+
|
96
|
+
/**
|
97
|
+
* Inserts a coordinate at the specified place in the list
|
98
|
+
*
|
99
|
+
* @param {Number}
|
100
|
+
* index The index where to insert the coordinate.
|
101
|
+
* @param {Coordinate}
|
102
|
+
* coord The coordinate.
|
103
|
+
* @param {boolean}
|
104
|
+
* allowRepeated if set to false, repeated coordinates are collapsed.
|
105
|
+
*/
|
106
|
+
jsts.geom.CoordinateList.prototype.insertCoordinate = function(index, coord,
|
107
|
+
allowRepeated) {
|
108
|
+
// don't add duplicate coordinates
|
109
|
+
if (!allowRepeated) {
|
110
|
+
var before = index > 0 ? index - 1 : -1;
|
111
|
+
if (before !== -1 && this.get(before).equals2D(coord)) {
|
112
|
+
return;
|
113
|
+
}
|
114
|
+
|
115
|
+
var after = index < this.size() - 1 ? index + 1 : -1;
|
116
|
+
if (after !== -1 && this.get(after).equals2D(coord)) {
|
117
|
+
return;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
this.array.splice(index, 0, coord);
|
121
|
+
};
|
122
|
+
|
123
|
+
/**
|
124
|
+
* Ensure this coordList is a ring, by adding the start point if necessary
|
125
|
+
*/
|
126
|
+
jsts.geom.CoordinateList.prototype.closeRing = function() {
|
127
|
+
if (this.size() > 0) {
|
128
|
+
this.addCoordinate(new jsts.geom.Coordinate(this.get(0)), false);
|
129
|
+
}
|
130
|
+
};
|
131
|
+
|
132
|
+
/**
|
133
|
+
* Creates a standard javascript-array from the contents of this list
|
134
|
+
*
|
135
|
+
* @return {Array}
|
136
|
+
* the created array.
|
137
|
+
*/
|
138
|
+
jsts.geom.CoordinateList.prototype.toArray = function() {
|
139
|
+
var i, il, arr;
|
140
|
+
i = 0, il = this.size(), arr = [];
|
141
|
+
|
142
|
+
for (i; i < il; i++) {
|
143
|
+
arr[i] = this.get(i);
|
144
|
+
}
|
145
|
+
|
146
|
+
return arr;
|
147
|
+
};
|
148
|
+
|
149
|
+
/** Returns the Coordinates in this collection.
|
150
|
+
*
|
151
|
+
* @return the coordinates.
|
152
|
+
*/
|
153
|
+
jsts.geom.CoordinateList.prototype.toCoordinateArray = function() {
|
154
|
+
return this.toArray();
|
155
|
+
};
|
156
|
+
|
157
|
+
// TODO: port rest?
|