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.
Files changed (209) hide show
  1. checksums.yaml +8 -8
  2. data/lib/jsts-rails/version.rb +1 -1
  3. data/vendor/assets/javascripts/javascript.util.js +33 -1
  4. data/vendor/assets/javascripts/jsts-original.js +164 -1573
  5. data/vendor/assets/javascripts/jsts.js +197 -0
  6. data/vendor/assets/javascripts/jsts/algorithm/Angle.js +387 -0
  7. data/vendor/assets/javascripts/jsts/algorithm/BoundaryNodeRule.js +67 -0
  8. data/vendor/assets/javascripts/jsts/algorithm/CGAlgorithms.js +596 -0
  9. data/vendor/assets/javascripts/jsts/algorithm/CentralEndpointIntersector.js +118 -0
  10. data/vendor/assets/javascripts/jsts/algorithm/CentroidArea.js +225 -0
  11. data/vendor/assets/javascripts/jsts/algorithm/CentroidLine.js +85 -0
  12. data/vendor/assets/javascripts/jsts/algorithm/CentroidPoint.js +77 -0
  13. data/vendor/assets/javascripts/jsts/algorithm/ConvexHull.js +409 -0
  14. data/vendor/assets/javascripts/jsts/algorithm/HCoordinate.js +234 -0
  15. data/vendor/assets/javascripts/jsts/algorithm/LineIntersector.js +502 -0
  16. data/vendor/assets/javascripts/jsts/algorithm/MCPointInRing.js +124 -0
  17. data/vendor/assets/javascripts/jsts/algorithm/PointLocator.js +247 -0
  18. data/vendor/assets/javascripts/jsts/algorithm/RayCrossingCounter.js +215 -0
  19. data/vendor/assets/javascripts/jsts/algorithm/RobustDeterminant.js +353 -0
  20. data/vendor/assets/javascripts/jsts/algorithm/RobustLineIntersector.js +477 -0
  21. data/vendor/assets/javascripts/jsts/algorithm/distance/DiscreteHausdorffDistance.js +228 -0
  22. data/vendor/assets/javascripts/jsts/algorithm/distance/DistanceToPoint.js +68 -0
  23. data/vendor/assets/javascripts/jsts/algorithm/distance/PointPairDistance.js +104 -0
  24. data/vendor/assets/javascripts/jsts/algorithm/locate/PointOnGeometryLocator.js +7 -0
  25. data/vendor/assets/javascripts/jsts/algorithm/locate/SimplePointInAreaLocator.js +102 -0
  26. data/vendor/assets/javascripts/jsts/geom/Coordinate.js +158 -0
  27. data/vendor/assets/javascripts/jsts/geom/CoordinateArrays.js +148 -0
  28. data/vendor/assets/javascripts/jsts/geom/CoordinateFilter.js +29 -0
  29. data/vendor/assets/javascripts/jsts/geom/CoordinateList.js +157 -0
  30. data/vendor/assets/javascripts/jsts/geom/CoordinateSequenceFilter.js +63 -0
  31. data/vendor/assets/javascripts/jsts/geom/Dimension.js +137 -0
  32. data/vendor/assets/javascripts/jsts/geom/Envelope.js +833 -0
  33. data/vendor/assets/javascripts/jsts/geom/Geometry.js +1535 -0
  34. data/vendor/assets/javascripts/jsts/geom/GeometryCollection.js +230 -0
  35. data/vendor/assets/javascripts/jsts/geom/GeometryComponentFilter.js +36 -0
  36. data/vendor/assets/javascripts/jsts/geom/GeometryFactory.js +263 -0
  37. data/vendor/assets/javascripts/jsts/geom/GeometryFilter.js +29 -0
  38. data/vendor/assets/javascripts/jsts/geom/IntersectionMatrix.js +650 -0
  39. data/vendor/assets/javascripts/jsts/geom/LineSegment.js +275 -0
  40. data/vendor/assets/javascripts/jsts/geom/LineString.js +299 -0
  41. data/vendor/assets/javascripts/jsts/geom/LinearRing.js +69 -0
  42. data/vendor/assets/javascripts/jsts/geom/Location.js +83 -0
  43. data/vendor/assets/javascripts/jsts/geom/MultiLineString.js +47 -0
  44. data/vendor/assets/javascripts/jsts/geom/MultiPoint.js +64 -0
  45. data/vendor/assets/javascripts/jsts/geom/MultiPolygon.js +64 -0
  46. data/vendor/assets/javascripts/jsts/geom/Point.js +197 -0
  47. data/vendor/assets/javascripts/jsts/geom/Polygon.js +263 -0
  48. data/vendor/assets/javascripts/jsts/geom/PrecisionModel.js +187 -0
  49. data/vendor/assets/javascripts/jsts/geom/Triangle.js +313 -0
  50. data/vendor/assets/javascripts/jsts/geom/util/GeometryCombiner.js +143 -0
  51. data/vendor/assets/javascripts/jsts/geom/util/GeometryExtracter.js +76 -0
  52. data/vendor/assets/javascripts/jsts/geom/util/GeometryTransformer.js +295 -0
  53. data/vendor/assets/javascripts/jsts/geom/util/LinearComponentExtracter.js +207 -0
  54. data/vendor/assets/javascripts/jsts/geom/util/PointExtracter.js +67 -0
  55. data/vendor/assets/javascripts/jsts/geom/util/PolygonExtracter.js +71 -0
  56. data/vendor/assets/javascripts/jsts/geomgraph/Depth.js +145 -0
  57. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdge.js +270 -0
  58. data/vendor/assets/javascripts/jsts/geomgraph/DirectedEdgeStar.js +388 -0
  59. data/vendor/assets/javascripts/jsts/geomgraph/Edge.js +291 -0
  60. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEnd.js +188 -0
  61. data/vendor/assets/javascripts/jsts/geomgraph/EdgeEndStar.js +322 -0
  62. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersection.js +122 -0
  63. data/vendor/assets/javascripts/jsts/geomgraph/EdgeIntersectionList.js +146 -0
  64. data/vendor/assets/javascripts/jsts/geomgraph/EdgeList.js +111 -0
  65. data/vendor/assets/javascripts/jsts/geomgraph/EdgeNodingValidator.js +76 -0
  66. data/vendor/assets/javascripts/jsts/geomgraph/EdgeRing.js +230 -0
  67. data/vendor/assets/javascripts/jsts/geomgraph/GeometryGraph.js +469 -0
  68. data/vendor/assets/javascripts/jsts/geomgraph/GraphComponent.js +181 -0
  69. data/vendor/assets/javascripts/jsts/geomgraph/Label.js +316 -0
  70. data/vendor/assets/javascripts/jsts/geomgraph/Node.js +105 -0
  71. data/vendor/assets/javascripts/jsts/geomgraph/NodeFactory.js +22 -0
  72. data/vendor/assets/javascripts/jsts/geomgraph/NodeMap.js +128 -0
  73. data/vendor/assets/javascripts/jsts/geomgraph/PlanarGraph.js +214 -0
  74. data/vendor/assets/javascripts/jsts/geomgraph/Position.js +63 -0
  75. data/vendor/assets/javascripts/jsts/geomgraph/Quadrant.js +143 -0
  76. data/vendor/assets/javascripts/jsts/geomgraph/TopologyLocation.js +251 -0
  77. data/vendor/assets/javascripts/jsts/geomgraph/index/EdgeSetIntersector.js +47 -0
  78. data/vendor/assets/javascripts/jsts/geomgraph/index/SegmentIntersector.js +298 -0
  79. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleEdgeSetIntersector.js +107 -0
  80. data/vendor/assets/javascripts/jsts/geomgraph/index/SimpleMCSweepLineIntersector.js +29 -0
  81. data/vendor/assets/javascripts/jsts/index/ArrayListVisitor.js +37 -0
  82. data/vendor/assets/javascripts/jsts/index/DoubleBits.js +132 -0
  83. data/vendor/assets/javascripts/jsts/index/IntervalSize.js +55 -0
  84. data/vendor/assets/javascripts/jsts/index/ItemVisitor.js +23 -0
  85. data/vendor/assets/javascripts/jsts/index/SpatialIndex.js +67 -0
  86. data/vendor/assets/javascripts/jsts/index/bintree/Bintree.js +224 -0
  87. data/vendor/assets/javascripts/jsts/index/bintree/Interval.js +160 -0
  88. data/vendor/assets/javascripts/jsts/index/bintree/Key.js +110 -0
  89. data/vendor/assets/javascripts/jsts/index/bintree/Node.js +204 -0
  90. data/vendor/assets/javascripts/jsts/index/bintree/NodeBase.js +220 -0
  91. data/vendor/assets/javascripts/jsts/index/bintree/Root.js +113 -0
  92. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChain.js +244 -0
  93. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainBuilder.js +106 -0
  94. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainOverlapAction.js +56 -0
  95. data/vendor/assets/javascripts/jsts/index/chain/MonotoneChainSelectAction.js +44 -0
  96. data/vendor/assets/javascripts/jsts/index/kdtree/KdNode.js +171 -0
  97. data/vendor/assets/javascripts/jsts/index/kdtree/KdTree.js +218 -0
  98. data/vendor/assets/javascripts/jsts/index/quadtree/Key.js +134 -0
  99. data/vendor/assets/javascripts/jsts/index/quadtree/Node.js +220 -0
  100. data/vendor/assets/javascripts/jsts/index/quadtree/NodeBase.js +330 -0
  101. data/vendor/assets/javascripts/jsts/index/quadtree/Quadtree.js +228 -0
  102. data/vendor/assets/javascripts/jsts/index/quadtree/Root.js +105 -0
  103. data/vendor/assets/javascripts/jsts/index/strtree/AbstractNode.js +107 -0
  104. data/vendor/assets/javascripts/jsts/index/strtree/AbstractSTRtree.js +594 -0
  105. data/vendor/assets/javascripts/jsts/index/strtree/Boundable.js +37 -0
  106. data/vendor/assets/javascripts/jsts/index/strtree/BoundablePair.js +0 -0
  107. data/vendor/assets/javascripts/jsts/index/strtree/Interval.js +94 -0
  108. data/vendor/assets/javascripts/jsts/index/strtree/ItemBoundable.js +60 -0
  109. data/vendor/assets/javascripts/jsts/index/strtree/SIRtree.js +122 -0
  110. data/vendor/assets/javascripts/jsts/index/strtree/STRtree.js +450 -0
  111. data/vendor/assets/javascripts/jsts/io/GeoJSONParser.js +471 -0
  112. data/vendor/assets/javascripts/jsts/io/GeoJSONReader.js +58 -0
  113. data/vendor/assets/javascripts/jsts/io/GeoJSONWriter.js +38 -0
  114. data/vendor/assets/javascripts/jsts/io/OpenLayersParser.js +245 -0
  115. data/vendor/assets/javascripts/jsts/io/WKTParser.js +421 -0
  116. data/vendor/assets/javascripts/jsts/io/WKTReader.js +68 -0
  117. data/vendor/assets/javascripts/jsts/io/WKTWriter.js +61 -0
  118. data/vendor/assets/javascripts/jsts/noding/BasicSegmentString.js +87 -0
  119. data/vendor/assets/javascripts/jsts/noding/FastNodingValidator.js +127 -0
  120. data/vendor/assets/javascripts/jsts/noding/InteriorIntersectionFinder.js +171 -0
  121. data/vendor/assets/javascripts/jsts/noding/IntersectionAdder.js +198 -0
  122. data/vendor/assets/javascripts/jsts/noding/IntersectionFinderAdder.js +79 -0
  123. data/vendor/assets/javascripts/jsts/noding/MCIndexNoder.js +147 -0
  124. data/vendor/assets/javascripts/jsts/noding/NodableSegmentString.js +35 -0
  125. data/vendor/assets/javascripts/jsts/noding/NodedSegmentString.js +235 -0
  126. data/vendor/assets/javascripts/jsts/noding/Noder.js +41 -0
  127. data/vendor/assets/javascripts/jsts/noding/NodingValidator.js +5 -0
  128. data/vendor/assets/javascripts/jsts/noding/Octant.js +84 -0
  129. data/vendor/assets/javascripts/jsts/noding/OrientedCoordinateArray.js +94 -0
  130. data/vendor/assets/javascripts/jsts/noding/ScaledNoder.js +105 -0
  131. data/vendor/assets/javascripts/jsts/noding/SegmentIntersector.js +45 -0
  132. data/vendor/assets/javascripts/jsts/noding/SegmentNode.js +70 -0
  133. data/vendor/assets/javascripts/jsts/noding/SegmentNodeList.js +262 -0
  134. data/vendor/assets/javascripts/jsts/noding/SegmentPointComparator.js +78 -0
  135. data/vendor/assets/javascripts/jsts/noding/SegmentString.js +61 -0
  136. data/vendor/assets/javascripts/jsts/noding/SinglePassNoder.js +51 -0
  137. data/vendor/assets/javascripts/jsts/noding/snapround/HotPixel.js +271 -0
  138. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexPointSnapper.js +96 -0
  139. data/vendor/assets/javascripts/jsts/noding/snapround/MCIndexSnapRounder.js +147 -0
  140. data/vendor/assets/javascripts/jsts/operation/BoundaryOp.js +166 -0
  141. data/vendor/assets/javascripts/jsts/operation/GeometryGraphOperation.js +90 -0
  142. data/vendor/assets/javascripts/jsts/operation/IsSimpleOp.js +293 -0
  143. data/vendor/assets/javascripts/jsts/operation/buffer/BufferBuilder.js +317 -0
  144. data/vendor/assets/javascripts/jsts/operation/buffer/BufferInputLineSimplifier.js +294 -0
  145. data/vendor/assets/javascripts/jsts/operation/buffer/BufferOp.js +340 -0
  146. data/vendor/assets/javascripts/jsts/operation/buffer/BufferParameters.js +328 -0
  147. data/vendor/assets/javascripts/jsts/operation/buffer/BufferSubgraph.js +296 -0
  148. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveBuilder.js +369 -0
  149. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetCurveSetBuilder.js +301 -0
  150. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentGenerator.js +777 -0
  151. data/vendor/assets/javascripts/jsts/operation/buffer/OffsetSegmentString.js +109 -0
  152. data/vendor/assets/javascripts/jsts/operation/buffer/RightmostEdgeFinder.js +164 -0
  153. data/vendor/assets/javascripts/jsts/operation/buffer/SubgraphDepthLocater.js +220 -0
  154. data/vendor/assets/javascripts/jsts/operation/distance/ConnectedElementLocationFilter.js +67 -0
  155. data/vendor/assets/javascripts/jsts/operation/distance/DistanceOp.js +506 -0
  156. data/vendor/assets/javascripts/jsts/operation/distance/GeometryLocation.js +102 -0
  157. data/vendor/assets/javascripts/jsts/operation/overlay/LineBuilder.js +194 -0
  158. data/vendor/assets/javascripts/jsts/operation/overlay/MaximalEdgeRing.js +72 -0
  159. data/vendor/assets/javascripts/jsts/operation/overlay/MinimalEdgeRing.js +33 -0
  160. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayNodeFactory.js +26 -0
  161. data/vendor/assets/javascripts/jsts/operation/overlay/OverlayOp.js +584 -0
  162. data/vendor/assets/javascripts/jsts/operation/overlay/PointBuilder.js +103 -0
  163. data/vendor/assets/javascripts/jsts/operation/overlay/PolygonBuilder.js +282 -0
  164. data/vendor/assets/javascripts/jsts/operation/overlay/snap/GeometrySnapper.js +228 -0
  165. data/vendor/assets/javascripts/jsts/operation/overlay/snap/LineStringSnapper.js +228 -0
  166. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapIfNeededOverlayOp.js +85 -0
  167. data/vendor/assets/javascripts/jsts/operation/overlay/snap/SnapOverlayOp.js +134 -0
  168. data/vendor/assets/javascripts/jsts/operation/polygonize/EdgeRing.js +259 -0
  169. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeDirectedEdge.js +94 -0
  170. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeEdge.js +31 -0
  171. data/vendor/assets/javascripts/jsts/operation/polygonize/PolygonizeGraph.js +507 -0
  172. data/vendor/assets/javascripts/jsts/operation/polygonize/Polygonizer.js +259 -0
  173. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBuilder.js +140 -0
  174. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundle.js +183 -0
  175. data/vendor/assets/javascripts/jsts/operation/relate/EdgeEndBundleStar.js +48 -0
  176. data/vendor/assets/javascripts/jsts/operation/relate/RelateComputer.js +444 -0
  177. data/vendor/assets/javascripts/jsts/operation/relate/RelateNode.js +46 -0
  178. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeFactory.js +25 -0
  179. data/vendor/assets/javascripts/jsts/operation/relate/RelateNodeGraph.js +118 -0
  180. data/vendor/assets/javascripts/jsts/operation/relate/RelateOp.js +75 -0
  181. data/vendor/assets/javascripts/jsts/operation/union/CascadedPolygonUnion.js +319 -0
  182. data/vendor/assets/javascripts/jsts/operation/union/PointGeometryUnion.js +118 -0
  183. data/vendor/assets/javascripts/jsts/operation/union/UnaryUnionOp.js +244 -0
  184. data/vendor/assets/javascripts/jsts/operation/union/UnionInteracting.js +156 -0
  185. data/vendor/assets/javascripts/jsts/operation/valid/ConnectedInteriorTester.js +259 -0
  186. data/vendor/assets/javascripts/jsts/operation/valid/ConsistentAreaTester.js +127 -0
  187. data/vendor/assets/javascripts/jsts/operation/valid/IndexedNestedRingTester.js +89 -0
  188. data/vendor/assets/javascripts/jsts/operation/valid/IsValidOp.js +619 -0
  189. data/vendor/assets/javascripts/jsts/operation/valid/TopologyValidationError.js +199 -0
  190. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdge.js +232 -0
  191. data/vendor/assets/javascripts/jsts/planargraph/DirectedEdgeStar.js +168 -0
  192. data/vendor/assets/javascripts/jsts/planargraph/Edge.js +124 -0
  193. data/vendor/assets/javascripts/jsts/planargraph/GraphComponent.js +182 -0
  194. data/vendor/assets/javascripts/jsts/planargraph/Node.js +127 -0
  195. data/vendor/assets/javascripts/jsts/planargraph/NodeMap.js +76 -0
  196. data/vendor/assets/javascripts/jsts/planargraph/PlanarGraph.js +246 -0
  197. data/vendor/assets/javascripts/jsts/simplify/LineSegmentIndex.js +101 -0
  198. data/vendor/assets/javascripts/jsts/triangulate/DelaunayTriangulationBuilder.js +224 -0
  199. data/vendor/assets/javascripts/jsts/triangulate/IncrementalDelaunayTriangulator.js +111 -0
  200. data/vendor/assets/javascripts/jsts/triangulate/VoronoiDiagramBuilder.js +172 -0
  201. data/vendor/assets/javascripts/jsts/triangulate/quadedge/LastFoundQuadEdgeLocator.js +52 -0
  202. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdge.js +437 -0
  203. data/vendor/assets/javascripts/jsts/triangulate/quadedge/QuadEdgeSubdivision.js +1064 -0
  204. data/vendor/assets/javascripts/jsts/triangulate/quadedge/TrianglePredicate.js +350 -0
  205. data/vendor/assets/javascripts/jsts/triangulate/quadedge/Vertex.js +496 -0
  206. data/vendor/assets/javascripts/jsts/util/Assert.js +80 -0
  207. data/vendor/assets/javascripts/jsts/util/AssertionFailedException.js +23 -0
  208. data/vendor/assets/javascripts/jsts/util/UniqueCoordinateArrayFilter.js +52 -0
  209. metadata +204 -1
