-
-
Notifications
You must be signed in to change notification settings - Fork 232
/
Geometry.js
224 lines (178 loc) · 5.01 KB
/
Geometry.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import IllegalArgumentException from '../../../../java/lang/IllegalArgumentException.js'
import GeometryComponentFilter from './GeometryComponentFilter.js'
import Comparable from '../../../../java/lang/Comparable.js'
import Cloneable from '../../../../java/lang/Cloneable.js'
import Serializable from '../../../../java/io/Serializable.js'
import Envelope from './Envelope.js'
export default class Geometry {
constructor() {
Geometry.constructor_.apply(this, arguments)
}
isGeometryCollection() {
return this.getTypeCode() === Geometry.TYPECODE_GEOMETRYCOLLECTION
}
getFactory() {
return this._factory
}
getGeometryN(n) {
return this
}
getArea() {
return 0.0
}
isRectangle() {
return false
}
equalsExact(other) {
return this === other || this.equalsExact(other, 0)
}
geometryChanged() {
this.apply(Geometry.geometryChangedFilter)
}
geometryChangedAction() {
this._envelope = null
}
equalsNorm(g) {
if (g === null) return false
return this.norm().equalsExact(g.norm())
}
getLength() {
return 0.0
}
getNumGeometries() {
return 1
}
compareTo() {
let other
if (arguments.length === 1) {
const o = arguments[0]
other = o
if (this.getTypeCode() !== other.getTypeCode()) return this.getTypeCode() - other.getTypeCode()
if (this.isEmpty() && other.isEmpty()) return 0
if (this.isEmpty()) return -1
if (other.isEmpty()) return 1
return this.compareToSameClass(o)
} else if (arguments.length === 2) {
const o = arguments[0]; const comp = arguments[1]
other = o
if (this.getTypeCode() !== other.getTypeCode()) return this.getTypeCode() - other.getTypeCode()
if (this.isEmpty() && other.isEmpty()) return 0
if (this.isEmpty()) return -1
if (other.isEmpty()) return 1
return this.compareToSameClass(o, comp)
}
}
getUserData() {
return this._userData
}
getSRID() {
return this._SRID
}
getEnvelope() {
return this.getFactory().toGeometry(this.getEnvelopeInternal())
}
static checkNotGeometryCollection(g) {
if (g.getTypeCode() === Geometry.TYPECODE_GEOMETRYCOLLECTION) throw new IllegalArgumentException('This method does not support GeometryCollection arguments')
}
equal(a, b, tolerance) {
if (tolerance === 0) return a.equals(b)
return a.distance(b) <= tolerance
}
norm() {
const copy = this.copy()
copy.normalize()
return copy
}
reverse() {
const res = this.reverseInternal()
if (this.envelope != null) res.envelope = this.envelope.copy()
res.setSRID(this.getSRID())
return res
}
copy() {
const copy = this.copyInternal()
copy.envelope = this._envelope == null ? null : this._envelope.copy()
copy._SRID = this._SRID
copy._userData = this._userData
return copy
}
getPrecisionModel() {
return this._factory.getPrecisionModel()
}
getEnvelopeInternal() {
if (this._envelope === null) this._envelope = this.computeEnvelopeInternal()
return new Envelope(this._envelope)
}
setSRID(SRID) {
this._SRID = SRID
}
setUserData(userData) {
this._userData = userData
}
compare(a, b) {
const i = a.iterator()
const j = b.iterator()
while (i.hasNext() && j.hasNext()) {
const aElement = i.next()
const bElement = j.next()
const comparison = aElement.compareTo(bElement)
if (comparison !== 0) return comparison
}
if (i.hasNext()) return 1
if (j.hasNext()) return -1
return 0
}
hashCode() {
return this.getEnvelopeInternal().hashCode()
}
isEquivalentClass(other) {
return this.getTypeCode() == other.getTypeCode()
}
get interfaces_() {
return [Cloneable, Comparable, Serializable]
}
getClass() {
return Geometry
}
static hasNonEmptyElements(geometries) {
for (let i = 0; i < geometries.length; i++)
if (!geometries[i].isEmpty()) return true
return false
}
static hasNullElements(array) {
for (let i = 0; i < array.length; i++)
if (array[i] === null) return true
return false
}
}
Geometry.constructor_ = function(factory) {
if (!factory) return
this._envelope = null
this._userData = null
this._factory = factory
this._SRID = factory.getSRID()
}
Geometry.TYPECODE_POINT = 0
Geometry.TYPECODE_MULTIPOINT = 1
Geometry.TYPECODE_LINESTRING = 2
Geometry.TYPECODE_LINEARRING = 3
Geometry.TYPECODE_MULTILINESTRING = 4
Geometry.TYPECODE_POLYGON = 5
Geometry.TYPECODE_MULTIPOLYGON = 6
Geometry.TYPECODE_GEOMETRYCOLLECTION = 7
Geometry.TYPENAME_POINT = 'Point'
Geometry.TYPENAME_MULTIPOINT = 'MultiPoint'
Geometry.TYPENAME_LINESTRING = 'LineString'
Geometry.TYPENAME_LINEARRING = 'LinearRing'
Geometry.TYPENAME_MULTILINESTRING = 'MultiLineString'
Geometry.TYPENAME_POLYGON = 'Polygon'
Geometry.TYPENAME_MULTIPOLYGON = 'MultiPolygon'
Geometry.TYPENAME_GEOMETRYCOLLECTION = 'GeometryCollection'
Geometry.geometryChangedFilter = {
get interfaces_() {
return [GeometryComponentFilter]
},
filter(geom) {
geom.geometryChangedAction()
}
}