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,160 @@
|
|
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
|
+
* Represents an (1-dimensional) closed interval on the Real number line.
|
9
|
+
*
|
10
|
+
*/
|
11
|
+
(function() {
|
12
|
+
/**
|
13
|
+
* Constructs a new Interval and initializes it if arguments is provided
|
14
|
+
*
|
15
|
+
* @constructor
|
16
|
+
* @param {None}
|
17
|
+
* If no argument is specified, it will be initialized with 0.0, 0.0.
|
18
|
+
* @param {Number},
|
19
|
+
* { Number } min, max It can be initialized with min <-> max.
|
20
|
+
* @param {jsts.index.bintree.Interval}
|
21
|
+
* It can also be initialized with another interval.
|
22
|
+
*/
|
23
|
+
var Interval = function() {
|
24
|
+
this.min = 0.0;
|
25
|
+
this.max = 0.0;
|
26
|
+
|
27
|
+
if (arguments.length === 1) {
|
28
|
+
var interval = arguments[0];
|
29
|
+
this.init(interval.min, interval.max);
|
30
|
+
}else if (arguments.length === 2) {
|
31
|
+
this.init(arguments[0], arguments[1]);
|
32
|
+
}
|
33
|
+
};
|
34
|
+
|
35
|
+
/**
|
36
|
+
* Initializes the interval
|
37
|
+
*
|
38
|
+
* @param {Number}
|
39
|
+
* min
|
40
|
+
* @param {Number}
|
41
|
+
* max
|
42
|
+
*/
|
43
|
+
Interval.prototype.init = function(min, max) {
|
44
|
+
this.min = min;
|
45
|
+
this.max = max;
|
46
|
+
if (min > max) {
|
47
|
+
this.min = max;
|
48
|
+
this.max = min;
|
49
|
+
}
|
50
|
+
};
|
51
|
+
|
52
|
+
Interval.prototype.getMin = function() {
|
53
|
+
return this.min;
|
54
|
+
};
|
55
|
+
|
56
|
+
Interval.prototype.getMax = function() {
|
57
|
+
return this.max;
|
58
|
+
};
|
59
|
+
|
60
|
+
Interval.prototype.getWidth = function() {
|
61
|
+
return (this.max - this.min);
|
62
|
+
};
|
63
|
+
|
64
|
+
/**
|
65
|
+
* Expands this interval to include another interval
|
66
|
+
*
|
67
|
+
* @param {jsts.index.bintree.Interval}
|
68
|
+
* interval the interval to include.
|
69
|
+
*/
|
70
|
+
Interval.prototype.expandToInclude = function(interval) {
|
71
|
+
if (interval.max > this.max) {
|
72
|
+
this.max = interval.max;
|
73
|
+
}
|
74
|
+
if (interval.min < this.min) {
|
75
|
+
this.min = interval.min;
|
76
|
+
}
|
77
|
+
};
|
78
|
+
|
79
|
+
/**
|
80
|
+
* Checks if this interval overlaps. Calls correct overlaps- function based on
|
81
|
+
* arguments
|
82
|
+
*
|
83
|
+
* @return {Boolean} true if the interval overlaps.
|
84
|
+
*/
|
85
|
+
Interval.prototype.overlaps = function() {
|
86
|
+
if (arguments.length === 1) {
|
87
|
+
return this.overlapsInterval.apply(this, arguments);
|
88
|
+
}else {
|
89
|
+
return this.overlapsMinMax.apply(this, arguments);
|
90
|
+
}
|
91
|
+
};
|
92
|
+
|
93
|
+
/**
|
94
|
+
* Checks if this inteval overlaps another interval
|
95
|
+
*
|
96
|
+
* @param {jsts.index.bintree.Interval}
|
97
|
+
* interval the interval to check.
|
98
|
+
* @return {Boolean} true if the interval overlaps.
|
99
|
+
*/
|
100
|
+
Interval.prototype.overlapsInterval = function(interval) {
|
101
|
+
return this.overlaps(interval.min, interval.max);
|
102
|
+
};
|
103
|
+
|
104
|
+
/**
|
105
|
+
* Checks if this inteval overlaps the specified min/max values
|
106
|
+
*
|
107
|
+
* @param {Number}
|
108
|
+
* min minimum.
|
109
|
+
* @param {Number}
|
110
|
+
* max maximum.
|
111
|
+
* @return {Boolean} true if the interval overlaps.
|
112
|
+
*/
|
113
|
+
Interval.prototype.overlapsMinMax = function(min, max) {
|
114
|
+
if (this.min > max || this.max < min) {
|
115
|
+
return false;
|
116
|
+
}
|
117
|
+
return true;
|
118
|
+
};
|
119
|
+
|
120
|
+
/**
|
121
|
+
* Checks if this interval contains an interval, min -max pair or a point
|
122
|
+
*
|
123
|
+
* @return {Boolean} true if this interval contains the specified argument.
|
124
|
+
*/
|
125
|
+
Interval.prototype.contains = function() {
|
126
|
+
var interval;
|
127
|
+
if (arguments[0] instanceof jsts.index.bintree.Interval) {
|
128
|
+
interval = arguments[0];
|
129
|
+
return this.containsMinMax(interval.min, interval.max);
|
130
|
+
}else if (arguments.length === 1) {
|
131
|
+
return this.containsPoint(arguments[0]);
|
132
|
+
}else {
|
133
|
+
return this.containsMinMax(arguments[0], arguments[1]);
|
134
|
+
}
|
135
|
+
};
|
136
|
+
|
137
|
+
/**
|
138
|
+
* Checks if this interval contains the min- and max-point provided
|
139
|
+
*
|
140
|
+
* @param {Number}
|
141
|
+
* min the minpoint.
|
142
|
+
* @param {Number}
|
143
|
+
* max the maxpoint.
|
144
|
+
*/
|
145
|
+
Interval.prototype.containsMinMax = function(min, max) {
|
146
|
+
return (min >= this.min && max <= this.max);
|
147
|
+
};
|
148
|
+
|
149
|
+
/**
|
150
|
+
* Checks if this interval contains the specified point
|
151
|
+
*
|
152
|
+
* @param {Number}
|
153
|
+
* p the point to check.
|
154
|
+
*/
|
155
|
+
Interval.prototype.containsPoint = function(p) {
|
156
|
+
return (p >= this.min && p <= this.max);
|
157
|
+
};
|
158
|
+
|
159
|
+
jsts.index.bintree.Interval = Interval;
|
160
|
+
})();
|
@@ -0,0 +1,110 @@
|
|
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
|
+
* A Key is a unique identifier for a node in a tree. It contains a lower-left
|
9
|
+
* point and a level number. The level number is the power of two for the size
|
10
|
+
* of the node envelope
|
11
|
+
*/
|
12
|
+
(function() {
|
13
|
+
|
14
|
+
/**
|
15
|
+
* @requires jsts/index/bintree/Interval.js
|
16
|
+
* @requires jsts/index/DoubleBits.js
|
17
|
+
*/
|
18
|
+
|
19
|
+
var DoubleBits = jsts.index.DoubleBits;
|
20
|
+
var Interval = jsts.index.bintree.Interval;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Constructs a new Key
|
24
|
+
*
|
25
|
+
* @constructor
|
26
|
+
* @param {jsts.index.bintree.Interval}
|
27
|
+
* interval the interval to compute the key from.
|
28
|
+
*/
|
29
|
+
var Key = function(interval) {
|
30
|
+
this.pt = 0.0;
|
31
|
+
this.level = 0;
|
32
|
+
|
33
|
+
this.computeKey(interval);
|
34
|
+
};
|
35
|
+
|
36
|
+
/**
|
37
|
+
* Computes the level for an interval
|
38
|
+
*
|
39
|
+
* @param {jsts.index.bintree.Interval}
|
40
|
+
* interval the interval.
|
41
|
+
* @results {Number} the calculated level
|
42
|
+
*/
|
43
|
+
Key.computeLevel = function(interval) {
|
44
|
+
var dx = interval.getWidth(), level;
|
45
|
+
|
46
|
+
level = DoubleBits.exponent(dx) + 1;
|
47
|
+
return level;
|
48
|
+
};
|
49
|
+
|
50
|
+
/**
|
51
|
+
* Returns the point
|
52
|
+
*
|
53
|
+
* @return {Number} point.
|
54
|
+
*/
|
55
|
+
Key.prototype.getPoint = function() {
|
56
|
+
return this.pt;
|
57
|
+
};
|
58
|
+
|
59
|
+
/**
|
60
|
+
* Returns the level
|
61
|
+
*
|
62
|
+
* @return {Number} level.
|
63
|
+
*/
|
64
|
+
Key.prototype.getLevel = function() {
|
65
|
+
return this.level;
|
66
|
+
};
|
67
|
+
|
68
|
+
/**
|
69
|
+
* Returns the interval
|
70
|
+
*
|
71
|
+
* @return {jsts.index.bintree.Interval}
|
72
|
+
*/
|
73
|
+
Key.prototype.getInterval = function() {
|
74
|
+
return this.interval;
|
75
|
+
};
|
76
|
+
|
77
|
+
/**
|
78
|
+
* Calculates the key
|
79
|
+
*
|
80
|
+
* @param {jsts.index.bintree.Interval}
|
81
|
+
* itemInterval the interval.
|
82
|
+
*/
|
83
|
+
Key.prototype.computeKey = function(itemInterval) {
|
84
|
+
this.level = Key.computeLevel(itemInterval);
|
85
|
+
this.interval = new Interval();
|
86
|
+
this.computeInterval(this.level, itemInterval);
|
87
|
+
// MD - would be nice to have a non-iterative form of this algorithm
|
88
|
+
while (!this.interval.contains(itemInterval)) {
|
89
|
+
this.level += 1;
|
90
|
+
this.computeInterval(this.level, itemInterval);
|
91
|
+
}
|
92
|
+
};
|
93
|
+
|
94
|
+
/**
|
95
|
+
* Computes the interval
|
96
|
+
*
|
97
|
+
* @param {Number}
|
98
|
+
* level the level.
|
99
|
+
* @param {jsts.index.bintree.Interval}
|
100
|
+
* itemInterval an interval.
|
101
|
+
*/
|
102
|
+
Key.prototype.computeInterval = function(level, itemInterval) {
|
103
|
+
var size = DoubleBits.powerOf2(level);
|
104
|
+
|
105
|
+
this.pt = Math.floor(itemInterval.getMin() / size) * size;
|
106
|
+
this.interval.init(this.pt, this.pt + size);
|
107
|
+
};
|
108
|
+
|
109
|
+
jsts.index.bintree.Key = Key;
|
110
|
+
})();
|
@@ -0,0 +1,204 @@
|
|
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
|
+
* A node of a {@link Bintree}.
|
9
|
+
*/
|
10
|
+
(function() {
|
11
|
+
|
12
|
+
/**
|
13
|
+
* @requires jsts/index/bintree/NodeBase.js
|
14
|
+
* @requires jsts/index/bintree/Interval.js
|
15
|
+
* @requires jsts/index/bintree/Key.js
|
16
|
+
*/
|
17
|
+
|
18
|
+
var NodeBase = jsts.index.bintree.NodeBase;
|
19
|
+
var Key = jsts.index.bintree.Key;
|
20
|
+
var Interval = jsts.index.bintree.Interval;
|
21
|
+
|
22
|
+
/**
|
23
|
+
* Constructs a new Node
|
24
|
+
*
|
25
|
+
* @constructor
|
26
|
+
*/
|
27
|
+
var Node = function(interval, level) {
|
28
|
+
/**
|
29
|
+
* subnodes are numbered as follows:
|
30
|
+
*
|
31
|
+
* 0 | 1
|
32
|
+
*/
|
33
|
+
this.items = new javascript.util.ArrayList();
|
34
|
+
this.subnode = [null, null];
|
35
|
+
this.interval = interval;
|
36
|
+
this.level = level;
|
37
|
+
this.centre = (interval.getMin() + interval.getMax()) / 2;
|
38
|
+
};
|
39
|
+
Node.prototype = new NodeBase();
|
40
|
+
Node.constructor = Node;
|
41
|
+
|
42
|
+
/**
|
43
|
+
* Creates a node from a specified interval
|
44
|
+
*
|
45
|
+
* @param {jsts.index.bintree.Interval}
|
46
|
+
* itemInterval the interval.
|
47
|
+
* @return {jsts.index.bintree.Node} the created node.
|
48
|
+
*/
|
49
|
+
Node.createNode = function(itemInterval) {
|
50
|
+
var key, node;
|
51
|
+
|
52
|
+
key = new Key(itemInterval);
|
53
|
+
node = new Node(key.getInterval(), key.getLevel());
|
54
|
+
return node;
|
55
|
+
};
|
56
|
+
|
57
|
+
/**
|
58
|
+
* Creates an expanded node
|
59
|
+
*
|
60
|
+
* @param {jsts.index.bintree.Node}
|
61
|
+
* node the node.
|
62
|
+
* @param {jsts.index.bintree.Interval}
|
63
|
+
* addInterval the interval to add.
|
64
|
+
* @return {jsts.index.bintree.Node} the expanded node.
|
65
|
+
*/
|
66
|
+
Node.createExpanded = function(node, addInterval) {
|
67
|
+
var expandInt, largerNode;
|
68
|
+
expandInt = new Interval(addInterval);
|
69
|
+
if (node !== null) {
|
70
|
+
expandInt.expandToInclude(node.interval);
|
71
|
+
}
|
72
|
+
|
73
|
+
largerNode = Node.createNode(expandInt);
|
74
|
+
|
75
|
+
if (node !== null) {
|
76
|
+
largerNode.insert(node);
|
77
|
+
}
|
78
|
+
|
79
|
+
return largerNode;
|
80
|
+
};
|
81
|
+
|
82
|
+
Node.prototype.getInterval = function() {
|
83
|
+
return this.interval;
|
84
|
+
};
|
85
|
+
|
86
|
+
/**
|
87
|
+
* Checks if the input interval matches any items in this node
|
88
|
+
*
|
89
|
+
* @return {Boolean} true if there is a search match.
|
90
|
+
*/
|
91
|
+
Node.prototype.isSearchMatch = function(itemInterval) {
|
92
|
+
return itemInterval.overlaps(this.interval);
|
93
|
+
};
|
94
|
+
|
95
|
+
/**
|
96
|
+
* Returns the subnode containing the envelope. Creates the node if it does
|
97
|
+
* not already exist.
|
98
|
+
*
|
99
|
+
* @param {jsts.index.bintree.Interval}
|
100
|
+
* serachInterval the interval.
|
101
|
+
* @return {jsts.index.bintree.Node} the node.
|
102
|
+
*/
|
103
|
+
Node.prototype.getNode = function(searchInterval) {
|
104
|
+
var subnodeIndex = NodeBase.getSubnodeIndex(searchInterval, this.centre), node;
|
105
|
+
// if index is -1 searchEnv is not contained in a subnode
|
106
|
+
if (subnodeIndex != -1) {
|
107
|
+
// create the node if it does not exist
|
108
|
+
node = this.getSubnode(subnodeIndex);
|
109
|
+
// recursively search the found/created node
|
110
|
+
return node.getNode(searchInterval);
|
111
|
+
} else {
|
112
|
+
return this;
|
113
|
+
}
|
114
|
+
};
|
115
|
+
|
116
|
+
/**
|
117
|
+
* Returns the smallest <i>existing</i> node containing the envelope.
|
118
|
+
*
|
119
|
+
* @param {jsts.index.bintree.Interval}
|
120
|
+
* searchInterval the interval.
|
121
|
+
* @return {jsts.index.bintree.Node} the smallest node contained.
|
122
|
+
*/
|
123
|
+
Node.prototype.find = function(searchInterval) {
|
124
|
+
var subnodeIndex = NodeBase.getSubnodeIndex(searchInterval, this.centre), node;
|
125
|
+
if (subnodeIndex === -1) {
|
126
|
+
return this;
|
127
|
+
}
|
128
|
+
|
129
|
+
if (this.subnode[subnodeIndex] !== null) {
|
130
|
+
// query lies in subnode, so search it
|
131
|
+
node = this.subnode[subnodeIndex];
|
132
|
+
return node.find(searchInterval);
|
133
|
+
}
|
134
|
+
// no existing subnode, so return this one anyway
|
135
|
+
return this;
|
136
|
+
};
|
137
|
+
|
138
|
+
/**
|
139
|
+
* Inserts a node as a child node (at some level) in this node
|
140
|
+
*
|
141
|
+
* @param {jsts.index.bintree.Node}
|
142
|
+
* node the node to insert.
|
143
|
+
*/
|
144
|
+
Node.prototype.insert = function(node) {
|
145
|
+
//Assert.isTrue(interval == null || interval.contains(node.interval));
|
146
|
+
|
147
|
+
var index = NodeBase.getSubnodeIndex(node.interval, this.centre), childNode;
|
148
|
+
if (node.level === this.level - 1) {
|
149
|
+
this.subnode[index] = node;
|
150
|
+
} else {
|
151
|
+
// the node is not a direct child, so make a new child node to contain it
|
152
|
+
// and recursively insert the node
|
153
|
+
childNode = this.createSubnode(index);
|
154
|
+
childNode.insert(node);
|
155
|
+
this.subnode[index] = childNode;
|
156
|
+
}
|
157
|
+
};
|
158
|
+
|
159
|
+
/**
|
160
|
+
* get the subnode for the index. If it doesn't exist, create it
|
161
|
+
*
|
162
|
+
* @param {Number}
|
163
|
+
* index
|
164
|
+
* @return {jsts.index.bintree.Node} the found or created node.
|
165
|
+
*/
|
166
|
+
Node.prototype.getSubnode = function(index) {
|
167
|
+
if (this.subnode[index] === null) {
|
168
|
+
this.subnode[index] = this.createSubnode(index);
|
169
|
+
}
|
170
|
+
return this.subnode[index];
|
171
|
+
};
|
172
|
+
|
173
|
+
/**
|
174
|
+
* Creates a subnode
|
175
|
+
*
|
176
|
+
* @param {Number}
|
177
|
+
* index the index to create the subnode at.
|
178
|
+
* @return {jsts.index.bintree.Node} the created node.
|
179
|
+
*/
|
180
|
+
Node.prototype.createSubnode = function(index) {
|
181
|
+
// create a new subnode in the appropriate interval
|
182
|
+
|
183
|
+
var min, max, subInt, node;
|
184
|
+
|
185
|
+
min = 0.0;
|
186
|
+
max = 0.0;
|
187
|
+
|
188
|
+
switch (index) {
|
189
|
+
case 0:
|
190
|
+
min = this.interval.getMin();
|
191
|
+
max = this.centre;
|
192
|
+
break;
|
193
|
+
case 1:
|
194
|
+
min = this.centre;
|
195
|
+
max = this.interval.getMax();
|
196
|
+
break;
|
197
|
+
}
|
198
|
+
subInt = new Interval(min, max);
|
199
|
+
node = new Node(subInt, this.level - 1);
|
200
|
+
return node;
|
201
|
+
};
|
202
|
+
|
203
|
+
jsts.index.bintree.Node = Node;
|
204
|
+
})();
|