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,230 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ (function() {
8
+
9
+ /**
10
+ * @requires jsts/geom/Geometry.js
11
+ */
12
+
13
+ var Geometry = jsts.geom.Geometry;
14
+ var TreeSet = javascript.util.TreeSet;
15
+ var Arrays = javascript.util.Arrays;
16
+
17
+ /**
18
+ * @constructor
19
+ * @extends jsts.geom.Geometry
20
+ */
21
+ jsts.geom.GeometryCollection = function(geometries, factory) {
22
+ this.geometries = geometries || [];
23
+ this.factory = factory;
24
+ };
25
+
26
+ jsts.geom.GeometryCollection.prototype = new Geometry();
27
+ jsts.geom.GeometryCollection.constructor = jsts.geom.GeometryCollection;
28
+
29
+ /**
30
+ * @return {boolean}
31
+ */
32
+ jsts.geom.GeometryCollection.prototype.isEmpty = function() {
33
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
34
+ var geometry = this.getGeometryN(i);
35
+
36
+ if (!geometry.isEmpty()) {
37
+ return false;
38
+ }
39
+ }
40
+ return true;
41
+ };
42
+
43
+ jsts.geom.Geometry.prototype.getArea = function() {
44
+ var area = 0.0;
45
+
46
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
47
+ area += this.getGeometryN(i).getArea();
48
+ }
49
+
50
+ return area;
51
+ };
52
+
53
+ jsts.geom.Geometry.prototype.getLength = function() {
54
+ var length = 0.0;
55
+
56
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
57
+ length += this.getGeometryN(i).getLength();
58
+ }
59
+
60
+ return length;
61
+ };
62
+
63
+
64
+ /**
65
+ * @return {Coordinate}
66
+ */
67
+ jsts.geom.GeometryCollection.prototype.getCoordinate = function() {
68
+ if (this.isEmpty())
69
+ return null;
70
+
71
+ return this.getGeometryN(0).getCoordinate();
72
+ };
73
+
74
+
75
+ /**
76
+ * Collects all coordinates of all subgeometries into an Array.
77
+ *
78
+ * Note that while changes to the coordinate objects themselves may modify the
79
+ * Geometries in place, the returned Array as such is only a temporary
80
+ * container which is not synchronized back.
81
+ *
82
+ * @return {Coordinate[]} the collected coordinates.
83
+ */
84
+ jsts.geom.GeometryCollection.prototype.getCoordinates = function() {
85
+ var coordinates = [];
86
+ var k = -1;
87
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
88
+ var geometry = this.getGeometryN(i);
89
+
90
+ var childCoordinates = geometry.getCoordinates();
91
+ for (var j = 0; j < childCoordinates.length; j++) {
92
+ k++;
93
+ coordinates[k] = childCoordinates[j];
94
+ }
95
+ }
96
+ return coordinates;
97
+ };
98
+
99
+
100
+ /**
101
+ * @return {int}
102
+ */
103
+ jsts.geom.GeometryCollection.prototype.getNumGeometries = function() {
104
+ return this.geometries.length;
105
+ };
106
+
107
+
108
+ /**
109
+ * @param {int}
110
+ * n
111
+ * @return {Geometry}
112
+ */
113
+ jsts.geom.GeometryCollection.prototype.getGeometryN = function(n) {
114
+ var geometry = this.geometries[n];
115
+ if (geometry instanceof jsts.geom.Coordinate) {
116
+ geometry = new jsts.geom.Point(geometry);
117
+ }
118
+ return geometry;
119
+ };
120
+
121
+
122
+ /**
123
+ * @param {Geometry}
124
+ * other
125
+ * @param {double}
126
+ * tolerance
127
+ * @return {boolean}
128
+ */
129
+ jsts.geom.GeometryCollection.prototype.equalsExact = function(other,
130
+ tolerance) {
131
+ if (!this.isEquivalentClass(other)) {
132
+ return false;
133
+ }
134
+ if (this.geometries.length !== other.geometries.length) {
135
+ return false;
136
+ }
137
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
138
+ var geometry = this.getGeometryN(i);
139
+
140
+ if (!geometry.equalsExact(other.getGeometryN(i), tolerance)) {
141
+ return false;
142
+ }
143
+ }
144
+ return true;
145
+ };
146
+
147
+ /**
148
+ * Creates and returns a full copy of this {@link GeometryCollection} object.
149
+ * (including all coordinates contained by it).
150
+ *
151
+ * @return a clone of this instance.
152
+ */
153
+ jsts.geom.GeometryCollection.prototype.clone = function() {
154
+ var geometries = [];
155
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
156
+ geometries.push(this.geometries[i].clone());
157
+ }
158
+ return this.factory.createGeometryCollection(geometries);
159
+ };
160
+
161
+ jsts.geom.GeometryCollection.prototype.normalize = function() {
162
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
163
+ this.getGeometryN(i).normalize();
164
+ }
165
+ // TODO: might need to supply comparison function
166
+ this.geometries.sort();
167
+ };
168
+
169
+ jsts.geom.GeometryCollection.prototype.compareToSameClass = function(o) {
170
+ var theseElements = new TreeSet(Arrays.asList(this.geometries));
171
+ var otherElements = new TreeSet(Arrays.asList(o.geometries));
172
+ return this.compare(theseElements, otherElements);
173
+ };
174
+
175
+ jsts.geom.GeometryCollection.prototype.apply = function(filter) {
176
+ if (filter instanceof jsts.geom.GeometryFilter ||
177
+ filter instanceof jsts.geom.GeometryComponentFilter) {
178
+ filter.filter(this);
179
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
180
+ this.getGeometryN(i).apply(filter);
181
+ }
182
+ } else if (filter instanceof jsts.geom.CoordinateFilter) {
183
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
184
+ this.getGeometryN(i).apply(filter);
185
+ }
186
+ } else if (filter instanceof jsts.geom.CoordinateSequenceFilter) {
187
+ this.apply2.apply(this, arguments);
188
+ }
189
+ };
190
+
191
+ jsts.geom.GeometryCollection.prototype.apply2 = function(filter) {
192
+ if (this.geometries.length == 0)
193
+ return;
194
+ for (var i = 0; i < this.geometries.length; i++) {
195
+ this.geometries[i].apply(filter);
196
+ if (filter.isDone()) {
197
+ break;
198
+ }
199
+ }
200
+ if (filter.isGeometryChanged()) {
201
+ // TODO: call this.geometryChanged(); when ported
202
+ }
203
+ };
204
+
205
+ jsts.geom.GeometryCollection.prototype.getDimension = function() {
206
+ var dimension = jsts.geom.Dimension.FALSE;
207
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
208
+ var geometry = this.getGeometryN(i);
209
+ dimension = Math.max(dimension, geometry.getDimension());
210
+ }
211
+ return dimension;
212
+ };
213
+
214
+ /**
215
+ * @protected
216
+ */
217
+ jsts.geom.GeometryCollection.prototype.computeEnvelopeInternal = function() {
218
+ var envelope = new jsts.geom.Envelope();
219
+ for (var i = 0, len = this.geometries.length; i < len; i++) {
220
+ var geometry = this.getGeometryN(i);
221
+ envelope.expandToInclude(geometry.getEnvelopeInternal());
222
+ }
223
+ return envelope;
224
+ };
225
+
226
+ jsts.geom.GeometryCollection.prototype.CLASS_NAME = 'jsts.geom.GeometryCollection';
227
+
228
+ })();
229
+
230
+ // TODO: port rest
@@ -0,0 +1,36 @@
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
+ * <code>Geometry</code> classes support the concept of applying a
10
+ * <code>GeometryComponentFilter</code> filter to the <code>Geometry</code>.
11
+ * The filter is applied to every component of the <code>Geometry</code> which
12
+ * is itself a <code>Geometry</code> and which does not itself contain any
13
+ * components. (For instance, all the {@link LinearRing}s in {@link Polygon}s
14
+ * are visited, but in a {@link MultiPolygon} the {@link Polygon}s themselves
15
+ * are not visited.) Thus the only classes of Geometry which must be handled as
16
+ * arguments to {@link #filter} are {@link LineString}s, {@link LinearRing}s
17
+ * and {@link Point}s.
18
+ * <p>
19
+ * A <code>GeometryComponentFilter</code> filter can either record information
20
+ * about the <code>Geometry</code> or change the <code>Geometry</code> in
21
+ * some way. <code>GeometryComponentFilter</code> is an example of the
22
+ * Gang-of-Four Visitor pattern.
23
+ */
24
+ jsts.geom.GeometryComponentFilter = function() {
25
+ };
26
+
27
+
28
+ /**
29
+ * Performs an operation with or on <code>geom</code>.
30
+ *
31
+ * @param {Geometry}
32
+ * geom a <code>Geometry</code> to which the filter is applied.
33
+ */
34
+ jsts.geom.GeometryComponentFilter.prototype.filter = function(geom) {
35
+ throw new jsts.error.AbstractMethodInvocationError();
36
+ };
@@ -0,0 +1,263 @@
1
+ /* Copyright (c) 2011 by The Authors.
2
+ * Published under the LGPL 2.1 license.
3
+ * See /license-notice.txt for the full text of the license notice.
4
+ * See /license.txt for the full text of the license.
5
+ */
6
+
7
+ /**
8
+ * Supplies a set of utility methods for building Geometry objects from lists
9
+ * of Coordinates.
10
+ *
11
+ * Note that the factory constructor methods do <b>not</b> change the input
12
+ * coordinates in any way.
13
+ *
14
+ * In particular, they are not rounded to the supplied <tt>PrecisionModel</tt>.
15
+ * It is assumed that input Coordinates meet the given precision.
16
+ */
17
+
18
+ /**
19
+ * @requires jsts/geom/PrecisionModel.js
20
+ */
21
+
22
+ /**
23
+ * Constructs a GeometryFactory that generates Geometries having a floating
24
+ * PrecisionModel and a spatial-reference ID of 0.
25
+ *
26
+ * @constructor
27
+ */
28
+ jsts.geom.GeometryFactory = function(precisionModel) {
29
+ this.precisionModel = precisionModel || new jsts.geom.PrecisionModel();
30
+ };
31
+
32
+ jsts.geom.GeometryFactory.prototype.precisionModel = null;
33
+
34
+ jsts.geom.GeometryFactory.prototype.getPrecisionModel = function() {
35
+ return this.precisionModel;
36
+ };
37
+
38
+
39
+ /**
40
+ * Creates a Point using the given Coordinate; a null Coordinate will create an
41
+ * empty Geometry.
42
+ *
43
+ * @param {Coordinate}
44
+ * coordinate Coordinate to base this Point on.
45
+ * @return {Point} A new Point.
46
+ */
47
+ jsts.geom.GeometryFactory.prototype.createPoint = function(coordinate) {
48
+ var point = new jsts.geom.Point(coordinate, this);
49
+
50
+ return point;
51
+ };
52
+
53
+
54
+ /**
55
+ * Creates a LineString using the given Coordinates; a null or empty array will
56
+ * create an empty LineString. Consecutive points must not be equal.
57
+ *
58
+ * @param {Coordinate[]}
59
+ * coordinates an array without null elements, or an empty array, or
60
+ * null.
61
+ * @return {LineString} A new LineString.
62
+ */
63
+ jsts.geom.GeometryFactory.prototype.createLineString = function(coordinates) {
64
+ var lineString = new jsts.geom.LineString(coordinates, this);
65
+
66
+ return lineString;
67
+ };
68
+
69
+
70
+ /**
71
+ * Creates a LinearRing using the given Coordinates; a null or empty array will
72
+ * create an empty LinearRing. The points must form a closed and simple
73
+ * linestring. Consecutive points must not be equal.
74
+ *
75
+ * @param {Coordinate[]}
76
+ * coordinates an array without null elements, or an empty array, or
77
+ * null.
78
+ * @return {LinearRing} A new LinearRing.
79
+ */
80
+ jsts.geom.GeometryFactory.prototype.createLinearRing = function(coordinates) {
81
+ var linearRing = new jsts.geom.LinearRing(coordinates, this);
82
+
83
+ return linearRing;
84
+ };
85
+
86
+
87
+ /**
88
+ * Constructs a <code>Polygon</code> with the given exterior boundary and
89
+ * interior boundaries.
90
+ *
91
+ * @param {LinearRing}
92
+ * shell the outer boundary of the new <code>Polygon</code>, or
93
+ * <code>null</code> or an empty <code>LinearRing</code> if the
94
+ * empty geometry is to be created.
95
+ * @param {LinearRing[]}
96
+ * holes the inner boundaries of the new <code>Polygon</code>, or
97
+ * <code>null</code> or empty <code>LinearRing</code> s if the
98
+ * empty geometry is to be created.
99
+ * @return {Polygon} A new Polygon.
100
+ */
101
+ jsts.geom.GeometryFactory.prototype.createPolygon = function(shell, holes) {
102
+ var polygon = new jsts.geom.Polygon(shell, holes, this);
103
+
104
+ return polygon;
105
+ };
106
+
107
+
108
+ jsts.geom.GeometryFactory.prototype.createMultiPoint = function(points) {
109
+ if (points && points[0] instanceof jsts.geom.Coordinate) {
110
+ var converted = [];
111
+ var i;
112
+ for (i = 0; i < points.length; i++) {
113
+ converted.push(this.createPoint(points[i]));
114
+ }
115
+ points = converted;
116
+ }
117
+
118
+ return new jsts.geom.MultiPoint(points, this);
119
+ };
120
+
121
+ jsts.geom.GeometryFactory.prototype.createMultiLineString = function(
122
+ lineStrings) {
123
+ return new jsts.geom.MultiLineString(lineStrings, this);
124
+ };
125
+
126
+ jsts.geom.GeometryFactory.prototype.createMultiPolygon = function(polygons) {
127
+ return new jsts.geom.MultiPolygon(polygons, this);
128
+ };
129
+
130
+
131
+ /**
132
+ * Build an appropriate <code>Geometry</code>, <code>MultiGeometry</code>,
133
+ * or <code>GeometryCollection</code> to contain the <code>Geometry</code>s
134
+ * in it. For example:<br>
135
+ *
136
+ * <ul>
137
+ * <li> If <code>geomList</code> contains a single <code>Polygon</code>,
138
+ * the <code>Polygon</code> is returned.
139
+ * <li> If <code>geomList</code> contains several <code>Polygon</code>s, a
140
+ * <code>MultiPolygon</code> is returned.
141
+ * <li> If <code>geomList</code> contains some <code>Polygon</code>s and
142
+ * some <code>LineString</code>s, a <code>GeometryCollection</code> is
143
+ * returned.
144
+ * <li> If <code>geomList</code> is empty, an empty
145
+ * <code>GeometryCollection</code> is returned
146
+ * </ul>
147
+ *
148
+ * Note that this method does not "flatten" Geometries in the input, and hence
149
+ * if any MultiGeometries are contained in the input a GeometryCollection
150
+ * containing them will be returned.
151
+ *
152
+ * @param geomList
153
+ * the <code>Geometry</code>s to combine.
154
+ * @return {Geometry} a <code>Geometry</code> of the "smallest", "most
155
+ * type-specific" class that can contain the elements of
156
+ * <code>geomList</code> .
157
+ */
158
+ jsts.geom.GeometryFactory.prototype.buildGeometry = function(geomList) {
159
+
160
+ /**
161
+ * Determine some facts about the geometries in the list
162
+ */
163
+ var geomClass = null;
164
+ var isHeterogeneous = false;
165
+ var hasGeometryCollection = false;
166
+ for (var i = geomList.iterator(); i.hasNext();) {
167
+ var geom = i.next();
168
+
169
+ var partClass = geom.CLASS_NAME;
170
+
171
+ if (geomClass === null) {
172
+ geomClass = partClass;
173
+ }
174
+ if (!(partClass === geomClass)) {
175
+ isHeterogeneous = true;
176
+ }
177
+ if (geom.isGeometryCollectionBase())
178
+ hasGeometryCollection = true;
179
+ }
180
+
181
+ /**
182
+ * Now construct an appropriate geometry to return
183
+ */
184
+ // for the empty geometry, return an empty GeometryCollection
185
+ if (geomClass === null) {
186
+ return this.createGeometryCollection(null);
187
+ }
188
+ if (isHeterogeneous || hasGeometryCollection) {
189
+ return this.createGeometryCollection(geomList.toArray());
190
+ }
191
+ // at this point we know the collection is hetereogenous.
192
+ // Determine the type of the result from the first Geometry in the list
193
+ // this should always return a geometry, since otherwise an empty collection
194
+ // would have already been returned
195
+ var geom0 = geomList.get(0);
196
+ var isCollection = geomList.size() > 1;
197
+ if (isCollection) {
198
+ if (geom0 instanceof jsts.geom.Polygon) {
199
+ return this.createMultiPolygon(geomList.toArray());
200
+ } else if (geom0 instanceof jsts.geom.LineString) {
201
+ return this.createMultiLineString(geomList.toArray());
202
+ } else if (geom0 instanceof jsts.geom.Point) {
203
+ return this.createMultiPoint(geomList.toArray());
204
+ }
205
+ jsts.util.Assert.shouldNeverReachHere('Unhandled class: ' + geom0);
206
+ }
207
+ return geom0;
208
+ };
209
+
210
+ jsts.geom.GeometryFactory.prototype.createGeometryCollection = function(
211
+ geometries) {
212
+ return new jsts.geom.GeometryCollection(geometries, this);
213
+ };
214
+
215
+ /**
216
+ * Creates a {@link Geometry} with the same extent as the given envelope. The
217
+ * Geometry returned is guaranteed to be valid. To provide this behaviour, the
218
+ * following cases occur:
219
+ * <p>
220
+ * If the <code>Envelope</code> is:
221
+ * <ul>
222
+ * <li>null : returns an empty {@link Point}
223
+ * <li>a point : returns a non-empty {@link Point}
224
+ * <li>a line : returns a two-point {@link LineString}
225
+ * <li>a rectangle : returns a {@link Polygon}> whose points are (minx, miny),
226
+ * (minx, maxy), (maxx, maxy), (maxx, miny), (minx, miny).
227
+ * </ul>
228
+ *
229
+ * @param {jsts.geom.Envelope}
230
+ * envelope the <code>Envelope</code> to convert.
231
+ * @return {jsts.geom.Geometry} an empty <code>Point</code> (for null
232
+ * <code>Envelope</code>s), a <code>Point</code> (when min x = max
233
+ * x and min y = max y) or a <code>Polygon</code> (in all other cases).
234
+ */
235
+ jsts.geom.GeometryFactory.prototype.toGeometry = function(envelope) {
236
+ // null envelope - return empty point geometry
237
+ if (envelope.isNull()) {
238
+ return this.createPoint(null);
239
+ }
240
+
241
+ // point?
242
+ if (envelope.getMinX() === envelope.getMaxX() &&
243
+ envelope.getMinY() === envelope.getMaxY()) {
244
+ return this.createPoint(new jsts.geom.Coordinate(envelope.getMinX(),
245
+ envelope.getMinY()));
246
+ }
247
+
248
+ // vertical or horizontal line?
249
+ if (envelope.getMinX() === envelope.getMaxX() ||
250
+ envelope.getMinY() === envelope.getMaxY()) {
251
+ return this.createLineString([
252
+ new jsts.geom.Coordinate(envelope.getMinX(), envelope.getMinY()),
253
+ new jsts.geom.Coordinate(envelope.getMaxX(), envelope.getMaxY())]);
254
+ }
255
+
256
+ // create a CW ring for the polygon
257
+ return this.createPolygon(this.createLinearRing([
258
+ new jsts.geom.Coordinate(envelope.getMinX(), envelope.getMinY()),
259
+ new jsts.geom.Coordinate(envelope.getMinX(), envelope.getMaxY()),
260
+ new jsts.geom.Coordinate(envelope.getMaxX(), envelope.getMaxY()),
261
+ new jsts.geom.Coordinate(envelope.getMaxX(), envelope.getMinY()),
262
+ new jsts.geom.Coordinate(envelope.getMinX(), envelope.getMinY())]), null);
263
+ };