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,353 @@
|
|
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
|
+
* Port source:
|
9
|
+
* /jts/jts/java/src/com/vividsolutions/jts/algorithm/RobustDeterminant.java
|
10
|
+
* Revision: 626
|
11
|
+
*/
|
12
|
+
|
13
|
+
/**
|
14
|
+
* Implements an algorithm to compute the
|
15
|
+
* sign of a 2x2 determinant for double precision values robustly.
|
16
|
+
* It is a direct translation of code developed by Olivier Devillers.
|
17
|
+
* <p>
|
18
|
+
* The original code carries the following copyright notice:
|
19
|
+
*
|
20
|
+
* <pre>
|
21
|
+
*************************************************************************
|
22
|
+
* Author : Olivier Devillers
|
23
|
+
* Olivier.Devillers@sophia.inria.fr
|
24
|
+
* http:/www.inria.fr:/prisme/personnel/devillers/anglais/determinant.html
|
25
|
+
*
|
26
|
+
* Olivier Devillers has allowed the code to be distributed under
|
27
|
+
* the LGPL (2012-02-16) saying "It is ok for LGPL distribution."
|
28
|
+
*
|
29
|
+
**************************************************************************
|
30
|
+
*
|
31
|
+
**************************************************************************
|
32
|
+
* Copyright (c) 1995 by INRIA Prisme Project
|
33
|
+
* BP 93 06902 Sophia Antipolis Cedex, France.
|
34
|
+
* All rights reserved
|
35
|
+
**************************************************************************
|
36
|
+
* </pre>
|
37
|
+
* @constructor
|
38
|
+
*/
|
39
|
+
jsts.algorithm.RobustDeterminant = function() {
|
40
|
+
|
41
|
+
};
|
42
|
+
|
43
|
+
|
44
|
+
/**
|
45
|
+
* Computes the sign of the determinant of the 2x2 matrix
|
46
|
+
* with the given entries, in a robust way.
|
47
|
+
*
|
48
|
+
* @param {Number}
|
49
|
+
* x1 X-1.
|
50
|
+
* @param {Number}
|
51
|
+
* y1 Y-1.
|
52
|
+
* @param {Number}
|
53
|
+
* x2 X-2.
|
54
|
+
* @param {Number}
|
55
|
+
* y2 Y-1.
|
56
|
+
*
|
57
|
+
* @return {Number}
|
58
|
+
* -1 if the determinant is negative,.
|
59
|
+
* @return {Number}
|
60
|
+
* 1 if the determinant is positive,.
|
61
|
+
* @return {Number}
|
62
|
+
* 0 if the determinant is 0.
|
63
|
+
*/
|
64
|
+
jsts.algorithm.RobustDeterminant.signOfDet2x2 = function(x1, y1, x2, y2) {
|
65
|
+
//returns -1 if the determinant is negative,
|
66
|
+
// returns 1 if the determinant is positive,
|
67
|
+
// returns 0 if the determinant is null.
|
68
|
+
var sign, swap, k, count;
|
69
|
+
count = 0;
|
70
|
+
|
71
|
+
sign = 1;
|
72
|
+
|
73
|
+
/*
|
74
|
+
* testing null entries
|
75
|
+
*/
|
76
|
+
if ((x1 === 0.0) || (y2 === 0.0)) {
|
77
|
+
if ((y1 === 0.0) || (x2 === 0.0)) {
|
78
|
+
return 0;
|
79
|
+
}
|
80
|
+
else if (y1 > 0) {
|
81
|
+
if (x2 > 0) {
|
82
|
+
return -sign;
|
83
|
+
}
|
84
|
+
else {
|
85
|
+
return sign;
|
86
|
+
}
|
87
|
+
}
|
88
|
+
else {
|
89
|
+
if (x2 > 0) {
|
90
|
+
return sign;
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
return -sign;
|
94
|
+
}
|
95
|
+
}
|
96
|
+
}
|
97
|
+
if ((y1 === 0.0) || (x2 === 0.0)) {
|
98
|
+
if (y2 > 0) {
|
99
|
+
if (x1 > 0) {
|
100
|
+
return sign;
|
101
|
+
}
|
102
|
+
else {
|
103
|
+
return -sign;
|
104
|
+
}
|
105
|
+
}
|
106
|
+
else {
|
107
|
+
if (x1 > 0) {
|
108
|
+
return -sign;
|
109
|
+
}
|
110
|
+
else {
|
111
|
+
return sign;
|
112
|
+
}
|
113
|
+
}
|
114
|
+
}
|
115
|
+
|
116
|
+
/*
|
117
|
+
* making y coordinates positive and permuting the entries
|
118
|
+
*/
|
119
|
+
/*
|
120
|
+
* so that y2 is the biggest one
|
121
|
+
*/
|
122
|
+
if (0.0 < y1) {
|
123
|
+
if (0.0 < y2) {
|
124
|
+
if (y1 > y2) {
|
125
|
+
sign = -sign;
|
126
|
+
swap = x1;
|
127
|
+
x1 = x2;
|
128
|
+
x2 = swap;
|
129
|
+
swap = y1;
|
130
|
+
y1 = y2;
|
131
|
+
y2 = swap;
|
132
|
+
}
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
if (y1 <= -y2) {
|
136
|
+
sign = -sign;
|
137
|
+
x2 = -x2;
|
138
|
+
y2 = -y2;
|
139
|
+
}
|
140
|
+
else {
|
141
|
+
swap = x1;
|
142
|
+
x1 = -x2;
|
143
|
+
x2 = swap;
|
144
|
+
swap = y1;
|
145
|
+
y1 = -y2;
|
146
|
+
y2 = swap;
|
147
|
+
}
|
148
|
+
}
|
149
|
+
}
|
150
|
+
else {
|
151
|
+
if (0.0 < y2) {
|
152
|
+
if (-y1 <= y2) {
|
153
|
+
sign = -sign;
|
154
|
+
x1 = -x1;
|
155
|
+
y1 = -y1;
|
156
|
+
}
|
157
|
+
else {
|
158
|
+
swap = -x1;
|
159
|
+
x1 = x2;
|
160
|
+
x2 = swap;
|
161
|
+
swap = -y1;
|
162
|
+
y1 = y2;
|
163
|
+
y2 = swap;
|
164
|
+
}
|
165
|
+
}
|
166
|
+
else {
|
167
|
+
if (y1 >= y2) {
|
168
|
+
x1 = -x1;
|
169
|
+
y1 = -y1;
|
170
|
+
x2 = -x2;
|
171
|
+
y2 = -y2;
|
172
|
+
}
|
173
|
+
else {
|
174
|
+
sign = -sign;
|
175
|
+
swap = -x1;
|
176
|
+
x1 = -x2;
|
177
|
+
x2 = swap;
|
178
|
+
swap = -y1;
|
179
|
+
y1 = -y2;
|
180
|
+
y2 = swap;
|
181
|
+
}
|
182
|
+
}
|
183
|
+
}
|
184
|
+
|
185
|
+
/*
|
186
|
+
* making x coordinates positive
|
187
|
+
*/
|
188
|
+
/*
|
189
|
+
* if |x2| < |x1| one can conclude
|
190
|
+
*/
|
191
|
+
if (0.0 < x1) {
|
192
|
+
if (0.0 < x2) {
|
193
|
+
if (x1 > x2) {
|
194
|
+
return sign;
|
195
|
+
}
|
196
|
+
}
|
197
|
+
else {
|
198
|
+
return sign;
|
199
|
+
}
|
200
|
+
}
|
201
|
+
else {
|
202
|
+
if (0.0 < x2) {
|
203
|
+
return -sign;
|
204
|
+
}
|
205
|
+
else {
|
206
|
+
if (x1 >= x2) {
|
207
|
+
sign = -sign;
|
208
|
+
x1 = -x1;
|
209
|
+
x2 = -x2;
|
210
|
+
}
|
211
|
+
else {
|
212
|
+
return -sign;
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
/*
|
218
|
+
* all entries strictly positive x1 <= x2 and y1 <= y2
|
219
|
+
*/
|
220
|
+
while (true) {
|
221
|
+
count = count + 1;
|
222
|
+
k = Math.floor(x2 / x1);
|
223
|
+
x2 = x2 - k * x1;
|
224
|
+
y2 = y2 - k * y1;
|
225
|
+
|
226
|
+
/*
|
227
|
+
* testing if R (new U2) is in U1 rectangle
|
228
|
+
*/
|
229
|
+
if (y2 < 0.0) {
|
230
|
+
return -sign;
|
231
|
+
}
|
232
|
+
if (y2 > y1) {
|
233
|
+
return sign;
|
234
|
+
}
|
235
|
+
|
236
|
+
/*
|
237
|
+
* finding R'
|
238
|
+
*/
|
239
|
+
if (x1 > x2 + x2) {
|
240
|
+
if (y1 < y2 + y2) {
|
241
|
+
return sign;
|
242
|
+
}
|
243
|
+
}
|
244
|
+
else {
|
245
|
+
if (y1 > y2 + y2) {
|
246
|
+
return -sign;
|
247
|
+
}
|
248
|
+
else {
|
249
|
+
x2 = x1 - x2;
|
250
|
+
y2 = y1 - y2;
|
251
|
+
sign = -sign;
|
252
|
+
}
|
253
|
+
}
|
254
|
+
if (y2 === 0.0) {
|
255
|
+
if (x2 === 0.0) {
|
256
|
+
return 0;
|
257
|
+
}
|
258
|
+
else {
|
259
|
+
return -sign;
|
260
|
+
}
|
261
|
+
}
|
262
|
+
if (x2 === 0.0) {
|
263
|
+
return sign;
|
264
|
+
}
|
265
|
+
|
266
|
+
/*
|
267
|
+
* exchange 1 and 2 role.
|
268
|
+
*/
|
269
|
+
k = Math.floor(x1 / x2);
|
270
|
+
x1 = x1 - k * x2;
|
271
|
+
y1 = y1 - k * y2;
|
272
|
+
|
273
|
+
/*
|
274
|
+
* testing if R (new U1) is in U2 rectangle
|
275
|
+
*/
|
276
|
+
if (y1 < 0.0) {
|
277
|
+
return sign;
|
278
|
+
}
|
279
|
+
if (y1 > y2) {
|
280
|
+
return -sign;
|
281
|
+
}
|
282
|
+
|
283
|
+
/*
|
284
|
+
* finding R'
|
285
|
+
*/
|
286
|
+
if (x2 > x1 + x1) {
|
287
|
+
if (y2 < y1 + y1) {
|
288
|
+
return -sign;
|
289
|
+
}
|
290
|
+
}
|
291
|
+
else {
|
292
|
+
if (y2 > y1 + y1) {
|
293
|
+
return sign;
|
294
|
+
}
|
295
|
+
else {
|
296
|
+
x1 = x2 - x1;
|
297
|
+
y1 = y2 - y1;
|
298
|
+
sign = -sign;
|
299
|
+
}
|
300
|
+
}
|
301
|
+
if (y1 === 0.0) {
|
302
|
+
if (x1 === 0.0) {
|
303
|
+
return 0;
|
304
|
+
}
|
305
|
+
else {
|
306
|
+
return sign;
|
307
|
+
}
|
308
|
+
}
|
309
|
+
if (x1 === 0.0) {
|
310
|
+
return -sign;
|
311
|
+
}
|
312
|
+
}
|
313
|
+
};
|
314
|
+
|
315
|
+
|
316
|
+
/**
|
317
|
+
* Returns the index of the direction of the point <code>q</code> relative to
|
318
|
+
* a vector specified by <code>p1-p2</code>.
|
319
|
+
*
|
320
|
+
* @param p1 the origin point of the vector
|
321
|
+
* @param p2 the final point of the vector
|
322
|
+
* @param q the point to compute the direction to
|
323
|
+
*
|
324
|
+
* @return 1 if q is counter-clockwise (left) from p1-p2
|
325
|
+
* @return -1 if q is clockwise (right) from p1-p2
|
326
|
+
* @return 0 if q is collinear with p1-p2
|
327
|
+
*/
|
328
|
+
jsts.algorithm.RobustDeterminant.orientationIndex = function(p1, p2, q) {
|
329
|
+
/**
|
330
|
+
* MD - 9 Aug 2010 It seems that the basic algorithm is slightly orientation
|
331
|
+
* dependent, when computing the orientation of a point very close to a
|
332
|
+
* line. This is possibly due to the arithmetic in the translation to the
|
333
|
+
* origin.
|
334
|
+
*
|
335
|
+
* For instance, the following situation produces identical results in spite
|
336
|
+
* of the inverse orientation of the line segment:
|
337
|
+
*
|
338
|
+
* Coordinate p0 = new Coordinate(219.3649559090992, 140.84159161824724);
|
339
|
+
* Coordinate p1 = new Coordinate(168.9018919682399, -5.713787599646864);
|
340
|
+
*
|
341
|
+
* Coordinate p = new Coordinate(186.80814046338352, 46.28973405831556); int
|
342
|
+
* orient = orientationIndex(p0, p1, p); int orientInv =
|
343
|
+
* orientationIndex(p1, p0, p);
|
344
|
+
*
|
345
|
+
*
|
346
|
+
*/
|
347
|
+
|
348
|
+
var dx1 = p2.x - p1.x;
|
349
|
+
var dy1 = p2.y - p1.y;
|
350
|
+
var dx2 = q.x - p2.x;
|
351
|
+
var dy2 = q.y - p2.y;
|
352
|
+
return jsts.algorithm.RobustDeterminant.signOfDet2x2(dx1, dy1, dx2, dy2);
|
353
|
+
};
|
@@ -0,0 +1,477 @@
|
|
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
|
+
* @requires jsts/algorithm/LineIntersector.js
|
10
|
+
*/
|
11
|
+
|
12
|
+
|
13
|
+
|
14
|
+
/**
|
15
|
+
* A robust version of {@LineIntersector}.
|
16
|
+
*
|
17
|
+
* @constructor
|
18
|
+
* @augments jsts.algorithm.LineIntersector
|
19
|
+
*/
|
20
|
+
jsts.algorithm.RobustLineIntersector = function() {
|
21
|
+
jsts.algorithm.RobustLineIntersector.prototype.constructor.call(this);
|
22
|
+
};
|
23
|
+
|
24
|
+
jsts.algorithm.RobustLineIntersector.prototype = new jsts.algorithm.LineIntersector();
|
25
|
+
|
26
|
+
|
27
|
+
/**
|
28
|
+
* @param {Coordinate}
|
29
|
+
* p
|
30
|
+
* @param {Coordinate}
|
31
|
+
* p1
|
32
|
+
* @param {Coordinate}
|
33
|
+
* p2
|
34
|
+
*/
|
35
|
+
jsts.algorithm.RobustLineIntersector.prototype.computeIntersection = function(
|
36
|
+
p, p1, p2) {
|
37
|
+
|
38
|
+
if (arguments.length === 4) {
|
39
|
+
jsts.algorithm.LineIntersector.prototype.computeIntersection.apply(this, arguments);
|
40
|
+
return;
|
41
|
+
}
|
42
|
+
|
43
|
+
this._isProper = false;
|
44
|
+
// do between check first, since it is faster than the orientation test
|
45
|
+
if (jsts.geom.Envelope.intersects(p1, p2, p)) {
|
46
|
+
if ((jsts.algorithm.CGAlgorithms.orientationIndex(p1, p2, p) === 0) &&
|
47
|
+
(jsts.algorithm.CGAlgorithms.orientationIndex(p2, p1, p) === 0)) {
|
48
|
+
this._isProper = true;
|
49
|
+
if (p.equals(p1) || p.equals(p2)) {
|
50
|
+
this._isProper = false;
|
51
|
+
}
|
52
|
+
this.result = jsts.algorithm.LineIntersector.POINT_INTERSECTION;
|
53
|
+
return;
|
54
|
+
}
|
55
|
+
}
|
56
|
+
this.result = jsts.algorithm.LineIntersector.NO_INTERSECTION;
|
57
|
+
};
|
58
|
+
|
59
|
+
|
60
|
+
/**
|
61
|
+
* @param {Coordinate}
|
62
|
+
* p1
|
63
|
+
* @param {Coordinate}
|
64
|
+
* p2
|
65
|
+
* @param {Coordinate}
|
66
|
+
* q1
|
67
|
+
* @param {Coordinate}
|
68
|
+
* q2
|
69
|
+
* @return {Number}
|
70
|
+
* @protected
|
71
|
+
*/
|
72
|
+
jsts.algorithm.RobustLineIntersector.prototype.computeIntersect = function(p1,
|
73
|
+
p2, q1, q2) {
|
74
|
+
this._isProper = false;
|
75
|
+
|
76
|
+
// first try a fast test to see if the envelopes of the lines intersect
|
77
|
+
if (!jsts.geom.Envelope.intersects(p1, p2, q1, q2)) {
|
78
|
+
return jsts.algorithm.LineIntersector.NO_INTERSECTION;
|
79
|
+
}
|
80
|
+
|
81
|
+
// for each endpoint, compute which side of the other segment it lies
|
82
|
+
// if both endpoints lie on the same side of the other segment,
|
83
|
+
// the segments do not intersect
|
84
|
+
var Pq1 = jsts.algorithm.CGAlgorithms.orientationIndex(p1, p2, q1);
|
85
|
+
var Pq2 = jsts.algorithm.CGAlgorithms.orientationIndex(p1, p2, q2);
|
86
|
+
|
87
|
+
if ((Pq1 > 0 && Pq2 > 0) || (Pq1 < 0 && Pq2 < 0)) {
|
88
|
+
return jsts.algorithm.LineIntersector.NO_INTERSECTION;
|
89
|
+
}
|
90
|
+
|
91
|
+
var Qp1 = jsts.algorithm.CGAlgorithms.orientationIndex(q1, q2, p1);
|
92
|
+
var Qp2 = jsts.algorithm.CGAlgorithms.orientationIndex(q1, q2, p2);
|
93
|
+
|
94
|
+
if ((Qp1 > 0 && Qp2 > 0) || (Qp1 < 0 && Qp2 < 0)) {
|
95
|
+
return jsts.algorithm.LineIntersector.NO_INTERSECTION;
|
96
|
+
}
|
97
|
+
|
98
|
+
var collinear = Pq1 === 0 && Pq2 === 0 && Qp1 === 0 && Qp2 === 0;
|
99
|
+
if (collinear) {
|
100
|
+
return this.computeCollinearIntersection(p1, p2, q1, q2);
|
101
|
+
}
|
102
|
+
|
103
|
+
/**
|
104
|
+
* At this point we know that there is a single intersection point (since the
|
105
|
+
* lines are not collinear).
|
106
|
+
*/
|
107
|
+
|
108
|
+
/**
|
109
|
+
* Check if the intersection is an endpoint. If it is, copy the endpoint as
|
110
|
+
* the intersection point. Copying the point rather than computing it ensures
|
111
|
+
* the point has the exact value, which is important for robustness. It is
|
112
|
+
* sufficient to simply check for an endpoint which is on the other line,
|
113
|
+
* since at this point we know that the inputLines must intersect.
|
114
|
+
*/
|
115
|
+
if (Pq1 === 0 || Pq2 === 0 || Qp1 === 0 || Qp2 === 0) {
|
116
|
+
this._isProper = false;
|
117
|
+
|
118
|
+
/**
|
119
|
+
* Check for two equal endpoints. This is done explicitly rather than by the
|
120
|
+
* orientation tests below in order to improve robustness.
|
121
|
+
*
|
122
|
+
* [An example where the orientation tests fail to be consistent is the
|
123
|
+
* following (where the true intersection is at the shared endpoint POINT
|
124
|
+
* (19.850257749638203 46.29709338043669)
|
125
|
+
*
|
126
|
+
* LINESTRING ( 19.850257749638203 46.29709338043669, 20.31970698357233
|
127
|
+
* 46.76654261437082 ) and LINESTRING ( -48.51001596420236
|
128
|
+
* -22.063180333403878, 19.850257749638203 46.29709338043669 )
|
129
|
+
*
|
130
|
+
* which used to produce the INCORRECT result: (20.31970698357233,
|
131
|
+
* 46.76654261437082, NaN)
|
132
|
+
*
|
133
|
+
*/
|
134
|
+
if (p1.equals2D(q1) || p1.equals2D(q2)) {
|
135
|
+
this.intPt[0] = p1;
|
136
|
+
} else if (p2.equals2D(q1) || p2.equals2D(q2)) {
|
137
|
+
this.intPt[0] = p2;
|
138
|
+
}
|
139
|
+
|
140
|
+
/**
|
141
|
+
* Now check to see if any endpoint lies on the interior of the other
|
142
|
+
* segment.
|
143
|
+
*/
|
144
|
+
else if (Pq1 === 0) {
|
145
|
+
this.intPt[0] = new jsts.geom.Coordinate(q1);
|
146
|
+
} else if (Pq2 === 0) {
|
147
|
+
this.intPt[0] = new jsts.geom.Coordinate(q2);
|
148
|
+
} else if (Qp1 === 0) {
|
149
|
+
this.intPt[0] = new jsts.geom.Coordinate(p1);
|
150
|
+
} else if (Qp2 === 0) {
|
151
|
+
this.intPt[0] = new jsts.geom.Coordinate(p2);
|
152
|
+
}
|
153
|
+
} else {
|
154
|
+
this._isProper = true;
|
155
|
+
this.intPt[0] = this.intersection(p1, p2, q1, q2);
|
156
|
+
}
|
157
|
+
return jsts.algorithm.LineIntersector.POINT_INTERSECTION;
|
158
|
+
};
|
159
|
+
|
160
|
+
|
161
|
+
/**
|
162
|
+
* @param {Coordinate}
|
163
|
+
* p1
|
164
|
+
* @param {Coordinate}
|
165
|
+
* p2
|
166
|
+
* @param {Coordinate}
|
167
|
+
* q1
|
168
|
+
* @param {Coordinate}
|
169
|
+
* q2
|
170
|
+
* @return {Number}
|
171
|
+
* @private
|
172
|
+
*/
|
173
|
+
jsts.algorithm.RobustLineIntersector.prototype.computeCollinearIntersection = function(
|
174
|
+
p1, p2, q1, q2) {
|
175
|
+
var p1q1p2 = jsts.geom.Envelope.intersects(p1, p2, q1);
|
176
|
+
var p1q2p2 = jsts.geom.Envelope.intersects(p1, p2, q2);
|
177
|
+
var q1p1q2 = jsts.geom.Envelope.intersects(q1, q2, p1);
|
178
|
+
var q1p2q2 = jsts.geom.Envelope.intersects(q1, q2, p2);
|
179
|
+
|
180
|
+
if (p1q1p2 && p1q2p2) {
|
181
|
+
this.intPt[0] = q1;
|
182
|
+
this.intPt[1] = q2;
|
183
|
+
return jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION;
|
184
|
+
}
|
185
|
+
if (q1p1q2 && q1p2q2) {
|
186
|
+
this.intPt[0] = p1;
|
187
|
+
this.intPt[1] = p2;
|
188
|
+
return jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION;
|
189
|
+
}
|
190
|
+
if (p1q1p2 && q1p1q2) {
|
191
|
+
this.intPt[0] = q1;
|
192
|
+
this.intPt[1] = p1;
|
193
|
+
return q1.equals(p1) && !p1q2p2 && !q1p2q2 ? jsts.algorithm.LineIntersector.POINT_INTERSECTION
|
194
|
+
: jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION;
|
195
|
+
}
|
196
|
+
if (p1q1p2 && q1p2q2) {
|
197
|
+
this.intPt[0] = q1;
|
198
|
+
this.intPt[1] = p2;
|
199
|
+
return q1.equals(p2) && !p1q2p2 && !q1p1q2 ? jsts.algorithm.LineIntersector.POINT_INTERSECTION
|
200
|
+
: jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION;
|
201
|
+
}
|
202
|
+
if (p1q2p2 && q1p1q2) {
|
203
|
+
this.intPt[0] = q2;
|
204
|
+
this.intPt[1] = p1;
|
205
|
+
return q2.equals(p1) && !p1q1p2 && !q1p2q2 ? jsts.algorithm.LineIntersector.POINT_INTERSECTION
|
206
|
+
: jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION;
|
207
|
+
}
|
208
|
+
if (p1q2p2 && q1p2q2) {
|
209
|
+
this.intPt[0] = q2;
|
210
|
+
this.intPt[1] = p2;
|
211
|
+
return q2.equals(p2) && !p1q1p2 && !q1p1q2 ? jsts.algorithm.LineIntersector.POINT_INTERSECTION
|
212
|
+
: jsts.algorithm.LineIntersector.COLLINEAR_INTERSECTION;
|
213
|
+
}
|
214
|
+
return jsts.algorithm.LineIntersector.NO_INTERSECTION;
|
215
|
+
};
|
216
|
+
|
217
|
+
|
218
|
+
/**
|
219
|
+
* This method computes the actual value of the intersection point. To obtain
|
220
|
+
* the maximum precision from the intersection calculation, the coordinates are
|
221
|
+
* normalized by subtracting the minimum ordinate values (in absolute value).
|
222
|
+
* This has the effect of removing common significant digits from the
|
223
|
+
* calculation to maintain more bits of precision.
|
224
|
+
*
|
225
|
+
* @param {Coordinate}
|
226
|
+
* p1
|
227
|
+
* @param {Coordinate}
|
228
|
+
* p2
|
229
|
+
* @param {Coordinate}
|
230
|
+
* q1
|
231
|
+
* @param {Coordinate}
|
232
|
+
* q2
|
233
|
+
* @return {Coordinate}
|
234
|
+
* @private
|
235
|
+
*/
|
236
|
+
jsts.algorithm.RobustLineIntersector.prototype.intersection = function(p1, p2,
|
237
|
+
q1, q2) {
|
238
|
+
var intPt = this.intersectionWithNormalization(p1, p2, q1, q2);
|
239
|
+
|
240
|
+
/**
|
241
|
+
* Due to rounding it can happen that the computed intersection is outside the
|
242
|
+
* envelopes of the input segments. Clearly this is inconsistent. This code
|
243
|
+
* checks this condition and forces a more reasonable answer
|
244
|
+
*
|
245
|
+
* MD - May 4 2005 - This is still a problem. Here is a failure case:
|
246
|
+
*
|
247
|
+
* LINESTRING (2089426.5233462777 1180182.3877339689, 2085646.6891757075
|
248
|
+
* 1195618.7333999649) LINESTRING (1889281.8148903656 1997547.0560044837,
|
249
|
+
* 2259977.3672235999 483675.17050843034) int point =
|
250
|
+
* (2097408.2633752143,1144595.8008114607)
|
251
|
+
*
|
252
|
+
* MD - Dec 14 2006 - This does not seem to be a failure case any longer
|
253
|
+
*/
|
254
|
+
if (!this.isInSegmentEnvelopes(intPt)) {
|
255
|
+
// System.out.println("Intersection outside segment envelopes: " + intPt);
|
256
|
+
// System.out.println("Segments: " + this);
|
257
|
+
// compute a safer result
|
258
|
+
intPt = jsts.algorithm.CentralEndpointIntersector.getIntersection(p1, p2, q1, q2);
|
259
|
+
// System.out.println("Snapped to " + intPt);
|
260
|
+
}
|
261
|
+
|
262
|
+
if (this.precisionModel !== null) {
|
263
|
+
this.precisionModel.makePrecise(intPt);
|
264
|
+
}
|
265
|
+
|
266
|
+
return intPt;
|
267
|
+
};
|
268
|
+
|
269
|
+
|
270
|
+
/**
|
271
|
+
* @param {Coordinate}
|
272
|
+
* p1
|
273
|
+
* @param {Coordinate}
|
274
|
+
* p2
|
275
|
+
* @param {Coordinate}
|
276
|
+
* q1
|
277
|
+
* @param {Coordinate}
|
278
|
+
* q2
|
279
|
+
* @return {Coordinate}
|
280
|
+
* @private
|
281
|
+
*/
|
282
|
+
jsts.algorithm.RobustLineIntersector.prototype.intersectionWithNormalization = function(
|
283
|
+
p1, p2, q1, q2) {
|
284
|
+
var n1 = new jsts.geom.Coordinate(p1);
|
285
|
+
var n2 = new jsts.geom.Coordinate(p2);
|
286
|
+
var n3 = new jsts.geom.Coordinate(q1);
|
287
|
+
var n4 = new jsts.geom.Coordinate(q2);
|
288
|
+
var normPt = new jsts.geom.Coordinate();
|
289
|
+
this.normalizeToEnvCentre(n1, n2, n3, n4, normPt);
|
290
|
+
|
291
|
+
var intPt = this.safeHCoordinateIntersection(n1, n2, n3, n4);
|
292
|
+
|
293
|
+
intPt.x += normPt.x;
|
294
|
+
intPt.y += normPt.y;
|
295
|
+
|
296
|
+
return intPt;
|
297
|
+
};
|
298
|
+
|
299
|
+
|
300
|
+
/**
|
301
|
+
* Computes a segment intersection using homogeneous coordinates. Round-off
|
302
|
+
* error can cause the raw computation to fail, (usually due to the segments
|
303
|
+
* being approximately parallel). If this happens, a reasonable approximation is
|
304
|
+
* computed instead.
|
305
|
+
*
|
306
|
+
* @param {Coordinate}
|
307
|
+
* p1 a segment endpoint.
|
308
|
+
* @param {Coordinate}
|
309
|
+
* p2 a segment endpoint.
|
310
|
+
* @param {Coordinate}
|
311
|
+
* q1 a segment endpoint.
|
312
|
+
* @param {Coordinate}
|
313
|
+
* q2 a segment endpoint.
|
314
|
+
* @return {Coordinate} the computed intersection point.
|
315
|
+
* @private
|
316
|
+
*/
|
317
|
+
jsts.algorithm.RobustLineIntersector.prototype.safeHCoordinateIntersection = function(
|
318
|
+
p1, p2, q1, q2) {
|
319
|
+
var intPt = null;
|
320
|
+
try {
|
321
|
+
intPt = jsts.algorithm.HCoordinate.intersection(p1, p2, q1, q2);
|
322
|
+
} catch (e) {
|
323
|
+
if (e instanceof jsts.error.NotRepresentableError) {
|
324
|
+
// System.out.println("Not calculable: " + this);
|
325
|
+
// compute an approximate result
|
326
|
+
intPt = jsts.algorithm.CentralEndpointIntersector.getIntersection(p1, p2,
|
327
|
+
q1, q2);
|
328
|
+
// System.out.println("Snapped to " + intPt);
|
329
|
+
} else {
|
330
|
+
throw e;
|
331
|
+
}
|
332
|
+
}
|
333
|
+
|
334
|
+
return intPt;
|
335
|
+
};
|
336
|
+
|
337
|
+
|
338
|
+
/**
|
339
|
+
* Normalize the supplied coordinates so that their minimum ordinate values lie
|
340
|
+
* at the origin. NOTE: this normalization technique appears to cause large
|
341
|
+
* errors in the position of the intersection point for some cases.
|
342
|
+
*
|
343
|
+
* @param {Coordinate}
|
344
|
+
* n1
|
345
|
+
* @param {Coordinate}
|
346
|
+
* n2
|
347
|
+
* @param {Coordinate}
|
348
|
+
* n3
|
349
|
+
* @param {Coordinate}
|
350
|
+
* n4
|
351
|
+
* @param {Coordinate}
|
352
|
+
* normPt
|
353
|
+
*/
|
354
|
+
jsts.algorithm.RobustLineIntersector.prototype.normalizeToMinimum = function(
|
355
|
+
n1, n2, n3, n4, normPt) {
|
356
|
+
normPt.x = this.smallestInAbsValue(n1.x, n2.x, n3.x, n4.x);
|
357
|
+
normPt.y = this.smallestInAbsValue(n1.y, n2.y, n3.y, n4.y);
|
358
|
+
n1.x -= normPt.x;
|
359
|
+
n1.y -= normPt.y;
|
360
|
+
n2.x -= normPt.x;
|
361
|
+
n2.y -= normPt.y;
|
362
|
+
n3.x -= normPt.x;
|
363
|
+
n3.y -= normPt.y;
|
364
|
+
n4.x -= normPt.x;
|
365
|
+
n4.y -= normPt.y;
|
366
|
+
};
|
367
|
+
|
368
|
+
|
369
|
+
/**
|
370
|
+
* Normalize the supplied coordinates to so that the midpoint of their
|
371
|
+
* intersection envelope lies at the origin.
|
372
|
+
*
|
373
|
+
* @param {Coordinate}
|
374
|
+
* n00
|
375
|
+
* @param {Coordinate}
|
376
|
+
* n01
|
377
|
+
* @param {Coordinate}
|
378
|
+
* n10
|
379
|
+
* @param {Coordinate}
|
380
|
+
* n11
|
381
|
+
* @param {Coordinate}
|
382
|
+
* normPt
|
383
|
+
*/
|
384
|
+
jsts.algorithm.RobustLineIntersector.prototype.normalizeToEnvCentre = function(
|
385
|
+
n00, n01, n10, n11, normPt) {
|
386
|
+
var minX0 = n00.x < n01.x ? n00.x : n01.x;
|
387
|
+
var minY0 = n00.y < n01.y ? n00.y : n01.y;
|
388
|
+
var maxX0 = n00.x > n01.x ? n00.x : n01.x;
|
389
|
+
var maxY0 = n00.y > n01.y ? n00.y : n01.y;
|
390
|
+
|
391
|
+
var minX1 = n10.x < n11.x ? n10.x : n11.x;
|
392
|
+
var minY1 = n10.y < n11.y ? n10.y : n11.y;
|
393
|
+
var maxX1 = n10.x > n11.x ? n10.x : n11.x;
|
394
|
+
var maxY1 = n10.y > n11.y ? n10.y : n11.y;
|
395
|
+
|
396
|
+
var intMinX = minX0 > minX1 ? minX0 : minX1;
|
397
|
+
var intMaxX = maxX0 < maxX1 ? maxX0 : maxX1;
|
398
|
+
var intMinY = minY0 > minY1 ? minY0 : minY1;
|
399
|
+
var intMaxY = maxY0 < maxY1 ? maxY0 : maxY1;
|
400
|
+
|
401
|
+
var intMidX = (intMinX + intMaxX) / 2.0;
|
402
|
+
var intMidY = (intMinY + intMaxY) / 2.0;
|
403
|
+
normPt.x = intMidX;
|
404
|
+
normPt.y = intMidY;
|
405
|
+
|
406
|
+
/*
|
407
|
+
// equilavalent code using more modular but slower method
|
408
|
+
Envelope env0 = new Envelope(n00, n01);
|
409
|
+
Envelope env1 = new Envelope(n10, n11);
|
410
|
+
Envelope intEnv = env0.intersection(env1);
|
411
|
+
Coordinate intMidPt = intEnv.centre();
|
412
|
+
|
413
|
+
normPt.x = intMidPt.x;
|
414
|
+
normPt.y = intMidPt.y;
|
415
|
+
*/
|
416
|
+
|
417
|
+
n00.x -= normPt.x;
|
418
|
+
n00.y -= normPt.y;
|
419
|
+
n01.x -= normPt.x;
|
420
|
+
n01.y -= normPt.y;
|
421
|
+
n10.x -= normPt.x;
|
422
|
+
n10.y -= normPt.y;
|
423
|
+
n11.x -= normPt.x;
|
424
|
+
n11.y -= normPt.y;
|
425
|
+
};
|
426
|
+
|
427
|
+
|
428
|
+
/**
|
429
|
+
* @param {double}
|
430
|
+
* x1
|
431
|
+
* @param {double}
|
432
|
+
* x2
|
433
|
+
* @param {double}
|
434
|
+
* x3
|
435
|
+
* @param {double}
|
436
|
+
* x4
|
437
|
+
* @return {double}
|
438
|
+
*/
|
439
|
+
jsts.algorithm.RobustLineIntersector.prototype.smallestInAbsValue = function(
|
440
|
+
x1, x2, x3, x4) {
|
441
|
+
var x = x1;
|
442
|
+
var xabs = Math.abs(x);
|
443
|
+
if (Math.abs(x2) < xabs) {
|
444
|
+
x = x2;
|
445
|
+
xabs = Math.abs(x2);
|
446
|
+
}
|
447
|
+
if (Math.abs(x3) < xabs) {
|
448
|
+
x = x3;
|
449
|
+
xabs = Math.abs(x3);
|
450
|
+
}
|
451
|
+
if (Math.abs(x4) < xabs) {
|
452
|
+
x = x4;
|
453
|
+
}
|
454
|
+
return x;
|
455
|
+
};
|
456
|
+
|
457
|
+
|
458
|
+
/**
|
459
|
+
* Test whether a point lies in the envelopes of both input segments. A
|
460
|
+
* correctly computed intersection point should return <code>true</code> for
|
461
|
+
* this test. Since this test is for debugging purposes only, no attempt is made
|
462
|
+
* to optimize the envelope test.
|
463
|
+
*
|
464
|
+
* @param {Coordinate}
|
465
|
+
* intPt
|
466
|
+
* @return {boolean} <code>true</code> if the input point lies within both
|
467
|
+
* input segment envelopes.
|
468
|
+
* @private
|
469
|
+
*/
|
470
|
+
jsts.algorithm.RobustLineIntersector.prototype.isInSegmentEnvelopes = function(
|
471
|
+
intPt) {
|
472
|
+
var env0 = new jsts.geom.Envelope(this.inputLines[0][0],
|
473
|
+
this.inputLines[0][1]);
|
474
|
+
var env1 = new jsts.geom.Envelope(this.inputLines[1][0],
|
475
|
+
this.inputLines[1][1]);
|
476
|
+
return env0.contains(intPt) && env1.contains(intPt);
|
477
|
+
};
|