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,63 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ /**
8
+ * Port source:
9
+ * /jts/jts/java/src/com/vividsolutions/jts/geom/CoordinateSequenceFilter.js
10
+ * Revision: 6
11
+ */
12
+
13
+
14
+ /**
15
+ * Interface for classes which provide operations that can be applied to the
16
+ * coordinates in a {@link CoordinateSequence}. A CoordinateSequence filter can
17
+ * either record information about each coordinate or change the coordinate in
18
+ * some way. CoordinateSequence filters can be used to implement such things as
19
+ * coordinate transformations, centroid and envelope computation, and many other
20
+ * functions. For maximum efficiency, the execution of filters can be
21
+ * short-circuited. {@link Geometry} classes support the concept of applying a
22
+ * <code>CoordinateSequenceFilter</code> to each {@link CoordinateSequence}s
23
+ * they contain.
24
+ * <p>
25
+ * <code>CoordinateSequenceFilter</code> is an example of the Gang-of-Four
26
+ * Visitor pattern.
27
+ *
28
+ * @see Geometry#apply(CoordinateSequenceFilter)
29
+ */
30
+ jsts.geom.CoordinateSequenceFilter = function() {
31
+
32
+ };
33
+
34
+ /**
35
+ * Performs an operation on a coordinate in a {@link CoordinateSequence}.
36
+ *
37
+ * @param seq
38
+ * the <code>CoordinateSequence</code> to which the filter is applied.
39
+ * @param i
40
+ * the index of the coordinate to apply the filter to.
41
+ */
42
+ jsts.geom.CoordinateSequenceFilter.prototype.filter = jsts.abstractFunc;
43
+
44
+ /**
45
+ * Reports whether the application of this filter can be terminated. Once this
46
+ * method returns <tt>false</tt>, it should continue to return <tt>false</tt>
47
+ * on every subsequent call.
48
+ *
49
+ * @return true if the application of this filter can be terminated.
50
+ */
51
+ jsts.geom.CoordinateSequenceFilter.prototype.isDone = jsts.abstractFunc;
52
+
53
+ /**
54
+ * Reports whether the execution of this filter has modified the coordinates of
55
+ * the geometry. If so, {@link Geometry#geometryChanged} will be executed after
56
+ * this filter has finished being executed.
57
+ * <p>
58
+ * Most filters can simply return a constant value reflecting whether they are
59
+ * able to change the coordinates.
60
+ *
61
+ * @return true if this filter has changed the coordinates of the geometry.
62
+ */
63
+ jsts.geom.CoordinateSequenceFilter.prototype.isGeometryChanged = jsts.abstractFunc;
@@ -0,0 +1,137 @@
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
+ * Provides constants representing the dimensions of a point, a curve and a
11
+ * surface. Also provides constants representing the dimensions of the empty
12
+ * geometry and non-empty geometries, and the wildcard constant
13
+ * {@link #DONTCARE} meaning "any dimension". These constants are used as the
14
+ * entries in {@link IntersectionMatrix}s.
15
+ *
16
+ * @constructor
17
+ */
18
+ jsts.geom.Dimension = function() {
19
+ };
20
+
21
+
22
+ /**
23
+ * Dimension value of a point (0).
24
+ *
25
+ * @const
26
+ * @type {number}
27
+ */
28
+ jsts.geom.Dimension.P = 0;
29
+
30
+
31
+ /**
32
+ * Dimension value of a curve (1).
33
+ *
34
+ * @const
35
+ * @type {number}
36
+ */
37
+ jsts.geom.Dimension.L = 1;
38
+
39
+
40
+ /**
41
+ * Dimension value of a surface (2).
42
+ *
43
+ * @const
44
+ * @type {number}
45
+ */
46
+ jsts.geom.Dimension.A = 2;
47
+
48
+
49
+ /**
50
+ * Dimension value of the empty geometry (-1).
51
+ *
52
+ * @const
53
+ * @type {number}
54
+ */
55
+ jsts.geom.Dimension.FALSE = -1;
56
+
57
+
58
+ /**
59
+ * Dimension value of non-empty geometries (= {P, L, A}).
60
+ *
61
+ * @const
62
+ * @type {number}
63
+ */
64
+ jsts.geom.Dimension.TRUE = -2;
65
+
66
+
67
+ /**
68
+ * Dimension value for any dimension (= {FALSE, TRUE}).
69
+ *
70
+ * @const
71
+ * @type {number}
72
+ */
73
+ jsts.geom.Dimension.DONTCARE = -3;
74
+
75
+
76
+ /**
77
+ * Converts the dimension value to a dimension symbol, for example,
78
+ * <code>TRUE => 'T'</code> .
79
+ *
80
+ * @param {number}
81
+ * dimensionValue a number that can be stored in the
82
+ * <code>IntersectionMatrix</code> . Possible values are
83
+ * <code>{TRUE, FALSE, DONTCARE, 0, 1, 2}</code>.
84
+ * @return {String} a character for use in the string representation of an
85
+ * <code>IntersectionMatrix</code>. Possible values are
86
+ * <code>{T, F, * , 0, 1, 2}</code> .
87
+ */
88
+ jsts.geom.Dimension.toDimensionSymbol = function(dimensionValue) {
89
+ switch (dimensionValue) {
90
+ case jsts.geom.Dimension.FALSE:
91
+ return 'F';
92
+ case jsts.geom.Dimension.TRUE:
93
+ return 'T';
94
+ case jsts.geom.Dimension.DONTCARE:
95
+ return '*';
96
+ case jsts.geom.Dimension.P:
97
+ return '0';
98
+ case jsts.geom.Dimension.L:
99
+ return '1';
100
+ case jsts.geom.Dimension.A:
101
+ return '2';
102
+ }
103
+ throw new jsts.IllegalArgumentError('Unknown dimension value: ' +
104
+ dimensionValue);
105
+ };
106
+
107
+
108
+ /**
109
+ * Converts the dimension symbol to a dimension value, for example,
110
+ * <code>'*' => DONTCARE</code> .
111
+ *
112
+ * @param {string}
113
+ * dimensionSymbol a character for use in the string representation of
114
+ * an <code>IntersectionMatrix</code>. Possible values are
115
+ * <code>{T, F, * , 0, 1, 2}</code> .
116
+ * @return {number} a number that can be stored in the
117
+ * <code>IntersectionMatrix</code> . Possible values are
118
+ * <code>{TRUE, FALSE, DONTCARE, 0, 1, 2}</code>.
119
+ */
120
+ jsts.geom.Dimension.toDimensionValue = function(dimensionSymbol) {
121
+ switch (dimensionSymbol.toUpperCase()) {
122
+ case 'F':
123
+ return jsts.geom.Dimension.FALSE;
124
+ case 'T':
125
+ return jsts.geom.Dimension.TRUE;
126
+ case '*':
127
+ return jsts.geom.Dimension.DONTCARE;
128
+ case '0':
129
+ return jsts.geom.Dimension.P;
130
+ case '1':
131
+ return jsts.geom.Dimension.L;
132
+ case '2':
133
+ return jsts.geom.Dimension.A;
134
+ }
135
+ throw new jsts.error.IllegalArgumentError('Unknown dimension symbol: ' +
136
+ dimensionSymbol);
137
+ };
@@ -0,0 +1,833 @@
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
+ * @requires jsts/geom/Coordinate.js
9
+ */
10
+
11
+ /**
12
+ * Defines a rectangular region of the 2D coordinate plane. It is often used to
13
+ * represent the bounding box of a {@link Geometry}, e.g. the minimum and
14
+ * maximum x and y values of the {@link Coordinate}s.
15
+ * <p>
16
+ * Note that Envelopes support infinite or half-infinite regions, by using the
17
+ * values of <code>Double.POSITIVE_INFINITY</code> and
18
+ * <code>Double.NEGATIVE_INFINITY</code>.
19
+ * <p>
20
+ * When Envelope objects are created or initialized, the supplies extent values
21
+ * are automatically sorted into the correct order.
22
+ */
23
+
24
+
25
+
26
+ /**
27
+ * Creates an <code>Envelope</code> for a region defined by maximum and
28
+ * minimum values.
29
+ *
30
+ * @constructor
31
+ */
32
+ jsts.geom.Envelope = function() {
33
+ jsts.geom.Envelope.prototype.init.apply(this, arguments);
34
+ };
35
+
36
+
37
+ /**
38
+ * the minimum x-coordinate
39
+ *
40
+ * @type {?number}
41
+ */
42
+ jsts.geom.Envelope.prototype.minx = null;
43
+
44
+
45
+ /**
46
+ * the maximum x-coordinate
47
+ *
48
+ * @type {?number}
49
+ */
50
+ jsts.geom.Envelope.prototype.maxx = null;
51
+
52
+
53
+ /**
54
+ * the minimum y-coordinate
55
+ *
56
+ * @type {?number}
57
+ */
58
+ jsts.geom.Envelope.prototype.miny = null;
59
+
60
+
61
+ /**
62
+ * the maximum y-coordinate
63
+ *
64
+ * @type {?number}
65
+ */
66
+ jsts.geom.Envelope.prototype.maxy = null;
67
+
68
+
69
+ /**
70
+ * Creates an <code>Envelope</code> for a region defined by maximum and
71
+ * minimum values.
72
+ *
73
+ * Will call appropriate init* method depending on arguments.
74
+ */
75
+ jsts.geom.Envelope.prototype.init = function() {
76
+ if (typeof arguments[0] === 'number' && arguments.length === 4) {
77
+ this.initFromValues(arguments[0], arguments[1], arguments[2], arguments[3]);
78
+ } else if (arguments[0] instanceof jsts.geom.Coordinate &&
79
+ arguments.length === 1) {
80
+ this.initFromCoordinate(arguments[0]);
81
+ } else if (arguments[0] instanceof jsts.geom.Coordinate &&
82
+ arguments.length === 2) {
83
+ this.initFromCoordinates(arguments[0], arguments[1]);
84
+ } else if (arguments[0] instanceof jsts.geom.Envelope &&
85
+ arguments.length === 1) {
86
+ this.initFromEnvelope(arguments[0]);
87
+ } else {
88
+ this.setToNull();
89
+ }
90
+ };
91
+
92
+
93
+ /**
94
+ * Initialize an <code>Envelope</code> for a region defined by maximum and
95
+ * minimum values.
96
+ *
97
+ * @param {number}
98
+ * x1 the first x-value.
99
+ * @param {number}
100
+ * x2 the second x-value.
101
+ * @param {number}
102
+ * y1 the first y-value.
103
+ * @param {number}
104
+ * y2 the second y-value.
105
+ */
106
+ jsts.geom.Envelope.prototype.initFromValues = function(x1, x2, y1, y2) {
107
+ if (x1 < x2) {
108
+ this.minx = x1;
109
+ this.maxx = x2;
110
+ } else {
111
+ this.minx = x2;
112
+ this.maxx = x1;
113
+ }
114
+ if (y1 < y2) {
115
+ this.miny = y1;
116
+ this.maxy = y2;
117
+ } else {
118
+ this.miny = y2;
119
+ this.maxy = y1;
120
+ }
121
+ };
122
+
123
+
124
+ /**
125
+ * Initialize an <code>Envelope</code> to a region defined by two Coordinates.
126
+ *
127
+ * @param {jsts.geom.Coordinate}
128
+ * p1 the first Coordinate.
129
+ * @param {jsts.geom.Coordinate}
130
+ * p2 the second Coordinate.
131
+ */
132
+ jsts.geom.Envelope.prototype.initFromCoordinates = function(p1, p2) {
133
+ this.initFromValues(p1.x, p2.x, p1.y, p2.y);
134
+ };
135
+
136
+
137
+ /**
138
+ * Initialize an <code>Envelope</code> to a region defined by a single
139
+ * Coordinate.
140
+ *
141
+ * @param {jsts.geom.Coordinate}
142
+ * p the Coordinate.
143
+ */
144
+ jsts.geom.Envelope.prototype.initFromCoordinate = function(p) {
145
+ this.initFromValues(p.x, p.x, p.y, p.y);
146
+ };
147
+
148
+
149
+ /**
150
+ * Initialize an <code>Envelope</code> from an existing Envelope.
151
+ *
152
+ * @param {jsts.geom.Envelope}
153
+ * env the Envelope to initialize from.
154
+ */
155
+ jsts.geom.Envelope.prototype.initFromEnvelope = function(env) {
156
+ this.minx = env.minx;
157
+ this.maxx = env.maxx;
158
+ this.miny = env.miny;
159
+ this.maxy = env.maxy;
160
+ };
161
+
162
+
163
+ /**
164
+ * Makes this <code>Envelope</code> a "null" envelope, that is, the envelope
165
+ * of the empty geometry.
166
+ */
167
+ jsts.geom.Envelope.prototype.setToNull = function() {
168
+ this.minx = 0;
169
+ this.maxx = -1;
170
+ this.miny = 0;
171
+ this.maxy = -1;
172
+ };
173
+
174
+
175
+ /**
176
+ * Returns <code>true</code> if this <code>Envelope</code> is a "null"
177
+ * envelope.
178
+ *
179
+ * @return {boolean} <code>true</code> if this <code>Envelope</code> is
180
+ * uninitialized or is the envelope of the empty geometry.
181
+ */
182
+ jsts.geom.Envelope.prototype.isNull = function() {
183
+ return this.maxx < this.minx;
184
+ };
185
+
186
+
187
+ /**
188
+ * Returns the difference between the maximum and minimum y values.
189
+ *
190
+ * @return {number} max y - min y, or 0 if this is a null <code>Envelope.</code>
191
+ */
192
+ jsts.geom.Envelope.prototype.getHeight = function() {
193
+ if (this.isNull()) {
194
+ return 0;
195
+ }
196
+ return this.maxy - this.miny;
197
+ };
198
+
199
+
200
+ /**
201
+ * Returns the difference between the maximum and minimum x values.
202
+ *
203
+ * @return {number} max x - min x, or 0 if this is a null <code>Envelope.</code>
204
+ */
205
+ jsts.geom.Envelope.prototype.getWidth = function() {
206
+ if (this.isNull()) {
207
+ return 0;
208
+ }
209
+ return this.maxx - this.minx;
210
+ };
211
+
212
+
213
+ /**
214
+ * Returns the <code>Envelope</code>s minimum x-value. min x > max x
215
+ * indicates that this is a null <code>Envelope</code>.
216
+ *
217
+ * @return {number} the minimum x-coordinate.
218
+ */
219
+ jsts.geom.Envelope.prototype.getMinX = function() {
220
+ return this.minx;
221
+ };
222
+
223
+
224
+ /**
225
+ * Returns the <code>Envelope</code>s maximum x-value. min x > max x
226
+ * indicates that this is a null <code>Envelope</code>.
227
+ *
228
+ * @return {number} the maximum x-coordinate.
229
+ */
230
+ jsts.geom.Envelope.prototype.getMaxX = function() {
231
+ return this.maxx;
232
+ };
233
+
234
+
235
+ /**
236
+ * Returns the <code>Envelope</code>s minimum y-value. min y > max y
237
+ * indicates that this is a null <code>Envelope</code>.
238
+ *
239
+ * @return {number} the minimum y-coordinate.
240
+ */
241
+ jsts.geom.Envelope.prototype.getMinY = function() {
242
+ return this.miny;
243
+ };
244
+
245
+
246
+ /**
247
+ * Returns the <code>Envelope</code>s maximum y-value. min y > max y
248
+ * indicates that this is a null <code>Envelope</code>.
249
+ *
250
+ * @return {number} the maximum y-coordinate.
251
+ */
252
+ jsts.geom.Envelope.prototype.getMaxY = function() {
253
+ return this.maxy;
254
+ };
255
+
256
+
257
+ /**
258
+ * Gets the area of this envelope.
259
+ *
260
+ * @return {number} the area of the envelope, 0.0 if the envelope is null.
261
+ */
262
+ jsts.geom.Envelope.prototype.getArea = function() {
263
+ return this.getWidth() * this.getHeight();
264
+ };
265
+
266
+
267
+ /**
268
+ * Enlarges this <code>Envelope</code>
269
+ *
270
+ * Will call appropriate expandToInclude* depending on arguments.
271
+ */
272
+ jsts.geom.Envelope.prototype.expandToInclude = function() {
273
+ if (arguments[0] instanceof jsts.geom.Coordinate) {
274
+ this.expandToIncludeCoordinate(arguments[0]);
275
+ } else if (arguments[0] instanceof jsts.geom.Envelope) {
276
+ this.expandToIncludeEnvelope(arguments[0]);
277
+ } else {
278
+ this.expandToIncludeValues(arguments[0], arguments[1]);
279
+ }
280
+ };
281
+
282
+
283
+ /**
284
+ * Enlarges this <code>Envelope</code> so that it contains the given
285
+ * {@link Coordinate}. Has no effect if the point is already on or within the
286
+ * envelope.
287
+ *
288
+ * @param {jsts.geom.Coordinate}
289
+ * p the Coordinate to expand to include.
290
+ */
291
+ jsts.geom.Envelope.prototype.expandToIncludeCoordinate = function(p) {
292
+ this.expandToIncludeValues(p.x, p.y);
293
+ };
294
+
295
+
296
+ /**
297
+ * Enlarges this <code>Envelope</code> so that it contains the given point.
298
+ * Has no effect if the point is already on or within the envelope.
299
+ *
300
+ * @param {number}
301
+ * x the value to lower the minimum x to or to raise the maximum x to.
302
+ * @param {number}
303
+ * y the value to lower the minimum y to or to raise the maximum y to.
304
+ */
305
+ jsts.geom.Envelope.prototype.expandToIncludeValues = function(x, y) {
306
+ if (this.isNull()) {
307
+ this.minx = x;
308
+ this.maxx = x;
309
+ this.miny = y;
310
+ this.maxy = y;
311
+ } else {
312
+ if (x < this.minx) {
313
+ this.minx = x;
314
+ }
315
+ if (x > this.maxx) {
316
+ this.maxx = x;
317
+ }
318
+ if (y < this.miny) {
319
+ this.miny = y;
320
+ }
321
+ if (y > this.maxy) {
322
+ this.maxy = y;
323
+ }
324
+ }
325
+ };
326
+
327
+
328
+ /**
329
+ * Enlarges this <code>Envelope</code> so that it contains the
330
+ * <code>other</code> Envelope. Has no effect if <code>other</code> is
331
+ * wholly on or within the envelope.
332
+ *
333
+ * @param {jsts.geom.Envelope}
334
+ * other the <code>Envelope</code> to expand to include.
335
+ */
336
+ jsts.geom.Envelope.prototype.expandToIncludeEnvelope = function(other) {
337
+ if (other.isNull()) {
338
+ return;
339
+ }
340
+ if (this.isNull()) {
341
+ this.minx = other.getMinX();
342
+ this.maxx = other.getMaxX();
343
+ this.miny = other.getMinY();
344
+ this.maxy = other.getMaxY();
345
+ } else {
346
+ if (other.minx < this.minx) {
347
+ this.minx = other.minx;
348
+ }
349
+ if (other.maxx > this.maxx) {
350
+ this.maxx = other.maxx;
351
+ }
352
+ if (other.miny < this.miny) {
353
+ this.miny = other.miny;
354
+ }
355
+ if (other.maxy > this.maxy) {
356
+ this.maxy = other.maxy;
357
+ }
358
+ }
359
+ };
360
+
361
+
362
+ /**
363
+ * Enlarges this <code>Envelope</code>
364
+ *
365
+ * Will call appropriate expandBy* depending on arguments.
366
+ */
367
+ jsts.geom.Envelope.prototype.expandBy = function() {
368
+ if (arguments.length === 1) {
369
+ this.expandByDistance(arguments[0]);
370
+ } else {
371
+ this.expandByDistances(arguments[0], arguments[1]);
372
+ }
373
+ };
374
+
375
+
376
+ /**
377
+ * Expands this envelope by a given distance in all directions. Both positive
378
+ * and negative distances are supported.
379
+ *
380
+ * @param {number}
381
+ * distance the distance to expand the envelope.
382
+ */
383
+ jsts.geom.Envelope.prototype.expandByDistance = function(distance) {
384
+ this.expandByDistances(distance, distance);
385
+ };
386
+
387
+
388
+ /**
389
+ * Expands this envelope by a given distance in all directions. Both positive
390
+ * and negative distances are supported.
391
+ *
392
+ * @param {number}
393
+ * deltaX the distance to expand the envelope along the the X axis.
394
+ * @param {number}
395
+ * deltaY the distance to expand the envelope along the the Y axis.
396
+ */
397
+ jsts.geom.Envelope.prototype.expandByDistances = function(deltaX, deltaY) {
398
+ if (this.isNull()) {
399
+ return;
400
+ }
401
+
402
+ this.minx -= deltaX;
403
+ this.maxx += deltaX;
404
+ this.miny -= deltaY;
405
+ this.maxy += deltaY;
406
+
407
+ // check for envelope disappearing
408
+ if (this.minx > this.maxx || this.miny > this.maxy) {
409
+ this.setToNull();
410
+ }
411
+ };
412
+
413
+
414
+ /**
415
+ * Translates this envelope by given amounts in the X and Y direction.
416
+ *
417
+ * @param {number}
418
+ * transX the amount to translate along the X axis.
419
+ * @param {number}
420
+ * transY the amount to translate along the Y axis.
421
+ */
422
+ jsts.geom.Envelope.prototype.translate = function(transX, transY) {
423
+ if (this.isNull()) {
424
+ return;
425
+ }
426
+ this.init(this.minx + transX, this.maxx + transX, this.miny + transY,
427
+ this.maxy + transY);
428
+ };
429
+
430
+
431
+ /**
432
+ * Computes the coordinate of the centre of this envelope (as long as it is
433
+ * non-null
434
+ *
435
+ * @return {jsts.geom.Coordinate} the centre coordinate of this envelope <code>null</code>
436
+ * if the envelope is null.
437
+ */
438
+ jsts.geom.Envelope.prototype.centre = function() {
439
+ if (this.isNull()) {
440
+ return null;
441
+ }
442
+ return new jsts.geom.Coordinate((this.minx + this.maxx) / 2.0,
443
+ (this.miny + this.maxy) / 2.0);
444
+ };
445
+
446
+
447
+ /**
448
+ * Computes the intersection of two {@link Envelopes}
449
+ *
450
+ * @param {jsts.geom.Envelope}
451
+ * env the envelope to intersect with.
452
+ * @return {jsts.geom.Envelope} a new Envelope representing the intersection of
453
+ * the envelopes (this will be the null envelope if either argument is
454
+ * null, or they do not intersect.
455
+ */
456
+ jsts.geom.Envelope.prototype.intersection = function(env) {
457
+ if (this.isNull() || env.isNull() || !this.intersects(env)) {
458
+ return new jsts.geom.Envelope();
459
+ }
460
+
461
+ var intMinX = this.minx > env.minx ? this.minx : env.minx;
462
+ var intMinY = this.miny > env.miny ? this.miny : env.miny;
463
+ var intMaxX = this.maxx < env.maxx ? this.maxx : env.maxx;
464
+ var intMaxY = this.maxy < env.maxy ? this.maxy : env.maxy;
465
+
466
+ return new jsts.geom.Envelope(intMinX, intMaxX, intMinY, intMaxY);
467
+ };
468
+
469
+
470
+ /**
471
+ * Check if the region defined by input overlaps (intersects) the region of this
472
+ * <code>Envelope</code>.
473
+ *
474
+ * Will call appropriate intersects* depending on arguments.
475
+ *
476
+ * @return {boolean} <code>true</code> if an overlap is found.
477
+ */
478
+ jsts.geom.Envelope.prototype.intersects = function() {
479
+ if (arguments[0] instanceof jsts.geom.Envelope) {
480
+ return this.intersectsEnvelope(arguments[0]);
481
+ } else if (arguments[0] instanceof jsts.geom.Coordinate) {
482
+ return this.intersectsCoordinate(arguments[0]);
483
+ } else {
484
+ return this.intersectsValues(arguments[0], arguments[1]);
485
+ }
486
+ };
487
+
488
+
489
+ /**
490
+ * Check if the region defined by <code>other</code> overlaps (intersects) the
491
+ * region of this <code>Envelope</code>.
492
+ *
493
+ * @param {jsts.geom.Envelope}
494
+ * other the <code>Envelope</code> which this <code>Envelope</code>
495
+ * is being checked for overlapping.
496
+ * @return {boolean} <code>true</code> if the <code>Envelope</code>s
497
+ * overlap.
498
+ */
499
+ jsts.geom.Envelope.prototype.intersectsEnvelope = function(other) {
500
+ if (this.isNull() || other.isNull()) {
501
+ return false;
502
+ }
503
+
504
+ var result = !(other.minx > this.maxx || other.maxx < this.minx ||
505
+ other.miny > this.maxy || other.maxy < this.miny);
506
+ return result;
507
+ };
508
+
509
+
510
+ /**
511
+ * Check if the point <code>p</code> overlaps (lies inside) the region of this
512
+ * <code>Envelope</code>.
513
+ *
514
+ * @param {jsts.geom.Coordinate}
515
+ * p the <code>Coordinate</code> to be tested.
516
+ * @return {boolean} <code>true</code> if the point overlaps this
517
+ * <code>Envelope.</code>
518
+ */
519
+ jsts.geom.Envelope.prototype.intersectsCoordinate = function(p) {
520
+ return this.intersectsValues(p.x, p.y);
521
+ };
522
+
523
+
524
+ /**
525
+ * Check if the point <code>(x, y)</code> overlaps (lies inside) the region of
526
+ * this <code>Envelope</code>.
527
+ *
528
+ * @param {number}
529
+ * x the x-ordinate of the point.
530
+ * @param {number}
531
+ * y the y-ordinate of the point.
532
+ * @return {boolean} <code>true</code> if the point overlaps this
533
+ * <code>Envelope.</code>
534
+ */
535
+ jsts.geom.Envelope.prototype.intersectsValues = function(x, y) {
536
+ if (this.isNull()) {
537
+ return false;
538
+ }
539
+
540
+ return !(x > this.maxx || x < this.minx || y > this.maxy || y < this.miny);
541
+ };
542
+
543
+
544
+ /**
545
+ * Tests if the input lies wholely inside this <code>Envelope</code>
546
+ * (inclusive of the boundary).
547
+ *
548
+ * Will call appropriate contains* depending on arguments.
549
+ *
550
+ * @return {boolean} true if input is contained in this <code>Envelope.</code>
551
+ */
552
+ jsts.geom.Envelope.prototype.contains = function() {
553
+ if (arguments[0] instanceof jsts.geom.Envelope) {
554
+ return this.containsEnvelope(arguments[0]);
555
+ } else if (arguments[0] instanceof jsts.geom.Coordinate) {
556
+ return this.containsCoordinate(arguments[0]);
557
+ } else {
558
+ return this.containsValues(arguments[0], arguments[1]);
559
+ }
560
+ };
561
+
562
+
563
+ /**
564
+ * Tests if the <code>Envelope other</code> lies wholely inside this
565
+ * <code>Envelope</code> (inclusive of the boundary).
566
+ * <p>
567
+ * Note that this is <b>not</b> the same definition as the SFS
568
+ * <tt>contains</tt>, which would exclude the envelope boundary.
569
+ *
570
+ * @param {jsts.geom.Envelope}
571
+ * other the <code>Envelope</code> to check.
572
+ * @return {boolean} true if <code>other</code> is contained in this
573
+ * <code>Envelope.</code>
574
+ *
575
+ * @see covers(Envelope)
576
+ */
577
+ jsts.geom.Envelope.prototype.containsEnvelope = function(other) {
578
+ return this.coversEnvelope(other);
579
+ };
580
+
581
+
582
+ /**
583
+ * Tests if the given point lies in or on the envelope.
584
+ * <p>
585
+ * Note that this is <b>not</b> the same definition as the SFS
586
+ * <tt>contains</tt>, which would exclude the envelope boundary.
587
+ *
588
+ * @param {jsts.geom.Coordinate}
589
+ * p the point which this <code>Envelope</code> is being checked for
590
+ * containing.
591
+ * @return {boolean} <code>true</code> if the point lies in the interior or on
592
+ * the boundary of this <code>Envelope</code>.
593
+ *
594
+ * @see covers(Coordinate)
595
+ */
596
+ jsts.geom.Envelope.prototype.containsCoordinate = function(p) {
597
+ return this.coversCoordinate(p);
598
+ };
599
+
600
+
601
+ /**
602
+ * Tests if the given point lies in or on the envelope.
603
+ * <p>
604
+ * Note that this is <b>not</b> the same definition as the SFS
605
+ * <tt>contains</tt>, which would exclude the envelope boundary.
606
+ *
607
+ * @param {number}
608
+ * x the x-coordinate of the point which this <code>Envelope</code>
609
+ * is being checked for containing.
610
+ * @param {number}
611
+ * y the y-coordinate of the point which this <code>Envelope</code>
612
+ * is being checked for containing.
613
+ * @return {boolean} <code>true</code> if <code>(x, y)</code> lies in the
614
+ * interior or on the boundary of this <code>Envelope</code>.
615
+ *
616
+ * @see covers(double, double)
617
+ */
618
+ jsts.geom.Envelope.prototype.containsValues = function(x, y) {
619
+ return this.coversValues(x, y);
620
+ };
621
+
622
+
623
+ /**
624
+ * Tests if the given point lies in or on the envelope.
625
+ *
626
+ * Will call appropriate contains* depending on arguments.
627
+ */
628
+ jsts.geom.Envelope.prototype.covers = function() {
629
+ if (p instanceof jsts.geom.Envelope) {
630
+ this.coversEnvelope(arguments[0]);
631
+ } else if (p instanceof jsts.geom.Coordinate) {
632
+ this.coversCoordinate(arguments[0]);
633
+ } else {
634
+ this.coversValues(arguments[0], arguments[1]);
635
+ }
636
+ };
637
+
638
+
639
+ /**
640
+ * Tests if the given point lies in or on the envelope.
641
+ *
642
+ * @param {number}
643
+ * x the x-coordinate of the point which this <code>Envelope</code>
644
+ * is being checked for containing.
645
+ * @param {number}
646
+ * y the y-coordinate of the point which this <code>Envelope</code>
647
+ * is being checked for containing.
648
+ * @return {boolean} <code>true</code> if <code>(x, y)</code> lies in the
649
+ * interior or on the boundary of this <code>Envelope</code>.
650
+ */
651
+ jsts.geom.Envelope.prototype.coversValues = function(x, y) {
652
+ if (this.isNull()) {
653
+ return false;
654
+ }
655
+ return x >= this.minx && x <= this.maxx && y >= this.miny && y <= this.maxy;
656
+ };
657
+
658
+
659
+ /**
660
+ * Tests if the given point lies in or on the envelope.
661
+ *
662
+ * @param {jsts.geom.Coordinate}
663
+ * p the point which this <code>Envelope</code> is being checked for
664
+ * containing.
665
+ * @return {boolean} <code>true</code> if the point lies in the interior or on
666
+ * the boundary of this <code>Envelope</code>.
667
+ */
668
+ jsts.geom.Envelope.prototype.coversCoordinate = function(p) {
669
+ return this.coversValues(p.x, p.y);
670
+ };
671
+
672
+
673
+ /**
674
+ * Tests if the <code>Envelope other</code> lies wholely inside this
675
+ * <code>Envelope</code> (inclusive of the boundary).
676
+ *
677
+ * @param {jsts.geom.Envelope}
678
+ * other the <code>Envelope</code> to check.
679
+ * @return {boolean} true if this <code>Envelope</code> covers the
680
+ * <code>other.</code>
681
+ */
682
+ jsts.geom.Envelope.prototype.coversEnvelope = function(other) {
683
+ if (this.isNull() || other.isNull()) {
684
+ return false;
685
+ }
686
+ return other.minx >= this.minx && other.maxx <= this.maxx &&
687
+ other.miny >= this.miny && other.maxy <= this.maxy;
688
+ };
689
+
690
+
691
+ /**
692
+ * Computes the distance between this and another <code>Envelope</code>.
693
+ *
694
+ * @param {jsts.geom.Envelope}
695
+ * env The <code>Envelope</code> to test this <code>Envelope</code>
696
+ * against.
697
+ * @return {number} The distance between overlapping Envelopes is 0. Otherwise,
698
+ * the distance is the Euclidean distance between the closest points.
699
+ */
700
+ jsts.geom.Envelope.prototype.distance = function(env) {
701
+ if (this.intersects(env)) {
702
+ return 0;
703
+ }
704
+ var dx = 0.0;
705
+ if (this.maxx < env.minx) {
706
+ dx = env.minx - this.maxx;
707
+ }
708
+ if (this.minx > env.maxx) {
709
+ dx = this.minx - env.maxx;
710
+ }
711
+
712
+ var dy = 0.0;
713
+ if (this.maxy < env.miny) {
714
+ dy = env.miny - this.maxy;
715
+ }
716
+ if (this.miny > env.maxy) {
717
+ dy = this.miny - env.maxy;
718
+ }
719
+
720
+ // if either is zero, the envelopes overlap either vertically or horizontally
721
+ if (dx === 0.0) {
722
+ return dy;
723
+ }
724
+ if (dy === 0.0) {
725
+ return dx;
726
+ }
727
+ return Math.sqrt(dx * dx + dy * dy);
728
+ };
729
+
730
+
731
+ /**
732
+ * @param {jsts.geom.Envelope}
733
+ * other the <code>Envelope</code> to check against.
734
+ * @return {boolean} true if envelopes are equal.
735
+ */
736
+ jsts.geom.Envelope.prototype.equals = function(other) {
737
+ if (this.isNull()) {
738
+ return other.isNull();
739
+ }
740
+ return this.maxx === other.maxx && this.maxy === other.maxy &&
741
+ this.minx === other.minx && this.miny === other.miny;
742
+ };
743
+
744
+
745
+ /**
746
+ * @return {string} String representation of this <code>Envelope.</code>
747
+ */
748
+ jsts.geom.Envelope.prototype.toString = function() {
749
+ return 'Env[' + this.minx + ' : ' + this.maxx + ', ' + this.miny + ' : ' +
750
+ this.maxy + ']';
751
+ };
752
+
753
+
754
+ /**
755
+ * Test the point q to see whether it intersects the Envelope defined by p1-p2
756
+ *
757
+ * NOTE: calls intersectsEnvelope if four arguments are given to simulate
758
+ * overloaded function
759
+ *
760
+ * @param {jsts.geom.Coordinate}
761
+ * p1 one extremal point of the envelope.
762
+ * @param {jsts.geom.Coordinate}
763
+ * p2 another extremal point of the envelope.
764
+ * @param {jsts.geom.Coordinate}
765
+ * q the point to test for intersection.
766
+ * @return {boolean} <code>true</code> if q intersects the envelope p1-p2.
767
+ */
768
+ jsts.geom.Envelope.intersects = function(p1, p2, q) {
769
+ if (arguments.length === 4) {
770
+ return jsts.geom.Envelope.intersectsEnvelope(arguments[0], arguments[1],
771
+ arguments[2], arguments[3]);
772
+ }
773
+
774
+ var xc1 = p1.x < p2.x ? p1.x : p2.x;
775
+ var xc2 = p1.x > p2.x ? p1.x : p2.x;
776
+ var yc1 = p1.y < p2.y ? p1.y : p2.y;
777
+ var yc2 = p1.y > p2.y ? p1.y : p2.y;
778
+
779
+ if (((q.x >= xc1) && (q.x <= xc2)) && ((q.y >= yc1) && (q.y <= yc2))) {
780
+ return true;
781
+ }
782
+ return false;
783
+ };
784
+
785
+
786
+ /**
787
+ * Test the envelope defined by p1-p2 for intersection with the envelope defined
788
+ * by q1-q2
789
+ *
790
+ * @param {jsts.geom.Coordinate}
791
+ * p1 one extremal point of the envelope P.
792
+ * @param {jsts.geom.Coordinate}
793
+ * p2 another extremal point of the envelope P.
794
+ * @param {jsts.geom.Coordinate}
795
+ * q1 one extremal point of the envelope Q.
796
+ * @param {jsts.geom.Coordinate}
797
+ * q2 another extremal point of the envelope Q.
798
+ * @return {boolean} <code>true</code> if Q intersects P.
799
+ */
800
+ jsts.geom.Envelope.intersectsEnvelope = function(p1, p2, q1, q2) {
801
+ var minq = Math.min(q1.x, q2.x);
802
+ var maxq = Math.max(q1.x, q2.x);
803
+ var minp = Math.min(p1.x, p2.x);
804
+ var maxp = Math.max(p1.x, p2.x);
805
+
806
+ if (minp > maxq) {
807
+ return false;
808
+ }
809
+ if (maxp < minq) {
810
+ return false;
811
+ }
812
+
813
+ minq = Math.min(q1.y, q2.y);
814
+ maxq = Math.max(q1.y, q2.y);
815
+ minp = Math.min(p1.y, p2.y);
816
+ maxp = Math.max(p1.y, p2.y);
817
+
818
+ if (minp > maxq) {
819
+ return false;
820
+ }
821
+ if (maxp < minq) {
822
+ return false;
823
+ }
824
+ return true;
825
+ };
826
+
827
+
828
+ /**
829
+ * @return {jsts.geom.Envelope} A new instance copied from this.
830
+ */
831
+ jsts.geom.Envelope.prototype.clone = function() {
832
+ return new jsts.geom.Envelope(this.minx, this.maxx, this.miny, this.maxy);
833
+ };