nodes2ts 3.0.0 → 4.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +102 -15
  3. package/dist/export.cjs +5350 -0
  4. package/dist/export.cjs.map +1 -0
  5. package/dist/export.d.cts +1847 -0
  6. package/dist/export.d.ts +1837 -20
  7. package/dist/export.js +5299 -62
  8. package/dist/export.js.map +1 -1
  9. package/package.json +34 -55
  10. package/.eslintignore +0 -3
  11. package/.eslintrc.cjs +0 -11
  12. package/.github/workflows/lint.js.yml +0 -22
  13. package/.github/workflows/node.js.yml +0 -22
  14. package/.mocharc.js +0 -7
  15. package/dist/Interval.d.ts +0 -24
  16. package/dist/Interval.js +0 -23
  17. package/dist/Interval.js.map +0 -1
  18. package/dist/MutableInteger.d.ts +0 -4
  19. package/dist/MutableInteger.js +0 -10
  20. package/dist/MutableInteger.js.map +0 -1
  21. package/dist/Platform.d.ts +0 -15
  22. package/dist/Platform.js +0 -53
  23. package/dist/Platform.js.map +0 -1
  24. package/dist/R1Interval.d.ts +0 -76
  25. package/dist/R1Interval.js +0 -158
  26. package/dist/R1Interval.js.map +0 -1
  27. package/dist/R2Vector.d.ts +0 -34
  28. package/dist/R2Vector.js +0 -131
  29. package/dist/R2Vector.js.map +0 -1
  30. package/dist/S1Angle.d.ts +0 -60
  31. package/dist/S1Angle.js +0 -133
  32. package/dist/S1Angle.js.map +0 -1
  33. package/dist/S1ChordAngle.d.ts +0 -166
  34. package/dist/S1ChordAngle.js +0 -318
  35. package/dist/S1ChordAngle.js.map +0 -1
  36. package/dist/S1Interval.d.ts +0 -109
  37. package/dist/S1Interval.js +0 -398
  38. package/dist/S1Interval.js.map +0 -1
  39. package/dist/S2.d.ts +0 -96
  40. package/dist/S2.js +0 -231
  41. package/dist/S2.js.map +0 -1
  42. package/dist/S2Cap.d.ts +0 -122
  43. package/dist/S2Cap.js +0 -399
  44. package/dist/S2Cap.js.map +0 -1
  45. package/dist/S2Cell.d.ts +0 -106
  46. package/dist/S2Cell.js +0 -358
  47. package/dist/S2Cell.js.map +0 -1
  48. package/dist/S2CellId.d.ts +0 -290
  49. package/dist/S2CellId.js +0 -983
  50. package/dist/S2CellId.js.map +0 -1
  51. package/dist/S2CellUnion.d.ts +0 -179
  52. package/dist/S2CellUnion.js +0 -523
  53. package/dist/S2CellUnion.js.map +0 -1
  54. package/dist/S2EdgeUtil.d.ts +0 -17
  55. package/dist/S2EdgeUtil.js +0 -785
  56. package/dist/S2EdgeUtil.js.map +0 -1
  57. package/dist/S2LatLng.d.ts +0 -77
  58. package/dist/S2LatLng.js +0 -186
  59. package/dist/S2LatLng.js.map +0 -1
  60. package/dist/S2LatLngRect.d.ts +0 -190
  61. package/dist/S2LatLngRect.js +0 -624
  62. package/dist/S2LatLngRect.js.map +0 -1
  63. package/dist/S2Metric.d.ts +0 -38
  64. package/dist/S2Metric.js +0 -79
  65. package/dist/S2Metric.js.map +0 -1
  66. package/dist/S2Point.d.ts +0 -78
  67. package/dist/S2Point.js +0 -250
  68. package/dist/S2Point.js.map +0 -1
  69. package/dist/S2Projections.d.ts +0 -102
  70. package/dist/S2Projections.js +0 -331
  71. package/dist/S2Projections.js.map +0 -1
  72. package/dist/S2Region.d.ts +0 -31
  73. package/dist/S2Region.js +0 -18
  74. package/dist/S2Region.js.map +0 -1
  75. package/dist/S2RegionCoverer.d.ts +0 -186
  76. package/dist/S2RegionCoverer.js +0 -471
  77. package/dist/S2RegionCoverer.js.map +0 -1
  78. package/dist/utils/preconditions.d.ts +0 -2
  79. package/dist/utils/preconditions.js +0 -16
  80. package/dist/utils/preconditions.js.map +0 -1
