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,263 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ (function() {
8
+
9
+ /**
10
+ * Represents a linear polygon, which may include holes. The shell and holes
11
+ * of the polygon are represented by {@link LinearRing}s. In a valid polygon,
12
+ * holes may touch the shell or other holes at a single point. However, no
13
+ * sequence of touching holes may split the polygon into two pieces. The
14
+ * orientation of the rings in the polygon does not matter.
15
+ *
16
+ * The shell and holes must conform to the assertions specified in the <A
17
+ * HREF="http://www.opengis.org/techno/specs.htm">OpenGIS Simple Features
18
+ * Specification for SQL</A>.
19
+ */
20
+
21
+
22
+ /**
23
+ * @requires jsts/geom/Geometry.js
24
+ */
25
+
26
+ /**
27
+ * @extends {jsts.geom.Geometry}
28
+ * @constructor
29
+ */
30
+ jsts.geom.Polygon = function(shell, holes, factory) {
31
+ this.shell = shell || factory.createLinearRing(null);
32
+ this.holes = holes || [];
33
+ this.factory = factory;
34
+ };
35
+
36
+ jsts.geom.Polygon.prototype = new jsts.geom.Geometry();
37
+ jsts.geom.Polygon.constructor = jsts.geom.Polygon;
38
+
39
+ jsts.geom.Polygon.prototype.getCoordinate = function() {
40
+ return this.shell.getCoordinate();
41
+ };
42
+
43
+ jsts.geom.Polygon.prototype.getCoordinates = function() {
44
+ if (this.isEmpty()) {
45
+ return [];
46
+ }
47
+ var coordinates = [];
48
+ var k = -1;
49
+ var shellCoordinates = this.shell.getCoordinates();
50
+ for (var x = 0; x < shellCoordinates.length; x++) {
51
+ k++;
52
+ coordinates[k] = shellCoordinates[x];
53
+ }
54
+ for (var i = 0; i < this.holes.length; i++) {
55
+ var childCoordinates = this.holes[i].getCoordinates();
56
+ for (var j = 0; j < childCoordinates.length; j++) {
57
+ k++;
58
+ coordinates[k] = childCoordinates[j];
59
+ }
60
+ }
61
+ return coordinates;
62
+ };
63
+
64
+ /**
65
+ * @return {boolean}
66
+ */
67
+ jsts.geom.Polygon.prototype.isEmpty = function() {
68
+ return this.shell.isEmpty();
69
+ };
70
+
71
+ jsts.geom.Polygon.prototype.getExteriorRing = function() {
72
+ return this.shell;
73
+ };
74
+
75
+ jsts.geom.Polygon.prototype.getInteriorRingN = function(n) {
76
+ return this.holes[n];
77
+ };
78
+
79
+ jsts.geom.Polygon.prototype.getNumInteriorRing = function() {
80
+ return this.holes.length;
81
+ };
82
+
83
+ /**
84
+ * Returns the area of this <code>Polygon</code>
85
+ *
86
+ * @return the area of the polygon.
87
+ */
88
+ jsts.geom.Polygon.prototype.getArea = function() {
89
+ var area = 0.0;
90
+ area += Math.abs(jsts.algorithm.CGAlgorithms.signedArea(this.shell
91
+ .getCoordinateSequence()));
92
+ for (var i = 0; i < this.holes.length; i++) {
93
+ area -= Math.abs(jsts.algorithm.CGAlgorithms.signedArea(this.holes[i]
94
+ .getCoordinateSequence()));
95
+ }
96
+ return area;
97
+ };
98
+
99
+ /**
100
+ * Returns the perimeter of this <code>Polygon</code>
101
+ *
102
+ * @return the perimeter of the polygon.
103
+ */
104
+ jsts.geom.Polygon.prototype.getLength = function() {
105
+ var len = 0.0;
106
+ len += this.shell.getLength();
107
+ for (var i = 0; i < this.holes.length; i++) {
108
+ len += this.holes[i].getLength();
109
+ }
110
+ return len;
111
+ };
112
+
113
+ /**
114
+ * Computes the boundary of this geometry
115
+ *
116
+ * @return {Geometry} a lineal geometry (which may be empty).
117
+ * @see Geometry#getBoundary
118
+ */
119
+ jsts.geom.Polygon.prototype.getBoundary = function() {
120
+ if (this.isEmpty()) {
121
+ return this.getFactory().createMultiLineString(null);
122
+ }
123
+ var rings = [];
124
+ rings[0] = this.shell.clone();
125
+ for (var i = 0, len = this.holes.length; i < len; i++) {
126
+ rings[i + 1] = this.holes[i].clone();
127
+ }
128
+ // create LineString or MultiLineString as appropriate
129
+ if (rings.length <= 1)
130
+ return rings[0];
131
+ return this.getFactory().createMultiLineString(rings);
132
+ };
133
+
134
+ jsts.geom.Polygon.prototype.computeEnvelopeInternal = function() {
135
+ return this.shell.getEnvelopeInternal();
136
+ };
137
+
138
+ jsts.geom.Polygon.prototype.getDimension = function() {
139
+ return 2;
140
+ };
141
+
142
+ jsts.geom.Polygon.prototype.getBoundaryDimension = function() {
143
+ return 1;
144
+ };
145
+
146
+
147
+ /**
148
+ * @param {Geometry}
149
+ * other
150
+ * @param {number}
151
+ * tolerance
152
+ * @return {boolean}
153
+ */
154
+ jsts.geom.Polygon.prototype.equalsExact = function(other, tolerance) {
155
+ if (!this.isEquivalentClass(other)) {
156
+ return false;
157
+ }
158
+ if (this.isEmpty() && other.isEmpty()) {
159
+ return true;
160
+ }
161
+ if (this.isEmpty() !== other.isEmpty()) {
162
+ return false;
163
+ }
164
+
165
+ if (!this.shell.equalsExact(other.shell, tolerance)) {
166
+ return false;
167
+ }
168
+ if (this.holes.length !== other.holes.length) {
169
+ return false;
170
+ }
171
+ if (this.holes.length !== other.holes.length) {
172
+ return false;
173
+ }
174
+ for (var i = 0; i < this.holes.length; i++) {
175
+ if (!(this.holes[i]).equalsExact(other.holes[i], tolerance)) {
176
+ return false;
177
+ }
178
+ }
179
+ return true;
180
+ };
181
+
182
+ jsts.geom.Polygon.prototype.compareToSameClass = function(o) {
183
+ return this.shell.compareToSameClass(o.shell);
184
+ };
185
+
186
+ jsts.geom.Polygon.prototype.apply = function(filter) {
187
+ if (filter instanceof jsts.geom.GeometryComponentFilter) {
188
+ filter.filter(this);
189
+ this.shell.apply(filter);
190
+ for (var i = 0, len = this.holes.length; i < len; i++) {
191
+ this.holes[i].apply(filter);
192
+ }
193
+ } else if (filter instanceof jsts.geom.GeometryFilter) {
194
+ filter.filter(this);
195
+ } else if (filter instanceof jsts.geom.CoordinateFilter) {
196
+ this.shell.apply(filter);
197
+ for (var i = 0, len = this.holes.length; i < len; i++) {
198
+ this.holes[i].apply(filter);
199
+ }
200
+ } else if (filter instanceof jsts.geom.CoordinateSequenceFilter) {
201
+ this.apply2.apply(this, arguments);
202
+ }
203
+ };
204
+
205
+ jsts.geom.Polygon.prototype.apply2 = function(filter) {
206
+ this.shell.apply(filter);
207
+ if (!filter.isDone()) {
208
+ for (var i = 0; i < this.holes.length; i++) {
209
+ this.holes[i].apply(filter);
210
+ if (filter.isDone())
211
+ break;
212
+ }
213
+ }
214
+ if (filter.isGeometryChanged()) {
215
+ // TODO: call this.geometryChanged(); when ported
216
+ }
217
+ };
218
+
219
+ /**
220
+ * Creates and returns a full copy of this {@link Polygon} object. (including
221
+ * all coordinates contained by it).
222
+ *
223
+ * @return a clone of this instance.
224
+ */
225
+ jsts.geom.Polygon.prototype.clone = function() {
226
+ var holes = [];
227
+
228
+ for (var i = 0, len = this.holes.length; i < len; i++) {
229
+ holes.push(this.holes[i].clone());
230
+ }
231
+
232
+ return this.factory.createPolygon(this.shell.clone(), holes);
233
+ };
234
+
235
+ jsts.geom.Polygon.prototype.normalize = function() {
236
+ this.normalize2(this.shell, true);
237
+ for (var i = 0, len = this.holes.length; i < len; i++) {
238
+ this.normalize2(this.holes[i], false);
239
+ }
240
+ // TODO: might need to supply comparison function
241
+ this.holes.sort();
242
+ };
243
+
244
+ /**
245
+ * @private
246
+ */
247
+ jsts.geom.Polygon.prototype.normalize2 = function(ring, clockwise) {
248
+ if (ring.isEmpty()) {
249
+ return;
250
+ }
251
+ var uniqueCoordinates = ring.points.slice(0, ring.points.length - 1);
252
+ var minCoordinate = jsts.geom.CoordinateArrays.minCoordinate(ring.points);
253
+ jsts.geom.CoordinateArrays.scroll(uniqueCoordinates, minCoordinate);
254
+ ring.points = uniqueCoordinates.concat();
255
+ ring.points[uniqueCoordinates.length] = uniqueCoordinates[0];
256
+ if (jsts.algorithm.CGAlgorithms.isCCW(ring.points) === clockwise) {
257
+ ring.points.reverse();
258
+ }
259
+ };
260
+
261
+ jsts.geom.Polygon.prototype.CLASS_NAME = 'jsts.geom.Polygon';
262
+
263
+ })();
@@ -0,0 +1,187 @@
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
+ * Specifies the precision model of the {@link Coordinate}s in a
11
+ * {@link Geometry}. In other words, specifies the grid of allowable points for
12
+ * all <code>Geometry</code>s.
13
+ * <p>
14
+ * The {@link makePrecise} method allows rounding a coordinate to a "precise"
15
+ * value; that is, one whose precision is known exactly.
16
+ * <p>
17
+ * Coordinates are assumed to be precise in geometries. That is, the coordinates
18
+ * are assumed to be rounded to the precision model given for the geometry. JTS
19
+ * input routines automatically round coordinates to the precision model before
20
+ * creating Geometries. All internal operations assume that coordinates are
21
+ * rounded to the precision model. Constructive methods (such as boolean
22
+ * operations) always round computed coordinates to the appropriate precision
23
+ * model.
24
+ * <p>
25
+ * Currently one type of precision model are supported:
26
+ * <ul>
27
+ * <li>FLOATING - represents full double precision floating point.
28
+ * <p>
29
+ * Coordinates are represented internally as Java double-precision values. Since
30
+ * Java uses the IEEE-754 floating point standard, this provides 53 bits of
31
+ * precision.
32
+ * <p>
33
+ * JSTS methods currently do not handle inputs with different precision models.
34
+ *
35
+ * @constructor
36
+ */
37
+ jsts.geom.PrecisionModel = function(modelType) {
38
+ if (typeof modelType === 'number') {
39
+ this.modelType = jsts.geom.PrecisionModel.FIXED;
40
+ this.scale = modelType;
41
+ return;
42
+ }
43
+
44
+ this.modelType = modelType || jsts.geom.PrecisionModel.FLOATING;
45
+
46
+ if (this.modelType === jsts.geom.PrecisionModel.FIXED) {
47
+ this.scale = 1.0;
48
+ }
49
+ };
50
+
51
+
52
+ /**
53
+ * @type {string}
54
+ */
55
+ jsts.geom.PrecisionModel.FLOATING = 'FLOATING';
56
+
57
+
58
+ /**
59
+ * @type {string}
60
+ */
61
+ jsts.geom.PrecisionModel.FIXED = 'FIXED';
62
+
63
+
64
+ /**
65
+ * @type {string}
66
+ */
67
+ jsts.geom.PrecisionModel.FLOATING_SINGLE = 'FLOATING_SINGLE';
68
+
69
+ jsts.geom.PrecisionModel.prototype.scale = null;
70
+ jsts.geom.PrecisionModel.prototype.modelType = null;
71
+
72
+
73
+ /**
74
+ * Tests whether the precision model supports floating point
75
+ *
76
+ * @return {boolean} if the precision model supports floating point.
77
+ */
78
+ jsts.geom.PrecisionModel.prototype.isFloating = function() {
79
+ return this.modelType === jsts.geom.PrecisionModel.FLOATING ||
80
+ this.modelType === jsts.geom.PrecisionModel.FLOATING_SINLGE;
81
+ };
82
+
83
+ /**
84
+ * Returns the scale factor used to specify a fixed precision model. The number
85
+ * of decimal places of precision is equal to the base-10 logarithm of the scale
86
+ * factor. Non-integral and negative scale factors are supported. Negative scale
87
+ * factors indicate that the places of precision is to the left of the decimal
88
+ * point.
89
+ *
90
+ * @return the scale factor for the fixed precision model.
91
+ */
92
+ jsts.geom.PrecisionModel.prototype.getScale = function() {
93
+ return this.scale;
94
+ };
95
+
96
+ /**
97
+ * @return {string} always jsts.geom.PrecisionModel.FLOATING.
98
+ */
99
+ jsts.geom.PrecisionModel.prototype.getType = function() {
100
+ return this.modelType;
101
+ };
102
+
103
+ jsts.geom.PrecisionModel.prototype.equals = function(other) {
104
+ return true;
105
+
106
+ if (!(other instanceof jsts.geom.PrecisionModel)) {
107
+ return false;
108
+ }
109
+ var otherPrecisionModel = other;
110
+ return this.modelType === otherPrecisionModel.modelType &&
111
+ this.scale === otherPrecisionModel.scale;
112
+ };
113
+
114
+
115
+ /**
116
+ * Rounds a numeric value to the PrecisionModel grid. Asymmetric Arithmetic
117
+ * Rounding is used, to provide uniform rounding behaviour no matter where the
118
+ * number is on the number line.
119
+ * <p>
120
+ * This method has no effect on NaN values.
121
+ * <p>
122
+ * <b>Note:</b> Java's <code>Math#rint</code> uses the "Banker's Rounding"
123
+ * algorithm, which is not suitable for precision operations elsewhere in JTS.
124
+ */
125
+ jsts.geom.PrecisionModel.prototype.makePrecise = function(val) {
126
+ if (val instanceof jsts.geom.Coordinate) {
127
+ this.makePrecise2(val);
128
+ return;
129
+ }
130
+
131
+ // don't change NaN values
132
+ if (isNaN(val))
133
+ return val;
134
+
135
+ // TODO: support single precision?
136
+ /*if (this.modelType == FLOATING_SINGLE) {
137
+ float floatSingleVal = (float) val;
138
+ return (double) floatSingleVal;
139
+ }*/
140
+ if (this.modelType === jsts.geom.PrecisionModel.FIXED) {
141
+ return Math.round(val * this.scale) / this.scale;
142
+ }
143
+ // modelType == FLOATING - no rounding necessary
144
+ return val;
145
+ };
146
+
147
+
148
+ /**
149
+ * Rounds a Coordinate to the PrecisionModel grid.
150
+ */
151
+ jsts.geom.PrecisionModel.prototype.makePrecise2 = function(coord) {
152
+ // optimization for full precision
153
+ if (this.modelType === jsts.geom.PrecisionModel.FLOATING)
154
+ return;
155
+
156
+ coord.x = this.makePrecise(coord.x);
157
+ coord.y = this.makePrecise(coord.y);
158
+ // MD says it's OK that we're not makePrecise'ing the z [Jon Aquino]
159
+ };
160
+
161
+
162
+ /**
163
+ * Compares this {@link PrecisionModel} object with the specified object for
164
+ * order. A PrecisionModel is greater than another if it provides greater
165
+ * precision. The comparison is based on the value returned by the
166
+ * {@link #getMaximumSignificantDigits} method. This comparison is not strictly
167
+ * accurate when comparing floating precision models to fixed models; however,
168
+ * it is correct when both models are either floating or fixed.
169
+ *
170
+ * @param o
171
+ * the <code>PrecisionModel</code> with which this
172
+ * <code>PrecisionModel</code> is being compared.
173
+ * @return a negative integer, zero, or a positive integer as this
174
+ * <code>PrecisionModel</code> is less than, equal to, or greater than
175
+ * the specified <code>PrecisionModel.</code>
176
+ */
177
+ jsts.geom.PrecisionModel.prototype.compareTo = function(o) {
178
+ var other = o;
179
+
180
+ // TODO: needs to be ported for fixed precision
181
+
182
+ // var sigDigits = this.getMaximumSignificantDigits();
183
+ // var otherSigDigits = other.getMaximumSignificantDigits();
184
+ // return (new Integer(sigDigits)).compareTo(new Integer(otherSigDigits));
185
+
186
+ return 0;
187
+ };
@@ -0,0 +1,313 @@
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
+ * Represents a planar triangle, and provides methods for calculating various
11
+ * properties of triangles.
12
+ *
13
+ * @constructor
14
+ * @param {jsts.geom.Coordinate}
15
+ * p0 a coordinate.
16
+ * @param {jsts.geom.Coordinate}
17
+ * p1 a coordinate.
18
+ * @param {jsts.geom.Coordinate}
19
+ * p2 a coordinate.
20
+ */
21
+ jsts.geom.Triangle = function(p0, p1, p2) {
22
+ this.p0 = p0;
23
+ this.p1 = p1;
24
+ this.p2 = p2;
25
+ };
26
+
27
+ /**
28
+ * Tests whether a triangle is acute. A triangle is acute iff all interior
29
+ * angles are acute. This is a strict test - right triangles will return
30
+ * <tt>false</tt> A triangle which is not acute is either right or obtuse.
31
+ * <p>
32
+ * Note: this implementation is not robust for angles very close to 90 degrees.
33
+ *
34
+ * @param {jsts.geom.Coordinate}
35
+ * a a vertex of the triangle.
36
+ * @param {jsts.geom.Coordinate}
37
+ * b a vertex of the triangle.
38
+ * @param {jsts.geom.Coordinate}
39
+ * c a vertex of the triangle.
40
+ * @return {Boolean} true if the triangle is acute.
41
+ */
42
+ jsts.geom.Triangle.isAcute = function(a, b, c) {
43
+ if (!jsts.algorithm.Angle.isAcute(a, b, c)) {
44
+ return false;
45
+ }
46
+ if (!jsts.algorithm.Angle.isAcute(b, c, a)) {
47
+ return false;
48
+ }
49
+ if (!jsts.algorithm.Angle.isAcute(c, a, b)) {
50
+ return false;
51
+ }
52
+ return true;
53
+ };
54
+
55
+
56
+ /**
57
+ * Computes the line which is the perpendicular bisector of the line segment
58
+ * a-b.
59
+ *
60
+ * @param {jsts.geom.Coordinate}
61
+ * a a point.
62
+ * @param {jsts.geom.Coordinate}
63
+ * b another point.
64
+ * @return {jsts.algorithm.HCoordinate} the perpendicular bisector, as an
65
+ * HCoordinate.
66
+ */
67
+ jsts.geom.Triangle.perpendicularBisector = function(a, b) {
68
+ // returns the perpendicular bisector of the line segment ab
69
+ var dx, dy, l1, l2;
70
+
71
+ dx = b.x - a.x;
72
+ dy = b.y - a.y;
73
+
74
+ l1 = new jsts.algorithm.HCoordinate(a.x + dx / 2.0, a.y + dy / 2.0, 1.0);
75
+ l2 = new jsts.algorithm.HCoordinate(a.x - dy + dx / 2.0, a.y + dx + dy / 2.0,
76
+ 1.0);
77
+ return new jsts.algorithm.HCoordinate(l1, l2);
78
+ };
79
+
80
+
81
+ /**
82
+ * Computes the circumcentre of a triangle. The circumcentre is the centre of
83
+ * the circumcircle, the smallest circle which encloses the triangle. It is also
84
+ * the common intersection point of the perpendicular bisectors of the sides of
85
+ * the triangle, and is the only point which has equal distance to all three
86
+ * vertices of the triangle.
87
+ * <p>
88
+ * This method uses an algorithm due to J.R.Shewchuk which uses normalization to
89
+ * the origin to improve the accuracy of computation. (See <i>Lecture Notes on
90
+ * Geometric Robustness</i>, Jonathan Richard Shewchuk, 1999).
91
+ *
92
+ * @param {jsts.geom.Coordinate}
93
+ * a a vertx of the triangle.
94
+ * @param {jsts.geom.Coordinate}
95
+ * b a vertx of the triangle.
96
+ * @param {jsts.geom.Coordinate}
97
+ * c a vertx of the triangle.
98
+ * @return {jsts.geom.Coordinate} the circumcentre of the triangle.
99
+ */
100
+ jsts.geom.Triangle.circumcentre = function(a, b, c) {
101
+ var cx, cy, ax, ay, bx, by, denom, numx, numy, ccx, ccy;
102
+
103
+ cx = c.x;
104
+ cy = c.y;
105
+ ax = a.x - cx;
106
+ ay = a.y - cy;
107
+ bx = b.x - cx;
108
+ by = b.y - cy;
109
+
110
+ denom = 2 * jsts.geom.Triangle.det(ax, ay, bx, by);
111
+ numx = jsts.geom.Triangle.det(ay, ax * ax + ay * ay, by, bx * bx + by * by);
112
+ numy = jsts.geom.Triangle.det(ax, ax * ax + ay * ay, bx, bx * bx + by * by);
113
+
114
+ ccx = cx - numx / denom;
115
+ ccy = cy + numy / denom;
116
+
117
+ return new jsts.geom.Coordinate(ccx, ccy);
118
+ };
119
+
120
+
121
+ /**
122
+ * Computes the determinant of a 2x2 matrix. Uses standard double-precision
123
+ * arithmetic, so is susceptible to round-off error.
124
+ *
125
+ * @param {Number}
126
+ * m00 the [0,0] entry of the matrix.
127
+ * @param {Number}
128
+ * m01 the [0,1] entry of the matrix.
129
+ * @param {Number}
130
+ * m10 the [1,0] entry of the matrix.
131
+ * @param {Number}
132
+ * m11 the [1,1] entry of the matrix.
133
+ * @return {Number} the determinant.
134
+ */
135
+ jsts.geom.Triangle.det = function(m00, m01, m10, m11) {
136
+ return m00 * m11 - m01 * m10;
137
+ };
138
+
139
+
140
+ /**
141
+ * Computes the incentre of a triangle. The <i>inCentre</i> of a triangle is
142
+ * the point which is equidistant from the sides of the triangle. It is also the
143
+ * point at which the bisectors of the triangle's angles meet. It is the centre
144
+ * of the triangle's <i>incircle</i>, which is the unique circle that is
145
+ * tangent to each of the triangle's three sides.
146
+ *
147
+ * @param {jsts.geom.Coordinate}
148
+ * a a vertx of the triangle.
149
+ * @param {jsts.geom.Coordinate}
150
+ * b a vertx of the triangle.
151
+ * @param {jsts.geom.Coordinate}
152
+ * c a vertx of the triangle.
153
+ * @return {jsts.geom.Coordinate} the point which is the incentre of the
154
+ * triangle.
155
+ */
156
+ jsts.geom.Triangle.inCentre = function(a, b, c) {
157
+ var len0, len1, len2, circum, inCentreX, inCentreY;
158
+
159
+ // the lengths of the sides, labelled by their opposite vertex
160
+ len0 = b.distance(c);
161
+ len1 = a.distance(c);
162
+ len2 = a.distance(b);
163
+ circum = len0 + len1 + len2;
164
+
165
+ inCentreX = (len0 * a.x + len1 * b.x + len2 * c.x) / circum;
166
+ inCentreY = (len0 * a.y + len1 * b.y + len2 * c.y) / circum;
167
+
168
+ return new jsts.geom.Coordinate(inCentreX, inCentreY);
169
+ };
170
+
171
+
172
+ /**
173
+ * Computes the centroid (centre of mass) of a triangle. This is also the point
174
+ * at which the triangle's three medians intersect (a triangle median is the
175
+ * segment from a vertex of the triangle to the midpoint of the opposite side).
176
+ * The centroid divides each median in a ratio of 2:1. The centroid always lies
177
+ * within the triangle.
178
+ *
179
+ *
180
+ * @param {jsts.geom.Coordinate}
181
+ * a a vertx of the triangle.
182
+ * @param {jsts.geom.Coordinate}
183
+ * b a vertx of the triangle.
184
+ * @param {jsts.geom.Coordinate}
185
+ * c a vertx of the triangle.
186
+ * @return {jsts.geom.Coordinate} the centroid of the triangle.
187
+ */
188
+ jsts.geom.Triangle.centroid = function(a, b, c) {
189
+ var x, y;
190
+
191
+ x = (a.x + b.x + c.x) / 3;
192
+ y = (a.y + b.y + c.y) / 3;
193
+
194
+ return new jsts.geom.Coordinate(x, y);
195
+ };
196
+
197
+
198
+ /**
199
+ * Computes the length of the longest side of a triangle
200
+ *
201
+ * @param {jsts.geom.Coordinate}
202
+ * a a vertex of the triangle.
203
+ * @param {jsts.geom.Coordinate}
204
+ * b a vertex of the triangle.
205
+ * @param {jsts.geom.Coordinate}
206
+ * c a vertex of the triangle.
207
+ * @return {Number} the length of the longest side of the triangle.
208
+ */
209
+ jsts.geom.Triangle.longestSideLength = function(a, b, c) {
210
+ var lenAB, lenBC, lenCA, maxLen;
211
+
212
+ lenAB = a.distance(b);
213
+ lenBC = b.distance(c);
214
+ lenCA = c.distance(a);
215
+ maxLen = lenAB;
216
+
217
+ if (lenBC > maxLen) {
218
+ maxLen = lenBC;
219
+ }
220
+ if (lenCA > maxLen) {
221
+ maxLen = lenCA;
222
+ }
223
+ return maxLen;
224
+ };
225
+
226
+
227
+ /**
228
+ * Computes the point at which the bisector of the angle ABC cuts the segment
229
+ * AC.
230
+ *
231
+ * @param {jsts.geom.Coordinate}
232
+ * a a vertex of the triangle.
233
+ * @param {jsts.geom.Coordinate}
234
+ * b a vertex of the triangle.
235
+ * @param {jsts.geom.Coordinate}
236
+ * c a vertex of the triangle.
237
+ * @return {jsts.geom.Coordinate} the angle bisector cut point.
238
+ */
239
+ jsts.geom.Triangle.angleBisector = function(a, b, c) {
240
+ /**
241
+ * Uses the fact that the lengths of the parts of the split segment are
242
+ * proportional to the lengths of the adjacent triangle sides
243
+ */
244
+ var len0, len2, frac, dx, dy, splitPt;
245
+
246
+ len0 = b.distance(a);
247
+ len2 = b.distance(c);
248
+ frac = len0 / (len0 + len2);
249
+ dx = c.x - a.x;
250
+ dy = c.y - a.y;
251
+
252
+ splitPt = new jsts.geom.Coordinate(a.x + frac * dx, a.y + frac * dy);
253
+ return splitPt;
254
+ };
255
+
256
+
257
+ /**
258
+ * Computes the 2D area of a triangle. The area value is always non-negative.
259
+ *
260
+ * @param {jsts.geom.Coordinate}
261
+ * a a vertex of the triangle.
262
+ * @param {jsts.geom.Coordinate}
263
+ * b a vertex of the triangle.
264
+ * @param {jsts.geom.Coordinate}
265
+ * c a vertex of the triangle.
266
+ * @return {Number} the area of the triangle.
267
+ */
268
+ jsts.geom.Triangle.area = function(a, b, c) {
269
+ return Math
270
+ .abs(((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2.0);
271
+ };
272
+
273
+
274
+ /**
275
+ * Computes the signed 2D area of a triangle. The area value is positive if the
276
+ * triangle is oriented CW, and negative if it is oriented CCW.
277
+ * <p>
278
+ * The signed area value can be used to determine point orientation, but the
279
+ * implementation in this method is susceptible to round-off errors. Use
280
+ * {@link CGAlgorithms#orientationIndex(Coordinate, Coordinate, Coordinate)} for
281
+ * robust orientation calculation.
282
+ *
283
+ * @param {jsts.geom.Coordinate}
284
+ * a a vertex of the triangle.
285
+ * @param {jsts.geom.Coordinate}
286
+ * b a vertex of the triangle.
287
+ * @param {jsts.geom.Coordinate}
288
+ * c a vertex of the triangle.
289
+ * @return {Number} the signed 2D area of the triangle.
290
+ *
291
+ */
292
+ jsts.geom.Triangle.signedArea = function(a, b, c) {
293
+ /**
294
+ * Uses the formula 1/2 * | u x v | where u,v are the side vectors of the
295
+ * triangle x is the vector cross-product For 2D vectors, this formula
296
+ * simplifies to the expression below
297
+ */
298
+ return ((c.x - a.x) * (b.y - a.y) - (b.x - a.x) * (c.y - a.y)) / 2.0;
299
+ };
300
+
301
+ /**
302
+ * Computes the incentre of a triangle. The <i>incentre</i> of a triangle is
303
+ * the point which is equidistant from the sides of the triangle. It is also the
304
+ * point at which the bisectors of the triangle's angles meet. It is the centre
305
+ * of the triangle's <i>incircle</i>, which is the unique circle that is
306
+ * tangent to each of the triangle's three sides.
307
+ *
308
+ * @return {jsts.geom.Coordinate} the point which is the inCentre of the
309
+ * triangle.
310
+ */
311
+ jsts.geom.Triangle.prototype.inCentre = function() {
312
+ return jsts.geom.Triangle.inCentre(this.p0, this.p1, this.p2);
313
+ };