@@ -0,0 +1,350 @@
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
+ * Algorithms for computing values and predicates associated with triangles.
11
+ *
12
+ * For some algorithms extended-precision implementations are provided, which
13
+ * are more robust (i.e. they produce correct answers in more cases). Also, some
14
+ * more robust formulations of some algorithms are provided, which utilize
15
+ * normalization to the origin.
16
+ *
17
+ * @constructor
18
+ */
19
+ jsts.triangulate.quadedge.TrianglePredicate = function() {
20
+
21
+ };
22
+
23
+
24
+ /**
25
+ * Tests if a point is inside the circle defined by the points a, b, c. This
26
+ * test uses simple double-precision arithmetic, and thus may not be robust.
27
+ *
28
+ * @param {jsts.geom.Coordinate}
29
+ * a a vertex of the triangle.
30
+ * @param {jsts.geom.Coordinate}
31
+ * b a vertex of the triangle.
32
+ * @param {jsts.geom.Coordinate}
33
+ * c a vertex of the triangle.
34
+ * @param {jsts.geom.Coordinate}
35
+ * p the point to test.
36
+ * @return {Boolean} true if this point is inside the circle defined by the
37
+ * points a, b, c.
38
+ */
39
+ jsts.triangulate.quadedge.TrianglePredicate.isInCircleNonRobust = function(a,
40
+ b, c, p) {
41
+ var isInCircle = (a.x * a.x + a.y * a.y) *
42
+ jsts.triangulate.quadedge.TrianglePredicate.triArea(b, c, p) -
43
+ (b.x * b.x + b.y * b.y) *
44
+ jsts.triangulate.quadedge.TrianglePredicate.triArea(a, c, p) +
45
+ (c.x * c.x + c.y * c.y) *
46
+ jsts.triangulate.quadedge.TrianglePredicate.triArea(a, b, p) -
47
+ (p.x * p.x + p.y * p.y) *
48
+ jsts.triangulate.quadedge.TrianglePredicate.triArea(a, b, c) > 0;
49
+
50
+ return isInCircle;
51
+ };
52
+
53
+
54
+ /**
55
+ * Tests if a point is inside the circle defined by the points a, b, c. This
56
+ * test uses simple double-precision arithmetic, and thus is not 10% robust.
57
+ * However, by using normalization to the origin it provides improved robustness
58
+ * and increased performance.
59
+ * <p>
60
+ * Based on code by J.R.Shewchuk.
61
+ *
62
+ *
63
+ * @param {jsts.geom.Coordinate}
64
+ * a a vertex of the triangle.
65
+ * @param {jsts.geom.Coordinate}
66
+ * b a vertex of the triangle.
67
+ * @param {jsts.geom.Coordinate}
68
+ * c a vertex of the triangle.
69
+ * @param {jsts.geom.Coordinate}
70
+ * p the point to test.
71
+ * @return {Boolean} true if this point is inside the circle defined by the
72
+ * points a, b, c.
73
+ */
74
+ jsts.triangulate.quadedge.TrianglePredicate.isInCircleNormalized = function(a,
75
+ b, c, p) {
76
+ var adx, ady, bdx, bdy, cdx, cdy, abdet, bcdet, cadet, alift, blift, clift, disc;
77
+
78
+ adx = a.x - p.x;
79
+ ady = a.y - p.y;
80
+ bdx = b.x - p.x;
81
+ bdy = b.y - p.y;
82
+ cdx = c.x - p.x;
83
+ cdy = c.y - p.y;
84
+
85
+ abdet = adx * bdy - bdx * ady;
86
+ bcdet = bdx * cdy - cdx * bdy;
87
+ cadet = cdx * ady - adx * cdy;
88
+ alift = adx * adx + ady * ady;
89
+ blift = bdx * bdx + bdy * bdy;
90
+ clift = cdx * cdx + cdy * cdy;
91
+
92
+ disc = alift * bcdet + blift * cadet + clift * abdet;
93
+ return disc > 0;
94
+ };
95
+
96
+
97
+ /**
98
+ * Computes twice the area of the oriented triangle (a, b, c), i.e. the area is
99
+ * positive if the triangle is oriented counterclockwise.
100
+ *
101
+ * @param {jsts.geom.Coordinate}
102
+ * a a vertex of the triangle.
103
+ * @param {jsts.geom.Coordinate}
104
+ * b a vertex of the triangle.
105
+ * @param {jsts.geom.Coordinate}
106
+ * c a vertex of the triangle.
107
+ * @return {Number} The calculated area.
108
+ */
109
+ jsts.triangulate.quadedge.TrianglePredicate.triArea = function(a, b, c) {
110
+ return (b.x - a.x) * (c.y - a.y) - (b.y - a.y) * (c.x - a.x);
111
+ };
112
+
113
+
114
+ /**
115
+ * Tests if a point is inside the circle defined by the points a, b, c. This
116
+ * method uses more robust computation.
117
+ *
118
+ * @param {jsts.geom.Coordinate}
119
+ * a a vertex of the triangle.
120
+ * @param {jsts.geom.Coordinate}
121
+ * b a vertex of the triangle.
122
+ * @param {jsts.geom.Coordinate}
123
+ * c a vertex of the triangle.
124
+ * @param {jsts.geom.Coordinate}
125
+ * p the point to test.
126
+ * @return {Boolean} true if this point is inside the circle defined by the
127
+ * points a, b, c.
128
+ */
129
+ jsts.triangulate.quadedge.TrianglePredicate.isInCircleRobust = function(a, b,
130
+ c, p) {
131
+ return jsts.triangulate.quadedge.TrianglePredicate.isInCircleNormalized(a, b,
132
+ c, p);
133
+ };
134
+
135
+
136
+ /**
137
+ * Tests if a point is inside the circle defined by the points a, b, c. The
138
+ * computation uses {@link DD} arithmetic for robustness.
139
+ *
140
+ * @param {jsts.geom.Coordinate}
141
+ * a a vertex of the triangle.
142
+ * @param {jsts.geom.Coordinate}
143
+ * b a vertex of the triangle.
144
+ * @param {jsts.geom.Coordinate}
145
+ * c a vertex of the triangle.
146
+ * @param {jsts.geom.Coordinate}
147
+ * p the point to test.
148
+ * @return {Boolean} true if this point is inside the circle defined by the
149
+ * points a, b, c.
150
+ */
151
+ jsts.triangulate.quadedge.TrianglePredicate.isInCircleDDSlow = function(a, b,
152
+ c, p) {
153
+ var px, py, ax, ay, bx, by, cx, cy, aTerm, bTerm, cTerm, pTerm, sum, isInCircle;
154
+
155
+ px = jsts.math.DD.valueOf(p.x);
156
+ py = jsts.math.DD.valueOf(p.y);
157
+ ax = jsts.math.DD.valueOf(a.x);
158
+ ay = jsts.math.DD.valueOf(a.y);
159
+ bx = jsts.math.DD.valueOf(b.x);
160
+ by = jsts.math.DD.valueOf(b.y);
161
+ cx = jsts.math.DD.valueOf(c.x);
162
+ cy = jsts.math.DD.valueOf(c.y);
163
+
164
+ aTerm = (ax.multiply(ax).add(ay.multiply(ay)))
165
+ .multiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDSlow(bx,
166
+ by, cx, cy, px, py));
167
+ bTerm = (bx.multiply(bx).add(by.multiply(by)))
168
+ .multiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDSlow(ax,
169
+ ay, cx, cy, px, py));
170
+ cTerm = (cx.multiply(cx).add(cy.multiply(cy)))
171
+ .multiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDSlow(ax,
172
+ ay, bx, by, px, py));
173
+ pTerm = (px.multiply(px).add(py.multiply(py)))
174
+ .multiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDSlow(ax,
175
+ ay, bx, by, cx, cy));
176
+
177
+ sum = aTerm.subtract(bTerm).add(cTerm).subtract(pTerm);
178
+ isInCircle = sum.doubleValue() > 0;
179
+
180
+ return isInCircle;
181
+ };
182
+
183
+
184
+ /**
185
+ * Computes twice the area of the oriented triangle (a, b, c), i.e., the area is
186
+ * positive if the triangle is oriented counterclockwise. The computation uses
187
+ * {@link DD} arithmetic for robustness.
188
+ *
189
+ * @param {jsts.math.DD}
190
+ * ax the x ordinate of a vertex of the triangle.
191
+ * @param {jsts.math.DD}
192
+ * ay the y ordinate of a vertex of the triangle.
193
+ * @param {jsts.math.DD}
194
+ * bx the x ordinate of a vertex of the triangle.
195
+ * @param {jsts.math.DD}
196
+ * by the y ordinate of a vertex of the triangle.
197
+ * @param {jsts.math.DD}
198
+ * cx the x ordinate of a vertex of the triangle.
199
+ * @param {jsts.math.DD}
200
+ * cy the y ordinate of a vertex of the triangle.
201
+ * @return {jsts.math.DD} The calculated area.
202
+ */
203
+ jsts.triangulate.quadedge.TrianglePredicate.triAreaDDSlow = function(ax, ay,
204
+ bx, by, cx, cy) {
205
+ return (bx.subtract(ax).multiply(cy.subtract(ay)).subtract(by.subtract(ay)
206
+ .multiply(cx.subtract(ax))));
207
+ };
208
+
209
+
210
+ /**
211
+ * Tests if a point is inside the circle defined by the points a, b, c. The
212
+ * computation uses {@link DD} arithmetic for robustness.
213
+ *
214
+ * @param {jsts.geom.Coordinate}
215
+ * a a vertex of the triangle.
216
+ * @param {jsts.geom.Coordinate}
217
+ * b a vertex of the triangle.
218
+ * @param {jsts.geom.Coordinate}
219
+ * c a vertex of the triangle.
220
+ * @param {jsts.geom.Coordinate}
221
+ * p the point to test.
222
+ * @return {Boolean} true if this point is inside the circle defined by the
223
+ * points a, b, c.
224
+ */
225
+ jsts.triangulate.quadedge.TrianglePredicate.isInCircleDDFast = function(a, b,
226
+ c, p) {
227
+ var aTerm, bTerm, cTerm, pTerm, sum, isInCircle;
228
+
229
+ aTerm = (jsts.math.DD.sqr(a.x).selfAdd(jsts.math.DD.sqr(a.y)))
230
+ .selfMultiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDFast(
231
+ b, c, p));
232
+ bTerm = (jsts.math.DD.sqr(b.x).selfAdd(jsts.math.DD.sqr(b.y)))
233
+ .selfMultiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDFast(
234
+ a, c, p));
235
+ cTerm = (jsts.math.DD.sqr(c.x).selfAdd(jsts.math.DD.sqr(c.y)))
236
+ .selfMultiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDFast(
237
+ a, b, p));
238
+ pTerm = (jsts.math.DD.sqr(p.x).selfAdd(jsts.math.DD.sqr(p.y)))
239
+ .selfMultiply(jsts.triangulate.quadedge.TrianglePredicate.triAreaDDFast(
240
+ a, b, c));
241
+
242
+ sum = aTerm.selfSubtract(bTerm).selfAdd(cTerm).selfSubtract(pTerm);
243
+ isInCircle = sum.doubleValue() > 0;
244
+
245
+ return isInCircle;
246
+ };
247
+
248
+
249
+ /**
250
+ * Computes twice the area of the oriented triangle (a, b, c), i.e., the area is
251
+ * positive if the triangle is oriented counterclockwise. The computation uses
252
+ * {@link DD} arithmetic for robustness.
253
+ *
254
+ * @param {jsts.geom.Coordinate}
255
+ * a a vertex in the triangle.
256
+ * @param {jsts.geom.Coordinate}
257
+ * b a vertex in the triangle.
258
+ * @param {jsts.geom.Coordinate}
259
+ * c a vertex in the triangle.
260
+ * @return {jsts.math.DD} The calculated area.
261
+ */
262
+ jsts.triangulate.quadedge.TrianglePredicate.triAreaDDFast = function(a, b, c) {
263
+ var t1, t2;
264
+
265
+ t1 = jsts.math.DD.valueOf(b.x).selfSubtract(a.x).selfMultiply(
266
+ jsts.math.DD.valueOf(c.y).selfSubtract(a.y));
267
+
268
+ t2 = jsts.math.DD.valueOf(b.y).selSubtract(a.y).selfMultiply(
269
+ jsts.math.DD.valueOf(c.x).selfSubtract(a.x));
270
+
271
+ return t1.selfSubtract(t2);
272
+ };
273
+
274
+
275
+ /**
276
+ * Tests if a point is inside the circle defined by the points a, b, c. This
277
+ * test uses double-double precision arithmetic.
278
+ *
279
+ * @param {jsts.geom.Coordinate}
280
+ * a a vertex of the triangle.
281
+ * @param {jsts.geom.Coordinate}
282
+ * b a vertex of the triangle.
283
+ * @param {jsts.geom.Coordinate}
284
+ * c a vertex of the triangle.
285
+ * @param {jsts.geom.Coordinate}
286
+ * p the point to test.
287
+ * @return {Boolean} true if this point is inside the circle defined by the
288
+ * points a, b, c.
289
+ */
290
+ jsts.triangulate.quadedge.TrianglePredicate.isInCircleDDNormalized = function(
291
+ a, b, c, p) {
292
+ var adx, ady, bdx, bdy, cdx, cdy, abdet, bcdet, cadet, alift, blift, clift, sum, isInCircle;
293
+
294
+ adx = jsts.math.DD.valueOf(a.x).selfSubtract(p.x);
295
+ ady = jsts.math.DD.valueOf(a.y).selfSubtract(p.y);
296
+ bdx = jsts.math.DD.valueOf(b.x).selfSubtract(p.x);
297
+ bdx = jsts.math.DD.valueOf(b.y).selfSubtract(p.y);
298
+ cdx = jsts.math.DD.valueOf(c.x).selfSubtract(p.x);
299
+ cdx = jsts.math.DD.valueOf(c.y).selfSubtract(p.y);
300
+
301
+ abdet = adx.multiply(bdy).selfSubtract(bdx.multiply(ady));
302
+ bcdet = bdx.multiply(cdy).selfSubtract(cdx.multiply(bdy));
303
+ cadet = cdx.multiply(ady).selfSubtract(adx.multiply(cdy));
304
+ alift = adx.multiply(adx).selfAdd(ady.multiply(ady));
305
+ blift = bdx.multiply(bdx).selfAdd(bdy.multiply(bdy));
306
+ clift = cdx.multiply(cdx).selfAdd(cdy.multiply(cdy));
307
+
308
+ sum = alift.selfMultiply(bcdet).selfAdd(blift.selfMultiply(cadet)).selfAdd(
309
+ clift.selfMultiply(abdet));
310
+
311
+ isInCircle = sum.doubleValue() > 0;
312
+
313
+ return isInCircle;
314
+ };
315
+
316
+
317
+ /**
318
+ * Computes the inCircle test using distance from the circumcentre. Uses
319
+ * standard double-precision arithmetic.
320
+ * <p>
321
+ * In general this doesn't appear to be any more robust than the standard
322
+ * calculation. However, there is at least one case where the test point is far
323
+ * enough from the circumcircle that this test gives the correct answer.
324
+ *
325
+ * <pre>
326
+ * LINESTRING
327
+ * (1507029.9878 518325.7547, 1507022.1120341457 518332.8225183258,
328
+ * 1507029.9833 518325.7458, 1507029.9896965567 518325.744909031)
329
+ * </pre>
330
+ *
331
+ * @param {jsts.geom.Coordinate}
332
+ * a a vertex of the triangle.
333
+ * @param {jsts.geom.Coordinate}
334
+ * b a vertex of the triangle.
335
+ * @param {jsts.geom.Coordinate}
336
+ * c a vertex of the triangle.
337
+ * @param {jsts.geom.Coordinate}
338
+ * p the point to test.
339
+ * @return {Boolean} true if this point is inside the circle defined by the
340
+ * points a, b, c.
341
+ */
342
+ jsts.triangulate.quadedge.TrianglePredicate.isInCircleCC = function(a, b, c, p) {
343
+ var cc, ccRadius, pRadiusDiff;
344
+
345
+ cc = jsts.geom.Triangle.circumcentre(a, b, c);
346
+ ccRadius = a.distance(cc);
347
+ pRadiusDiff = p.distance(cc) - ccRadius;
348
+
349
+ return pRadiusDiff <= 0;
350
+ };
@@ -0,0 +1,496 @@
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
+ * Models a site (node) in a {@link QuadEdgeSubdivision}. The sites can be
10
+ * points on a lineString representing a linear site. The vertex can be
11
+ * considered as a vector with a norm, length, inner product, cross product,
12
+ * etc. Additionally, point relations (e.g., is a point to the left of a line,
13
+ * the circle defined by this point and two others, etc.) are also defined in
14
+ * this class.
15
+ *
16
+ * Initializes a new Vertex. Will call the correct init* -function based on
17
+ * arguments
18
+ *
19
+ * @constructor
20
+ */
21
+
22
+ jsts.triangulate.quadedge.Vertex = function() {
23
+ if (arguments.length === 1) {
24
+ this.initFromCoordinate(arguments[0]);
25
+ } else {
26
+ this.initFromXY(arguments[0], arguments[1]);
27
+ }
28
+ };
29
+
30
+
31
+ /**
32
+ * LEFT The integer representing left
33
+ */
34
+ jsts.triangulate.quadedge.Vertex.LEFT = 0;
35
+
36
+
37
+ /**
38
+ * RIGHT The integer representing right
39
+ */
40
+ jsts.triangulate.quadedge.Vertex.RIGHT = 1;
41
+
42
+
43
+ /**
44
+ * BEYOND The integer representing beyond
45
+ */
46
+ jsts.triangulate.quadedge.Vertex.BEYOND = 2;
47
+
48
+
49
+ /**
50
+ * BEHIND The integer representing behind
51
+ */
52
+ jsts.triangulate.quadedge.Vertex.BEHIND = 3;
53
+
54
+
55
+ /**
56
+ * BETWEEN The integer representing between
57
+ */
58
+ jsts.triangulate.quadedge.Vertex.BETWEEN = 4;
59
+
60
+
61
+ /**
62
+ * ORIGIN The integer representing origin
63
+ */
64
+ jsts.triangulate.quadedge.Vertex.ORIGIN = 5;
65
+
66
+
67
+ /**
68
+ * DESTINATION The integer representing destination
69
+ */
70
+ jsts.triangulate.quadedge.Vertex.DESTINATION = 6;
71
+
72
+
73
+ /**
74
+ * Initializes a new Vertex
75
+ *
76
+ * @param {Number}
77
+ * x the X-coordinate.
78
+ * @param {Number}
79
+ * y the Y-coordinate.
80
+ */
81
+ jsts.triangulate.quadedge.Vertex.prototype.initFromXY = function(x, y) {
82
+ this.p = new jsts.geom.Coordinate(x, y);
83
+ };
84
+
85
+
86
+ /**
87
+ * Initializes a new Vertex
88
+ *
89
+ * @param {jsts.geom.Coordinate}
90
+ * _p the coordinate to initialize the vertex from.
91
+ */
92
+ jsts.triangulate.quadedge.Vertex.prototype.initFromCoordinate = function(_p) {
93
+ this.p = new jsts.geom.Coordinate(_p);
94
+ };
95
+
96
+
97
+ /**
98
+ * Gets the X-coordinate
99
+ *
100
+ * @return {Number} The X-coordinate.
101
+ */
102
+ jsts.triangulate.quadedge.Vertex.prototype.getX = function() {
103
+ return this.p.x;
104
+ };
105
+
106
+
107
+ /**
108
+ * Gets the Y-coordinate
109
+ *
110
+ * @return {Number} The Y-coordinate.
111
+ */
112
+ jsts.triangulate.quadedge.Vertex.prototype.getY = function() {
113
+ return this.p.y;
114
+ };
115
+
116
+
117
+ /**
118
+ * Gets the Z-coordinate
119
+ *
120
+ * @return {Number} The Z-coordinate.
121
+ */
122
+ jsts.triangulate.quadedge.Vertex.prototype.getZ = function() {
123
+ return this.p.z;
124
+ };
125
+
126
+
127
+ /**
128
+ * Sets the Z-coordinate
129
+ *
130
+ * @param {Number}
131
+ * z the new z-coordinate.
132
+ */
133
+ jsts.triangulate.quadedge.Vertex.prototype.setZ = function(z) {
134
+ this.p.z = z;
135
+ };
136
+
137
+
138
+ /**
139
+ * Gets the coordinate of the vertex
140
+ *
141
+ * @return {jsts.geom.Coordinate} The coordinate.
142
+ */
143
+ jsts.triangulate.quadedge.Vertex.prototype.getCoordinate = function() {
144
+ return this.p;
145
+ };
146
+
147
+
148
+ /**
149
+ * Gets the string representation of the vertex
150
+ *
151
+ * @return {String} The string representing the vertex.
152
+ */
153
+ jsts.triangulate.quadedge.Vertex.prototype.toString = function() {
154
+ return 'POINT (' + this.p.x + ' ' + this.p.y + ')';
155
+ };
156
+
157
+
158
+ /**
159
+ * Checks if this vertex is identical to another vertex.
160
+ *
161
+ * Calls correct equals* function based on arguments
162
+ *
163
+ * @return {Boolean} true if the vertex equals eachother.
164
+ */
165
+ jsts.triangulate.quadedge.Vertex.prototype.equals = function() {
166
+ if (arguments.length === 1) {
167
+ return this.equalsExact(arguments[0]);
168
+ } else {
169
+ return this.equalsWithTolerance(arguments[0], arguments[1]);
170
+ }
171
+ };
172
+
173
+
174
+ /**
175
+ * Checks if this vertex is identical to other
176
+ *
177
+ * @param {jsts.triangulate.quadedge.Vertex}
178
+ * other The vertex to compare this vertex to.
179
+ * @return {Boolean} true if this vertex equals other.
180
+ */
181
+ jsts.triangulate.quadedge.Vertex.prototype.equalsExact = function(other) {
182
+ return (this.p.x === other.getX() && this.p.y === other.getY());
183
+ };
184
+
185
+
186
+ /**
187
+ * Checks if this vertex is identical to other with respect to a tolerance
188
+ *
189
+ * @param {jsts.triangulate.quadedge.Vertex}
190
+ * other The vertex to compare this vertex to.
191
+ * @param {Number}
192
+ * tolerance The tolerance to consider when comparing the two vertexes.
193
+ * @return {Boolean} true if this vertex equals other.
194
+ */
195
+ jsts.triangulate.quadedge.Vertex.prototype.equalsWithTolerance = function(other,
196
+ tolerance) {
197
+ return (this.p.distance(other.getCoordinate()) < tolerance);
198
+ };
199
+
200
+
201
+ /**
202
+ * Clasifys a vertex with respect to another vertex
203
+ *
204
+ * @param {jsts.triangulate.quadedge.Vertex}
205
+ * p0 The first vertex.
206
+ * @param {jsts.triangulate.quadedge.Vertex}
207
+ * p1 The second vertex.
208
+ * @return {Number} The classification.
209
+ */
210
+ jsts.triangulate.quadedge.Vertex.prototype.classify = function(p0, p1) {
211
+ var p2, a, b, sa;
212
+
213
+ p2 = this;
214
+ a = p1.sub(p0);
215
+ b = p2.sub(p0);
216
+ sa = a.crossProduct(b);
217
+
218
+ if (sa > 0.0) {
219
+ return jsts.triangulate.quadedge.Vertex.LEFT;
220
+ }
221
+ if (sa < 0.0) {
222
+ return jsts.triangulate.quadedge.Vertex.RIGHT;
223
+ }
224
+ if ((a.getX() * b.getX() < 0.0) || (a.getY() * b.getY() < 0.0)) {
225
+ return jsts.triangulate.quadedge.Vertex.BEHIND;
226
+ }
227
+ if (a.magn() < b.magn()) {
228
+ return jsts.triangulate.quadedge.Vertex.BEYOND;
229
+ }
230
+ if (p0.equals(p2)) {
231
+ return jsts.triangulate.quadedge.Vertex.ORIGIN;
232
+ }
233
+ if (p1.equals(p2)) {
234
+ return jsts.triangulate.quadedge.Vertex.DESTINATION;
235
+ }
236
+ return jsts.triangulate.quadedge.Vertex.BETWEEN;
237
+ };
238
+
239
+
240
+ /**
241
+ * Computes the cross product k = u X v.
242
+ *
243
+ * @param {jsts.triangulate.quadedge.Vertex}
244
+ * v a vertex.
245
+ * @return {Number} The magnitude of u X v.
246
+ */
247
+ jsts.triangulate.quadedge.Vertex.prototype.crossProduct = function(v) {
248
+ return ((this.p.x * v.getY()) - (this.p.y * v.getX()));
249
+ };
250
+
251
+
252
+ /**
253
+ * Computes the inner or dot product
254
+ *
255
+ * @param {jsts.triangulate.quadedge.Vertex}
256
+ * v a vertex.
257
+ * @return {Number} The dot product u.v.
258
+ */
259
+ jsts.triangulate.quadedge.Vertex.prototype.dot = function(v) {
260
+ return ((this.p.x * v.getX()) + (this.p.y * v.getY()));
261
+ };
262
+
263
+
264
+ /**
265
+ * Computes the scalar product c(v).
266
+ *
267
+ * @param {Number}
268
+ * c The scalar.
269
+ * @return {jsts.triangulate.quadedge.Vertex} The scaled vector.
270
+ */
271
+ jsts.triangulate.quadedge.Vertex.prototype.times = function(c) {
272
+ return new jsts.triangulate.quadedge.Vertex(c * this.p.x, c * this.p.y);
273
+ };
274
+
275
+
276
+ /**
277
+ * Computes the sum of vectors.
278
+ *
279
+ * @param {jsts.triangulate.quadedge.Vertex}
280
+ * v Another vertex.
281
+ * @return {jsts.triangulate.quadedge.Vertex} The sum of the this and v.
282
+ */
283
+ jsts.triangulate.quadedge.Vertex.prototype.sum = function(v) {
284
+ return new jsts.triangulate.quadedge.Vertex(this.p.x + v.getX(), this.p.y +
285
+ v.getY());
286
+ };
287
+
288
+
289
+ /**
290
+ * Computes the substraction of vectors.
291
+ *
292
+ * @param {jsts.triangulate.quadedge.Vertex}
293
+ * v Another vertex.
294
+ * @return {jsts.triangulate.quadedge.Vertex} The substraction of v from this.
295
+ */
296
+ jsts.triangulate.quadedge.Vertex.prototype.sub = function(v) {
297
+ return new jsts.triangulate.quadedge.Vertex(this.p.x - v.getX(), this.p.y -
298
+ v.getY());
299
+ };
300
+
301
+
302
+ /**
303
+ * Computes the magnitude.
304
+ *
305
+ * @return {Number} The magnitude of this vertex.
306
+ */
307
+ jsts.triangulate.quadedge.Vertex.prototype.magn = function() {
308
+ return (Math.sqrt((this.p.x * this.p.x) + (this.p.y * this.p.y)));
309
+ };
310
+
311
+
312
+ /**
313
+ * Returns k X v (cross product). This is a vector perpendicular to v.
314
+ *
315
+ * @return {jsts.triangulate.quadedge.Vertex} A perpendicular vertex to this
316
+ * vertex.
317
+ */
318
+ jsts.triangulate.quadedge.Vertex.prototype.cross = function() {
319
+ return new Vertex(this.p.y, -this.p.x);
320
+ };
321
+
322
+
323
+ /**
324
+ * Checks if this vertex lies in the circle defined by a, b and c
325
+ *
326
+ * @param {jsts.triangulate.quadedge.Vertex}
327
+ * a A vertex.
328
+ * @param {jsts.triangulate.quadedge.Vertex}
329
+ * b A vertex.
330
+ * @param {jsts.triangulate.quadedge.Vertex}
331
+ * c A vertex.
332
+ * @return {Boolean} true if this vertex lies in the circle.
333
+ */
334
+ jsts.triangulate.quadedge.Vertex.prototype.isInCircle = function(a, b, c) {
335
+ return jsts.triangulate.quadedge.TrianglePredicate.isInCircleRobust(a.p, b.p, c.p, this.p);
336
+ };
337
+
338
+
339
+ /**
340
+ * Tests whether the triangle formed by this vertex and two other vertices is in
341
+ * CCW orientation.
342
+ *
343
+ * @param {jsts.triangulate.quadedge.Vertex}
344
+ * b a vertex.
345
+ * @param {jsts.triangulate.quadedge.Vertex}
346
+ * c a vertex.
347
+ * @return {Boolean} true if the triangle is oriented CCW.
348
+ */
349
+ jsts.triangulate.quadedge.Vertex.prototype.isCCW = function(b, c) {
350
+ // is equal to the signed area of the triangle
351
+ return ((b.p.x - this.p.x) * (c.p.y - this.p.y) - (b.p.y - this.p.y) *
352
+ (c.p.x - this.p.x) > 0);
353
+ };
354
+
355
+
356
+ /**
357
+ * Tests wheter this vertex lies to the right of an edge
358
+ *
359
+ * @param {jsts.triangulate.quadedge.QuadEdge}
360
+ * e A quadedge.
361
+ * @return {Boolean} true if this vertex lies to the right of the edge.
362
+ */
363
+ jsts.triangulate.quadedge.Vertex.prototype.rightOf = function(e) {
364
+ return this.isCCW(e.dest(), e.orig());
365
+ };
366
+
367
+
368
+ /**
369
+ * Tests wheter this vertex lies to the left of an edge
370
+ *
371
+ * @param {jsts.triangulate.quadedge.QuadEdge}
372
+ * e A quadedge.
373
+ * @return {Boolean} true if this vertex lies to the left of the edge.
374
+ */
375
+ jsts.triangulate.quadedge.Vertex.prototype.leftOf = function(e) {
376
+ return this.isCCW(e.orig(), e.dest());
377
+ };
378
+
379
+
380
+ /**
381
+ * Returns the perpendicular bisector of the line between the input vertices
382
+ *
383
+ * @param {jsts.triangulate.quadedge.Vertex}
384
+ * a A vertex.
385
+ * @param {jsts.triangulate.quadedge.Vertex}
386
+ * b A vertex.
387
+ * @return {jsts.algorithm.HCoordinate} The bisector.
388
+ */
389
+ jsts.triangulate.quadedge.Vertex.prototype.bisector = function(a, b) {
390
+ var dx, dy, l1, l2;
391
+
392
+ dx = b.getX() - a.getX();
393
+ dy = b.getY() - a.getY();
394
+
395
+ l1 = new jsts.algorithm.HCoordinate(a.getX() + (dx / 2.0), a.getY() +
396
+ (dy / 2.0), 1.0);
397
+ l2 = new jsts.algorithm.HCoordinate(a.getX() - dy + (dx / 2.0), a.getY() +
398
+ dx + (dy / 2.0), 1.0);
399
+ return new jsts.algorithm.HCoordinate(l1, l2);
400
+ };
401
+
402
+
403
+ /**
404
+ * Calculates the distance between two vertices
405
+ *
406
+ * @param {jsts.triangulate.quadedge.Vertex}
407
+ * v1 a vertex.
408
+ * @param {jsts.triangulate.quadedge.Vertex}
409
+ * v2 a vertex.
410
+ * @return {Number} The distance.
411
+ */
412
+ jsts.triangulate.quadedge.Vertex.prototype.distance = function(v1, v2) {
413
+ return v1.p.distance(v2.p);
414
+ };
415
+
416
+
417
+ /**
418
+ * Computes the value of the ratio of the circumradius to shortest edge. If
419
+ * smaller than some given tolerance B, the associated triangle is considered
420
+ * skinny.
421
+ *
422
+ * For an equal lateral triangle this value is 0.57735. The ratio is related to
423
+ * the minimum triangle angle theta by: circumRadius/shortestEdge =
424
+ * 1/(2sin(theta)).
425
+ *
426
+ * @param {jsts.triangulate.quadedge}
427
+ * b second vertex of the triangle.
428
+ * @param {jsts.triangulate.quadedge}
429
+ * c third vertex of the triangle.
430
+ * @return {Number} ratio of circumradius to shortest edge.
431
+ */
432
+ jsts.triangulate.quadedge.Vertex.prototype.circumRadiusRatio = function(b, c) {
433
+ var x, radius, edgeLength, el;
434
+
435
+ x = this.circleCenter(b, c);
436
+ radius = this.distance(x, b);
437
+ edgeLength = this.distance(this, b);
438
+ el = this.distance(b, c);
439
+
440
+ if (el < edgeLength) {
441
+ edgeLength = el;
442
+ }
443
+ el = this.distance(c, this);
444
+ if (el < edgeLength) {
445
+ edgeLength = el;
446
+ }
447
+ return radius / edgeLength;
448
+ };
449
+
450
+
451
+ /**
452
+ * returns a new vertex that is mid-way between this vertex and another end
453
+ * point.
454
+ *
455
+ * @param {jsts.triangulate.quadedge.Vertex}
456
+ * a the other end point.
457
+ * @return {jsts.triangulate.quadedge.Vertex} the point mid-way between this and
458
+ * that.
459
+ */
460
+ jsts.triangulate.quadedge.Vertex.prototype.midPoint = function(a) {
461
+ var xm, ym;
462
+ xm = (this.p.x + a.getX()) / 2.0;
463
+ ym = (this.p.y + a.getY()) / 2.0;
464
+
465
+ return new jsts.triangulate.quadedge.Vertex(xm, ym);
466
+ };
467
+
468
+
469
+ /**
470
+ * Computes the centre of the circumcircle of this vertex and two others.
471
+ *
472
+ * @param {jsts.triangulate.quadedge.Vertex}
473
+ * b a vertex.
474
+ * @param {jsts.triangulate.quadedge.Vertex}
475
+ * c a vertex.
476
+ * @return {jsts.triangulate.quadedge.Vertex} the Coordinate which is the
477
+ * circumcircle of the 3 points.
478
+ */
479
+ jsts.triangulate.quadedge.Vertex.prototype.circleCenter = function(b, c) {
480
+ var a, cab, cbc, hcc, cc;
481
+
482
+ a = new jsts.triangulate.quadedge.Vertex(this.getX(), this.getY());
483
+ // compute the perpendicular bisector of cord ab
484
+ cab = this.bisector(a, b);
485
+ // compute the perpendicular bisector of cord bc
486
+ cbc = this.bisector(b, c);
487
+ // compute the intersection of the bisectors (circle radii)
488
+ hcc = new jsts.algorithm.HCoordinate(cab, cbc);
489
+ cc = null;
490
+ try {
491
+ cc = new jsts.triangulate.quadedge.Vertex(hcc.getX(), hcc.getY());
492
+ } catch (err) {
493
+ }
494
+
495
+ return cc;
496
+ };