@@ -1,785 +0,0 @@
1
- "use strict";
2
- /*
3
- * Copyright 2006 Google Inc.
4
- *
5
- * Licensed under the Apache License, Version 2.0 (the "License");
6
- * you may not use this file except in compliance with the License.
7
- * You may obtain a copy of the License at
8
- *
9
- * http://www.apache.org/licenses/LICENSE-2.0
10
- *
11
- * Unless required by applicable law or agreed to in writing, software
12
- * distributed under the License is distributed on an "AS IS" BASIS,
13
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
- * See the License for the specific language governing permissions and
15
- * limitations under the License.
16
- */
17
- Object.defineProperty(exports, "__esModule", { value: true });
18
- exports.S2EdgeUtil = void 0;
19
- const S2Point_1 = require("./S2Point");
20
- const S2_1 = require("./S2");
21
- const S1Angle_1 = require("./S1Angle");
22
- /**
23
- * This class contains various utility functions related to edges. It collects
24
- * together common code that is needed to implement polygonal geometry such as
25
- * polylines, loops, and general polygons.
26
- *
27
- */
28
- class S2EdgeUtil {
29
- // /**
30
- // * IEEE floating-point operations have a maximum error of 0.5 ULPS (units in
31
- // * the last place). For double-precision numbers, this works out to 2**-53
32
- // * (about 1.11e-16) times the magnitude of the result. It is possible to
33
- // * analyze the calculation done by getIntersection() and work out the
34
- // * worst-case rounding error. I have done a rough version of this, and my
35
- // * estimate is that the worst case distance from the intersection point X to
36
- // * the great circle through (a0, a1) is about 12 ULPS, or about 1.3e-15. This
37
- // * needs to be increased by a factor of (1/0.866) to account for the
38
- // * edgeSpliceFraction() in S2PolygonBuilder. Note that the maximum error
39
- // * measured by the unittest in 1,000,000 trials is less than 3e-16.
40
- // */
41
- // public static final S1Angle DEFAULT_INTERSECTION_TOLERANCE = S1Angle.radians(1.5e-15);
42
- //
43
- // /**
44
- // * This class allows a vertex chain v0, v1, v2, ... to be efficiently tested
45
- // * for intersection with a given fixed edge AB.
46
- // */
47
- // public static class EdgeCrosser {
48
- // // The fields below are all constant.
49
- //
50
- // private final S2Point a;
51
- // private final S2Point b;
52
- // private final S2Point aCrossB;
53
- //
54
- // // The fields below are updated for each vertex in the chain.
55
- //
56
- // // Previous vertex in the vertex chain.
57
- // private S2Point c;
58
- // // The orientation of the triangle ACB.
59
- // private int acb;
60
- //
61
- // /**
62
- // * AB is the given fixed edge, and C is the first vertex of the vertex
63
- // * chain. All parameters must point to fixed storage that persists for the
64
- // * lifetime of the EdgeCrosser object.
65
- // */
66
- // public EdgeCrosser(S2Point a, S2Point b, S2Point c) {
67
- // this.a = a;
68
- // this.b = b;
69
- // this.aCrossB = S2Point.crossProd(a, b);
70
- // restartAt(c);
71
- // }
72
- //
73
- // /**
74
- // * Call this function when your chain 'jumps' to a new place.
75
- // */
76
- // public void restartAt(S2Point c) {
77
- // this.c = c;
78
- // this.acb = -S2.robustCCW(this.a, this.b, c, this.aCrossB);
79
- // }
80
- //
81
- // /**
82
- // * This method is equivalent to calling the S2EdgeUtil.robustCrossing()
83
- // * function (defined below) on the edges AB and CD. It returns +1 if there
84
- // * is a crossing, -1 if there is no crossing, and 0 if two points from
85
- // * different edges are the same. Returns 0 or -1 if either edge is
86
- // * degenerate. As a side effect, it saves vertex D to be used as the next
87
- // * vertex C.
88
- // */
89
- // public int robustCrossing(S2Point d) {
90
- // // For there to be an edge crossing, the triangles ACB, CBD, BDA, DAC must
91
- // // all be oriented the same way (CW or CCW). We keep the orientation
92
- // // of ACB as part of our state. When each new point D arrives, we
93
- // // compute the orientation of BDA and check whether it matches ACB.
94
- // // This checks whether the points C and D are on opposite sides of the
95
- // // great circle through AB.
96
- //
97
- // // Recall that robustCCW is invariant with respect to rotating its
98
- // // arguments, i.e. ABC has the same orientation as BDA.
99
- // int bda = S2.robustCCW(this.a, this.b, d, this.aCrossB);
100
- // int result;
101
- //
102
- // if (bda == -this.acb && bda != 0) {
103
- // // Most common case -- triangles have opposite orientations.
104
- // result = -1;
105
- // } else if ((bda & this.acb) == 0) {
106
- // // At least one value is zero -- two vertices are identical.
107
- // result = 0;
108
- // } else {
109
- // // assert (bda == acb && bda != 0);
110
- // result = robustCrossingInternal(d); // Slow path.
111
- // }
112
- // // Now save the current vertex D as the next vertex C, and also save the
113
- // // orientation of the new triangle ACB (which is opposite to the current
114
- // // triangle BDA).
115
- // this.c = d;
116
- // this.acb = -bda;
117
- // return result;
118
- // }
119
- //
120
- // /**
121
- // * This method is equivalent to the S2EdgeUtil.edgeOrVertexCrossing() method
122
- // * defined below. It is similar to robustCrossing, but handles cases where
123
- // * two vertices are identical in a way that makes it easy to implement
124
- // * point-in-polygon containment tests.
125
- // */
126
- // public boolean edgeOrVertexCrossing(S2Point d) {
127
- // // We need to copy c since it is clobbered by robustCrossing().
128
- // S2Point c2 = new S2Point(this.c.get(0), this.c.get(1), this.c.get(2));
129
- //
130
- // int crossing = robustCrossing(d);
131
- // if (crossing < 0) {
132
- // return false;
133
- // }
134
- // if (crossing > 0) {
135
- // return true;
136
- // }
137
- //
138
- // return vertexCrossing(this.a, this.b, c2, d);
139
- // }
140
- //
141
- // /**
142
- // * This function handles the "slow path" of robustCrossing().
143
- // */
144
- // private int robustCrossingInternal(S2Point d) {
145
- // // ACB and BDA have the appropriate orientations, so now we check the
146
- // // triangles CBD and DAC.
147
- // S2Point cCrossD = S2Point.crossProd(this.c, d);
148
- // int cbd = -S2.robustCCW(this.c, d, this.b, cCrossD);
149
- // if (cbd != this.acb) {
150
- // return -1;
151
- // }
152
- //
153
- // int dac = S2.robustCCW(this.c, d, this.a, cCrossD);
154
- // return (dac == this.acb) ? 1 : -1;
155
- // }
156
- // }
157
- //
158
- // /**
159
- // * This class computes a bounding rectangle that contains all edges defined by
160
- // * a vertex chain v0, v1, v2, ... All vertices must be unit length. Note that
161
- // * the bounding rectangle of an edge can be larger than the bounding rectangle
162
- // * of its endpoints, e.g. consider an edge that passes through the north pole.
163
- // */
164
- // public static class RectBounder {
165
- // // The previous vertex in the chain.
166
- // private S2Point a;
167
- //
168
- // // The corresponding latitude-longitude.
169
- // private S2LatLng aLatLng;
170
- //
171
- // // The current bounding rectangle.
172
- // private S2LatLngRect bound;
173
- //
174
- // public RectBounder() {
175
- // this.bound = S2LatLngRect.empty();
176
- // }
177
- //
178
- // /**
179
- // * This method is called to add each vertex to the chain. 'b' must point to
180
- // * fixed storage that persists for the lifetime of the RectBounder.
181
- // */
182
- // public void addPoint(S2Point b) {
183
- // // assert (S2.isUnitLength(b));
184
- //
185
- // S2LatLng bLatLng = new S2LatLng(b);
186
- //
187
- // if (this.bound.isEmpty()) {
188
- // this.bound = this.bound.addPoint(bLatLng);
189
- // } else {
190
- // // We can't just call bound.addPoint(bLatLng) here, since we need to
191
- // // ensure that all the longitudes between "a" and "b" are included.
192
- // this.bound = this.bound.union(S2LatLngRect.fromPointPair(this.aLatLng, bLatLng));
193
- //
194
- // // Check whether the min/max latitude occurs in the edge interior.
195
- // // We find the normal to the plane containing AB, and then a vector
196
- // // "dir" in this plane that also passes through the equator. We use
197
- // // RobustCrossProd to ensure that the edge normal is accurate even
198
- // // when the two points are very close together.
199
- // S2Point aCrossB = S2.robustCrossProd(this.a, b);
200
- // S2Point dir = S2Point.crossProd(aCrossB, new S2Point(0, 0, 1));
201
- // double da = dir.dotProd(this.a);
202
- // double db = dir.dotProd(b);
203
- //
204
- // if (da * db < 0) {
205
- // // Minimum/maximum latitude occurs in the edge interior. This affects
206
- // // the latitude bounds but not the longitude bounds.
207
- // double absLat = Math.acos(Math.abs(aCrossB.get(2) / aCrossB.norm()));
208
- // R1Interval lat = this.bound.lat();
209
- // if (da < 0) {
210
- // // It's possible that absLat < lat.lo() due to numerical errors.
211
- // lat = new R1Interval(lat.lo(), Math.max(absLat, this.bound.lat().hi()));
212
- // } else {
213
- // lat = new R1Interval(Math.min(-absLat, this.bound.lat().lo()), lat.hi());
214
- // }
215
- // this.bound = new S2LatLngRect(lat, this.bound.lng());
216
- // }
217
- // }
218
- // this.a = b;
219
- // this.aLatLng = bLatLng;
220
- // }
221
- //
222
- // /**
223
- // * Return the bounding rectangle of the edge chain that connects the
224
- // * vertices defined so far.
225
- // */
226
- // public S2LatLngRect getBound() {
227
- // return this.bound;
228
- // }
229
- //
230
- // }
231
- //
232
- // /**
233
- // * The purpose of this class is to find edges that intersect a given XYZ
234
- // * bounding box. It can be used as an efficient rejection test when attempting to
235
- // * find edges that intersect a given region. It accepts a vertex chain v0, v1,
236
- // * v2, ... and returns a boolean value indicating whether each edge intersects
237
- // * the specified bounding box.
238
- // *
239
- // * We use XYZ intervals instead of something like longitude intervals because
240
- // * it is cheap to collect from S2Point lists and any slicing strategy should
241
- // * give essentially equivalent results. See S2Loop for an example of use.
242
- // */
243
- // public static class XYZPruner {
244
- // private S2Point lastVertex;
245
- //
246
- // // The region to be tested against.
247
- // private boolean boundSet;
248
- // private double xmin;
249
- // private double ymin;
250
- // private double zmin;
251
- // private double xmax;
252
- // private double ymax;
253
- // private double zmax;
254
- // private double maxDeformation;
255
- //
256
- // public XYZPruner() {
257
- // this.boundSet = false;
258
- // }
259
- //
260
- // /**
261
- // * Accumulate a bounding rectangle from provided edges.
262
- // *
263
- // * @param from start of edge
264
- // * @param to end of edge.
265
- // */
266
- // public void addEdgeToBounds(S2Point from, S2Point to) {
267
- // if (!this.boundSet) {
268
- // this.boundSet = true;
269
- // this.xmin = this.xmax = from.x;
270
- // this.ymin = this.ymax = from.y;
271
- // this.zmin = this.zmax = from.z;
272
- // }
273
- // this.xmin = Math.min(this.xmin, Math.min(to.x, from.x));
274
- // this.ymin = Math.min(this.ymin, Math.min(to.y, from.y));
275
- // this.zmin = Math.min(this.zmin, Math.min(to.z, from.z));
276
- // this.xmax = Math.max(this.xmax, Math.max(to.x, from.x));
277
- // this.ymax = Math.max(this.ymax, Math.max(to.y, from.y));
278
- // this.zmax = Math.max(this.zmax, Math.max(to.z, from.z));
279
- //
280
- // // Because our arcs are really geodesics on the surface of the earth
281
- // // an edge can have intermediate points outside the xyz bounds implicit
282
- // // in the end points. Based on the length of the arc we compute a
283
- // // generous bound for the maximum amount of deformation. For small edges
284
- // // it will be very small but for some large arcs (ie. from (1N,90W) to
285
- // // (1N,90E) the path can be wildly deformed. I did a bunch of
286
- // // experiments with geodesics to get safe bounds for the deformation.
287
- // double approxArcLen =
288
- // Math.abs(from.x - to.x) + Math.abs(from.y - to.y) + Math.abs(from.z - to.z);
289
- // if (approxArcLen < 0.025) { // less than 2 degrees
290
- // this.maxDeformation = Math.max(this.maxDeformation, approxArcLen * 0.0025);
291
- // } else if (approxArcLen < 1.0) { // less than 90 degrees
292
- // this.maxDeformation = Math.max(this.maxDeformation, approxArcLen * 0.11);
293
- // } else {
294
- // this.maxDeformation = approxArcLen * 0.5;
295
- // }
296
- // }
297
- //
298
- // public void setFirstIntersectPoint(S2Point v0) {
299
- // this.xmin = this.xmin - this.maxDeformation;
300
- // this.ymin = this.ymin - this.maxDeformation;
301
- // this.zmin = this.zmin - this.maxDeformation;
302
- // this.xmax = this.xmax + this.maxDeformation;
303
- // this.ymax = this.ymax + this.maxDeformation;
304
- // this.zmax = this.zmax + this.maxDeformation;
305
- // this.lastVertex = v0;
306
- // }
307
- //
308
- // /**
309
- // * Returns true if the edge going from the last point to this point passes
310
- // * through the pruner bounding box, otherwise returns false. So the
311
- // * method returns false if we are certain there is no intersection, but it
312
- // * may return true when there turns out to be no intersection.
313
- // */
314
- // public boolean intersects(S2Point v1) {
315
- // boolean result = true;
316
- //
317
- // if ((v1.x < this.xmin && this.lastVertex.x < this.xmin) || (v1.x > this.xmax && this.lastVertex.x > this.xmax)) {
318
- // result = false;
319
- // } else if ((v1.y < this.ymin && this.lastVertex.y < this.ymin) || (v1.y > this.ymax && this.lastVertex.y > this.ymax)) {
320
- // result = false;
321
- // } else if ((v1.z < this.zmin && this.lastVertex.z < this.zmin) || (v1.z > this.zmax && this.lastVertex.z > this.zmax)) {
322
- // result = false;
323
- // }
324
- //
325
- // this.lastVertex = v1;
326
- // return result;
327
- // }
328
- // }
329
- //
330
- // /**
331
- // * The purpose of this class is to find edges that intersect a given longitude
332
- // * interval. It can be used as an efficient rejection test when attempting to
333
- // * find edges that intersect a given region. It accepts a vertex chain v0, v1,
334
- // * v2, ... and returns a boolean value indicating whether each edge intersects
335
- // * the specified longitude interval.
336
- // *
337
- // * This class is not currently used as the XYZPruner is preferred for
338
- // * S2Loop, but this should be usable in similar circumstances. Be wary
339
- // * of the cost of atan2() in conversions from S2Point to longitude!
340
- // */
341
- // public static class LongitudePruner {
342
- // // The interval to be tested against.
343
- // private S1Interval interval;
344
- //
345
- // // The longitude of the next v0.
346
- // private double lng0;
347
- //
348
- // /**
349
- // *'interval' is the longitude interval to be tested against, and 'v0' is
350
- // * the first vertex of edge chain.
351
- // */
352
- // public LongitudePruner(S1Interval interval, S2Point v0) {
353
- // this.interval = interval;
354
- // this.lng0 = S2LatLng.longitude(v0).radians();
355
- // }
356
- //
357
- // /**
358
- // * Returns true if the edge (v0, v1) intersects the given longitude
359
- // * interval, and then saves 'v1' to be used as the next 'v0'.
360
- // */
361
- // public boolean intersects(S2Point v1) {
362
- // double lng1 = S2LatLng.longitude(v1).radians();
363
- // boolean result = this.interval.intersects(S1Interval.fromPointPair(this.lng0, lng1));
364
- // this.lng0 = lng1;
365
- // return result;
366
- // }
367
- // }
368
- //
369
- // /**
370
- // * A wedge relation's test method accepts two edge chains A=(a0,a1,a2) and
371
- // * B=(b0,b1,b2) where a1==b1, and returns either -1, 0, or 1 to indicate the
372
- // * relationship between the region to the left of A and the region to the left
373
- // * of B. Wedge relations are used to determine the local relationship between
374
- // * two polygons that share a common vertex.
375
- // *
376
- // * All wedge relations require that a0 != a2 and b0 != b2. Other degenerate
377
- // * cases (such as a0 == b2) are handled as expected. The parameter "ab1"
378
- // * denotes the common vertex a1 == b1.
379
- // */
380
- // public interface WedgeRelation {
381
- // int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2);
382
- // }
383
- //
384
- // public static class WedgeContains implements WedgeRelation {
385
- // /**
386
- // * Given two edge chains (see WedgeRelation above), this function returns +1
387
- // * if the region to the left of A contains the region to the left of B, and
388
- // * 0 otherwise.
389
- // */
390
- // @Override
391
- // public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {
392
- // // For A to contain B (where each loop interior is defined to be its left
393
- // // side), the CCW edge order around ab1 must be a2 b2 b0 a0. We split
394
- // // this test into two parts that test three vertices each.
395
- // return S2.orderedCCW(a2, b2, b0, ab1) && S2.orderedCCW(b0, a0, a2, ab1) ? 1 : 0;
396
- // }
397
- // }
398
- //
399
- // public static class WedgeIntersects implements WedgeRelation {
400
- // /**
401
- // * Given two edge chains (see WedgeRelation above), this function returns -1
402
- // * if the region to the left of A intersects the region to the left of B,
403
- // * and 0 otherwise. Note that regions are defined such that points along a
404
- // * boundary are contained by one side or the other, not both. So for
405
- // * example, if A,B,C are distinct points ordered CCW around a vertex O, then
406
- // * the wedges BOA, AOC, and COB do not intersect.
407
- // */
408
- // @Override
409
- // public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {
410
- // // For A not to intersect B (where each loop interior is defined to be
411
- // // its left side), the CCW edge order around ab1 must be a0 b2 b0 a2.
412
- // // Note that it's important to write these conditions as negatives
413
- // // (!OrderedCCW(a,b,c,o) rather than Ordered(c,b,a,o)) to get correct
414
- // // results when two vertices are the same.
415
- // return (S2.orderedCCW(a0, b2, b0, ab1) && S2.orderedCCW(b0, a2, a0, ab1) ? 0 : -1);
416
- // }
417
- // }
418
- //
419
- // public static class WedgeContainsOrIntersects implements WedgeRelation {
420
- // /**
421
- // * Given two edge chains (see WedgeRelation above), this function returns +1
422
- // * if A contains B, 0 if A and B are disjoint, and -1 if A intersects but
423
- // * does not contain B.
424
- // */
425
- // @Override
426
- // public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {
427
- // // This is similar to WedgeContainsOrCrosses, except that we want to
428
- // // distinguish cases (1) [A contains B], (3) [A and B are disjoint],
429
- // // and (2,4,5,6) [A intersects but does not contain B].
430
- //
431
- // if (S2.orderedCCW(a0, a2, b2, ab1)) {
432
- // // We are in case 1, 5, or 6, or case 2 if a2 == b2.
433
- // return S2.orderedCCW(b2, b0, a0, ab1) ? 1 : -1; // Case 1 vs. 2,5,6.
434
- // }
435
- // // We are in cases 2, 3, or 4.
436
- // if (!S2.orderedCCW(a2, b0, b2, ab1)) {
437
- // return 0; // Case 3.
438
- // }
439
- //
440
- // // We are in case 2 or 4, or case 3 if a2 == b0.
441
- // return (a2.equals(b0)) ? 0 : -1; // Case 3 vs. 2,4.
442
- // }
443
- // }
444
- //
445
- // public static class WedgeContainsOrCrosses implements WedgeRelation {
446
- // /**
447
- // * Given two edge chains (see WedgeRelation above), this function returns +1
448
- // * if A contains B, 0 if B contains A or the two wedges do not intersect,
449
- // * and -1 if the edge chains A and B cross each other (i.e. if A intersects
450
- // * both the interior and exterior of the region to the left of B). In
451
- // * degenerate cases where more than one of these conditions is satisfied,
452
- // * the maximum possible result is returned. For example, if A == B then the
453
- // * result is +1.
454
- // */
455
- // @Override
456
- // public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {
457
- // // There are 6 possible edge orderings at a shared vertex (all
458
- // // of these orderings are circular, i.e. abcd == bcda):
459
- // //
460
- // // (1) a2 b2 b0 a0: A contains B
461
- // // (2) a2 a0 b0 b2: B contains A
462
- // // (3) a2 a0 b2 b0: A and B are disjoint
463
- // // (4) a2 b0 a0 b2: A and B intersect in one wedge
464
- // // (5) a2 b2 a0 b0: A and B intersect in one wedge
465
- // // (6) a2 b0 b2 a0: A and B intersect in two wedges
466
- // //
467
- // // In cases (4-6), the boundaries of A and B cross (i.e. the boundary
468
- // // of A intersects the interior and exterior of B and vice versa).
469
- // // Thus we want to distinguish cases (1), (2-3), and (4-6).
470
- // //
471
- // // Note that the vertices may satisfy more than one of the edge
472
- // // orderings above if two or more vertices are the same. The tests
473
- // // below are written so that we take the most favorable
474
- // // interpretation, i.e. preferring (1) over (2-3) over (4-6). In
475
- // // particular note that if orderedCCW(a,b,c,o) returns true, it may be
476
- // // possible that orderedCCW(c,b,a,o) is also true (if a == b or b == c).
477
- //
478
- // if (S2.orderedCCW(a0, a2, b2, ab1)) {
479
- // // The cases with this vertex ordering are 1, 5, and 6,
480
- // // although case 2 is also possible if a2 == b2.
481
- // if (S2.orderedCCW(b2, b0, a0, ab1)) {
482
- // return 1; // Case 1 (A contains B)
483
- // }
484
- //
485
- // // We are in case 5 or 6, or case 2 if a2 == b2.
486
- // return (a2.equals(b2)) ? 0 : -1; // Case 2 vs. 5,6.
487
- // }
488
- // // We are in case 2, 3, or 4.
489
- // return S2.orderedCCW(a0, b0, a2, ab1) ? 0 : -1; // Case 2,3 vs. 4.
490
- // }
491
- // }
492
- //
493
- // /**
494
- // * Return true if edge AB crosses CD at a point that is interior to both
495
- // * edges. Properties:
496
- // *
497
- // * (1) simpleCrossing(b,a,c,d) == simpleCrossing(a,b,c,d) (2)
498
- // * simpleCrossing(c,d,a,b) == simpleCrossing(a,b,c,d)
499
- // */
500
- // public static boolean simpleCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {
501
- // // We compute simpleCCW() for triangles ACB, CBD, BDA, and DAC. All
502
- // // of these triangles need to have the same orientation (CW or CCW)
503
- // // for an intersection to exist. Note that this is slightly more
504
- // // restrictive than the corresponding definition for planar edges,
505
- // // since we need to exclude pairs of line segments that would
506
- // // otherwise "intersect" by crossing two antipodal points.
507
- //
508
- // S2Point ab = S2Point.crossProd(a, b);
509
- // double acb = -(ab.dotProd(c));
510
- // double bda = ab.dotProd(d);
511
- // if (acb * bda <= 0) {
512
- // return false;
513
- // }
514
- //
515
- // S2Point cd = S2Point.crossProd(c, d);
516
- // double cbd = -(cd.dotProd(b));
517
- // double dac = cd.dotProd(a);
518
- // return (acb * cbd > 0) && (acb * dac > 0);
519
- // }
520
- //
521
- // /**
522
- // * Like SimpleCrossing, except that points that lie exactly on a line are
523
- // * arbitrarily classified as being on one side or the other (according to the
524
- // * rules of S2.robustCCW). It returns +1 if there is a crossing, -1 if there
525
- // * is no crossing, and 0 if any two vertices from different edges are the
526
- // * same. Returns 0 or -1 if either edge is degenerate. Properties of
527
- // * robustCrossing:
528
- // *
529
- // * (1) robustCrossing(b,a,c,d) == robustCrossing(a,b,c,d) (2)
530
- // * robustCrossing(c,d,a,b) == robustCrossing(a,b,c,d) (3)
531
- // * robustCrossing(a,b,c,d) == 0 if a==c, a==d, b==c, b==d (3)
532
- // * robustCrossing(a,b,c,d) <= 0 if a==b or c==d
533
- // *
534
- // * Note that if you want to check an edge against a *chain* of other edges,
535
- // * it is much more efficient to use an EdgeCrosser (above).
536
- // */
537
- // public static int robustCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {
538
- // // For there to be a crossing, the triangles ACB, CBD, BDA, DAC must
539
- // // all have the same orientation (clockwise or counterclockwise).
540
- // //
541
- // // First we compute the orientation of ACB and BDA. We permute the
542
- // // arguments to robustCCW so that we can reuse the cross-product of A and B.
543
- // // Recall that when the arguments to robustCCW are permuted, the sign of the
544
- // // result changes according to the sign of the permutation. Thus ACB and
545
- // // ABC are oppositely oriented, while BDA and ABD are the same.
546
- // S2Point aCrossB = S2Point.crossProd(a, b);
547
- // int acb = -S2.robustCCW(a, b, c, aCrossB);
548
- // int bda = S2.robustCCW(a, b, d, aCrossB);
549
- //
550
- // // If any two vertices are the same, the result is degenerate.
551
- // if ((bda & acb) == 0) {
552
- // return 0;
553
- // }
554
- //
555
- // // If ABC and BDA have opposite orientations (the most common case),
556
- // // there is no crossing.
557
- // if (bda != acb) {
558
- // return -1;
559
- // }
560
- //
561
- // // Otherwise we compute the orientations of CBD and DAC, and check whether
562
- // // their orientations are compatible with the other two triangles.
563
- // S2Point cCrossD = S2Point.crossProd(c, d);
564
- // int cbd = -S2.robustCCW(c, d, b, cCrossD);
565
- // if (cbd != acb) {
566
- // return -1;
567
- // }
568
- //
569
- // int dac = S2.robustCCW(c, d, a, cCrossD);
570
- // return (dac == acb) ? 1 : -1;
571
- // }
572
- //
573
- // /**
574
- // * Given two edges AB and CD where at least two vertices are identical (i.e.
575
- // * robustCrossing(a,b,c,d) == 0), this function defines whether the two edges
576
- // * "cross" in a such a way that point-in-polygon containment tests can be
577
- // * implemented by counting the number of edge crossings. The basic rule is
578
- // * that a "crossing" occurs if AB is encountered after CD during a CCW sweep
579
- // * around the shared vertex starting from a fixed reference point.
580
- // *
581
- // * Note that according to this rule, if AB crosses CD then in general CD does
582
- // * not cross AB. However, this leads to the correct result when counting
583
- // * polygon edge crossings. For example, suppose that A,B,C are three
584
- // * consecutive vertices of a CCW polygon. If we now consider the edge
585
- // * crossings of a segment BP as P sweeps around B, the crossing number changes
586
- // * parity exactly when BP crosses BA or BC.
587
- // *
588
- // * Useful properties of VertexCrossing (VC):
589
- // *
590
- // * (1) VC(a,a,c,d) == VC(a,b,c,c) == false (2) VC(a,b,a,b) == VC(a,b,b,a) ==
591
- // * true (3) VC(a,b,c,d) == VC(a,b,d,c) == VC(b,a,c,d) == VC(b,a,d,c) (3) If
592
- // * exactly one of a,b equals one of c,d, then exactly one of VC(a,b,c,d) and
593
- // * VC(c,d,a,b) is true
594
- // *
595
- // * It is an error to call this method with 4 distinct vertices.
596
- // */
597
- // public static boolean vertexCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {
598
- // // If A == B or C == D there is no intersection. We need to check this
599
- // // case first in case 3 or more input points are identical.
600
- // if (a.equals(b) || c.equals(d)) {
601
- // return false;
602
- // }
603
- //
604
- // // If any other pair of vertices is equal, there is a crossing if and only
605
- // // if orderedCCW() indicates that the edge AB is further CCW around the
606
- // // shared vertex than the edge CD.
607
- // if (a.equals(d)) {
608
- // return S2.orderedCCW(S2.ortho(a), c, b, a);
609
- // }
610
- // if (b.equals(c)) {
611
- // return S2.orderedCCW(S2.ortho(b), d, a, b);
612
- // }
613
- // if (a.equals(c)) {
614
- // return S2.orderedCCW(S2.ortho(a), d, b, a);
615
- // }
616
- // if (b.equals(d)) {
617
- // return S2.orderedCCW(S2.ortho(b), c, a, b);
618
- // }
619
- //
620
- // // assert (false);
621
- // return false;
622
- // }
623
- //
624
- // /**
625
- // * A convenience function that calls robustCrossing() to handle cases where
626
- // * all four vertices are distinct, and VertexCrossing() to handle cases where
627
- // * two or more vertices are the same. This defines a crossing function such
628
- // * that point-in-polygon containment tests can be implemented by simply
629
- // * counting edge crossings.
630
- // */
631
- // public static boolean edgeOrVertexCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {
632
- // int crossing = robustCrossing(a, b, c, d);
633
- // if (crossing < 0) {
634
- // return false;
635
- // }
636
- // if (crossing > 0) {
637
- // return true;
638
- // }
639
- // return vertexCrossing(a, b, c, d);
640
- // }
641
- //
642
- // static class CloserResult {
643
- // private double dmin2;
644
- // private S2Point vmin;
645
- //
646
- // public double getDmin2() {
647
- // return this.dmin2;
648
- // }
649
- //
650
- // public S2Point getVmin() {
651
- // return this.vmin;
652
- // }
653
- //
654
- // public CloserResult(double dmin2, S2Point vmin) {
655
- // this.dmin2 = dmin2;
656
- // this.vmin = vmin;
657
- // }
658
- //
659
- // public void replaceIfCloser(S2Point x, S2Point y) {
660
- // // If the squared distance from x to y is less than dmin2, then replace
661
- // // vmin by y and update dmin2 accordingly.
662
- // double d2 = S2Point.minus(x, y).norm2();
663
- // if (d2 < this.dmin2 || (d2 == this.dmin2 && y.lessThan(this.vmin))) {
664
- // this.dmin2 = d2;
665
- // this.vmin = y;
666
- // }
667
- // }
668
- // }
669
- //
670
- // /*
671
- // * Given two edges AB and CD such that robustCrossing() is true, return their
672
- // * intersection point. Useful properties of getIntersection (GI):
673
- // *
674
- // * (1) GI(b,a,c,d) == GI(a,b,d,c) == GI(a,b,c,d) (2) GI(c,d,a,b) ==
675
- // * GI(a,b,c,d)
676
- // *
677
- // * The returned intersection point X is guaranteed to be close to the edges AB
678
- // * and CD, but if the edges intersect at a very small angle then X may not be
679
- // * close to the true mathematical intersection point P. See the description of
680
- // * "DEFAULT_INTERSECTION_TOLERANCE" below for details.
681
- // */
682
- // public static S2Point getIntersection(S2Point a0, S2Point a1, S2Point b0, S2Point b1) {
683
- // Preconditions.checkArgument(robustCrossing(a0, a1, b0, b1) > 0,
684
- // "Input edges a0a1 and b0b1 muct have a true robustCrossing.");
685
- //
686
- // // We use robustCrossProd() to get accurate results even when two endpoints
687
- // // are close together, or when the two line segments are nearly parallel.
688
- // S2Point aNorm = S2Point.normalize(S2.robustCrossProd(a0, a1));
689
- // S2Point bNorm = S2Point.normalize(S2.robustCrossProd(b0, b1));
690
- // S2Point x = S2Point.normalize(S2.robustCrossProd(aNorm, bNorm));
691
- //
692
- // // Make sure the intersection point is on the correct side of the sphere.
693
- // // Since all vertices are unit length, and edges are less than 180 degrees,
694
- // // (a0 + a1) and (b0 + b1) both have positive dot product with the
695
- // // intersection point. We use the sum of all vertices to make sure that the
696
- // // result is unchanged when the edges are reversed or exchanged.
697
- // if (x.dotProd(S2Point.add(S2Point.add(a0, a1), S2Point.add(b0, b1))) < 0) {
698
- // x = S2Point.neg(x);
699
- // }
700
- //
701
- // // The calculation above is sufficient to ensure that "x" is within
702
- // // DEFAULT_INTERSECTION_TOLERANCE of the great circles through (a0,a1) and
703
- // // (b0,b1).
704
- // // However, if these two great circles are very close to parallel, it is
705
- // // possible that "x" does not lie between the endpoints of the given line
706
- // // segments. In other words, "x" might be on the great circle through
707
- // // (a0,a1) but outside the range covered by (a0,a1). In this case we do
708
- // // additional clipping to ensure that it does.
709
- //
710
- // if (S2.orderedCCW(a0, x, a1, aNorm) && S2.orderedCCW(b0, x, b1, bNorm)) {
711
- // return x;
712
- // }
713
- //
714
- // // Find the acceptable endpoint closest to x and return it. An endpoint is
715
- // // acceptable if it lies between the endpoints of the other line segment.
716
- // CloserResult r = new CloserResult(10, x);
717
- // if (S2.orderedCCW(b0, a0, b1, bNorm)) {
718
- // r.replaceIfCloser(x, a0);
719
- // }
720
- // if (S2.orderedCCW(b0, a1, b1, bNorm)) {
721
- // r.replaceIfCloser(x, a1);
722
- // }
723
- // if (S2.orderedCCW(a0, b0, a1, aNorm)) {
724
- // r.replaceIfCloser(x, b0);
725
- // }
726
- // if (S2.orderedCCW(a0, b1, a1, aNorm)) {
727
- // r.replaceIfCloser(x, b1);
728
- // }
729
- // return r.getVmin();
730
- // }
731
- //
732
- // /**
733
- // * Given a point X and an edge AB, return the distance ratio AX / (AX + BX).
734
- // * If X happens to be on the line segment AB, this is the fraction "t" such
735
- // * that X == Interpolate(A, B, t). Requires that A and B are distinct.
736
- // */
737
- // public static double getDistanceFraction(S2Point x, S2Point a0, S2Point a1) {
738
- // Preconditions.checkArgument(!a0.equals(a1));
739
- // double d0 = x.angle(a0);
740
- // double d1 = x.angle(a1);
741
- // return d0 / (d0 + d1);
742
- // }
743
- //
744
- // /**
745
- // * Return the minimum distance from X to any point on the edge AB. The result
746
- // * is very accurate for small distances but may have some numerical error if
747
- // * the distance is large (approximately Pi/2 or greater). The case A == B is
748
- // * handled correctly. Note: x, a and b must be of unit length. Throws
749
- // * IllegalArgumentException if this is not the case.
750
- // */
751
- // public static getDistance(x:S2Point , a:S2Point , b:S2Point ):S1Angle {
752
- // return this.getDistance(x, a, b, S2.robustCrossProd(a, b));
753
- // }
754
- /**
755
- * A slightly more efficient version of getDistance() where the cross product
756
- * of the two endpoints has been precomputed. The cross product does not need
757
- * to be normalized, but should be computed using S2.robustCrossProd() for the
758
- * most accurate results.
759
- */
760
- static getDistance(x, a, b, aCrossB = S2_1.S2.robustCrossProd(a, b)) {
761
- // Preconditions.checkArgument(S2.isUnitLength(x));
762
- // Preconditions.checkArgument(S2.isUnitLength(a));
763
- // Preconditions.checkArgument(S2.isUnitLength(b));
764
- // There are three cases. If X is located in the spherical wedge defined by
765
- // A, B, and the axis A x B, then the closest point is on the segment AB.
766
- // Otherwise the closest point is either A or B; the dividing line between
767
- // these two cases is the great circle passing through (A x B) and the
768
- // midpoint of AB.
769
- if (S2_1.S2.simpleCCW(aCrossB, a, x) && S2_1.S2.simpleCCW(x, b, aCrossB)) {
770
- // The closest point to X lies on the segment AB. We compute the distance
771
- // to the corresponding great circle. The result is accurate for small
772
- // distances but not necessarily for large distances (approaching Pi/2).
773
- const sinDist = Math.abs(x.dotProd(aCrossB)) / (aCrossB.norm());
774
- return new S1Angle_1.S1Angle(Math.asin(Math.min(1.0, sinDist)));
775
- }
776
- // Otherwise, the closest point is either A or B. The cheapest method is
777
- // just to compute the minimum of the two linear (as opposed to spherical)
778
- // distances and convert the result to an angle. Again, this method is
779
- // accurate for small but not large distances (approaching Pi).
780
- const linearDist2 = Math.min(S2Point_1.S2Point.minus(x, a).norm2(), S2Point_1.S2Point.minus(x, b).norm2());
781
- return new S1Angle_1.S1Angle(Math.asin(Math.min(1.0, Math.sqrt(linearDist2) * 0.5)) * 2);
782
- }
783
- }
784
- exports.S2EdgeUtil = S2EdgeUtil;
785
- //# sourceMappingURL=S2EdgeUtil.js.map