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,1535 @@
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
+ * The base class for all geometric objects.
9
+ *
10
+ * <H3>Binary Predicates</H3>
11
+ * Because it is not clear at this time
12
+ * what semantics for spatial
13
+ * analysis methods involving <code>GeometryCollection</code>s would be useful,
14
+ * <code>GeometryCollection</code>s are not supported as arguments to binary
15
+ * predicates (other than <code>convexHull</code>) or the <code>relate</code>
16
+ * method.
17
+ *
18
+ * <H3>Set-Theoretic Methods</H3>
19
+ *
20
+ * The spatial analysis methods will
21
+ * return the most specific class possible to represent the result. If the
22
+ * result is homogeneous, a <code>Point</code>, <code>LineString</code>, or
23
+ * <code>Polygon</code> will be returned if the result contains a single
24
+ * element; otherwise, a <code>MultiPoint</code>, <code>MultiLineString</code>,
25
+ * or <code>MultiPolygon</code> will be returned. If the result is
26
+ * heterogeneous a <code>GeometryCollection</code> will be returned. <P>
27
+ *
28
+ * Because it is not clear at this time what semantics for set-theoretic
29
+ * methods involving <code>GeometryCollection</code>s would be useful,
30
+ * <code>GeometryCollections</code>
31
+ * are not supported as arguments to the set-theoretic methods.
32
+ *
33
+ * <H4>Representation of Computed Geometries </H4>
34
+ *
35
+ * The SFS states that the result
36
+ * of a set-theoretic method is the "point-set" result of the usual
37
+ * set-theoretic definition of the operation (SFS 3.2.21.1). However, there are
38
+ * sometimes many ways of representing a point set as a <code>Geometry</code>.
39
+ * <P>
40
+ *
41
+ * The SFS does not specify an unambiguous representation of a given point set
42
+ * returned from a spatial analysis method. One goal of JTS is to make this
43
+ * specification precise and unambiguous. JTS will use a canonical form for
44
+ * <code>Geometry</code>s returned from spatial analysis methods. The canonical
45
+ * form is a <code>Geometry</code> which is simple and noded:
46
+ * <UL>
47
+ * <LI> Simple means that the Geometry returned will be simple according to
48
+ * the JTS definition of <code>isSimple</code>.
49
+ * <LI> Noded applies only to overlays involving <code>LineString</code>s. It
50
+ * means that all intersection points on <code>LineString</code>s will be
51
+ * present as endpoints of <code>LineString</code>s in the result.
52
+ * </UL>
53
+ * This definition implies that non-simple geometries which are arguments to
54
+ * spatial analysis methods must be subjected to a line-dissolve process to
55
+ * ensure that the results are simple.
56
+ *
57
+ * <H4> Constructed Points And The Precision Model </H4>
58
+ *
59
+ * The results computed by the set-theoretic methods may contain constructed
60
+ * points which are not present in the input <code>Geometry</code>.
61
+ * These new points arise from intersections between line segments in the
62
+ * edges of the input <code>Geometry</code>s. In the general case it is not
63
+ * possible to represent constructed points exactly. This is due to the fact
64
+ * that the coordinates of an intersection point may contain twice as many bits
65
+ * of precision as the coordinates of the input line segments. In order to
66
+ * represent these constructed points explicitly, JTS must truncate them to fit
67
+ * the <code>PrecisionModel</code>.
68
+ *
69
+ * Unfortunately, truncating coordinates moves them slightly. Line segments
70
+ * which would not be coincident in the exact result may become coincident in
71
+ * the truncated representation. This in turn leads to "topology collapses" --
72
+ * situations where a computed element has a lower dimension than it would in
73
+ * the exact result.
74
+ *
75
+ * When JTS detects topology collapses during the computation of spatial
76
+ * analysis methods, it will throw an exception. If possible the exception will
77
+ * report the location of the collapse.
78
+ *
79
+ * #equals(Object) and #hashCode are not overridden, so that when two
80
+ * topologically equal Geometries are added to HashMaps and HashSets, they
81
+ * remain distinct. This behaviour is desired in many cases.
82
+ */
83
+
84
+
85
+
86
+ /**
87
+ * Creates a new <tt>Geometry</tt> via the specified GeometryFactory.
88
+ *
89
+ * @constructor
90
+ */
91
+ jsts.geom.Geometry = function(factory) {
92
+ this.factory = factory;
93
+ };
94
+
95
+
96
+ /**
97
+ * The bounding box of this <code>Geometry</code>.
98
+ */
99
+ jsts.geom.Geometry.prototype.envelope = null;
100
+
101
+ /**
102
+ * The {@link GeometryFactory} used to create this Geometry
103
+ *
104
+ * @protected
105
+ */
106
+ jsts.geom.Geometry.prototype.factory = null;
107
+
108
+
109
+ /**
110
+ * Returns the name of this object's <code>com.vivid.jts.geom</code>
111
+ * interface.
112
+ *
113
+ * @return {string} the name of this <code>Geometry</code>s most specific
114
+ * <code>jsts.geom</code> interface.
115
+ */
116
+ jsts.geom.Geometry.prototype.getGeometryType = function() {
117
+ return 'Geometry';
118
+ };
119
+
120
+
121
+ /**
122
+ * Returns true if the array contains any non-empty <code>Geometry</code>s.
123
+ *
124
+ * @param {Geometry[]}
125
+ * geometries an array of <code>Geometry</code>s; no elements may be
126
+ * <code>null.</code>
127
+ * @return {boolean} <code>true</code> if any of the <code>Geometry</code>s
128
+ * <code>isEmpty</code> methods return <code>false.</code>
129
+ */
130
+ jsts.geom.Geometry.hasNonEmptyElements = function(geometries) {
131
+ var i;
132
+ for (i = 0; i < geometries.length; i++) {
133
+ if (!geometries[i].isEmpty()) {
134
+ return true;
135
+ }
136
+ }
137
+ return false;
138
+ };
139
+
140
+
141
+ /**
142
+ * Returns true if the array contains any <code>null</code> elements.
143
+ *
144
+ * @param {Object[]}
145
+ * array an array to validate.
146
+ * @return {boolean} <code>true</code> if any of <code>array</code>s
147
+ * elements are <code>null.</code>
148
+ */
149
+ jsts.geom.Geometry.hasNullElements = function(array) {
150
+ var i;
151
+ for (i = 0; i < array.length; i++) {
152
+ if (array[i] === null) {
153
+ return true;
154
+ }
155
+ }
156
+ return false;
157
+ };
158
+
159
+
160
+ /**
161
+ * Gets the factory which contains the context in which this geometry was
162
+ * created.
163
+ *
164
+ * @return {jsts.geom.GeometryFactory} the factory for this geometry.
165
+ */
166
+ jsts.geom.Geometry.prototype.getFactory = function() {
167
+ // NOTE: Geometry could be created without JSTS constructor so need to check
168
+ // for member data
169
+ // TODO: above should not happen
170
+ if (this.factory === null || this.factory === undefined) {
171
+ this.factory = new jsts.geom.GeometryFactory();
172
+ }
173
+
174
+ return this.factory;
175
+ };
176
+
177
+
178
+ /**
179
+ * Returns the number of {@link Geometry}s in a {@link GeometryCollection} (or
180
+ * 1, if the geometry is not a collection).
181
+ *
182
+ * @return {number} the number of geometries contained in this geometry.
183
+ */
184
+ jsts.geom.Geometry.prototype.getNumGeometries = function() {
185
+ return 1;
186
+ };
187
+
188
+
189
+ /**
190
+ * Returns an element {@link Geometry} from a {@link GeometryCollection} (or
191
+ * <code>this</code>, if the geometry is not a collection).
192
+ *
193
+ * @param {number}
194
+ * n the index of the geometry element.
195
+ * @return {Geometry} the n'th geometry contained in this geometry.
196
+ */
197
+ jsts.geom.Geometry.prototype.getGeometryN = function(n) {
198
+ return this;
199
+ };
200
+
201
+
202
+ /**
203
+ * Returns the <code>PrecisionModel</code> used by the <code>Geometry</code>.
204
+ *
205
+ * @return {PrecisionModel} the specification of the grid of allowable points,
206
+ * for this <code>Geometry</code> and all other <code>Geometry</code>s.
207
+ */
208
+ jsts.geom.Geometry.prototype.getPrecisionModel = function() {
209
+ return this.getFactory().getPrecisionModel();
210
+ };
211
+
212
+
213
+
214
+ /**
215
+ * Returns a vertex of this <code>Geometry</code> (usually, but not
216
+ * necessarily, the first one). The returned coordinate should not be assumed to
217
+ * be an actual Coordinate object used in the internal representation.
218
+ *
219
+ * @return {Coordinate} a {@link Coordinate} which is a vertex of this
220
+ * <code>Geometry</code>. null if this Geometry is empty.
221
+ */
222
+ jsts.geom.Geometry.prototype.getCoordinate = function() {
223
+ throw new jsts.error.AbstractMethodInvocationError();
224
+ };
225
+
226
+
227
+ /**
228
+ * Returns an array containing the values of all the vertices for this geometry.
229
+ * If the geometry is a composite, the array will contain all the vertices for
230
+ * the components, in the order in which the components occur in the geometry.
231
+ * <p>
232
+ * In general, the array cannot be assumed to be the actual internal storage for
233
+ * the vertices. Thus modifying the array may not modify the geometry itself.
234
+ * Use the {@link CoordinateSequence#setOrdinate} method (possibly on the
235
+ * components) to modify the underlying data. If the coordinates are modified,
236
+ * {@link #geometryChanged} must be called afterwards.
237
+ *
238
+ * @return {Coordinate[]} the vertices of this <code>Geometry.</code>
239
+ * @see geometryChanged
240
+ * @see CoordinateSequence#setOrdinate
241
+ */
242
+ jsts.geom.Geometry.prototype.getCoordinates = function() {
243
+ throw new jsts.error.AbstractMethodInvocationError();
244
+ };
245
+
246
+
247
+ /**
248
+ * Returns the count of this <code>Geometry</code>s vertices. The
249
+ * <code>Geometry</code> s contained by composite <code>Geometry</code>s
250
+ * must be Geometry's; that is, they must implement <code>getNumPoints</code>
251
+ *
252
+ * @return {number} the number of vertices in this <code>Geometry.</code>
253
+ */
254
+ jsts.geom.Geometry.prototype.getNumPoints = function() {
255
+ throw new jsts.error.AbstractMethodInvocationError();
256
+ };
257
+
258
+
259
+ /**
260
+ * Tests whether this {@link Geometry} is simple. In general, the SFS
261
+ * specification of simplicity follows the rule:
262
+ * <UL>
263
+ * <LI> A Geometry is simple iff the only self-intersections are at boundary
264
+ * points.
265
+ * </UL>
266
+ * Simplicity is defined for each {@link Geometry} subclass as follows:
267
+ * <ul>
268
+ * <li>Valid polygonal geometries are simple by definition, so
269
+ * <code>isSimple</code> trivially returns true.
270
+ * <li>Linear geometries are simple iff they do not self-intersect at points
271
+ * other than boundary points.
272
+ * <li>Zero-dimensional geometries (points) are simple iff they have no
273
+ * repeated points.
274
+ * <li>Empty <code>Geometry</code>s are always simple
275
+ * <ul>
276
+ *
277
+ * @return {boolean} <code>true</code> if this <code>Geometry</code> has any
278
+ * points of self-tangency, self-intersection or other anomalous points.
279
+ * @see #isValid
280
+ */
281
+ jsts.geom.Geometry.prototype.isSimple = function() {
282
+ this.checkNotGeometryCollection(this);
283
+ var op = new jsts.operation.IsSimpleOp(this);
284
+ return op.isSimple();
285
+ };
286
+
287
+
288
+ /**
289
+ * Tests the validity of this <code>Geometry</code>. Subclasses provide their
290
+ * own definition of "valid".
291
+ *
292
+ * @return {boolean} <code>true</code> if this <code>Geometry</code> is
293
+ * valid.
294
+ *
295
+ * @see IsValidOp
296
+ */
297
+ jsts.geom.Geometry.prototype.isValid = function() {
298
+ var isValidOp = new jsts.operation.valid.IsValidOp(this);
299
+ return isValidOp.isValid();
300
+ };
301
+
302
+
303
+ /**
304
+ * Returns whether or not the set of points in this <code>Geometry</code> is
305
+ * empty.
306
+ *
307
+ * @return {boolean} <code>true</code> if this <code>Geometry</code> equals
308
+ * the empty geometry.
309
+ */
310
+ jsts.geom.Geometry.prototype.isEmpty = function() {
311
+ throw new jsts.error.AbstractMethodInvocationError();
312
+ };
313
+
314
+
315
+ /**
316
+ * Returns the minimum distance between this <code>Geometry</code> and the
317
+ * <code>Geometry</code> g
318
+ *
319
+ * @param {Geometry}
320
+ * g the <code>Geometry</code> from which to compute the distance.
321
+ * @return {number} the distance between the geometries. 0 if either input
322
+ * geometry is empty.
323
+ * @throws IllegalArgumentException
324
+ * if g is null
325
+ */
326
+ jsts.geom.Geometry.prototype.distance = function(g) {
327
+ return jsts.operation.distance.DistanceOp.distance(this, g);
328
+ };
329
+
330
+
331
+ /**
332
+ * Tests whether the distance from this <code>Geometry</code> to another is
333
+ * less than or equal to a specified value.
334
+ *
335
+ * @param {Geometry}
336
+ * geom the Geometry to check the distance to.
337
+ * @param {number}
338
+ * distance the distance value to compare.
339
+ * @return {boolean} <code>true</code> if the geometries are less than
340
+ * <code>distance</code> apart.
341
+ */
342
+ jsts.geom.Geometry.prototype.isWithinDistance = function(geom, distance) {
343
+ var envDist = this.getEnvelopeInternal().distance(geom.getEnvelopeInternal());
344
+ if (envDist > distance) {
345
+ return false;
346
+ }
347
+ return DistanceOp.isWithinDistance(this, geom, distance);
348
+ };
349
+
350
+ jsts.geom.Geometry.prototype.isRectangle = function() {
351
+ // Polygon overrides to check for actual rectangle
352
+ return false;
353
+ };
354
+
355
+ /**
356
+ * Returns the area of this <code>Geometry</code>. Areal Geometries have a
357
+ * non-zero area. They override this function to compute the area. Others return
358
+ * 0.0
359
+ *
360
+ * @return the area of the Geometry.
361
+ */
362
+ jsts.geom.Geometry.prototype.getArea = function() {
363
+ return 0.0;
364
+ };
365
+
366
+ /**
367
+ * Returns the length of this <code>Geometry</code>. Linear geometries return
368
+ * their length. Areal geometries return their perimeter. They override this
369
+ * function to compute the area. Others return 0.0
370
+ *
371
+ * @return the length of the Geometry.
372
+ */
373
+ jsts.geom.Geometry.prototype.getLength = function() {
374
+ return 0.0;
375
+ };
376
+
377
+ /**
378
+ * Computes the centroid of this <code>Geometry</code>. The centroid is equal
379
+ * to the centroid of the set of component Geometries of highest dimension
380
+ * (since the lower-dimension geometries contribute zero "weight" to the
381
+ * centroid)
382
+ *
383
+ * @return a {@link Point} which is the centroid of this Geometry.
384
+ */
385
+ jsts.geom.Geometry.prototype.getCentroid = function() {
386
+ if (this.isEmpty()) {
387
+ return null;
388
+ }
389
+ var cent;
390
+ var centPt = null;
391
+ var dim = this.getDimension();
392
+ if (dim === 0) {
393
+ cent = new jsts.algorithm.CentroidPoint();
394
+ cent.add(this);
395
+ centPt = cent.getCentroid();
396
+ } else if (dim === 1) {
397
+ cent = new jsts.algorithm.CentroidLine();
398
+ cent.add(this);
399
+ centPt = cent.getCentroid();
400
+ } else {
401
+ cent = new jsts.algorithm.CentroidArea();
402
+ cent.add(this);
403
+ centPt = cent.getCentroid();
404
+ }
405
+ return this.createPointFromInternalCoord(centPt, this);
406
+
407
+ };
408
+
409
+
410
+ /**
411
+ * Computes an interior point of this <code>Geometry</code>. An interior
412
+ * point is guaranteed to lie in the interior of the Geometry, if it possible to
413
+ * calculate such a point exactly. Otherwise, the point may lie on the boundary
414
+ * of the geometry.
415
+ *
416
+ * @return {Point} a {@link Point} which is in the interior of this Geometry.
417
+ */
418
+ jsts.geom.Geometry.prototype.getInteriorPoint = function() {
419
+ var intPt;
420
+ var interiorPt = null;
421
+ var dim = this.getDimension();
422
+ if (dim === 0) {
423
+ intPt = new InteriorPointPoint(this);
424
+ interiorPt = intPt.getInteriorPoint();
425
+ } else if (dim === 1) {
426
+ intPt = new InteriorPointLine(this);
427
+ interiorPt = intPt.getInteriorPoint();
428
+ } else {
429
+ intPt = new InteriorPointArea(this);
430
+ interiorPt = intPt.getInteriorPoint();
431
+ }
432
+ return this.createPointFromInternalCoord(interiorPt, this);
433
+ };
434
+
435
+
436
+ /**
437
+ * Returns the dimension of this geometry. The dimension of a geometry is is the
438
+ * topological dimension of its embedding in the 2-D Euclidean plane. In the JTS
439
+ * spatial model, dimension values are in the set {0,1,2}.
440
+ * <p>
441
+ * Note that this is a different concept to the dimension of the vertex
442
+ * {@link Coordinate}s. The geometry dimension can never be greater than the
443
+ * coordinate dimension. For example, a 0-dimensional geometry (e.g. a Point)
444
+ * may have a coordinate dimension of 3 (X,Y,Z).
445
+ *
446
+ * @return {number} the topological dimension of this geometry.
447
+ */
448
+ jsts.geom.Geometry.prototype.getDimension = function() {
449
+ throw new jsts.error.AbstractMethodInvocationError();
450
+ };
451
+
452
+
453
+ /**
454
+ * Returns the boundary, or an empty geometry of appropriate dimension if this
455
+ * <code>Geometry</code> is empty. (In the case of zero-dimensional
456
+ * geometries, ' an empty GeometryCollection is returned.) For a discussion of
457
+ * this function, see the OpenGIS Simple Features Specification. As stated in
458
+ * SFS Section 2.1.13.1, "the boundary of a Geometry is a set of Geometries of
459
+ * the next lower dimension."
460
+ *
461
+ * @return {Geometry} the closure of the combinatorial boundary of this
462
+ * <code>Geometry.</code>
463
+ */
464
+ jsts.geom.Geometry.prototype.getBoundary = function() {
465
+ throw new jsts.error.AbstractMethodInvocationError();
466
+ };
467
+
468
+
469
+ /**
470
+ * Returns the dimension of this <code>Geometry</code>s inherent boundary.
471
+ *
472
+ * @return {number} the dimension of the boundary of the class implementing this
473
+ * interface, whether or not this object is the empty geometry. Returns
474
+ * <code>Dimension.FALSE</code> if the boundary is the empty geometry.
475
+ */
476
+ jsts.geom.Geometry.prototype.getBoundaryDimension = function() {
477
+ throw new jsts.error.AbstractMethodInvocationError();
478
+ };
479
+
480
+
481
+ /**
482
+ * Returns this <code>Geometry</code>s bounding box. If this
483
+ * <code>Geometry</code> is the empty geometry, returns an empty
484
+ * <code>Point</code>. If the <code>Geometry</code> is a point, returns a
485
+ * non-empty <code>Point</code>. Otherwise, returns a <code>Polygon</code>
486
+ * whose points are (minx, miny), (maxx, miny), (maxx, maxy), (minx, maxy),
487
+ * (minx, miny).
488
+ *
489
+ * @return {Geometry} an empty <code>Point</code> (for empty
490
+ * <code>Geometry</code>s), a <code>Point</code> (for
491
+ * <code>Point</code>s) or a <code>Polygon</code> (in all other
492
+ * cases).
493
+ */
494
+ jsts.geom.Geometry.prototype.getEnvelope = function() {
495
+ return this.getFactory().toGeometry(this.getEnvelopeInternal());
496
+ };
497
+
498
+
499
+ /**
500
+ * Returns the minimum and maximum x and y values in this <code>Geometry</code>,
501
+ * or a null <code>Envelope</code> if this <code>Geometry</code> is empty.
502
+ *
503
+ * @return {Envelope} this <code>Geometry</code>s bounding box; if the
504
+ * <code>Geometry</code> is empty, <code>Envelope#isNull</code> will
505
+ * return <code>true.</code>
506
+ */
507
+ jsts.geom.Geometry.prototype.getEnvelopeInternal = function() {
508
+ if (this.envelope === null) {
509
+ this.envelope = this.computeEnvelopeInternal();
510
+ }
511
+ return this.envelope;
512
+ };
513
+
514
+
515
+ /**
516
+ * Tests whether this geometry is disjoint from the specified geometry.
517
+ * <p>
518
+ * The <code>disjoint</code> predicate has the following equivalent
519
+ * definitions:
520
+ * <ul>
521
+ * <li>The two geometries have no point in common
522
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
523
+ * <code>[FF*FF****]</code>
524
+ * <li><code>! g.intersects(this)</code> (<code>disjoint</code> is the
525
+ * inverse of <code>intersects</code>)
526
+ * </ul>
527
+ *
528
+ * @param {Geometry}
529
+ * g the <code>Geometry</code> with which to compare this
530
+ * <code>Geometry.</code>
531
+ * @return {boolean} <code>true</code> if the two <code>Geometry</code>s
532
+ * are disjoint.
533
+ *
534
+ * @see Geometry#intersects
535
+ */
536
+ jsts.geom.Geometry.prototype.disjoint = function(g) {
537
+ return !this.intersects(g);
538
+ };
539
+
540
+
541
+ /**
542
+ * Tests whether this geometry touches the specified geometry.
543
+ * <p>
544
+ * The <code>touches</code> predicate has the following equivalent
545
+ * definitions:
546
+ * <ul>
547
+ * <li>The geometries have at least one point in common, but their interiors do
548
+ * not intersect.
549
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
550
+ * <code>[FT*******]</code> or <code>[F**T*****]</code> or
551
+ * <code>[F***T****]</code>
552
+ * </ul>
553
+ * If both geometries have dimension 0, this predicate returns
554
+ * <code>false</code>
555
+ *
556
+ * @param {Geometry}
557
+ * g the <code>Geometry</code> with which to compare this
558
+ * <code>Geometry.</code>
559
+ * @return {boolean} <code>true</code> if the two <code>Geometry</code>s
560
+ * touch; Returns <code>false</code> if both <code>Geometry</code>s
561
+ * are points.
562
+ */
563
+ jsts.geom.Geometry.prototype.touches = function(g) {
564
+ // short-circuit test
565
+ if (!this.getEnvelopeInternal().intersects(g.getEnvelopeInternal())) {
566
+ return false;
567
+ }
568
+ return this.relate(g).isTouches(this.getDimension(), g.getDimension());
569
+ };
570
+
571
+
572
+ /**
573
+ * Tests whether this geometry intersects the specified geometry.
574
+ * <p>
575
+ * The <code>intersects</code> predicate has the following equivalent
576
+ * definitions:
577
+ * <ul>
578
+ * <li>The two geometries have at least one point in common
579
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
580
+ * <code>[T********]</code> or <code>[*T*******]</code> or
581
+ * <code>[***T*****]</code> or <code>[****T****]</code>
582
+ * <li><code>! g.disjoint(this)</code> (<code>intersects</code> is the
583
+ * inverse of <code>disjoint</code>)
584
+ * </ul>
585
+ *
586
+ * @param {Geometry}
587
+ * g the <code>Geometry</code> with which to compare this
588
+ * <code>Geometry.</code>
589
+ * @return {boolean} <code>true</code> if the two <code>Geometry</code>s
590
+ * intersect.
591
+ *
592
+ * @see Geometry#disjoint
593
+ */
594
+ jsts.geom.Geometry.prototype.intersects = function(g) {
595
+
596
+ // short-circuit envelope test
597
+ if (!this.getEnvelopeInternal().intersects(g.getEnvelopeInternal())) {
598
+ return false;
599
+ }
600
+
601
+ // optimization for rectangle arguments
602
+ if (this.isRectangle()) {
603
+ return RectangleIntersects.intersects(this, g);
604
+ }
605
+ if (g.isRectangle()) {
606
+ return RectangleIntersects.intersects(g, this);
607
+ }
608
+ // general case
609
+ return this.relate(g).isIntersects();
610
+ };
611
+
612
+
613
+ /**
614
+ * Tests whether this geometry crosses the specified geometry.
615
+ * <p>
616
+ * The <code>crosses</code> predicate has the following equivalent
617
+ * definitions:
618
+ * <ul>
619
+ * <li>The geometries have some but not all interior points in common.
620
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
621
+ * <ul>
622
+ * <li><code>[T*T******]</code> (for P/L, P/A, and L/A situations)
623
+ * <li><code>[T*****T**]</code> (for L/P, A/P, and A/L situations)
624
+ * <li><code>[0********]</code> (for L/L situations)
625
+ * </ul>
626
+ * </ul>
627
+ * For any other combination of dimensions this predicate returns
628
+ * <code>false</code>.
629
+ * <p>
630
+ * The SFS defined this predicate only for P/L, P/A, L/L, and L/A situations.
631
+ * JTS extends the definition to apply to L/P, A/P and A/L situations as well,
632
+ * in order to make the relation symmetric.
633
+ *
634
+ * @param {Geometry}
635
+ * g the <code>Geometry</code> with which to compare this
636
+ * <code>Geometry.</code>
637
+ * @return {boolean} <code>true</code> if the two <code>Geometry</code>s
638
+ * cross.
639
+ */
640
+ jsts.geom.Geometry.prototype.crosses = function(g) {
641
+ // short-circuit test
642
+ if (!this.getEnvelopeInternal().intersects(g.getEnvelopeInternal())) {
643
+ return false;
644
+ }
645
+ return this.relate(g).isCrosses(this.getDimension(), g.getDimension());
646
+ };
647
+
648
+
649
+ /**
650
+ * Tests whether this geometry is within the specified geometry.
651
+ * <p>
652
+ * The <code>within</code> predicate has the following equivalent definitions:
653
+ * <ul>
654
+ * <li>Every point of this geometry is a point of the other geometry, and the
655
+ * interiors of the two geometries have at least one point in common.
656
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
657
+ * <code>[T*F**F***]</code>
658
+ * <li><code>g.contains(this)</code> (<code>within</code> is the converse
659
+ * of <code>contains</code>)
660
+ * </ul>
661
+ * An implication of the definition is that "The boundary of a Geometry is not
662
+ * within the Geometry". In other words, if a geometry A is a subset of the
663
+ * points in the boundary of a geomtry B, <code>A.within(B) = false</code>
664
+ *
665
+ * @param {Geometry}
666
+ * g the <code>Geometry</code> with which to compare this
667
+ * <code>Geometry.</code>
668
+ * @return {boolean} <code>true</code> if this <code>Geometry</code> is
669
+ * within <code>other.</code>
670
+ *
671
+ * @see Geometry#contains
672
+ */
673
+ jsts.geom.Geometry.prototype.within = function(g) {
674
+ return g.contains(this);
675
+ };
676
+
677
+
678
+ /**
679
+ * Tests whether this geometry contains the specified geometry.
680
+ * <p>
681
+ * The <code>contains</code> predicate has the following equivalent
682
+ * definitions:
683
+ * <ul>
684
+ * <li>Every point of the other geometry is a point of this geometry, and the
685
+ * interiors of the two geometries have at least one point in common.
686
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
687
+ * <code>[T*****FF*]</code>
688
+ * <li><code>g.within(this)</code> (<code>contains</code> is the converse
689
+ * of <code>within</code>)
690
+ * </ul>
691
+ * An implication of the definition is that "Geometries do not contain their
692
+ * boundary". In other words, if a geometry A is a subset of the points in the
693
+ * boundary of a geometry B, <code>B.contains(A) = false</code>
694
+ *
695
+ * @param {Geometry}
696
+ * g the <code>Geometry</code> with which to compare this
697
+ * <code>Geometry.</code>
698
+ * @return {boolean} <code>true</code> if this <code>Geometry</code>
699
+ * contains <code>g.</code>
700
+ *
701
+ * @see Geometry#within
702
+ */
703
+ jsts.geom.Geometry.prototype.contains = function(g) {
704
+ // short-circuit test
705
+ if (!this.getEnvelopeInternal().contains(g.getEnvelopeInternal())) {
706
+ return false;
707
+ }
708
+ // optimization for rectangle arguments
709
+ if (this.isRectangle()) {
710
+ return RectangleContains.contains(this, g);
711
+ }
712
+ // general case
713
+ return this.relate(g).isContains();
714
+ };
715
+
716
+
717
+ /**
718
+ * Tests whether this geometry overlaps the specified geometry.
719
+ * <p>
720
+ * The <code>overlaps</code> predicate has the following equivalent
721
+ * definitions:
722
+ * <ul>
723
+ * <li>The geometries have at least one point each not shared by the other (or
724
+ * equivalently neither covers the other), they have the same dimension, and the
725
+ * intersection of the interiors of the two geometries has the same dimension as
726
+ * the geometries themselves.
727
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
728
+ * <code>[T*T***T**]</code> (for two points or two surfaces) or
729
+ * <code>[1*T***T**]</code> (for two curves)
730
+ * </ul>
731
+ * If the geometries are of different dimension this predicate returns
732
+ * <code>false</code>.
733
+ *
734
+ * @param {Geometry}
735
+ * g the <code>Geometry</code> with which to compare this
736
+ * <code>Geometry.</code>
737
+ * @return {boolean} <code>true</code> if the two <code>Geometry</code>s
738
+ * overlap.
739
+ */
740
+ jsts.geom.Geometry.prototype.overlaps = function(g) {
741
+ // short-circuit test
742
+ if (!this.getEnvelopeInternal().intersects(g.getEnvelopeInternal())) {
743
+ return false;
744
+ }
745
+ return this.relate(g).isOverlaps(this.getDimension(), g.getDimension());
746
+ };
747
+
748
+
749
+ /**
750
+ * Tests whether this geometry covers the specified geometry.
751
+ * <p>
752
+ * The <code>covers</code> predicate has the following equivalent definitions:
753
+ * <ul>
754
+ * <li>Every point of the other geometry is a point of this geometry.
755
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
756
+ * <code>[T*****FF*]</code> or <code>[*T****FF*]</code> or
757
+ * <code>[***T**FF*]</code> or <code>[****T*FF*]</code>
758
+ * <li><code>g.coveredBy(this)</code> (<code>covers</code> is the converse
759
+ * of <code>coveredBy</code>)
760
+ * </ul>
761
+ * If either geometry is empty, the value of this predicate is <tt>false</tt>.
762
+ * <p>
763
+ * This predicate is similar to {@link #contains}, but is more inclusive (i.e.
764
+ * returns <tt>true</tt> for more cases). In particular, unlike
765
+ * <code>contains</code> it does not distinguish between points in the
766
+ * boundary and in the interior of geometries. For most situations,
767
+ * <code>covers</code> should be used in preference to <code>contains</code>.
768
+ * As an added benefit, <code>covers</code> is more amenable to optimization,
769
+ * and hence should be more performant.
770
+ *
771
+ * @param {Geometry}
772
+ * g the <code>Geometry</code> with which to compare this
773
+ * <code>Geometry.</code>
774
+ * @return {boolean} <code>true</code> if this <code>Geometry</code> covers
775
+ * <code>g.</code>
776
+ *
777
+ * @see Geometry#contains
778
+ * @see Geometry#coveredBy
779
+ */
780
+ jsts.geom.Geometry.prototype.covers = function(g) {
781
+ // short-circuit test
782
+ if (!this.getEnvelopeInternal().covers(g.getEnvelopeInternal())) {
783
+ return false;
784
+ }
785
+ // optimization for rectangle arguments
786
+ if (this.isRectangle()) {
787
+ // since we have already tested that the test envelope is covered
788
+ return true;
789
+ }
790
+ return this.relate(g).isCovers();
791
+ };
792
+
793
+
794
+ /**
795
+ * Tests whether this geometry is covered by the specified geometry.
796
+ * <p>
797
+ * The <code>coveredBy</code> predicate has the following equivalent
798
+ * definitions:
799
+ * <ul>
800
+ * <li>Every point of this geometry is a point of the other geometry.
801
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches
802
+ * <code>[T*F**F***]</code> or <code>[*TF**F***]</code> or
803
+ * <code>[**FT*F***]</code> or <code>[**F*TF***]</code>
804
+ * <li><code>g.covers(this)</code> (<code>coveredBy</code> is the converse
805
+ * of <code>covers</code>)
806
+ * </ul>
807
+ * If either geometry is empty, the value of this predicate is <tt>false</tt>.
808
+ * <p>
809
+ * This predicate is similar to {@link #within}, but is more inclusive (i.e.
810
+ * returns <tt>true</tt> for more cases).
811
+ *
812
+ * @param {Geometry}
813
+ * g the <code>Geometry</code> with which to compare this
814
+ * <code>Geometry.</code>
815
+ * @return {boolean} <code>true</code> if this <code>Geometry</code> is
816
+ * covered by <code>g.</code>
817
+ *
818
+ * @see Geometry#within
819
+ * @see Geometry#covers
820
+ */
821
+ jsts.geom.Geometry.prototype.coveredBy = function(g) {
822
+ return g.covers(this);
823
+ };
824
+
825
+
826
+ /**
827
+ * Tests whether the elements in the DE-9IM {@link IntersectionMatrix} for the
828
+ * two <code>Geometry</code>s match the elements in
829
+ * <code>intersectionPattern</code>. The pattern is a 9-character string,
830
+ * with symbols drawn from the following set:
831
+ * <UL>
832
+ * <LI> 0 (dimension 0)
833
+ * <LI> 1 (dimension 1)
834
+ * <LI> 2 (dimension 2)
835
+ * <LI> T ( matches 0, 1 or 2)
836
+ * <LI> F ( matches FALSE)
837
+ * <LI> * ( matches any value)
838
+ * </UL>
839
+ * For more information on the DE-9IM, see the <i>OpenGIS Simple Features
840
+ * Specification</i>.
841
+ *
842
+ * @param {Geometry}
843
+ * other the <code>Geometry</code> with which to compare this
844
+ * <code>Geometry.</code>
845
+ * @param {string}
846
+ * intersectionPattern the pattern against which to check the
847
+ * intersection matrix for the two <code>Geometry</code>s.
848
+ * @return {boolean} <code>true</code> if the DE-9IM intersection matrix for
849
+ * the two <code>Geometry</code>s match
850
+ * <code>intersectionPattern.</code>
851
+ * @see IntersectionMatrix
852
+ */
853
+ jsts.geom.Geometry.prototype.relate = function(g, intersectionPattern) {
854
+ if (arguments.length === 1) {
855
+ return this.relate2.apply(this, arguments);
856
+ }
857
+
858
+ return this.relate2(g).matches(intersectionPattern);
859
+ };
860
+
861
+
862
+ /**
863
+ * Returns the DE-9IM {@link IntersectionMatrix} for the two
864
+ * <code>Geometry</code>s.
865
+ *
866
+ * @param {Geometry}
867
+ * g the <code>Geometry</code> with which to compare this
868
+ * <code>Geometry.</code>
869
+ * @return {IntersectionMatrix} an {@link IntersectionMatrix} describing the
870
+ * intersections of the interiors, boundaries and exteriors of the two
871
+ * <code>Geometry</code>s.
872
+ */
873
+ jsts.geom.Geometry.prototype.relate2 = function(g) {
874
+ this.checkNotGeometryCollection(this);
875
+ this.checkNotGeometryCollection(g);
876
+ return jsts.operation.relate.RelateOp.relate(this, g);
877
+ };
878
+
879
+
880
+ /**
881
+ * Tests whether this geometry is topologically equal to the argument geometry
882
+ * as defined by the SFS <tt>equals</tt> predicate.
883
+ * <p>
884
+ * The SFS <code>equals</code> predicate has the following equivalent
885
+ * definitions:
886
+ * <ul>
887
+ * <li>The two geometries have at least one point in common, and no point of
888
+ * either geometry lies in the exterior of the other geometry.
889
+ * <li>The DE-9IM Intersection Matrix for the two geometries matches the
890
+ * pattern <tt>T*F**FFF*</tt>
891
+ * <pre>
892
+ * T*F
893
+ * **F
894
+ * FF*
895
+ * </pre>
896
+ *
897
+ * </ul>
898
+ * <b>Note</b> that this method computes <b>topologically equality</b>. For
899
+ * structural equality, see {@link #equalsExact(Geometry)}.
900
+ *
901
+ * @param {Geometry}
902
+ * g the <code>Geometry</code> with which to compare this
903
+ * <code>Geometry.</code>
904
+ * @return {boolean} <code>true</code> if the two <code>Geometry</code>s
905
+ * are topologically equal.
906
+ *
907
+ * @see #equalsExact(Geometry)
908
+ */
909
+ jsts.geom.Geometry.prototype.equalsTopo = function(g) {
910
+ // short-circuit test
911
+ if (!this.getEnvelopeInternal().equals(g.getEnvelopeInternal())) {
912
+ return false;
913
+ }
914
+ return this.relate(g).isEquals(this.getDimension(), g.getDimension());
915
+ };
916
+
917
+
918
+ /**
919
+ * Tests whether this geometry is structurally and numerically equal to a given
920
+ * <tt>Object</tt>. If the argument <tt>Object</tt> is not a
921
+ * <tt>Geometry</tt>, the result is <tt>false</tt>. Otherwise, the result
922
+ * is computed using {@link #equalsExact(Geometry)}.
923
+ * <p>
924
+ * This method is provided to fulfill the Java contract for value-based object
925
+ * equality. In conjunction with {@link #hashCode()} it provides semantics which
926
+ * are most useful for using <tt>Geometry</tt>s as keys and values in Java
927
+ * collections.
928
+ * <p>
929
+ * Note that to produce the expected result the input geometries should be in
930
+ * normal form. It is the caller's responsibility to perform this where required
931
+ * (using {@link Geometry#norm() or {@link #normalize()} as appropriate).
932
+ *
933
+ * @param {Object}
934
+ * o the Object to compare.
935
+ * @return {boolean} true if this geometry is exactly equal to the argument.
936
+ *
937
+ * @see #equalsExact(Geometry)
938
+ * @see #hashCode()
939
+ * @see #norm()
940
+ * @see #normalize()
941
+ */
942
+ jsts.geom.Geometry.prototype.equals = function(o) {
943
+ if (o instanceof jsts.geom.Geometry || o instanceof jsts.geom.LinearRing ||
944
+ o instanceof jsts.geom.Polygon ||
945
+ o instanceof jsts.geom.GeometryCollection ||
946
+ o instanceof jsts.geom.MultiPoint ||
947
+ o instanceof jsts.geom.MultiLineString ||
948
+ o instanceof jsts.geom.MultiPolygon) {
949
+ return this.equalsExact(o);
950
+ }
951
+ return false;
952
+ };
953
+
954
+ /**
955
+ * Computes a buffer area around this geometry having the given width and with a
956
+ * specified accuracy of approximation for circular arcs, and using a specified
957
+ * end cap style.
958
+ * <p>
959
+ * Mathematically-exact buffer area boundaries can contain circular arcs. To
960
+ * represent these arcs using linear geometry they must be approximated with
961
+ * line segments. The <code>quadrantSegments</code> argument allows
962
+ * controlling the accuracy of the approximation by specifying the number of
963
+ * line segments used to represent a quadrant of a circle
964
+ * <p>
965
+ * The end cap style specifies the buffer geometry that will be created at the
966
+ * ends of linestrings. The styles provided are:
967
+ * <ul>
968
+ * <li><tt>BufferOp.CAP_ROUND</tt> - (default) a semi-circle
969
+ * <li><tt>BufferOp.CAP_BUTT</tt> - a straight line perpendicular to the end
970
+ * segment
971
+ * <li><tt>BufferOp.CAP_SQUARE</tt> - a half-square
972
+ * </ul>
973
+ * <p>
974
+ * The buffer operation always returns a polygonal result. The negative or
975
+ * zero-distance buffer of lines and points is always an empty {@link Polygon}.
976
+ * This is also the result for the buffers of degenerate (zero-area) polygons.
977
+ *
978
+ * @param {number}
979
+ * distance the width of the buffer (may be positive, negative or 0).
980
+ * @param {number}
981
+ * quadrantSegments the number of line segments used to represent a
982
+ * quadrant of a circle.
983
+ * @param {number}
984
+ * endCapStyle the end cap style to use.
985
+ * @return {Geometry} a polygonal geometry representing the buffer region (which
986
+ * may be empty).
987
+ *
988
+ * @throws TopologyException
989
+ * if a robustness error occurs
990
+ *
991
+ * @see #buffer(double)
992
+ * @see #buffer(double, int)
993
+ * @see BufferOp
994
+ */
995
+ jsts.geom.Geometry.prototype.buffer = function(distance, quadrantSegments, endCapStyle) {
996
+ var params = new jsts.operation.buffer.BufferParameters(quadrantSegments, endCapStyle)
997
+ return jsts.operation.buffer.BufferOp.bufferOp2(this, distance, params);
998
+ };
999
+
1000
+
1001
+ /**
1002
+ * Computes the smallest convex <code>Polygon</code> that contains all the
1003
+ * points in the <code>Geometry</code>. This obviously applies only to
1004
+ * <code>Geometry</code> s which contain 3 or more points; the results for
1005
+ * degenerate cases are specified as follows: <TABLE>
1006
+ * <TR>
1007
+ * <TH> Number of <code>Point</code>s in argument <code>Geometry</code>
1008
+ * </TH>
1009
+ * <TH> <code>Geometry</code> class of result </TH>
1010
+ * </TR>
1011
+ * <TR>
1012
+ * <TD> 0 </TD>
1013
+ * <TD> empty <code>GeometryCollection</code> </TD>
1014
+ * </TR>
1015
+ * <TR>
1016
+ * <TD> 1 </TD>
1017
+ * <TD> <code>Point</code> </TD>
1018
+ * </TR>
1019
+ * <TR>
1020
+ * <TD> 2 </TD>
1021
+ * <TD> <code>LineString</code> </TD>
1022
+ * </TR>
1023
+ * <TR>
1024
+ * <TD> 3 or more </TD>
1025
+ * <TD> <code>Polygon</code> </TD>
1026
+ * </TR>
1027
+ * </TABLE>
1028
+ *
1029
+ * @return {Geometry} the minimum-area convex polygon containing this
1030
+ * <code>Geometry</code>' s points.
1031
+ */
1032
+ jsts.geom.Geometry.prototype.convexHull = function() {
1033
+ return new jsts.algorithm.ConvexHull(this).getConvexHull();
1034
+ };
1035
+
1036
+
1037
+ /**
1038
+ * Computes a <code>Geometry</code> representing the points shared by this
1039
+ * <code>Geometry</code> and <code>other</code>. {@link GeometryCollection}s
1040
+ * support intersection with homogeneous collection types, with the semantics
1041
+ * that the result is a {@link GeometryCollection} of the intersection of each
1042
+ * element of the target with the argument.
1043
+ *
1044
+ * @param {Geometry}
1045
+ * other the <code>Geometry</code> with which to compute the
1046
+ * intersection.
1047
+ * @return {Geometry} the points common to the two <code>Geometry</code>s.
1048
+ * @throws TopologyException
1049
+ * if a robustness error occurs
1050
+ * @throws IllegalArgumentException
1051
+ * if the argument is a non-empty GeometryCollection
1052
+ */
1053
+ jsts.geom.Geometry.prototype.intersection = function(other) {
1054
+ /**
1055
+ * TODO: MD - add optimization for P-A case using Point-In-Polygon
1056
+ */
1057
+ // special case: if one input is empty ==> empty
1058
+ if (this.isEmpty()) {
1059
+ return this.getFactory().createGeometryCollection(null);
1060
+ }
1061
+ if (other.isEmpty()) {
1062
+ return this.getFactory().createGeometryCollection(null);
1063
+ }
1064
+
1065
+ // compute for GCs
1066
+ if (this.isGeometryCollection(this)) {
1067
+ var g2 = other;
1068
+ // TODO: probably not straightforward to port...
1069
+ /*
1070
+ * return GeometryCollectionMapper.map(this, new
1071
+ * GeometryCollectionMapper.MapOp() { public Geometry map(Geometry g) {
1072
+ * return g.intersection(g2); } });
1073
+ */
1074
+ }
1075
+
1076
+ this.checkNotGeometryCollection(this);
1077
+ this.checkNotGeometryCollection(other);
1078
+ return jsts.operation.overlay.snap.SnapIfNeededOverlayOp.overlayOp(this,
1079
+ other, jsts.operation.overlay.OverlayOp.INTERSECTION);
1080
+ };
1081
+
1082
+
1083
+ /**
1084
+ * Computes a <code>Geometry</code> representing all the points in this
1085
+ * <code>Geometry</code> and <code>other</code>.
1086
+ *
1087
+ * Or without arguments:
1088
+ *
1089
+ * Computes the union of all the elements of this geometry. Heterogeneous
1090
+ * {@link GeometryCollection}s are fully supported.
1091
+ *
1092
+ * The result obeys the following contract:
1093
+ * <ul>
1094
+ * <li>Unioning a set of {@link LineString}s has the effect of fully noding
1095
+ * and dissolving the linework.
1096
+ * <li>Unioning a set of {@link Polygon}s will always return a
1097
+ * {@link Polygonal} geometry (unlike {link #union(Geometry)}, which may return
1098
+ * geometrys of lower dimension if a topology collapse occurred.
1099
+ * </ul>
1100
+ *
1101
+ * @param {Geometry}
1102
+ * other the <code>Geometry</code> with which to compute the union.
1103
+ * @return {Geometry} a set combining the points of this <code>Geometry</code>
1104
+ * and the points of <code>other.</code>
1105
+ * @throws TopologyException
1106
+ * if a robustness error occurs
1107
+ * @throws IllegalArgumentException
1108
+ * if either input is a non-empty GeometryCollection
1109
+ */
1110
+ jsts.geom.Geometry.prototype.union = function(other) {
1111
+ if (arguments.length === 0) {
1112
+ return jsts.operation.union.UnaryUnionOp.union(this);
1113
+ }
1114
+
1115
+ // special case: if either input is empty ==> other input
1116
+ if (this.isEmpty()) {
1117
+ return other.clone();
1118
+ }
1119
+ if (other.isEmpty()) {
1120
+ return this.clone();
1121
+ }
1122
+
1123
+ // TODO: optimize if envelopes of geometries do not intersect
1124
+
1125
+ this.checkNotGeometryCollection(this);
1126
+ this.checkNotGeometryCollection(other);
1127
+ return jsts.operation.overlay.snap.SnapIfNeededOverlayOp.overlayOp(this,
1128
+ other, jsts.operation.overlay.OverlayOp.UNION);
1129
+ };
1130
+
1131
+
1132
+ /**
1133
+ * Computes a <code>Geometry</code> representing the points making up this
1134
+ * <code>Geometry</code> that do not make up <code>other</code>. This
1135
+ * method returns the closure of the resultant <code>Geometry</code>.
1136
+ *
1137
+ * @param {Geometry}
1138
+ * other the <code>Geometry</code> with which to compute the
1139
+ * difference.
1140
+ * @return {Geometry} the point set difference of this <code>Geometry</code>
1141
+ * with <code>other.</code>
1142
+ * @throws TopologyException
1143
+ * if a robustness error occurs
1144
+ * @throws IllegalArgumentException
1145
+ * if either input is a non-empty GeometryCollection
1146
+ */
1147
+ jsts.geom.Geometry.prototype.difference = function(other) {
1148
+ // mod to handle empty cases better - return type of input
1149
+ // if (this.isEmpty() || other.isEmpty()) return (Geometry) clone();
1150
+
1151
+ // special case: if A.isEmpty ==> empty; if B.isEmpty ==> A
1152
+ if (this.isEmpty()) {
1153
+ return this.getFactory().createGeometryCollection(null);
1154
+ }
1155
+ if (other.isEmpty()) {
1156
+ return this.clone();
1157
+ }
1158
+
1159
+ this.checkNotGeometryCollection(this);
1160
+ this.checkNotGeometryCollection(other);
1161
+ return jsts.operation.overlay.snap.SnapIfNeededOverlayOp.overlayOp(this,
1162
+ other, jsts.operation.overlay.OverlayOp.DIFFERENCE);
1163
+ };
1164
+
1165
+
1166
+ /**
1167
+ * Returns a set combining the points in this <code>Geometry</code> not in
1168
+ * <code>other</code>, and the points in <code>other</code> not in this
1169
+ * <code>Geometry</code>. This method returns the closure of the resultant
1170
+ * <code>Geometry</code>.
1171
+ *
1172
+ * @param {Geometry}
1173
+ * other the <code>Geometry</code> with which to compute the
1174
+ * symmetric difference.
1175
+ * @return {Geometry} the point set symmetric difference of this
1176
+ * <code>Geometry</code> with <code>other.</code>
1177
+ * @throws TopologyException
1178
+ * if a robustness error occurs
1179
+ * @throws IllegalArgumentException
1180
+ * if either input is a non-empty GeometryCollection
1181
+ */
1182
+ jsts.geom.Geometry.prototype.symDifference = function(other) {
1183
+ // special case: if either input is empty ==> other input
1184
+ if (this.isEmpty()) {
1185
+ return other.clone();
1186
+ }
1187
+ if (other.isEmpty()) {
1188
+ return this.clone();
1189
+ }
1190
+
1191
+ this.checkNotGeometryCollection(this);
1192
+ this.checkNotGeometryCollection(other);
1193
+ return jsts.operation.overlay.snap.SnapIfNeededOverlayOp.overlayOp(this,
1194
+ other, jsts.operation.overlay.OverlayOp.SYMDIFFERENCE);
1195
+ };
1196
+
1197
+ /**
1198
+ * Returns true if the two <code>Geometry</code>s are exactly equal, up to a
1199
+ * specified distance tolerance. Two Geometries are exactly equal within a
1200
+ * distance tolerance if and only if:
1201
+ * <ul>
1202
+ * <li>they have the same class
1203
+ * <li>they have the same values for their vertices, within the given tolerance
1204
+ * distance, in exactly the same order.
1205
+ * </ul>
1206
+ * If this and the other <code>Geometry</code>s are composites and any
1207
+ * children are not <code>Geometry</code>s, returns <code>false</code>.
1208
+ *
1209
+ * @param {Geometry}
1210
+ * other the <code>Geometry</code> with which to compare this
1211
+ * <code>Geometry.</code>
1212
+ * @param {number}
1213
+ * tolerance distance at or below which two <code>Coordinate</code>s
1214
+ * are considered equal.
1215
+ * @return {boolean}
1216
+ */
1217
+ jsts.geom.Geometry.prototype.equalsExact = function(other, tolerance) {
1218
+ throw new jsts.error.AbstractMethodInvocationError();
1219
+ };
1220
+
1221
+ /**
1222
+ * Tests whether two geometries are exactly equal in their normalized forms.
1223
+ * This is a convenience method which creates normalized versions of both
1224
+ * geometries before computing {@link #equalsExact(Geometry)}. This method is
1225
+ * relatively expensive to compute. For maximum performance, the client should
1226
+ * instead perform normalization itself at an appropriate point during
1227
+ * execution.
1228
+ *
1229
+ * @param {Geometry}
1230
+ * g a Geometry.
1231
+ * @return {boolean} true if the input geometries are exactly equal in their
1232
+ * normalized form.
1233
+ */
1234
+ jsts.geom.Geometry.prototype.equalsNorm = function(g) {
1235
+ if (g === null || g === undefined)
1236
+ return false;
1237
+ return this.norm().equalsExact(g.norm());
1238
+ };
1239
+
1240
+
1241
+ /**
1242
+ * Performs an operation with or on this <code>Geometry</code> and its
1243
+ * subelement <code>Geometry</code>s (if any). Only GeometryCollections and
1244
+ * subclasses have subelement Geometry's.
1245
+ *
1246
+ * @param filter
1247
+ * the filter to apply to this <code>Geometry</code> (and its
1248
+ * children, if it is a <code>GeometryCollection</code>).
1249
+ */
1250
+ jsts.geom.Geometry.prototype.apply = function(filter) {
1251
+ throw new jsts.error.AbstractMethodInvocationError();
1252
+ };
1253
+
1254
+ /**
1255
+ * Creates and returns a full copy of this {@link Geometry} object (including
1256
+ * all coordinates contained by it). Subclasses are responsible for overriding
1257
+ * this method and copying their internal data. Overrides should call this
1258
+ * method first.
1259
+ *
1260
+ * @return a clone of this instance.
1261
+ */
1262
+ jsts.geom.Geometry.prototype.clone = function() {
1263
+ throw new jsts.error.AbstractMethodInvocationError();
1264
+ };
1265
+
1266
+
1267
+ /**
1268
+ * Converts this <code>Geometry</code> to <b>normal form</b> (or <b>
1269
+ * canonical form</b> ). Normal form is a unique representation for
1270
+ * <code>Geometry</code> s. It can be used to test whether two
1271
+ * <code>Geometry</code>s are equal in a way that is independent of the
1272
+ * ordering of the coordinates within them. Normal form equality is a stronger
1273
+ * condition than topological equality, but weaker than pointwise equality. The
1274
+ * definitions for normal form use the standard lexicographical ordering for
1275
+ * coordinates. "Sorted in order of coordinates" means the obvious extension of
1276
+ * this ordering to sequences of coordinates.
1277
+ */
1278
+ jsts.geom.Geometry.prototype.normalize = function() {
1279
+ throw new jsts.error.AbstractMethodInvocationError();
1280
+ };
1281
+
1282
+ /**
1283
+ * Creates a new Geometry which is a normalized copy of this Geometry.
1284
+ *
1285
+ * @return a normalized copy of this geometry.
1286
+ * @see #normalize()
1287
+ */
1288
+ jsts.geom.Geometry.prototype.norm = function() {
1289
+ var copy = this.clone();
1290
+ copy.normalize();
1291
+ return copy;
1292
+ };
1293
+
1294
+
1295
+ /**
1296
+ * Returns whether this <code>Geometry</code> is greater than, equal to, or
1297
+ * less than another <code>Geometry</code>.
1298
+ * <P>
1299
+ *
1300
+ * If their classes are different, they are compared using the following
1301
+ * ordering:
1302
+ * <UL>
1303
+ * <LI> Point (lowest)
1304
+ * <LI> MultiPoint
1305
+ * <LI> LineString
1306
+ * <LI> LinearRing
1307
+ * <LI> MultiLineString
1308
+ * <LI> Polygon
1309
+ * <LI> MultiPolygon
1310
+ * <LI> GeometryCollection (highest)
1311
+ * </UL>
1312
+ * If the two <code>Geometry</code>s have the same class, their first
1313
+ * elements are compared. If those are the same, the second elements are
1314
+ * compared, etc.
1315
+ *
1316
+ * @param {Geometry}
1317
+ * other a <code>Geometry</code> with which to compare this
1318
+ * <code>Geometry.</code>
1319
+ * @return {number} a positive number, 0, or a negative number, depending on
1320
+ * whether this object is greater than, equal to, or less than
1321
+ * <code>o</code>, as defined in "Normal Form For Geometry" in the
1322
+ * JTS Technical Specifications.
1323
+ */
1324
+ jsts.geom.Geometry.prototype.compareTo = function(o) {
1325
+ var other = o;
1326
+ if (this.getClassSortIndex() !== other.getClassSortIndex()) {
1327
+ return this.getClassSortIndex() - other.getClassSortIndex();
1328
+ }
1329
+ if (this.isEmpty() && other.isEmpty()) {
1330
+ return 0;
1331
+ }
1332
+ if (this.isEmpty()) {
1333
+ return -1;
1334
+ }
1335
+ if (other.isEmpty()) {
1336
+ return 1;
1337
+ }
1338
+ return this.compareToSameClass(o);
1339
+ };
1340
+
1341
+ /**
1342
+ * Returns whether the two <code>Geometry</code>s are equal, from the point
1343
+ * of view of the <code>equalsExact</code> method. Called by
1344
+ * <code>equalsExact</code> . In general, two <code>Geometry</code> classes
1345
+ * are considered to be "equivalent" only if they are the same class. An
1346
+ * exception is <code>LineString</code> , which is considered to be equivalent
1347
+ * to its subclasses.
1348
+ *
1349
+ * @param {Geometry}
1350
+ * other the <code>Geometry</code> with which to compare this
1351
+ * <code>Geometry</code> for equality.
1352
+ * @return {boolean} <code>true</code> if the classes of the two
1353
+ * <code>Geometry</code> s are considered to be equal by the
1354
+ * <code>equalsExact</code> method.
1355
+ */
1356
+ jsts.geom.Geometry.prototype.isEquivalentClass = function(other) {
1357
+ if (this instanceof jsts.geom.Point && other instanceof jsts.geom.Point) {
1358
+ return true;
1359
+ } else if (this instanceof jsts.geom.LineString &&
1360
+ (other instanceof jsts.geom.LineString | other instanceof jsts.geom.LinearRing)) {
1361
+ return true;
1362
+ } else if (this instanceof jsts.geom.LinearRing &&
1363
+ (other instanceof jsts.geom.LineString | other instanceof jsts.geom.LinearRing)) {
1364
+ return true;
1365
+ } else if (this instanceof jsts.geom.Polygon &&
1366
+ (other instanceof jsts.geom.Polygon)) {
1367
+ return true;
1368
+ } else if (this instanceof jsts.geom.MultiPoint &&
1369
+ (other instanceof jsts.geom.MultiPoint)) {
1370
+ return true;
1371
+ } else if (this instanceof jsts.geom.MultiLineString &&
1372
+ (other instanceof jsts.geom.MultiLineString)) {
1373
+ return true;
1374
+ } else if (this instanceof jsts.geom.MultiPolygon &&
1375
+ (other instanceof jsts.geom.MultiPolygon)) {
1376
+ return true;
1377
+ } else if (this instanceof jsts.geom.GeometryCollection &&
1378
+ (other instanceof jsts.geom.GeometryCollection)) {
1379
+ return true;
1380
+ }
1381
+
1382
+ return false;
1383
+ };
1384
+
1385
+
1386
+
1387
+ /**
1388
+ * Throws an exception if <code>g</code>'s class is
1389
+ * <code>GeometryCollection</code> . (Its subclasses do not trigger an
1390
+ * exception).
1391
+ *
1392
+ * @param {Geometry}
1393
+ * g the <code>Geometry</code> to check.
1394
+ * @throws Error
1395
+ * if <code>g</code> is a <code>GeometryCollection</code> but not
1396
+ * one of its subclasses
1397
+ */
1398
+ jsts.geom.Geometry.prototype.checkNotGeometryCollection = function(g) {
1399
+ if (g.isGeometryCollectionBase()) {
1400
+ throw new jsts.error.IllegalArgumentError(
1401
+ 'This method does not support GeometryCollection');
1402
+ }
1403
+ };
1404
+
1405
+
1406
+ /**
1407
+ *
1408
+ * @return {boolean} true if this is a GeometryCollection.
1409
+ */
1410
+ jsts.geom.Geometry.prototype.isGeometryCollection = function() {
1411
+ return (this instanceof jsts.geom.GeometryCollection);
1412
+ };
1413
+
1414
+ /**
1415
+ *
1416
+ * @return {boolean} true if this is a GeometryCollection but not subclass.
1417
+ */
1418
+ jsts.geom.Geometry.prototype.isGeometryCollectionBase = function() {
1419
+ return (this.CLASS_NAME === 'jsts.geom.GeometryCollection');
1420
+ };
1421
+
1422
+
1423
+ /**
1424
+ * Returns the minimum and maximum x and y values in this <code>Geometry</code>,
1425
+ * or a null <code>Envelope</code> if this <code>Geometry</code> is empty.
1426
+ * Unlike <code>getEnvelopeInternal</code>, this method calculates the
1427
+ * <code>Envelope</code> each time it is called;
1428
+ * <code>getEnvelopeInternal</code> caches the result of this method.
1429
+ *
1430
+ * @return {Envelope} this <code>Geometry</code>s bounding box; if the
1431
+ * <code>Geometry</code> is empty, <code>Envelope#isNull</code> will
1432
+ * return <code>true.</code>
1433
+ */
1434
+ jsts.geom.Geometry.prototype.computeEnvelopeInternal = function() {
1435
+ throw new jsts.error.AbstractMethodInvocationError();
1436
+ };
1437
+
1438
+
1439
+ /**
1440
+ * Returns whether this <code>Geometry</code> is greater than, equal to, or
1441
+ * less than another <code>Geometry</code> having the same class.
1442
+ *
1443
+ * @param o
1444
+ * a <code>Geometry</code> having the same class as this
1445
+ * <code>Geometry.</code>
1446
+ * @return a positive number, 0, or a negative number, depending on whether this
1447
+ * object is greater than, equal to, or less than <code>o</code>, as
1448
+ * defined in "Normal Form For Geometry" in the JTS Technical
1449
+ * Specifications.
1450
+ */
1451
+ jsts.geom.Geometry.prototype.compareToSameClass = function(o) {
1452
+ throw new jsts.error.AbstractMethodInvocationError();
1453
+ };
1454
+
1455
+ /**
1456
+ * Returns the first non-zero result of <code>compareTo</code> encountered as
1457
+ * the two <code>Collection</code>s are iterated over. If, by the time one of
1458
+ * the iterations is complete, no non-zero result has been encountered, returns
1459
+ * 0 if the other iteration is also complete. If <code>b</code> completes
1460
+ * before <code>a</code>, a positive number is returned; if a before b, a
1461
+ * negative number.
1462
+ *
1463
+ * @param {Array}
1464
+ * a a <code>Collection</code> of <code>Comparable</code>s.
1465
+ * @param {Array}
1466
+ * b a <code>Collection</code> of <code>Comparable</code>s.
1467
+ * @return {number} the first non-zero <code>compareTo</code> result, if any;
1468
+ * otherwise, zero.
1469
+ */
1470
+ jsts.geom.Geometry.prototype.compare = function(a, b) {
1471
+ var i = a.iterator();
1472
+ var j = b.iterator();
1473
+ while (i.hasNext() && j.hasNext()) {
1474
+ var aElement = i.next();
1475
+ var bElement = j.next();
1476
+ var comparison = aElement.compareTo(bElement);
1477
+ if (comparison !== 0) {
1478
+ return comparison;
1479
+ }
1480
+ }
1481
+ if (i.hasNext()) {
1482
+ return 1;
1483
+ }
1484
+ if (j.hasNext()) {
1485
+ return -1;
1486
+ }
1487
+ return 0;
1488
+ };
1489
+
1490
+
1491
+ /**
1492
+ * @param {jsts.geom.Coordinate}
1493
+ * a first Coordinate to compare.
1494
+ * @param {jsts.geom.Coordinate}
1495
+ * b second Coordinate to compare.
1496
+ * @param {number}
1497
+ * tolerance tolerance when comparing.
1498
+ * @return {boolean} true if equal.
1499
+ */
1500
+ jsts.geom.Geometry.prototype.equal = function(a, b, tolerance) {
1501
+ if (tolerance === undefined || tolerance === null || tolerance === 0) {
1502
+ return a.equals(b);
1503
+ }
1504
+ return a.distance(b) <= tolerance;
1505
+ };
1506
+
1507
+ /**
1508
+ * @private
1509
+ */
1510
+ jsts.geom.Geometry.prototype.getClassSortIndex = function() {
1511
+ var sortedClasses = [jsts.geom.Point, jsts.geom.MultiPoint,
1512
+ jsts.geom.LineString, jsts.geom.LinearRing, jsts.geom.MultiLineString,
1513
+ jsts.geom.Polygon, jsts.geom.MultiPolygon, jsts.geom.GeometryCollection];
1514
+
1515
+ for (var i = 0; i < sortedClasses.length; i++) {
1516
+ if (this instanceof sortedClasses[i])
1517
+ return i;
1518
+ }
1519
+ jsts.util.Assert.shouldNeverReachHere('Class not supported: ' + this);
1520
+ return -1;
1521
+ };
1522
+
1523
+ jsts.geom.Geometry.prototype.toString = function() {
1524
+ return new jsts.io.WKTWriter().write(this);
1525
+ };
1526
+
1527
+ /**
1528
+ * @return {Point}
1529
+ * @private
1530
+ */
1531
+ jsts.geom.Geometry.prototype.createPointFromInternalCoord = function(coord,
1532
+ exemplar) {
1533
+ exemplar.getPrecisionModel().makePrecise(coord);
1534
+ return exemplar.getFactory().createPoint(coord);
1535
+ };