nodes2ts 4.0.0 → 4.0.2
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.
- package/dist/export.cjs +85 -13
- package/dist/export.cjs.map +1 -1
- package/dist/export.d.cts +63 -14
- package/dist/export.d.ts +63 -14
- package/dist/export.js +85 -13
- package/dist/export.js.map +1 -1
- package/package.json +1 -1
package/dist/export.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/export.ts","../src/R2Vector.ts","../src/S2Point.ts","../src/Platform.ts","../src/S2Metric.ts","../src/S2.ts","../src/S1Angle.ts","../src/Interval.ts","../src/S1Interval.ts","../src/R1Interval.ts","../src/S2LatLng.ts","../src/S2EdgeUtil.ts","../src/S2LatLngRect.ts","../src/utils/preconditions.ts","../src/S1ChordAngle.ts","../src/S2Cap.ts","../src/uint64.ts","../src/S2Projections.ts","../src/S2CellId.ts","../src/compat.ts","../src/MutableInteger.ts","../src/S2Cell.ts","../src/S2CellUnion.ts","../src/S2RegionCoverer.ts"],"sourcesContent":["import {S2Region} from \"./S2Region\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {S2Cap} from \"./S2Cap\";\nexport * from './uint64';\nexport * from './compat';\nexport * from './Interval';\nexport * from './MutableInteger';\nexport * from './R1Interval';\nexport * from './R2Vector';\nexport * from './S1Angle';\nexport * from './S1Interval';\nexport * from './S2';\nexport * from './S2Cap';\nexport * from './S2Cell';\nexport * from './S2CellId';\nexport * from './S2CellUnion';\n// export * from './S2EdgeIndex';\n// export * from './S2EdgeUtil';\nexport * from './S2LatLng';\nexport * from './S2LatLngRect';\n// export * from './S2Loop';\nexport * from './S2Point';\nexport * from './S2Projections';\nexport * from './S2Region';\nexport * from './S2RegionCoverer';\n\nexport class Utils {\n\n /**\n * Calculates a region covering a circle\n * NOTE: The current implementation uses S2Cap while S2Loop would be better (S2Loop is not implemented yet)\n * @param center\n * @param radiusInKM\n * @param points the number of points to calculate. The higher the better precision\n * @returns {S2Region}\n */\n static calcRegionFromCenterRadius(center:S2LatLng, radiusInKM:number, points=16):S2Region {\n const pointsAtDistance = center.pointsAtDistance(radiusInKM, points);\n let s2Cap = S2Cap.empty().addPoint(center.toPoint());\n // It would be probably enough to add one of the points/2 pair of opposite points in the circle such\n // as (0, points/2). but since this is just a temporary solution lets stick with this as it\n // will come handy when implementing S2Loop.\n pointsAtDistance\n .map(p => p.toPoint())\n .forEach(p => {\n s2Cap = s2Cap.addPoint(p);\n });\n return s2Cap;\n }\n}\n","import {S2Point} from \"./S2Point\";\n/**\n * R2Vector represents a vector in the two-dimensional space. It defines the\n * basic geometrical operations for 2D vectors, e.g. cross product, addition,\n * norm, comparison etc.\n *\n */\nexport class R2Vector {\n private _x: number;\n private _y: number;\n constructor(_x:number, _y:number) {\n this._x = _x;\n this._y = _y;\n }\n\n get x() {\n return this._x;\n }\n\n get y() {\n return this._y;\n }\n\n\n public get(index:number) {\n if (index < 0 || index > 1) {\n throw new Error(`Index out fo bounds error ${index}`);\n }\n return index == 0 ? this._x : this._y;\n }\n\n static fromPointFace(p:S2Point, face:number): R2Vector {\n return p.toR2Vector(face);\n }\n public static add(p1:R2Vector, p2:R2Vector):R2Vector {\n return new R2Vector(p1._x + (p2._x), p1._y + (p2._y));\n }\n\n public static mul(p:R2Vector, m:number):R2Vector {\n return new R2Vector(m * (p._x), m * (p._y));\n }\n\n public norm2() {\n return this.x * this.x + this.y * this.y;\n }\n\n public static dotProd(p1:R2Vector, p2:R2Vector) {\n return p1.x * (p2.x) + (p1.y * (p2.y));\n }\n\n public dotProd(that:R2Vector) {\n return R2Vector.dotProd(this, that);\n }\n\n public crossProd(that:R2Vector) {\n return this.x*(that.y) - (this.y*(that.x));\n }\n\n public lessThan(vb:R2Vector):boolean {\n if (this.x < (vb.x)) {\n return true;\n }\n if (vb.x < (this.x)) {\n return false;\n }\n if (this.y < (vb.y)) {\n return true;\n }\n return false;\n }\n\n//\n// @Override\n// public boolean equals(Object that) {\n// if (!(that instanceof R2Vector)) {\n// return false;\n// }\n// R2Vector thatPoint = (R2Vector) that;\n// return this.x == thatPoint.x && this.y == thatPoint.y;\n// }\n\n// /**\n// * Calcualates hashcode based on stored coordinates. Since we want +0.0 and\n// * -0.0 to be treated the same, we ignore the sign of the coordinates.\n// */\n// @Override\n// public int hashCode() {\n// long value = 17;\n// value += 37 * value + Double.doubleToLongBits(Math.abs(x));\n// value += 37 * value + Double.doubleToLongBits(Math.abs(y));\n// return (int) (value ^ (value >>> 32));\n// }\n//\n\n public static fromSTVector(stVector: R2Vector):R2Vector{\n return new R2Vector(\n R2Vector.singleStTOUV(stVector.x),\n R2Vector.singleStTOUV(stVector.y)\n );\n\n }\n\n // from S2Projections.stToUV (QUADRATIC)\n public static singleStTOUV(s:number): number {\n if (s >= 0.5) {\n return (1 / 3) * (4 * s * s - 1);\n } else {\n return (1 / 3) * (1 - 4 * (1 - s) * (1 - s));\n }\n\n }\n public static singleUVToST(u:number): number {\n if (u >= 0) {\n return 0.5 * Math.sqrt(1 + 3 * u);\n } else {\n return 1 - 0.5 * Math.sqrt(1 - 3 * u);\n }\n }\n\n /**\n * To be used only if this vector is representing uv.\n * @param face\n * @returns {S2Point}\n */\n public toPoint(face:number) {\n switch (face) {\n case 0:\n return new S2Point(1, this.x, this.y);\n case 1:\n return new S2Point(this.x * -1 , 1, this.y);\n case 2:\n return new S2Point(this.x * -1, this.y * -1, 1);\n case 3:\n return new S2Point(-1, this.y * -1, this.x * -1);\n case 4:\n return new S2Point(this.y, -1, this.x * -1);\n default:\n return new S2Point(this.y, this.x, -1);\n }\n }\n\n public toSt(which: number) {\n return which == 0?R2Vector.singleUVToST(this.x): R2Vector.singleUVToST(this.y);\n }\n public toString():string {\n return \"(\" + this.x.toString() + \", \" + this.y.toString() + \")\";\n }\n\n}\n","/*\n * Copyright 2006 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {R2Vector} from \"./R2Vector\";\n\n///re\n/**\n * An S2Point represents a point on the unit sphere as a 3D vector. Usually\n * points are normalized to be unit length, but some methods do not require\n * this.\n *\n */\nexport class S2Point {\n\n /** Origin of the coordinate system, [0,0,0]. */\n public static ORIGIN = new S2Point(0, 0, 0);\n\n /** Direction of the x-axis. */\n public static X_POS = new S2Point(1, 0, 0);\n\n /** Opposite direction of the x-axis. */\n public static X_NEG = new S2Point(-1, 0, 0);\n\n /** Direction of the y-axis. */\n public static Y_POS = new S2Point(0, 1, 0);\n\n /** Opposite direction of the y-axis. */\n public static Y_NEG = new S2Point(0, -1, 0);\n\n /** Direction of the z-axis. */\n public static Z_POS = new S2Point(0, 0, 1);\n\n /** Opposite direction of the z-axis. */\n public static Z_NEG = new S2Point(0, 0, -1);\n\n public x: number;\n public y: number;\n public z: number;\n constructor(x:number, y:number, z:number) {\n this.x = (x);\n this.y = (y);\n this.z = (z);\n // this.y = typeof(y) === 'number'?new Decimal(y):y as Decimal;\n // this.z = typeof(z) === 'number'?new Decimal(z):z as Decimal;\n }\n\n static minus(p1:S2Point, p2:S2Point) {\n return S2Point.sub(p1, p2);\n }\n\n static neg(p: S2Point) {\n return new S2Point(p.x * -1, p.y*-1, p.z*-1);\n }\n\n public norm2() {\n return Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2);\n }\n\n public norm() {\n return Math.sqrt(this.norm2());\n }\n\n\n static crossProd(p1:S2Point, p2:S2Point):S2Point {\n return new S2Point(\n p1.y* (p2.z) - (p1.z* (p2.y)),\n p1.z* (p2.x) - (p1.x* (p2.z)),\n // p1.z * p2.x - p1.x * p2.z,\n p1.x* (p2.y) - (p1.y* (p2.x))\n // p1.x * p2.y - p1.y * p2.x\n );\n }\n\n static add(p1:S2Point, p2:S2Point):S2Point {\n return new S2Point(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z);\n }\n\n static sub(p1:S2Point, p2:S2Point):S2Point {\n return new S2Point(p1.x - p2.x, p1.y - p2.y, p1.z - p2.z);\n }\n\n public dotProd(that:S2Point) {\n return this.x*(that.x) +(this.y * that.y) + (this.z* (that.z));\n }\n\n public static mul(p, m: number):S2Point {\n return new S2Point(m* (p.x), m* (p.y) , m* (p.z));\n }\n\n public static div(p:S2Point, m:number):S2Point {\n return new S2Point(p.x / (m), p.y / (m), p.z / (m));\n }\n\n /**\n * Returns the distance in 3D coordinates from this to that.\n *\n * <p>Equivalent to {@code a.sub(b).norm()}, but significantly faster.\n *\n * <p>If ordering points by angle, this is faster than {@link #norm}, and much faster than {@link\n * #angle}, but consider using {@link S1ChordAngle}.\n */ \n public getDistance(that: S2Point): number {\n return Math.sqrt(this.getDistance2(that));\n }\n\n /**\n * Returns the square of the distance in 3D coordinates from this to that.\n *\n * <p>Equivalent to {@code getDistance(that)<sup>2</sup>}, but significantly faster.\n *\n * <p>If ordering points by angle, this is much faster than {@link #angle}, but consider using\n * {@link S1ChordAngle}.\n */\n public getDistance2(that: S2Point): number {\n const dx = this.x - that.x;\n const dy = this.y - that.y;\n const dz = this.z - that.z;\n return dx * dx + dy * dy + dz * dz;\n }\n\n /** return a vector orthogonal to this one */\n public ortho():S2Point {\n const k = this.largestAbsComponent();\n let temp;\n if (k == 1) {\n temp = new S2Point(1,0,0);\n } else if (k == 2) {\n temp = new S2Point(0,1,0);\n } else {\n temp = new S2Point(0,0,1);\n }\n return S2Point.normalize(S2Point.crossProd(this, temp));\n }\n\n /** Return the index of the largest component fabs */\n public largestAbsComponent():number {\n return S2Point.largestAbsComponent(this.x, this.y, this.z);\n }\n\n public static largestAbsComponent(x: number, y: number, z: number): number {\n const absX = Math.abs(x);\n const absY = Math.abs(y);\n const absZ = Math.abs(z);\n if (absX > absY) {\n if (absX > absZ) {\n return 0;\n } else {\n return 2;\n }\n } else {\n if (absY > absZ) {\n return 1;\n } else {\n return 2;\n }\n }\n }\n\n public get(axis: number): number {\n return (axis == 0) ? this.x : (axis == 1) ? this.y : this.z;\n }\n\n public static fabs(p:S2Point):S2Point {\n return new S2Point(Math.abs(p.x), Math.abs(p.y), Math.abs(p.z));\n }\n\n /** Returns a copy of 'p' rescaled to be unit-length. */\n public static normalize(p:S2Point) {\n let norm = p.norm();\n\n if (norm != 0) {\n norm = 1 / norm;\n }\n return S2Point.mul(p, norm);\n }\n\n axis(axis:number) {\n return (axis == 0) ? this.x : (axis == 1) ? this.y : this.z;\n }\n\n /** Return the angle between two vectors in radians */\n public angle(va) {\n return Math.atan2(S2Point.crossProd(this, va).norm(), this.dotProd(va));\n }\n\n /**\n * Compare two vectors, return true if all their components are within a\n * difference of margin.\n */\n aequal(that:S2Point, margin:number):boolean {\n return this.x - Math.abs(that.x) < (margin) &&\n this.y - Math.abs(that.y) < (margin) &&\n this.z - Math.abs(that.z) < (margin);\n }\n\n equals(that:S2Point):boolean {\n if (!(that instanceof S2Point)) {\n return false;\n }\n return this.x == (that.x) && this.y==(that.y) && this.z==(that.z);\n }\n\n public lessThan(vb:S2Point):boolean {\n if (this.x < (vb.x)) {\n return true;\n }\n if (vb.x < (this.x)) {\n return false;\n }\n if (this.y < (vb.y)) {\n return true;\n }\n if (vb.y < (this.y)) {\n return false;\n }\n if (this.z < (vb.z)) {\n return true;\n }\n return false;\n }\n\n public compareTo(other:S2Point):number {\n return (this.lessThan(other) ? -1 : (this.equals(other) ? 0 : 1));\n }\n\n\n toFace():number {\n let face = this.largestAbsComponent();\n if (this.axis(face) < (0)) {\n face += 3;\n }\n return face;\n }\n\n toR2Vector(face:number = this.toFace()):R2Vector {\n let u;\n let v;\n switch (face) {\n case 0:\n u = this.y / (this.x);\n v = this.z / (this.x);\n break;\n case 1:\n u = (this.x * -1) / (this.y);\n v = this.z / (this.y);\n break;\n case 2:\n u = (this.x * -1) / (this.z);\n v = (this.y * -1) / (this.z);\n break;\n case 3:\n u = this.z / (this.x);\n v = this.y / (this.x);\n break;\n case 4:\n u = this.z / (this.y);\n v = (this.x * -1) / (this.y);\n break;\n case 5:\n u = (this.y * -1) / (this.z);\n v = (this.x * -1) / (this.z);\n break;\n default:\n throw new Error('Invalid face');\n }\n return new R2Vector(u, v);\n }\n\n\n toString():string {\n return `Point(${this.x}, ${this.y}, ${this.z})`;\n }\n}\n","const exponentBuffer = new ArrayBuffer(8);\nconst exponentView = new DataView(exponentBuffer);\n\nfunction getFloat64Exponent(value: number): number {\n exponentView.setFloat64(0, value, false);\n const highWord = exponentView.getUint32(0, false);\n return ((highWord & 0x7ff00000) >>> 20) - 1023;\n}\n\nexport class Platform {\n public static IEEEremainder(f1: number, f2: number): number {\n // let r = f1 % f2;\n\n // if (isNaN(r) || r == (f2) || r <= (Math.abs(f2) / 2)) {\n // return r;\n // } else {\n // return (f1 >= (0) ? 1 : -1) * (r - f2);\n // }\n\n if (Number.isNaN(f1)) {\n return f1;\n }\n\n if (Number.isNaN(f2)) {\n return f2\n }\n\n if ((f2 === Number.POSITIVE_INFINITY || f2 === Number.NEGATIVE_INFINITY) && Number.isFinite(f1)) {\n return f1;\n }\n\n return f1 - (Math.round(f1 / f2) * f2);\n }\n\n /**\n * If v is non-zero, return an integer {@code exp} such that\n * {@code (0.5 <= |v|*2^(-exp) < 1)}. If v is zero, return 0.\n *\n * <p>Note that this arguably a bad definition of exponent because it makes\n * {@code exp(9) == 4}. In decimal this would be like saying that the\n * exponent of 1234 is 4, when in scientific 'exponent' notation 1234 is\n * {@code 1.234 x 10^3}.\n *\n * TODO(dbeaumont): Replace this with \"DoubleUtils.getExponent(v) - 1\" ?\n */\n public static getExponent(v:number ):number {\n // if (v == 0) {\n // return 0;\n // }\n // // IT should always be ((int)log(2,v))+1;\n // const start = Math.floor(Math.log(v)/Math.log(2));\n // for(let i= start; i<start+10; i++) {\n // const curVal = Math.abs(v) * Math.pow(2,-i);\n // if (curVal >= 0.5 && curVal < 1 ) {\n // return i;\n // }\n // }\n // throw new Error('method not written yet');\n // // return (int)((S2.EXPONENT_MASK & bits) >> S2.EXPONENT_SHIFT) - 1022;\n return getFloat64Exponent(v);\n }\n}\n","import { Platform } from \"./Platform\";\nimport {S2} from \"./S2\";\n/**\n * Defines an area or a length cell metric.\n */\nexport class S2Metric {\n private _dim:number;\n private _deriv:number;\n\n /**\n * Defines a cell metric of the given dimension (1 == length, 2 == area).\n */\n public constructor(_dim:number, _deriv:number) {\n this._dim = _dim;\n this._deriv = _deriv;\n\n }\n\n deriv() {\n return this._deriv;\n }\n\n dim() {\n return this._dim;\n }\n\n /** Return the value of a metric for cells at the given level. */\n public getValue(level:number):number {\n return this.deriv() * Math.pow(2, -this.dim() * level)\n }\n\n /**\n * Return the level at which the metric has approximately the given value.\n * For example, S2::kAvgEdge.GetClosestLevel(0.1) returns the level at which\n * the average cell edge length is approximately 0.1. The return value is\n * always a valid level.\n */\n public getClosestLevel(/*double*/value:number):number {\n return this.getMinLevel((this.dim() == 1 ? S2.M_SQRT2 : 2) * value);\n }\n\n /**\n * Return the minimum level such that the metric is at most the given value,\n * or S2CellId::kMaxLevel if there is no such level. For example,\n * S2::kMaxDiag.GetMinLevel(0.1) returns the minimum level such that all\n * cell diagonal lengths are 0.1 or smaller. The return value is always a\n * valid level.\n */\n public getMinLevel(value:number /*double*/):number /*int*/ {\n if (value <= 0) {\n return S2.MAX_LEVEL;\n }\n\n // This code is equivalent to computing a floating-point \"level\"\n // value and rounding up.\n // let exponent = Platform.getExponent(value / ((1 << this.dim()) * this.deriv()));\n const exponent = Platform.getExponent(this.deriv() / value);\n // let level = Math.max(0,\n // Math.min(S2.MAX_LEVEL, -((exponent - 1) >> (this.dim() - 1))));\n const level = Math.max(0, Math.min(S2.MAX_LEVEL, -(exponent >> (this.dim() - 1))));\n\n // assert (level == S2CellId.MAX_LEVEL || getValue(level) <= value);\n // assert (level == 0 || getValue(level - 1) > value);\n return level;\n }\n\n /**\n * Return the maximum level such that the metric is at least the given\n * value, or zero if there is no such level. For example,\n * S2.kMinWidth.GetMaxLevel(0.1) returns the maximum level such that all\n * cells have a minimum width of 0.1 or larger. The return value is always a\n * valid level.\n */\n public getMaxLevel(value:number /*double*/):number {\n if (value <= 0) {\n return S2.MAX_LEVEL;\n }\n\n // This code is equivalent to computing a floating-point \"level\"\n // value and rounding down.\n const exponent = Platform.getExponent(this.deriv() / value);\n const level = Math.max(0, Math.min(S2.MAX_LEVEL, exponent >> (this.dim() - 1)));\n\n // assert (level == 0 || getValue(level) >= value);\n // assert (level == S2CellId.MAX_LEVEL || getValue(level + 1) < value);\n return level;\n }\n}\n","import {S2Point} from \"./S2Point\";\nimport {S2Metric} from \"./S2Metric\";\nimport { Platform } from \"./Platform\";\n\nexport class S2 {\n\n public static M_PI = Math.PI;\n public static M_1_PI = 1.0 / Math.PI;\n public static M_PI_2 = Math.PI / 2.0;\n public static M_PI_4 = Math.PI / 4.0;\n public static M_SQRT2 = Math.sqrt(2);\n public static M_E = Math.E;\n // the axis directions are reversed).\n public static SWAP_MASK = 0x01;\n public static INVERT_MASK = 0x02;\n\n /** Mapping from cell orientation + Hilbert traversal to IJ-index. */\n public static POS_TO_ORIENTATION = [S2.SWAP_MASK, 0, 0, S2.INVERT_MASK + S2.SWAP_MASK];\n public static DBL_EPSILON = 2 * Number.EPSILON;\n\n public static POS_TO_IJ = [\n // 0 1 2 3\n [0, 1, 3, 2], // canonical order: (0,0), (0,1), (1,1), (1,0)\n [0, 2, 3, 1], // axes swapped: (0,0), (1,0), (1,1), (0,1)\n [3, 2, 0, 1], // bits inverted: (1,1), (1,0), (0,0), (0,1)\n [3, 1, 0, 2], // swapped & inverted: (1,1), (0,1), (0,0), (1,0)\n ];\n static MAX_LEVEL = 30;\n\n public static IEEEremainder(f1:number, f2:number): number {\n return Platform.IEEEremainder(f1, f2);\n }\n\n /**\n * Return true if the given point is approximately unit length (this is mainly\n * useful for assertions).\n */\n public static isUnitLength(p:S2Point):boolean {\n return Math.abs(p.norm2() - 1) <= (1e-15);\n }\n\n /**\n * If v is non-zero, return an integer {@code exp} such that\n * {@code (0.5 <= |v|*2^(-exp) < 1)}. If v is zero, return 0.\n *\n * <p>Note that this arguably a bad definition of exponent because it makes\n * {@code exp(9) == 4}. In decimal this would be like saying that the\n * exponent of 1234 is 4, when in scientific 'exponent' notation 1234 is\n * {@code 1.234 x 10^3}.\n *\n * TODO(dbeaumont): Replace this with \"DoubleUtils.getExponent(v) - 1\" ?\n */\n static exp(v:number /*double*/):number {\n return Platform.getExponent(v);\n }\n\n /**\n * Return a vector \"c\" that is orthogonal to the given unit-length vectors \"a\"\n * and \"b\". This function is similar to a.CrossProd(b) except that it does a\n * better job of ensuring orthogonality when \"a\" is nearly parallel to \"b\",\n * and it returns a non-zero result even when a == b or a == -b.\n *\n * It satisfies the following properties (RCP == RobustCrossProd):\n *\n * (1) RCP(a,b) != 0 for all a, b (2) RCP(b,a) == -RCP(a,b) unless a == b or\n * a == -b (3) RCP(-a,b) == -RCP(a,b) unless a == b or a == -b (4) RCP(a,-b)\n * == -RCP(a,b) unless a == b or a == -b\n */\n static robustCrossProd(a:S2Point, b:S2Point):S2Point {\n // The direction of a.CrossProd(b) becomes unstable as (a + b) or (a - b)\n // approaches zero. This leads to situations where a.CrossProd(b) is not\n // very orthogonal to \"a\" and/or \"b\". We could fix this using Gram-Schmidt,\n // but we also want b.RobustCrossProd(a) == -b.RobustCrossProd(a).\n //\n // The easiest fix is to just compute the cross product of (b+a) and (b-a).\n // Given that \"a\" and \"b\" are unit-length, this has good orthogonality to\n // \"a\" and \"b\" even if they differ only in the lowest bit of one component.\n\n // assert (isUnitLength(a) && isUnitLength(b));\n const x = S2Point.crossProd(S2Point.add(b, a), S2Point.sub(b, a));\n if (!x.equals(new S2Point(0, 0, 0))) {\n return x;\n }\n // The only result that makes sense mathematically is to return zero, but\n // we find it more convenient to return an arbitrary orthogonal vector.\n return a.ortho();\n }\n\n /**\n * Return the area of triangle ABC. The method used is about twice as\n * expensive as Girard's formula, but it is numerically stable for both large\n * and very small triangles. The points do not need to be normalized. The area\n * is always positive.\n *\n * The triangle area is undefined if it contains two antipodal points, and\n * becomes numerically unstable as the length of any edge approaches 180\n * degrees.\n */\n static area(a:S2Point, b:S2Point, c:S2Point) {\n // This method is based on l'Huilier's theorem,\n //\n // tan(E/4) = sqrt(tan(s/2) tan((s-a)/2) tan((s-b)/2) tan((s-c)/2))\n //\n // where E is the spherical excess of the triangle (i.e. its area),\n // a, b, c, are the side lengths, and\n // s is the semiperimeter (a + b + c) / 2 .\n //\n // The only significant source of error using l'Huilier's method is the\n // cancellation error of the terms (s-a), (s-b), (s-c). This leads to a\n // *relative* error of about 1e-16 * s / min(s-a, s-b, s-c). This compares\n // to a relative error of about 1e-15 / E using Girard's formula, where E is\n // the true area of the triangle. Girard's formula can be even worse than\n // this for very small triangles, e.g. a triangle with a true area of 1e-30\n // might evaluate to 1e-5.\n //\n // So, we prefer l'Huilier's formula unless dmin < s * (0.1 * E), where\n // dmin = min(s-a, s-b, s-c). This basically includes all triangles\n // except for extremely long and skinny ones.\n //\n // Since we don't know E, we would like a conservative upper bound on\n // the triangle area in terms of s and dmin. It's possible to show that\n // E <= k1 * s * sqrt(s * dmin), where k1 = 2*sqrt(3)/Pi (about 1).\n // Using this, it's easy to show that we should always use l'Huilier's\n // method if dmin >= k2 * s^5, where k2 is about 1e-2. Furthermore,\n // if dmin < k2 * s^5, the triangle area is at most k3 * s^4, where\n // k3 is about 0.1. Since the best case error using Girard's formula\n // is about 1e-15, this means that we shouldn't even consider it unless\n // s >= 3e-4 or so.\n\n // We use volatile doubles to force the compiler to truncate all of these\n // quantities to 64 bits. Otherwise it may compute a value of dmin > 0\n // simply because it chose to spill one of the intermediate values to\n // memory but not one of the others.\n const sa = b.angle(c);\n const sb = c.angle(a);\n const sc = a.angle(b);\n const s = sa+ (sb)+ (sc) * (0.5);\n // 0.5 * (sa + sb + sc);\n if (s >= (3e-4)) {\n // Consider whether Girard's formula might be more accurate.\n const s2 = s * 2;\n const dmin = s - Math.max(\n sa,\n sb,\n sc\n );\n if (dmin < (s2 * s2 * (s) * (1e-2))) {\n // This triangle is skinny enough to consider Girard's formula.\n const area = S2.girardArea(a, b, c);\n if (dmin < (s * (area * (0.1)))) {\n return area;\n }\n }\n }\n // Use l'Huilier's formula.\n return 4 * (\n Math.atan(\n Math.sqrt(\n Math.max(\n 0.0,\n Math.tan(s * (0.5))\n * (Math.tan(s - (sa) * (0.5)))\n * (Math.tan(s - (sb) * (0.5)))\n * (Math.tan(s - (sc) * (0.5)))\n )\n )\n )\n )\n }\n\n\n /**\n * Return the area of the triangle computed using Girard's formula. This is\n * slightly faster than the Area() method above is not accurate for very small\n * triangles.\n */\n static girardArea(a:S2Point, b:S2Point, c:S2Point) {\n // This is equivalent to the usual Girard's formula but is slightly\n // more accurate, faster to compute, and handles a == b == c without\n // a special case.\n\n const ab = S2Point.crossProd(a, b);\n const bc = S2Point.crossProd(b, c);\n const ac = S2Point.crossProd(a, c);\n return Math.max(\n 0,\n ab.angle(ac) - ab.angle(bc) + bc.angle(ac)\n );\n }\n\n /**\n * Return true if the points A, B, C are strictly counterclockwise. Return\n * false if the points are clockwise or colinear (i.e. if they are all\n * contained on some great circle).\n *\n * Due to numerical errors, situations may arise that are mathematically\n * impossible, e.g. ABC may be considered strictly CCW while BCA is not.\n * However, the implementation guarantees the following:\n *\n * If SimpleCCW(a,b,c), then !SimpleCCW(c,b,a) for all a,b,c.\n *\n * In other words, ABC and CBA are guaranteed not to be both CCW\n */\n public static simpleCCW(a:S2Point, b:S2Point, c:S2Point):boolean {\n // We compute the signed volume of the parallelepiped ABC. The usual\n // formula for this is (AxB).C, but we compute it here using (CxA).B\n // in order to ensure that ABC and CBA are not both CCW. This follows\n // from the following identities (which are true numerically, not just\n // mathematically):\n //\n // (1) x.CrossProd(y) == -(y.CrossProd(x))\n // (2) (-x).DotProd(y) == -(x.DotProd(y))\n\n return S2Point.crossProd(c, a).dotProd(b) > 0;\n }\n\n /**\n *\n * Return true if edge AB crosses CD at a point that is interior to both\n * edges. Properties:\n *\n * (1) SimpleCrossing(b,a,c,d) == SimpleCrossing(a,b,c,d) (2)\n * SimpleCrossing(c,d,a,b) == SimpleCrossing(a,b,c,d)\n */\n public static simpleCrossing(a:S2Point, b:S2Point, c:S2Point, d:S2Point):boolean {\n // We compute SimpleCCW() for triangles ACB, CBD, BDA, and DAC. All\n // of these triangles need to have the same orientation (CW or CCW)\n // for an intersection to exist. Note that this is slightly more\n // restrictive than the corresponding definition for planar edges,\n // since we need to exclude pairs of line segments that would\n // otherwise \"intersect\" by crossing two antipodal points.\n\n const ab = S2Point.crossProd(a, b);\n const cd = S2Point.crossProd(c, d);\n const acb = ab.dotProd(c) * -1;\n const cbd = cd.dotProd(b) * -1;\n const bda = ab.dotProd(d);\n const dac = cd.dotProd(a);\n\n return (acb * (cbd) > (0)) && (cbd * (bda) > (0)) && (bda * (dac) > (0));\n }\n\n public static approxEqualsPointError(a: S2Point, b: S2Point, maxError: number): boolean {\n return a.angle(b) <= maxError;\n }\n\n public static approxEqualsPoint(a: S2Point, b: S2Point): boolean {\n return this.approxEqualsPointError(a, b, 1e-15);\n }\n\n public static approxEqualsNumberError(a: number, b: number, maxError: number): boolean {\n return Math.abs(a - b) <= maxError;\n }\n\n public static approxEqualsNumber(a: number, b: number): boolean {\n return this.approxEqualsNumberError(a, b, 1e-15);\n }\n\n static Metric = S2Metric\n}\n\nexport { S2Metric };\n","import {S2Point} from \"./S2Point\";\n\nexport class S1Angle {\n public static INFINITY: S1Angle = new S1Angle(Number.POSITIVE_INFINITY);\n public static ZERO: S1Angle = new S1Angle(0);\n\n\n public radians: number;\n constructor(radians: number) {\n this.radians = radians;\n }\n\n\n public degrees() {\n return this.radians * 180 / Math.PI;\n }\n\n //\n // public long e5() {\n // return Math.round(degrees() * 1e5);\n // }\n //\n // public long e6() {\n // return Math.round(degrees() * 1e6);\n // }\n //\n // public long e7() {\n // return Math.round(degrees() * 1e7);\n // }\n\n /**\n * Return the angle between two points, which is also equal to the distance\n * between these points on the unit sphere. The points do not need to be\n * normalized.\n */\n static fromPoints(x: S2Point, y: S2Point) {\n return new S1Angle(x.angle(y));\n }\n\n public lessThan(that: S1Angle): boolean {\n return this.radians < (that.radians);\n }\n\n public greaterThan(that: S1Angle): boolean {\n return this.radians > (that.radians);\n }\n\n public lessOrEquals(that: S1Angle): boolean {\n return this.radians <= (that.radians);\n }\n\n public greaterOrEquals(that: S1Angle): boolean {\n return this.radians >= (that.radians);\n }\n\n public static max(left: S1Angle, right: S1Angle): S1Angle {\n return right.greaterThan(left) ? right : left;\n }\n\n public static min(left: S1Angle, right: S1Angle): S1Angle {\n return right.greaterThan(left) ? left : right;\n }\n\n public static radians(radians: number): S1Angle {\n return new S1Angle(radians);\n }\n\n public static degrees(degrees: number): S1Angle {\n return new S1Angle(degrees * (Math.PI / 180));\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this + a)</code>.\n */\n public add(a: S1Angle): S1Angle {\n return new S1Angle(this.radians + a.radians);\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this - a)</code>.\n */\n public sub(a: S1Angle): S1Angle {\n return new S1Angle(this.radians - a.radians);\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this * m)</code>.\n */\n public mul(m: number): S1Angle {\n return new S1Angle(this.radians * m);\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this / d)</code>.\n */\n public div(d: number): S1Angle {\n return new S1Angle(this.radians / d);\n }\n\n /**\n * Returns the trigonometric cosine of the angle.\n */\n public cos(): number {\n return Math.cos(this.radians);\n }\n\n /**\n * Returns the trigonometric sine of the angle.\n */\n public sin(): number {\n return Math.sin(this.radians);\n }\n\n /**\n * Returns the trigonometric tangent of the angle.\n */\n public tan(): number {\n return Math.tan(this.radians);\n }\n\n /** Returns the distance along the surface of a sphere of the given radius. */\n public distance(radius: number): number {\n return this.radians * radius;\n }\n\n //\n // public static S1Angle e5(long e5) {\n // return degrees(e5 * 1e-5);\n // }\n //\n // public static S1Angle e6(long e6) {\n // // Multiplying by 1e-6 isn't quite as accurate as dividing by 1e6,\n // // but it's about 10 times faster and more than accurate enough.\n // return degrees(e6 * 1e-6);\n // }\n //\n // public static S1Angle e7(long e7) {\n // return degrees(e7 * 1e-7);\n // }\n\n /**\n * Writes the angle in degrees with a \"d\" suffix, e.g. \"17.3745d\". By default\n * 6 digits are printed; this can be changed using setprecision(). Up to 17\n * digits are required to distinguish one angle from another.\n */\n public toString(): string {\n return this.degrees() + \"d\";\n }\n\n public compareTo(that: S1Angle): number {\n return this.radians < that.radians ? -1 : this.radians > that.radians ? 1 : 0;\n }\n\n public equals(that: S1Angle): boolean {\n return this.compareTo(that) === 0;\n }\n}\n","export abstract class Interval {\n public lo: number;\n public hi: number;\n\n constructor(lo:number, hi:number) {\n this.lo = lo;\n this.hi = hi;\n }\n\n /** Return true if the interval is empty, i.e. it contains no points. */\n\n public abstract isEmpty():boolean;\n\n /**\n * Return the center of the interval. For empty intervals, the result is\n * arbitrary.\n */\n public abstract getCenter(): number;\n\n /**\n * Return the length of the interval. The length of an empty interval is\n * negative.\n */\n public abstract getLength(): number;\n\n public abstract contains(p:number):boolean;\n\n public abstract interiorContains(p:number):boolean;\n\n public toString():string {\n return \"[\" + this.lo.toString() + \", \" + this.hi.toString() + \"]\";\n }\n\n\n /**\n * Return true if two intervals contains the same set of points.\n */\n public equals(that: Interval):boolean {\n if (that instanceof Interval) {\n return this.lo == that.lo && this.hi == that.hi;\n }\n return false;\n }\n\n\n}\n","import {Interval} from \"./Interval\";\nimport {S2} from \"./S2\";\nimport { Platform } from './Platform';\nexport class S1Interval extends Interval {\n\n constructor(lo:number, hi:number, checked = false) {\n super(lo, hi);\n if (!checked) {\n if (this.lo == (-S2.M_PI) && this.hi != (S2.M_PI)) {\n this.lo = (S2.M_PI);\n }\n if (this.hi == (-S2.M_PI) && this.lo != (S2.M_PI)) {\n this.hi = (S2.M_PI);\n }\n }\n }\n\n /**\n * An interval is valid if neither bound exceeds Pi in absolute value, and the\n * value -Pi appears only in the Empty() and Full() intervals.\n */\n isValid():boolean {\n return Math.abs(this.lo) <= (S2.M_PI) && Math.abs(this.hi) <= (S2.M_PI)\n && !(this.lo == (-S2.M_PI) && this.hi != (S2.M_PI))\n && !(this.hi == (-S2.M_PI) && this.lo != (S2.M_PI));\n // return (Math.abs(this.lo) <= S2.M_PI && Math.abs(this.hi) <= S2.M_PI\n // && !(this.lo == -S2.M_PI && this.hi != S2.M_PI) && !(this.hi == -S2.M_PI && this.lo != S2.M_PI));\n }\n\n /** Return true if the interval contains all points on the unit circle. */\n isFull() {\n // console.log(this.hi - (this.lo) == (2 * S2.M_PI));\n return this.hi - (this.lo) == (2 * S2.M_PI)\n }\n\n\n /** Return true if the interval is empty, i.e. it contains no points. */\n public isEmpty() {\n return this.lo - (this.hi) == (2 * S2.M_PI);\n }\n\n\n /* Return true if this.lo > this.hi. (This is true for empty intervals.) */\n public isInverted():boolean {\n return this.lo > (this.hi);\n }\n\n\n /**\n * Return the midpoint of the interval. For full and empty intervals, the\n * result is arbitrary.\n */\n public getCenter() {\n const center = (this.lo + this.hi) / 2;\n // let center = 0.5 * (this.lo + this.hi);\n if (!this.isInverted()) {\n return center;\n }\n // Return the center in the range (-Pi, Pi].\n return (center <= (0)) ? (center + (S2.M_PI)) : (center - (S2.M_PI));\n }\n\n\n /**\n * Return the length of the interval. The length of an empty interval is\n * negative.\n */\n public getLength() {\n let length = this.hi - (this.lo);\n if (length >= (0)) {\n return length;\n }\n length = length + (2 * S2.M_PI);\n // Empty intervals have a negative length.\n return (length > (0)) ? length : (-1);\n }\n\n /**\n * Return the complement of the interior of the interval. An interval and its\n * complement have the same boundary but do not share any interior values. The\n * complement operator is not a bijection, since the complement of a singleton\n * interval (containing a single value) is the same as the complement of an\n * empty interval.\n */\n public complement():S1Interval {\n if (this.lo == (this.hi)) {\n return S1Interval.full(); // Singleton.\n }\n return new S1Interval(this.hi, this.lo, true); // Handles\n // empty and\n // full.\n }\n\n /** Return true if the interval (which is closed) contains the point 'p'. */\n public contains(_p:number):boolean {\n let p = (_p);\n // Works for empty, full, and singleton intervals.\n // assert (Math.abs(p) <= S2.M_PI);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n return this.fastContains(p);\n }\n\n /**\n * Return true if the interval (which is closed) contains the point 'p'. Skips\n * the normalization of 'p' from -Pi to Pi.\n *\n */\n public fastContains(_p:number):boolean {\n const p = (_p);\n if (this.isInverted()) {\n return (p>= (this.lo) || p <= (this.hi)) && !this.isEmpty();\n } else {\n return p>= (this.lo) && p <= (this.hi);\n }\n }\n\n /** Return true if the interior of the interval contains the point 'p'. */\n public interiorContains(_p:number):boolean {\n // Works for empty, full, and singleton intervals.\n // assert (Math.abs(p) <= S2.M_PI);\n let p = (_p);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n\n if (this.isInverted()) {\n return p > (this.lo) || p < (this.hi);\n } else {\n return (p > (this.lo) && p < (this.hi)) || this.isFull();\n }\n }\n\n /**\n * Return true if the interval contains the given interval 'y'. Works for\n * empty, full, and singleton intervals.\n */\n public containsI(y:S1Interval):boolean {\n // It might be helpful to compare the structure of these tests to\n // the simpler Contains(number) method above.\n\n if (this.isInverted()) {\n if (y.isInverted()) {\n return y.lo>= (this.lo) && y.hi <= (this.hi);\n }\n return (y.lo>= (this.lo) || y.hi <= (this.hi)) && !this.isEmpty();\n } else {\n if (y.isInverted()) {\n return this.isFull() || y.isEmpty();\n }\n return y.lo>= (this.lo) && y.hi <= (this.hi);\n }\n }\n\n /**\n * Returns true if the interior of this interval contains the entire interval\n * 'y'. Note that x.InteriorContains(x) is true only when x is the empty or\n * full interval, and x.InteriorContains(S1Interval(p,p)) is equivalent to\n * x.InteriorContains(p).\n */\n public interiorContainsI(y:S1Interval):boolean {\n if (this.isInverted()) {\n if (!y.isInverted()) {\n return this.lo > (this.lo) || y.hi < (this.hi);\n }\n return (y.lo > (this.lo) && y.hi < (this.hi)) || y.isEmpty();\n } else {\n if (y.isInverted()) {\n return this.isFull() || y.isEmpty();\n }\n return (y.lo > (this.lo) && y.hi < (this.hi)) || this.isFull();\n }\n }\n\n /**\n * Return true if the two intervals contain any points in common. Note that\n * the point +/-Pi has two representations, so the intervals [-Pi,-3] and\n * [2,Pi] intersect, for example.\n */\n public intersects(y:S1Interval):boolean {\n if (this.isEmpty() || y.isEmpty()) {\n return false;\n }\n if (this.isInverted()) {\n // Every non-empty inverted interval contains Pi.\n return y.isInverted() || y.lo <= (this.hi) || y.hi>= (this.lo);\n } else {\n if (y.isInverted()) {\n return y.lo <= (this.hi) || y.hi>= (this.lo);\n }\n return y.lo <= (this.hi) && y.hi>= (this.lo);\n }\n }\n\n /**\n * Return true if the interior of this interval contains any point of the\n * interval 'y' (including its boundary). Works for empty, full, and singleton\n * intervals.\n */\n public interiorIntersects(y:S1Interval):boolean {\n if (this.isEmpty() || y.isEmpty() || this.lo == (this.hi)) {\n return false;\n }\n if (this.isInverted()) {\n return y.isInverted() || y.lo < (this.hi) || y.hi > (this.lo);\n } else {\n if (y.isInverted()) {\n return y.lo < (this.hi) || y.hi > (this.lo);\n }\n return (y.lo < (this.hi) && y.hi > (this.lo)) || this.isFull();\n }\n }\n\n /**\n * Expand the interval by the minimum amount necessary so that it contains the\n * given point \"p\" (an angle in the range [-Pi, Pi]).\n */\n public addPoint(_p:number):S1Interval {\n let p = (_p);\n // assert (Math.abs(p) <= S2.M_PI);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n\n if (this.fastContains(p)) {\n return new S1Interval(this.lo, this.hi);\n }\n\n if (this.isEmpty()) {\n return S1Interval.fromPoint(p);\n } else {\n // Compute distance from p to each endpoint.\n const dlo = S1Interval.positiveDistance(p, this.lo);\n const dhi = S1Interval.positiveDistance(this.hi, p);\n if (dlo < (dhi)) {\n return new S1Interval(p, this.hi);\n } else {\n return new S1Interval(this.lo, p);\n }\n // Adding a point can never turn a non-full interval into a full one.\n }\n }\n\n /**\n * Return an interval that contains all points within a distance \"radius\" of\n * a point in this interval. Note that the expansion of an empty interval is\n * always empty. The radius must be non-negative.\n */\n public expanded(radius:number):S1Interval {\n // assert (radius >= 0);\n if (this.isEmpty()) {\n return this;\n }\n\n // Check whether this interval will be full after expansion, allowing\n // for a 1-bit rounding error when computing each endpoint.\n if (this.getLength() + (radius * 2)>= (2*S2.M_PI-1e-15)) {\n return S1Interval.full();\n }\n\n // NOTE(dbeaumont): Should this remainder be 2 * M_PI or just M_PI ??\n let lo = Platform.IEEEremainder(this.lo - (radius), 2 * S2.M_PI);\n const hi = Platform.IEEEremainder(this.hi + (radius), 2 * S2.M_PI);\n\n if (lo == (-S2.M_PI)) {\n lo = (S2.M_PI);\n }\n return new S1Interval(lo, hi);\n }\n\n /**\n * Return the smallest interval that contains this interval and the given\n * interval \"y\".\n */\n public union(y:S1Interval):S1Interval {\n // The y.is_full() case is handled correctly in all cases by the code\n // below, but can follow three separate code paths depending on whether\n // this interval is inverted, is non-inverted but contains Pi, or neither.\n\n if (y.isEmpty()) {\n return this;\n }\n if (this.fastContains(y.lo)) {\n if (this.fastContains(y.hi)) {\n // Either this interval contains y, or the union of the two\n // intervals is the Full() interval.\n if (this.containsI(y)) {\n return this; // is_full() code path\n }\n return S1Interval.full();\n }\n return new S1Interval(this.lo, this.hi, true);\n }\n if (this.fastContains(y.hi)) {\n return new S1Interval(y.lo, this.hi, true);\n }\n\n // This interval contains neither endpoint of y. This means that either y\n // contains all of this interval, or the two intervals are disjoint.\n if (this.isEmpty() || y.fastContains(this.lo)) {\n return y;\n }\n\n // Check which pair of endpoints are closer together.\n const dlo = S1Interval.positiveDistance(y.hi, this.lo);\n const dhi = S1Interval.positiveDistance(this.hi, y.lo);\n if (dlo < dhi) {\n return new S1Interval(y.lo, this.hi, true);\n } else {\n return new S1Interval(this.lo, y.hi, true);\n }\n }\n\n /**\n * Return the smallest interval that contains the intersection of this\n * interval with \"y\". Note that the region of intersection may consist of two\n * disjoint intervals.\n */\n public intersection(y:S1Interval):S1Interval {\n // The y.is_full() case is handled correctly in all cases by the code\n // below, but can follow three separate code paths depending on whether\n // this interval is inverted, is non-inverted but contains Pi, or neither.\n\n if (y.isEmpty()) {\n return S1Interval.empty();\n }\n if (this.fastContains(y.lo)) {\n if (this.fastContains(y.hi)) {\n // Either this interval contains y, or the region of intersection\n // consists of two disjoint subintervals. In either case, we want\n // to return the shorter of the two original intervals.\n if (y.getLength() < (this.getLength())) {\n return y; // is_full() code path\n }\n return this;\n }\n return new S1Interval(y.lo, this.hi, true);\n }\n if (this.fastContains(y.hi)) {\n return new S1Interval(this.lo, y.hi, true);\n }\n\n // This interval contains neither endpoint of y. This means that either y\n // contains all of this interval, or the two intervals are disjoint.\n\n if (y.fastContains(this.lo)) {\n return this; // is_empty() okay here\n }\n // assert (!intersects(y));\n return S1Interval.empty();\n }\n\n /**\n * Return true if the length of the symmetric difference between the two\n * intervals is at most the given tolerance.\n */\n public approxEquals(y:S1Interval, maxError=1e-9):boolean {\n if (this.isEmpty()) {\n return y.getLength() <= (maxError);\n }\n if (y.isEmpty()) {\n return this.getLength() <= (maxError);\n }\n\n return Math.abs(Platform.IEEEremainder(y.lo - (this.lo), 2 * S2.M_PI))\n + (Math.abs(Platform.IEEEremainder(y.hi - (this.hi), 2 * S2.M_PI)))\n <= (maxError);\n }\n\n\n\n static empty():S1Interval {\n return new S1Interval(S2.M_PI, -S2.M_PI, true);\n }\n\n static full():S1Interval {\n return new S1Interval(-S2.M_PI, S2.M_PI, true);\n }\n\n static fromPoint(_p:number):S1Interval {\n let p = (_p);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n return new S1Interval(p, p, true);\n }\n\n\n /**\n * Convenience method to construct the minimal interval containing the two\n * given points. This is equivalent to starting with an empty interval and\n * calling AddPoint() twice, but it is more efficient.\n */\n static fromPointPair(_p1:number, _p2:number):S1Interval {\n // assert (Math.abs(p1) <= S2.M_PI && Math.abs(p2) <= S2.M_PI);\n let p1 = (_p1);\n let p2 = (_p2);\n if (p1 == (-S2.M_PI)) {\n p1 = (S2.M_PI);\n }\n if (p2 == (-S2.M_PI)) {\n p2 = (S2.M_PI);\n }\n if (S1Interval.positiveDistance(p1, p2) <= (S2.M_PI)) {\n return new S1Interval(p1, p2, true);\n } else {\n return new S1Interval(p2, p1, true);\n }\n }\n\n /**\n * Compute the distance from \"a\" to \"b\" in the range [0, 2*Pi). This is\n * equivalent to (drem(b - a - S2.M_PI, 2 * S2.M_PI) + S2.M_PI), except that\n * it is more numerically stable (it does not lose precision for very small\n * positive distances).\n */\n public static positiveDistance(_a:number, _b:number): number {\n const a = (_a);\n const b = (_b);\n const d = b - (a);\n if (d >= (0)) {\n return d;\n }\n // We want to ensure that if b == Pi and a == (-Pi + eps),\n // the return result is approximately 2*Pi and not zero.\n return b + (S2.M_PI) - (a - (S2.M_PI));\n }\n\n}\n","import {Interval} from \"./Interval\";\n/**\n * An R1Interval represents a closed interval on a unit circle (also known as a\n * 1-dimensional sphere). It is capable of representing the empty interval\n * (containing no points), the full interval (containing all points), and\n * zero-length intervals (containing a single point).\n *\n * Points are represented by the angle they make with the positive x-axis in\n * the range [-Pi, Pi]. An interval is represented by its lower and upper bounds\n * (both inclusive, since the interval is closed). The lower bound may be\n * greater than the upper bound, in which case the interval is \"inverted\" (i.e.\n * it passes through the point (-1, 0)).\n *\n * Note that the point (-1, 0) has two valid representations, Pi and -Pi. The\n * normalized representation of this point internally is Pi, so that endpoints\n * of normal intervals are in the range (-Pi, Pi]. However, we take advantage of\n * the point -Pi to construct two special intervals: the Full() interval is\n * [-Pi, Pi], and the Empty() interval is [Pi, -Pi].\n *\n */\n\nexport class R1Interval extends Interval {\n\n /** Return true if the interval is empty, i.e. it contains no points. */\n public isEmpty() {\n return this.lo > this.hi;\n }\n\n public getCenter() {\n return (this.lo + this.hi)/2;\n }\n\n public getLength() {\n return this.hi - this.lo;\n }\n\n public contains(p:number):boolean {\n return p >= this.lo && p <= this.hi;\n\n }\n\n /** Return true if the interior of the interval contains the point 'p'. */\n public interiorContains(p:number):boolean {\n return p > this.lo && p < this.hi;\n }\n\n /**\n * Return true if the interval contains the given interval 'y'. Works for\n * empty, full, and singleton intervals.\n */\n public containsI(y:R1Interval):boolean {\n if (y.isEmpty()) {\n return true;\n }\n return y.lo >= this.lo && y.hi <= this.hi;\n }\n\n\n public interiorContainsI(y:R1Interval):boolean {\n if (y.isEmpty()) {\n return true;\n }\n return y.lo > this.lo && y.hi < this.hi;\n }\n\n /**\n * Return true if this interval intersects the given interval, i.e. if they\n * have any points in common.\n */\n public intersects(y:R1Interval):boolean {\n if (this.lo <= y.lo) {\n return y.lo <= (this.hi) && y.lo <= (y.hi);\n } else {\n return this.lo <= (y.hi) && this.lo <= (this.hi);\n }\n }\n\n /**\n * Return true if the interior of this interval intersects any point of the\n * given interval (including its boundary).\n */\n public interiorIntersects(y:R1Interval):boolean {\n return y.lo < (this.hi) && this.lo < (y.hi) && this.lo < (this.hi) && y.lo <= (y.hi);\n }\n\n /** Expand the interval so that it contains the given point \"p\". */\n public addPoint(p:number):R1Interval {\n if (this.isEmpty()) {\n return R1Interval.fromPoint(p);\n } else if (p < (this.lo)) {\n return new R1Interval(p, this.hi);\n } else if (p > (this.hi)) {\n return new R1Interval(this.lo, p);\n } else {\n return new R1Interval(this.lo, this.hi);\n }\n }\n\n /**\n * Return an interval that contains all points with a distance \"radius\" of a\n * point in this interval. Note that the expansion of an empty interval is\n * always empty.\n */\n public expanded(radius:number):R1Interval {\n // assert (radius >= 0);\n if (this.isEmpty()) {\n return this;\n }\n return new R1Interval(this.lo - radius, this.hi + radius);\n }\n\n /**\n * Return the smallest interval that contains this interval and the given\n * interval \"y\".\n */\n public union(y:R1Interval):R1Interval {\n if (this.isEmpty()) {\n return y;\n }\n if (y.isEmpty()) {\n return this;\n }\n return new R1Interval(\n Math.min(this.lo, y.lo),\n Math.max(this.hi, y.hi)\n );\n }\n\n /**\n * Return the intersection of this interval with the given interval. Empty\n * intervals do not need to be special-cased.\n */\n public intersection(y:R1Interval):R1Interval {\n return new R1Interval(\n Math.max(this.lo, y.lo),\n Math.min(this.hi, y.hi)\n );\n }\n\n /**\n * Return true if the length of the symmetric difference between the two\n * intervals is at most the given tolerance.\n */\n public approxEquals(y:R1Interval, maxError=1e-15):boolean {\n if (this.isEmpty()) {\n return y.getLength() <= (maxError);\n }\n if (y.isEmpty()) {\n return this.getLength() <= ( maxError);\n }\n return Math.abs(y.lo - (this.lo)) + Math.abs(y.hi - this.hi) <= (maxError);\n }\n\n\n\n static empty():R1Interval {\n return new R1Interval(1, 0);\n }\n\n\n static fromPoint(p:number):R1Interval {\n return new R1Interval(p, p);\n }\n\n /**\n * Convenience method to construct the minimal interval containing the two\n * given points. This is equivalent to starting with an empty interval and\n * calling AddPoint() twice, but it is more efficient.\n */\n static fromPointPair(p1:number, p2:number):R1Interval {\n if (p1 <= (p2)) {\n return new R1Interval(p1, p2);\n } else {\n return new R1Interval(p2, p1);\n }\n }\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {S1Angle} from \"./S1Angle\";\nimport {S2Point} from \"./S2Point\";\nimport {S2} from \"./S2\";\nimport { Platform } from \"./Platform\";\n/**\n * This class represents a point on the unit sphere as a pair of\n * latitude-longitude coordinates. Like the rest of the \"geometry\" package, the\n * intent is to represent spherical geometry as a mathematical abstraction, so\n * functions that are specifically related to the Earth's geometry (e.g.\n * easting/northing conversions) should be put elsewhere.\n *\n */\nexport class S2LatLng {\n\n /**\n * Approximate \"effective\" radius of the Earth in meters.\n */\n public static EARTH_RADIUS_METERS = 6367000.0;\n\n /** The center point the lat/lng coordinate system. */\n public static CENTER = new S2LatLng(0.0, 0.0);\n\n public latRadians: number;\n public lngRadians: number;\n\n constructor(latRadians:number, lngRadians:number) {\n this.latRadians = latRadians;\n this.lngRadians = lngRadians;\n }\n\n get latDegrees() {\n return new S1Angle(this.latRadians).degrees();\n }\n\n get lngDegrees() {\n return new S1Angle(this.lngRadians).degrees();\n }\n\n// Clamps the latitude to the range [-90, 90] degrees, and adds or subtracts\n // a multiple of 360 degrees to the longitude if necessary to reduce it to\n // the range [-180, 180].\n /** Convert an S2LatLng to the equivalent unit-length vector (S2Point). */\n public toPoint():S2Point {\n const phi = this.latRadians;\n const theta = this.lngRadians;\n const cosphi = Math.cos(phi);\n\n return new S2Point(\n Math.cos(theta) * (cosphi),\n Math.sin(theta)* (cosphi),\n Math.sin(phi));\n }\n\n /**\n * Returns a new S2LatLng based on this instance for which {@link #isValid()}\n * will be {@code true}.\n * <ul>\n * <li>Latitude is clipped to the range {@code [-90, 90]}\n * <li>Longitude is normalized to be in the range {@code [-180, 180]}\n * </ul>\n * <p>If the current point is valid then the returned point will have the same\n * coordinates.\n */\n public normalized():S2LatLng {\n // drem(x, 2 * S2.M_PI) reduces its argument to the range\n // [-S2.M_PI, Math.atan2PI] inclusive, which is what we want here.\n return new S2LatLng(\n Math.max(\n -S2.M_PI_2,\n Math.min(\n S2.M_PI_2,\n this.latRadians\n )\n ),\n Platform.IEEEremainder(\n this.lngRadians,\n 2* (S2.M_PI)\n )\n );\n }\n\n public static fromDegrees(latDegrees:number, lngDegrees:number):S2LatLng {\n return new S2LatLng(S1Angle.degrees(latDegrees).radians, S1Angle.degrees(lngDegrees).radians);\n }\n\n public static fromRadians(latRadians:number, lngRadians:number):S2LatLng {\n return new S2LatLng(latRadians, lngRadians);\n }\n\n static fromPoint(p:S2Point) {\n return new S2LatLng(\n S2LatLng.latitude(p).radians,\n S2LatLng.longitude(p).radians\n );\n }\n\n /** Returns the latitude of this point as a new S1Angle. */\n public lat(): S1Angle {\n return S1Angle.radians(this.latRadians);\n }\n\n /** Returns the longitude of this point as a new S1Angle. */\n public lng(): S1Angle {\n return S1Angle.radians(this.lngRadians);\n }\n\n /**\n * Return true if the latitude is between -90 and 90 degrees inclusive and the\n * longitude is between -180 and 180 degrees inclusive.\n */\n public isValid():boolean {\n return Math.abs(this.latRadians) <= (S2.M_PI_2) &&\n Math.abs(this.lngRadians) <= (S2.M_PI);\n\n }\n\n\n /**\n * Scales this point by the given scaling factor.\n * Note that there is no guarantee that the new point will be <em>valid</em>.\n */\n public mul(m:number):S2LatLng {\n return new S2LatLng(this.latRadians* (m), this.lngRadians* (m));\n }\n\n public static latitude(p:S2Point) {\n // We use atan2 rather than asin because the input vector is not necessarily\n // unit length, and atan2 is much more accurate than asin near the poles.\n return new S1Angle(Math.atan2(p.z, Math.sqrt(p.x * p.x + p.y * p.y)));\n }\n\n public static longitude(p:S2Point):S1Angle {\n // Note that atan2(0, 0) is defined to be zero.\n return new S1Angle(Math.atan2(p.y, p.x));\n }\n\n equals(other:S2LatLng):boolean {\n return other.latRadians === this.latRadians && other.lngRadians === this.lngRadians;\n }\n\n pointAtDistance(distanceInKM:number, bearingRadians:number) {\n const distanceInM = distanceInKM * 1000;\n const distanceToRadius = distanceInM / (S2LatLng.EARTH_RADIUS_METERS);\n\n const newLat = Math.asin(Math.sin(this.latRadians) * Math.cos(distanceToRadius)\n + (\n Math.cos(this.latRadians) * Math.sin(distanceToRadius) * Math.cos(bearingRadians)\n ));\n const newLng = this.lngRadians + Math.atan2(\n Math.sin(bearingRadians)\n * (Math.sin(distanceToRadius))\n * (Math.cos(this.latRadians)),\n Math.cos(distanceToRadius) - (Math.sin(this.latRadians) * Math.sin(newLat)\n )\n );\n return new S2LatLng(newLat, newLng);\n }\n\n /**\n * Generates n LatLngs given a distance in km and the number of points wanted.\n * Generated points will be returned in a Clockwise order starting from North.\n * @param _distanceInKm\n * @param nPoints\n * @returns {S2LatLng[]}\n */\n pointsAtDistance(_distanceInKm:number, nPoints=4):S2LatLng[] {\n return [... new Array(nPoints)] // create an array filled of undefined!\n .map((p, idx) => 360 / nPoints * idx)\n .map(bearingDegree => S1Angle.degrees(bearingDegree).radians)\n .map(bearingRadians => this.pointAtDistance(_distanceInKm, bearingRadians));\n\n }\n\n getEarthDistance(other:S2LatLng) {\n return this.getDistance(other).radians * (S2LatLng.EARTH_RADIUS_METERS);\n }\n\n getDistance(other:S2LatLng):S1Angle {\n // This implements the Haversine formula, which is numerically stable for\n // small distances but only gets about 8 digits of precision for very large\n // distances (e.g. antipodal points). Note that 8 digits is still accurate\n // to within about 10cm for a sphere the size of the Earth.\n //\n // This could be fixed with another sin() and cos() below, but at that point\n // you might as well just convert both arguments to S2Points and compute the\n // distance that way (which gives about 15 digits of accuracy for all\n // distances).\n\n const lat1 = this.latRadians;\n const lat2 = other.latRadians\n const lng1 = this.lngRadians;\n const lng2 = other.lngRadians;\n const dLat = Math.sin(0.5 * (lat2 - lat1));\n const dLng = Math.sin(0.5 * (lng2 - lng1));\n const x = dLat * dLat + dLng * dLng * Math.cos(lat1) * Math.cos(lat2)\n\n return S1Angle.radians(2 * Math.asin(Math.sqrt(Math.min(1.0, x))));\n // Return the distance (measured along the surface of the sphere) to the\n // given S2LatLng. This is mathematically equivalent to:\n //\n // S1Angle::FromRadians(ToPoint().Angle(o.ToPoint())\n //\n // but this implementation is slightly more efficient.\n }\n\n public toString():string {\n return \"(\" + this.latRadians + \", \" + this.lngRadians + \")\";\n }\n\n public toStringDegrees():string {\n return \"(\" + this.latDegrees + \", \" + this.lngDegrees + \")\";\n }\n\n public toGEOJSON() {\n return {\n type: 'Feature',\n geometry: {\n type: \"Point\",\n coordinates: [this.lngDegrees, this.latDegrees]\n },\n properties: {}\n\n }\n }\n}\n","/*\n * Copyright 2006 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport {S2Point} from \"./S2Point\";\nimport {S2} from \"./S2\";\nimport {S1Angle} from \"./S1Angle\";\n\n/**\n * This class contains various utility functions related to edges. It collects\n * together common code that is needed to implement polygonal geometry such as\n * polylines, loops, and general polygons.\n *\n */\nexport class S2EdgeUtil {\n// /**\n// * IEEE floating-point operations have a maximum error of 0.5 ULPS (units in\n// * the last place). For double-precision numbers, this works out to 2**-53\n// * (about 1.11e-16) times the magnitude of the result. It is possible to\n// * analyze the calculation done by getIntersection() and work out the\n// * worst-case rounding error. I have done a rough version of this, and my\n// * estimate is that the worst case distance from the intersection point X to\n// * the great circle through (a0, a1) is about 12 ULPS, or about 1.3e-15. This\n// * needs to be increased by a factor of (1/0.866) to account for the\n// * edgeSpliceFraction() in S2PolygonBuilder. Note that the maximum error\n// * measured by the unittest in 1,000,000 trials is less than 3e-16.\n// */\n// public static final S1Angle DEFAULT_INTERSECTION_TOLERANCE = S1Angle.radians(1.5e-15);\n//\n// /**\n// * This class allows a vertex chain v0, v1, v2, ... to be efficiently tested\n// * for intersection with a given fixed edge AB.\n// */\n// public static class EdgeCrosser {\n// // The fields below are all constant.\n//\n// private final S2Point a;\n// private final S2Point b;\n// private final S2Point aCrossB;\n//\n// // The fields below are updated for each vertex in the chain.\n//\n// // Previous vertex in the vertex chain.\n// private S2Point c;\n// // The orientation of the triangle ACB.\n// private int acb;\n//\n// /**\n// * AB is the given fixed edge, and C is the first vertex of the vertex\n// * chain. All parameters must point to fixed storage that persists for the\n// * lifetime of the EdgeCrosser object.\n// */\n// public EdgeCrosser(S2Point a, S2Point b, S2Point c) {\n// this.a = a;\n// this.b = b;\n// this.aCrossB = S2Point.crossProd(a, b);\n// restartAt(c);\n// }\n//\n// /**\n// * Call this function when your chain 'jumps' to a new place.\n// */\n// public void restartAt(S2Point c) {\n// this.c = c;\n// this.acb = -S2.robustCCW(this.a, this.b, c, this.aCrossB);\n// }\n//\n// /**\n// * This method is equivalent to calling the S2EdgeUtil.robustCrossing()\n// * function (defined below) on the edges AB and CD. It returns +1 if there\n// * is a crossing, -1 if there is no crossing, and 0 if two points from\n// * different edges are the same. Returns 0 or -1 if either edge is\n// * degenerate. As a side effect, it saves vertex D to be used as the next\n// * vertex C.\n// */\n// public int robustCrossing(S2Point d) {\n// // For there to be an edge crossing, the triangles ACB, CBD, BDA, DAC must\n// // all be oriented the same way (CW or CCW). We keep the orientation\n// // of ACB as part of our state. When each new point D arrives, we\n// // compute the orientation of BDA and check whether it matches ACB.\n// // This checks whether the points C and D are on opposite sides of the\n// // great circle through AB.\n//\n// // Recall that robustCCW is invariant with respect to rotating its\n// // arguments, i.e. ABC has the same orientation as BDA.\n// int bda = S2.robustCCW(this.a, this.b, d, this.aCrossB);\n// int result;\n//\n// if (bda == -this.acb && bda != 0) {\n// // Most common case -- triangles have opposite orientations.\n// result = -1;\n// } else if ((bda & this.acb) == 0) {\n// // At least one value is zero -- two vertices are identical.\n// result = 0;\n// } else {\n// // assert (bda == acb && bda != 0);\n// result = robustCrossingInternal(d); // Slow path.\n// }\n// // Now save the current vertex D as the next vertex C, and also save the\n// // orientation of the new triangle ACB (which is opposite to the current\n// // triangle BDA).\n// this.c = d;\n// this.acb = -bda;\n// return result;\n// }\n//\n// /**\n// * This method is equivalent to the S2EdgeUtil.edgeOrVertexCrossing() method\n// * defined below. It is similar to robustCrossing, but handles cases where\n// * two vertices are identical in a way that makes it easy to implement\n// * point-in-polygon containment tests.\n// */\n// public boolean edgeOrVertexCrossing(S2Point d) {\n// // We need to copy c since it is clobbered by robustCrossing().\n// S2Point c2 = new S2Point(this.c.get(0), this.c.get(1), this.c.get(2));\n//\n// int crossing = robustCrossing(d);\n// if (crossing < 0) {\n// return false;\n// }\n// if (crossing > 0) {\n// return true;\n// }\n//\n// return vertexCrossing(this.a, this.b, c2, d);\n// }\n//\n// /**\n// * This function handles the \"slow path\" of robustCrossing().\n// */\n// private int robustCrossingInternal(S2Point d) {\n// // ACB and BDA have the appropriate orientations, so now we check the\n// // triangles CBD and DAC.\n// S2Point cCrossD = S2Point.crossProd(this.c, d);\n// int cbd = -S2.robustCCW(this.c, d, this.b, cCrossD);\n// if (cbd != this.acb) {\n// return -1;\n// }\n//\n// int dac = S2.robustCCW(this.c, d, this.a, cCrossD);\n// return (dac == this.acb) ? 1 : -1;\n// }\n// }\n//\n// /**\n// * This class computes a bounding rectangle that contains all edges defined by\n// * a vertex chain v0, v1, v2, ... All vertices must be unit length. Note that\n// * the bounding rectangle of an edge can be larger than the bounding rectangle\n// * of its endpoints, e.g. consider an edge that passes through the north pole.\n// */\n// public static class RectBounder {\n// // The previous vertex in the chain.\n// private S2Point a;\n//\n// // The corresponding latitude-longitude.\n// private S2LatLng aLatLng;\n//\n// // The current bounding rectangle.\n// private S2LatLngRect bound;\n//\n// public RectBounder() {\n// this.bound = S2LatLngRect.empty();\n// }\n//\n// /**\n// * This method is called to add each vertex to the chain. 'b' must point to\n// * fixed storage that persists for the lifetime of the RectBounder.\n// */\n// public void addPoint(S2Point b) {\n// // assert (S2.isUnitLength(b));\n//\n// S2LatLng bLatLng = new S2LatLng(b);\n//\n// if (this.bound.isEmpty()) {\n// this.bound = this.bound.addPoint(bLatLng);\n// } else {\n// // We can't just call bound.addPoint(bLatLng) here, since we need to\n// // ensure that all the longitudes between \"a\" and \"b\" are included.\n// this.bound = this.bound.union(S2LatLngRect.fromPointPair(this.aLatLng, bLatLng));\n//\n// // Check whether the min/max latitude occurs in the edge interior.\n// // We find the normal to the plane containing AB, and then a vector\n// // \"dir\" in this plane that also passes through the equator. We use\n// // RobustCrossProd to ensure that the edge normal is accurate even\n// // when the two points are very close together.\n// S2Point aCrossB = S2.robustCrossProd(this.a, b);\n// S2Point dir = S2Point.crossProd(aCrossB, new S2Point(0, 0, 1));\n// double da = dir.dotProd(this.a);\n// double db = dir.dotProd(b);\n//\n// if (da * db < 0) {\n// // Minimum/maximum latitude occurs in the edge interior. This affects\n// // the latitude bounds but not the longitude bounds.\n// double absLat = Math.acos(Math.abs(aCrossB.get(2) / aCrossB.norm()));\n// R1Interval lat = this.bound.lat();\n// if (da < 0) {\n// // It's possible that absLat < lat.lo() due to numerical errors.\n// lat = new R1Interval(lat.lo(), Math.max(absLat, this.bound.lat().hi()));\n// } else {\n// lat = new R1Interval(Math.min(-absLat, this.bound.lat().lo()), lat.hi());\n// }\n// this.bound = new S2LatLngRect(lat, this.bound.lng());\n// }\n// }\n// this.a = b;\n// this.aLatLng = bLatLng;\n// }\n//\n// /**\n// * Return the bounding rectangle of the edge chain that connects the\n// * vertices defined so far.\n// */\n// public S2LatLngRect getBound() {\n// return this.bound;\n// }\n//\n// }\n//\n// /**\n// * The purpose of this class is to find edges that intersect a given XYZ\n// * bounding box. It can be used as an efficient rejection test when attempting to\n// * find edges that intersect a given region. It accepts a vertex chain v0, v1,\n// * v2, ... and returns a boolean value indicating whether each edge intersects\n// * the specified bounding box.\n// *\n// * We use XYZ intervals instead of something like longitude intervals because\n// * it is cheap to collect from S2Point lists and any slicing strategy should\n// * give essentially equivalent results. See S2Loop for an example of use.\n// */\n// public static class XYZPruner {\n// private S2Point lastVertex;\n//\n// // The region to be tested against.\n// private boolean boundSet;\n// private double xmin;\n// private double ymin;\n// private double zmin;\n// private double xmax;\n// private double ymax;\n// private double zmax;\n// private double maxDeformation;\n//\n// public XYZPruner() {\n// this.boundSet = false;\n// }\n//\n// /**\n// * Accumulate a bounding rectangle from provided edges.\n// *\n// * @param from start of edge\n// * @param to end of edge.\n// */\n// public void addEdgeToBounds(S2Point from, S2Point to) {\n// if (!this.boundSet) {\n// this.boundSet = true;\n// this.xmin = this.xmax = from.x;\n// this.ymin = this.ymax = from.y;\n// this.zmin = this.zmax = from.z;\n// }\n// this.xmin = Math.min(this.xmin, Math.min(to.x, from.x));\n// this.ymin = Math.min(this.ymin, Math.min(to.y, from.y));\n// this.zmin = Math.min(this.zmin, Math.min(to.z, from.z));\n// this.xmax = Math.max(this.xmax, Math.max(to.x, from.x));\n// this.ymax = Math.max(this.ymax, Math.max(to.y, from.y));\n// this.zmax = Math.max(this.zmax, Math.max(to.z, from.z));\n//\n// // Because our arcs are really geodesics on the surface of the earth\n// // an edge can have intermediate points outside the xyz bounds implicit\n// // in the end points. Based on the length of the arc we compute a\n// // generous bound for the maximum amount of deformation. For small edges\n// // it will be very small but for some large arcs (ie. from (1N,90W) to\n// // (1N,90E) the path can be wildly deformed. I did a bunch of\n// // experiments with geodesics to get safe bounds for the deformation.\n// double approxArcLen =\n// Math.abs(from.x - to.x) + Math.abs(from.y - to.y) + Math.abs(from.z - to.z);\n// if (approxArcLen < 0.025) { // less than 2 degrees\n// this.maxDeformation = Math.max(this.maxDeformation, approxArcLen * 0.0025);\n// } else if (approxArcLen < 1.0) { // less than 90 degrees\n// this.maxDeformation = Math.max(this.maxDeformation, approxArcLen * 0.11);\n// } else {\n// this.maxDeformation = approxArcLen * 0.5;\n// }\n// }\n//\n// public void setFirstIntersectPoint(S2Point v0) {\n// this.xmin = this.xmin - this.maxDeformation;\n// this.ymin = this.ymin - this.maxDeformation;\n// this.zmin = this.zmin - this.maxDeformation;\n// this.xmax = this.xmax + this.maxDeformation;\n// this.ymax = this.ymax + this.maxDeformation;\n// this.zmax = this.zmax + this.maxDeformation;\n// this.lastVertex = v0;\n// }\n//\n// /**\n// * Returns true if the edge going from the last point to this point passes\n// * through the pruner bounding box, otherwise returns false. So the\n// * method returns false if we are certain there is no intersection, but it\n// * may return true when there turns out to be no intersection.\n// */\n// public boolean intersects(S2Point v1) {\n// boolean result = true;\n//\n// if ((v1.x < this.xmin && this.lastVertex.x < this.xmin) || (v1.x > this.xmax && this.lastVertex.x > this.xmax)) {\n// result = false;\n// } else if ((v1.y < this.ymin && this.lastVertex.y < this.ymin) || (v1.y > this.ymax && this.lastVertex.y > this.ymax)) {\n// result = false;\n// } else if ((v1.z < this.zmin && this.lastVertex.z < this.zmin) || (v1.z > this.zmax && this.lastVertex.z > this.zmax)) {\n// result = false;\n// }\n//\n// this.lastVertex = v1;\n// return result;\n// }\n// }\n//\n// /**\n// * The purpose of this class is to find edges that intersect a given longitude\n// * interval. It can be used as an efficient rejection test when attempting to\n// * find edges that intersect a given region. It accepts a vertex chain v0, v1,\n// * v2, ... and returns a boolean value indicating whether each edge intersects\n// * the specified longitude interval.\n// *\n// * This class is not currently used as the XYZPruner is preferred for\n// * S2Loop, but this should be usable in similar circumstances. Be wary\n// * of the cost of atan2() in conversions from S2Point to longitude!\n// */\n// public static class LongitudePruner {\n// // The interval to be tested against.\n// private S1Interval interval;\n//\n// // The longitude of the next v0.\n// private double lng0;\n//\n// /**\n// *'interval' is the longitude interval to be tested against, and 'v0' is\n// * the first vertex of edge chain.\n// */\n// public LongitudePruner(S1Interval interval, S2Point v0) {\n// this.interval = interval;\n// this.lng0 = S2LatLng.longitude(v0).radians();\n// }\n//\n// /**\n// * Returns true if the edge (v0, v1) intersects the given longitude\n// * interval, and then saves 'v1' to be used as the next 'v0'.\n// */\n// public boolean intersects(S2Point v1) {\n// double lng1 = S2LatLng.longitude(v1).radians();\n// boolean result = this.interval.intersects(S1Interval.fromPointPair(this.lng0, lng1));\n// this.lng0 = lng1;\n// return result;\n// }\n// }\n//\n// /**\n// * A wedge relation's test method accepts two edge chains A=(a0,a1,a2) and\n// * B=(b0,b1,b2) where a1==b1, and returns either -1, 0, or 1 to indicate the\n// * relationship between the region to the left of A and the region to the left\n// * of B. Wedge relations are used to determine the local relationship between\n// * two polygons that share a common vertex.\n// *\n// * All wedge relations require that a0 != a2 and b0 != b2. Other degenerate\n// * cases (such as a0 == b2) are handled as expected. The parameter \"ab1\"\n// * denotes the common vertex a1 == b1.\n// */\n// public interface WedgeRelation {\n// int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2);\n// }\n//\n// public static class WedgeContains implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns +1\n// * if the region to the left of A contains the region to the left of B, and\n// * 0 otherwise.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // For A to contain B (where each loop interior is defined to be its left\n// // side), the CCW edge order around ab1 must be a2 b2 b0 a0. We split\n// // this test into two parts that test three vertices each.\n// return S2.orderedCCW(a2, b2, b0, ab1) && S2.orderedCCW(b0, a0, a2, ab1) ? 1 : 0;\n// }\n// }\n//\n// public static class WedgeIntersects implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns -1\n// * if the region to the left of A intersects the region to the left of B,\n// * and 0 otherwise. Note that regions are defined such that points along a\n// * boundary are contained by one side or the other, not both. So for\n// * example, if A,B,C are distinct points ordered CCW around a vertex O, then\n// * the wedges BOA, AOC, and COB do not intersect.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // For A not to intersect B (where each loop interior is defined to be\n// // its left side), the CCW edge order around ab1 must be a0 b2 b0 a2.\n// // Note that it's important to write these conditions as negatives\n// // (!OrderedCCW(a,b,c,o) rather than Ordered(c,b,a,o)) to get correct\n// // results when two vertices are the same.\n// return (S2.orderedCCW(a0, b2, b0, ab1) && S2.orderedCCW(b0, a2, a0, ab1) ? 0 : -1);\n// }\n// }\n//\n// public static class WedgeContainsOrIntersects implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns +1\n// * if A contains B, 0 if A and B are disjoint, and -1 if A intersects but\n// * does not contain B.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // This is similar to WedgeContainsOrCrosses, except that we want to\n// // distinguish cases (1) [A contains B], (3) [A and B are disjoint],\n// // and (2,4,5,6) [A intersects but does not contain B].\n//\n// if (S2.orderedCCW(a0, a2, b2, ab1)) {\n// // We are in case 1, 5, or 6, or case 2 if a2 == b2.\n// return S2.orderedCCW(b2, b0, a0, ab1) ? 1 : -1; // Case 1 vs. 2,5,6.\n// }\n// // We are in cases 2, 3, or 4.\n// if (!S2.orderedCCW(a2, b0, b2, ab1)) {\n// return 0; // Case 3.\n// }\n//\n// // We are in case 2 or 4, or case 3 if a2 == b0.\n// return (a2.equals(b0)) ? 0 : -1; // Case 3 vs. 2,4.\n// }\n// }\n//\n// public static class WedgeContainsOrCrosses implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns +1\n// * if A contains B, 0 if B contains A or the two wedges do not intersect,\n// * and -1 if the edge chains A and B cross each other (i.e. if A intersects\n// * both the interior and exterior of the region to the left of B). In\n// * degenerate cases where more than one of these conditions is satisfied,\n// * the maximum possible result is returned. For example, if A == B then the\n// * result is +1.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // There are 6 possible edge orderings at a shared vertex (all\n// // of these orderings are circular, i.e. abcd == bcda):\n// //\n// // (1) a2 b2 b0 a0: A contains B\n// // (2) a2 a0 b0 b2: B contains A\n// // (3) a2 a0 b2 b0: A and B are disjoint\n// // (4) a2 b0 a0 b2: A and B intersect in one wedge\n// // (5) a2 b2 a0 b0: A and B intersect in one wedge\n// // (6) a2 b0 b2 a0: A and B intersect in two wedges\n// //\n// // In cases (4-6), the boundaries of A and B cross (i.e. the boundary\n// // of A intersects the interior and exterior of B and vice versa).\n// // Thus we want to distinguish cases (1), (2-3), and (4-6).\n// //\n// // Note that the vertices may satisfy more than one of the edge\n// // orderings above if two or more vertices are the same. The tests\n// // below are written so that we take the most favorable\n// // interpretation, i.e. preferring (1) over (2-3) over (4-6). In\n// // particular note that if orderedCCW(a,b,c,o) returns true, it may be\n// // possible that orderedCCW(c,b,a,o) is also true (if a == b or b == c).\n//\n// if (S2.orderedCCW(a0, a2, b2, ab1)) {\n// // The cases with this vertex ordering are 1, 5, and 6,\n// // although case 2 is also possible if a2 == b2.\n// if (S2.orderedCCW(b2, b0, a0, ab1)) {\n// return 1; // Case 1 (A contains B)\n// }\n//\n// // We are in case 5 or 6, or case 2 if a2 == b2.\n// return (a2.equals(b2)) ? 0 : -1; // Case 2 vs. 5,6.\n// }\n// // We are in case 2, 3, or 4.\n// return S2.orderedCCW(a0, b0, a2, ab1) ? 0 : -1; // Case 2,3 vs. 4.\n// }\n// }\n//\n// /**\n// * Return true if edge AB crosses CD at a point that is interior to both\n// * edges. Properties:\n// *\n// * (1) simpleCrossing(b,a,c,d) == simpleCrossing(a,b,c,d) (2)\n// * simpleCrossing(c,d,a,b) == simpleCrossing(a,b,c,d)\n// */\n// public static boolean simpleCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// // We compute simpleCCW() for triangles ACB, CBD, BDA, and DAC. All\n// // of these triangles need to have the same orientation (CW or CCW)\n// // for an intersection to exist. Note that this is slightly more\n// // restrictive than the corresponding definition for planar edges,\n// // since we need to exclude pairs of line segments that would\n// // otherwise \"intersect\" by crossing two antipodal points.\n//\n// S2Point ab = S2Point.crossProd(a, b);\n// double acb = -(ab.dotProd(c));\n// double bda = ab.dotProd(d);\n// if (acb * bda <= 0) {\n// return false;\n// }\n//\n// S2Point cd = S2Point.crossProd(c, d);\n// double cbd = -(cd.dotProd(b));\n// double dac = cd.dotProd(a);\n// return (acb * cbd > 0) && (acb * dac > 0);\n// }\n//\n// /**\n// * Like SimpleCrossing, except that points that lie exactly on a line are\n// * arbitrarily classified as being on one side or the other (according to the\n// * rules of S2.robustCCW). It returns +1 if there is a crossing, -1 if there\n// * is no crossing, and 0 if any two vertices from different edges are the\n// * same. Returns 0 or -1 if either edge is degenerate. Properties of\n// * robustCrossing:\n// *\n// * (1) robustCrossing(b,a,c,d) == robustCrossing(a,b,c,d) (2)\n// * robustCrossing(c,d,a,b) == robustCrossing(a,b,c,d) (3)\n// * robustCrossing(a,b,c,d) == 0 if a==c, a==d, b==c, b==d (3)\n// * robustCrossing(a,b,c,d) <= 0 if a==b or c==d\n// *\n// * Note that if you want to check an edge against a *chain* of other edges,\n// * it is much more efficient to use an EdgeCrosser (above).\n// */\n// public static int robustCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// // For there to be a crossing, the triangles ACB, CBD, BDA, DAC must\n// // all have the same orientation (clockwise or counterclockwise).\n// //\n// // First we compute the orientation of ACB and BDA. We permute the\n// // arguments to robustCCW so that we can reuse the cross-product of A and B.\n// // Recall that when the arguments to robustCCW are permuted, the sign of the\n// // result changes according to the sign of the permutation. Thus ACB and\n// // ABC are oppositely oriented, while BDA and ABD are the same.\n// S2Point aCrossB = S2Point.crossProd(a, b);\n// int acb = -S2.robustCCW(a, b, c, aCrossB);\n// int bda = S2.robustCCW(a, b, d, aCrossB);\n//\n// // If any two vertices are the same, the result is degenerate.\n// if ((bda & acb) == 0) {\n// return 0;\n// }\n//\n// // If ABC and BDA have opposite orientations (the most common case),\n// // there is no crossing.\n// if (bda != acb) {\n// return -1;\n// }\n//\n// // Otherwise we compute the orientations of CBD and DAC, and check whether\n// // their orientations are compatible with the other two triangles.\n// S2Point cCrossD = S2Point.crossProd(c, d);\n// int cbd = -S2.robustCCW(c, d, b, cCrossD);\n// if (cbd != acb) {\n// return -1;\n// }\n//\n// int dac = S2.robustCCW(c, d, a, cCrossD);\n// return (dac == acb) ? 1 : -1;\n// }\n//\n// /**\n// * Given two edges AB and CD where at least two vertices are identical (i.e.\n// * robustCrossing(a,b,c,d) == 0), this function defines whether the two edges\n// * \"cross\" in a such a way that point-in-polygon containment tests can be\n// * implemented by counting the number of edge crossings. The basic rule is\n// * that a \"crossing\" occurs if AB is encountered after CD during a CCW sweep\n// * around the shared vertex starting from a fixed reference point.\n// *\n// * Note that according to this rule, if AB crosses CD then in general CD does\n// * not cross AB. However, this leads to the correct result when counting\n// * polygon edge crossings. For example, suppose that A,B,C are three\n// * consecutive vertices of a CCW polygon. If we now consider the edge\n// * crossings of a segment BP as P sweeps around B, the crossing number changes\n// * parity exactly when BP crosses BA or BC.\n// *\n// * Useful properties of VertexCrossing (VC):\n// *\n// * (1) VC(a,a,c,d) == VC(a,b,c,c) == false (2) VC(a,b,a,b) == VC(a,b,b,a) ==\n// * true (3) VC(a,b,c,d) == VC(a,b,d,c) == VC(b,a,c,d) == VC(b,a,d,c) (3) If\n// * exactly one of a,b equals one of c,d, then exactly one of VC(a,b,c,d) and\n// * VC(c,d,a,b) is true\n// *\n// * It is an error to call this method with 4 distinct vertices.\n// */\n// public static boolean vertexCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// // If A == B or C == D there is no intersection. We need to check this\n// // case first in case 3 or more input points are identical.\n// if (a.equals(b) || c.equals(d)) {\n// return false;\n// }\n//\n// // If any other pair of vertices is equal, there is a crossing if and only\n// // if orderedCCW() indicates that the edge AB is further CCW around the\n// // shared vertex than the edge CD.\n// if (a.equals(d)) {\n// return S2.orderedCCW(S2.ortho(a), c, b, a);\n// }\n// if (b.equals(c)) {\n// return S2.orderedCCW(S2.ortho(b), d, a, b);\n// }\n// if (a.equals(c)) {\n// return S2.orderedCCW(S2.ortho(a), d, b, a);\n// }\n// if (b.equals(d)) {\n// return S2.orderedCCW(S2.ortho(b), c, a, b);\n// }\n//\n// // assert (false);\n// return false;\n// }\n//\n// /**\n// * A convenience function that calls robustCrossing() to handle cases where\n// * all four vertices are distinct, and VertexCrossing() to handle cases where\n// * two or more vertices are the same. This defines a crossing function such\n// * that point-in-polygon containment tests can be implemented by simply\n// * counting edge crossings.\n// */\n// public static boolean edgeOrVertexCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// int crossing = robustCrossing(a, b, c, d);\n// if (crossing < 0) {\n// return false;\n// }\n// if (crossing > 0) {\n// return true;\n// }\n// return vertexCrossing(a, b, c, d);\n// }\n//\n// static class CloserResult {\n// private double dmin2;\n// private S2Point vmin;\n//\n// public double getDmin2() {\n// return this.dmin2;\n// }\n//\n// public S2Point getVmin() {\n// return this.vmin;\n// }\n//\n// public CloserResult(double dmin2, S2Point vmin) {\n// this.dmin2 = dmin2;\n// this.vmin = vmin;\n// }\n//\n// public void replaceIfCloser(S2Point x, S2Point y) {\n// // If the squared distance from x to y is less than dmin2, then replace\n// // vmin by y and update dmin2 accordingly.\n// double d2 = S2Point.minus(x, y).norm2();\n// if (d2 < this.dmin2 || (d2 == this.dmin2 && y.lessThan(this.vmin))) {\n// this.dmin2 = d2;\n// this.vmin = y;\n// }\n// }\n// }\n//\n// /*\n// * Given two edges AB and CD such that robustCrossing() is true, return their\n// * intersection point. Useful properties of getIntersection (GI):\n// *\n// * (1) GI(b,a,c,d) == GI(a,b,d,c) == GI(a,b,c,d) (2) GI(c,d,a,b) ==\n// * GI(a,b,c,d)\n// *\n// * The returned intersection point X is guaranteed to be close to the edges AB\n// * and CD, but if the edges intersect at a very small angle then X may not be\n// * close to the true mathematical intersection point P. See the description of\n// * \"DEFAULT_INTERSECTION_TOLERANCE\" below for details.\n// */\n// public static S2Point getIntersection(S2Point a0, S2Point a1, S2Point b0, S2Point b1) {\n// Preconditions.checkArgument(robustCrossing(a0, a1, b0, b1) > 0,\n// \"Input edges a0a1 and b0b1 muct have a true robustCrossing.\");\n//\n// // We use robustCrossProd() to get accurate results even when two endpoints\n// // are close together, or when the two line segments are nearly parallel.\n// S2Point aNorm = S2Point.normalize(S2.robustCrossProd(a0, a1));\n// S2Point bNorm = S2Point.normalize(S2.robustCrossProd(b0, b1));\n// S2Point x = S2Point.normalize(S2.robustCrossProd(aNorm, bNorm));\n//\n// // Make sure the intersection point is on the correct side of the sphere.\n// // Since all vertices are unit length, and edges are less than 180 degrees,\n// // (a0 + a1) and (b0 + b1) both have positive dot product with the\n// // intersection point. We use the sum of all vertices to make sure that the\n// // result is unchanged when the edges are reversed or exchanged.\n// if (x.dotProd(S2Point.add(S2Point.add(a0, a1), S2Point.add(b0, b1))) < 0) {\n// x = S2Point.neg(x);\n// }\n//\n// // The calculation above is sufficient to ensure that \"x\" is within\n// // DEFAULT_INTERSECTION_TOLERANCE of the great circles through (a0,a1) and\n// // (b0,b1).\n// // However, if these two great circles are very close to parallel, it is\n// // possible that \"x\" does not lie between the endpoints of the given line\n// // segments. In other words, \"x\" might be on the great circle through\n// // (a0,a1) but outside the range covered by (a0,a1). In this case we do\n// // additional clipping to ensure that it does.\n//\n// if (S2.orderedCCW(a0, x, a1, aNorm) && S2.orderedCCW(b0, x, b1, bNorm)) {\n// return x;\n// }\n//\n// // Find the acceptable endpoint closest to x and return it. An endpoint is\n// // acceptable if it lies between the endpoints of the other line segment.\n// CloserResult r = new CloserResult(10, x);\n// if (S2.orderedCCW(b0, a0, b1, bNorm)) {\n// r.replaceIfCloser(x, a0);\n// }\n// if (S2.orderedCCW(b0, a1, b1, bNorm)) {\n// r.replaceIfCloser(x, a1);\n// }\n// if (S2.orderedCCW(a0, b0, a1, aNorm)) {\n// r.replaceIfCloser(x, b0);\n// }\n// if (S2.orderedCCW(a0, b1, a1, aNorm)) {\n// r.replaceIfCloser(x, b1);\n// }\n// return r.getVmin();\n// }\n//\n// /**\n// * Given a point X and an edge AB, return the distance ratio AX / (AX + BX).\n// * If X happens to be on the line segment AB, this is the fraction \"t\" such\n// * that X == Interpolate(A, B, t). Requires that A and B are distinct.\n// */\n// public static double getDistanceFraction(S2Point x, S2Point a0, S2Point a1) {\n// Preconditions.checkArgument(!a0.equals(a1));\n// double d0 = x.angle(a0);\n// double d1 = x.angle(a1);\n// return d0 / (d0 + d1);\n// }\n//\n// /**\n// * Return the minimum distance from X to any point on the edge AB. The result\n// * is very accurate for small distances but may have some numerical error if\n// * the distance is large (approximately Pi/2 or greater). The case A == B is\n// * handled correctly. Note: x, a and b must be of unit length. Throws\n// * IllegalArgumentException if this is not the case.\n// */\n// public static getDistance(x:S2Point , a:S2Point , b:S2Point ):S1Angle {\n// return this.getDistance(x, a, b, S2.robustCrossProd(a, b));\n// }\n\n/**\n * A slightly more efficient version of getDistance() where the cross product\n * of the two endpoints has been precomputed. The cross product does not need\n * to be normalized, but should be computed using S2.robustCrossProd() for the\n * most accurate results.\n */\npublic static getDistance(x:S2Point , a:S2Point , b:S2Point , aCrossB:S2Point=S2.robustCrossProd(a,b) ):S1Angle {\n // Preconditions.checkArgument(S2.isUnitLength(x));\n // Preconditions.checkArgument(S2.isUnitLength(a));\n // Preconditions.checkArgument(S2.isUnitLength(b));\n\n // There are three cases. If X is located in the spherical wedge defined by\n // A, B, and the axis A x B, then the closest point is on the segment AB.\n // Otherwise the closest point is either A or B; the dividing line between\n // these two cases is the great circle passing through (A x B) and the\n // midpoint of AB.\n\n if (S2.simpleCCW(aCrossB, a, x) && S2.simpleCCW(x, b, aCrossB)) {\n // The closest point to X lies on the segment AB. We compute the distance\n // to the corresponding great circle. The result is accurate for small\n // distances but not necessarily for large distances (approaching Pi/2).\n\n const sinDist = Math.abs(x.dotProd(aCrossB)) / ( aCrossB.norm());\n return new S1Angle(Math.asin(Math.min(1.0, sinDist)));\n }\n\n // Otherwise, the closest point is either A or B. The cheapest method is\n // just to compute the minimum of the two linear (as opposed to spherical)\n // distances and convert the result to an angle. Again, this method is\n // accurate for small but not large distances (approaching Pi).\n\n const linearDist2 = Math.min(S2Point.minus(x, a).norm2(), S2Point.minus(x, b).norm2());\n return new S1Angle(\n Math.asin(\n Math.min(\n 1.0,\n Math.sqrt(linearDist2) * 0.5\n )\n ) * 2\n );\n}\n//\n// /**\n// * Returns the point on edge AB closest to X. x, a and b must be of unit\n// * length. Throws IllegalArgumentException if this is not the case.\n// *\n// */\n// public static S2Point getClosestPoint(S2Point x, S2Point a, S2Point b) {\n// Preconditions.checkArgument(S2.isUnitLength(x));\n// Preconditions.checkArgument(S2.isUnitLength(a));\n// Preconditions.checkArgument(S2.isUnitLength(b));\n//\n// S2Point crossProd = S2.robustCrossProd(a, b);\n// // Find the closest point to X along the great circle through AB.\n// S2Point p = S2Point.minus(x, S2Point.mul(crossProd, x.dotProd(crossProd) / crossProd.norm2()));\n//\n// // If p is on the edge AB, then it's the closest point.\n// if (S2.simpleCCW(crossProd, a, p) && S2.simpleCCW(p, b, crossProd)) {\n// return S2Point.normalize(p);\n// }\n// // Otherwise, the closest point is either A or B.\n// return S2Point.minus(x, a).norm2() <= S2Point.minus(x, b).norm2() ? a : b;\n// }\n//\n// /** Constructor is private so that this class is never instantiated. */\n// private S2EdgeUtil() {\n// }\n}\n","import {S1Interval} from \"./S1Interval\";\nimport {R1Interval} from \"./R1Interval\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {S2Region} from \"./S2Region\";\nimport {S2} from \"./S2\";\nimport {S2Point} from \"./S2Point\";\nimport {S1Angle} from \"./S1Angle\";\nimport {S2Cell} from \"./S2Cell\";\nimport {S2EdgeUtil} from \"./S2EdgeUtil\";\nimport {S2Cap} from \"./S2Cap\";\nimport { Platform } from \"./Platform\";\n\nexport class S2LatLngRect implements S2Region {\n constructor(public lat:R1Interval, public lng:S1Interval) {\n\n }\n\n static fromLatLng(lo:S2LatLng, hi:S2LatLng):S2LatLngRect {\n return new S2LatLngRect(\n new R1Interval(\n lo.latRadians,\n hi.latRadians\n ),\n new S1Interval(\n lo.lngRadians,\n hi.lngRadians\n )\n );\n }\n\n\n /** The canonical empty rectangle */\n public static empty():S2LatLngRect {\n return new S2LatLngRect(R1Interval.empty(), S1Interval.empty());\n }\n\n /** The canonical full rectangle. */\n public static full():S2LatLngRect {\n return new S2LatLngRect(S2LatLngRect.fullLat(), S1Interval.full());\n }\n\n /** The full allowable range of latitudes. */\n public static fullLat() {\n return new R1Interval(-S2.M_PI_2, S2.M_PI_2);\n }\n\n\n /**\n * Construct a rectangle from a center point (in lat-lng space) and size in\n * each dimension. If size.lng is greater than 360 degrees it is clamped,\n * and latitudes greater than +/- 90 degrees are also clamped. So for example,\n * FromCenterSize((80,170),(20,20)) -> (lo=(60,150),hi=(90,-170)).\n */\n public static fromCenterSize(center:S2LatLng, size:S2LatLng) {\n return S2LatLngRect.fromPoint(center).expanded(size.mul(0.5));\n }\n\n /** Convenience method to construct a rectangle containing a single point. */\n public static fromPoint(p:S2LatLng):S2LatLngRect {\n // assert (p.isValid());\n return S2LatLngRect.fromLatLng(p, p);\n }\n\n /**\n * Convenience method to construct the minimal bounding rectangle containing\n * the two given points. This is equivalent to starting with an empty\n * rectangle and calling AddPoint() twice. Note that it is different than the\n * S2LatLngRect(lo, hi) constructor, where the first point is always used as\n * the lower-left corner of the resulting rectangle.\n */\n public static fromPointPair(p1:S2LatLng, p2:S2LatLng):S2LatLngRect {\n // assert (p1.isValid() && p2.isValid());\n return new S2LatLngRect(R1Interval.fromPointPair(p1.latRadians, p2\n .latRadians), S1Interval.fromPointPair(p1.lngRadians, p2.lngRadians));\n }\n\n /**\n * Return a latitude-longitude rectangle that contains the edge from \"a\" to\n * \"b\". Both points must be unit-length. Note that the bounding rectangle of\n * an edge can be larger than the bounding rectangle of its endpoints.\n */\n public static fromEdge(a:S2Point, b:S2Point):S2LatLngRect {\n // assert (S2.isUnitLength(a) && S2.isUnitLength(b));\n const r = S2LatLngRect.fromPointPair(S2LatLng.fromPoint(a), S2LatLng.fromPoint(b));\n\n // Check whether the min/max latitude occurs in the edge interior.\n // We find the normal to the plane containing AB, and then a vector \"dir\" in\n // this plane that also passes through the equator. We use RobustCrossProd\n // to ensure that the edge normal is accurate even when the two points are\n // very close together.\n const ab = S2.robustCrossProd(a, b);\n const dir = S2Point.crossProd(ab, new S2Point(0, 0, 1));\n const da = dir.dotProd(a);\n const db = dir.dotProd(b);\n if (da * db >= 0) {\n // Minimum and maximum latitude are attained at the vertices.\n return r;\n }\n // Minimum/maximum latitude occurs in the edge interior. This affects the\n // latitude bounds but not the longitude bounds.\n const absLat = Math.acos(ab.z / Math.abs(ab.norm()));\n if (da < 0) {\n return new S2LatLngRect(new R1Interval(r.lat.lo, absLat), r.lng);\n } else {\n return new S2LatLngRect(new R1Interval(-absLat, r.lat.hi), r.lng);\n }\n }\n\n /**\n * Return true if the rectangle is valid, which essentially just means that\n * the latitude bounds do not exceed Pi/2 in absolute value and the longitude\n * bounds do not exceed Pi in absolute value.\n *\n */\n public isValid():boolean {\n // The lat/lng ranges must either be both empty or both non-empty.\n return (Math.abs(this.lat.lo) <= S2.M_PI_2 && Math.abs(this.lat.hi) <= (S2.M_PI_2)\n && this.lng.isValid() && this.lat.isEmpty() == this.lng.isEmpty());\n }\n\n public lo():S2LatLng {\n return new S2LatLng(this.lat.lo, this.lng.lo);\n }\n\n public hi():S2LatLng {\n return new S2LatLng(this.lat.hi, this.lng.hi);\n }\n\n public latLo(): S1Angle {\n return S1Angle.radians(this.lat.lo);\n }\n\n public latHi(): S1Angle {\n return S1Angle.radians(this.lat.hi);\n }\n\n public lngLo(): S1Angle {\n return S1Angle.radians(this.lng.lo);\n }\n\n public lngHi(): S1Angle {\n return S1Angle.radians(this.lng.hi);\n }\n\n /**\n * Return true if the rectangle is empty, i.e. it contains no points at all.\n */\n public isEmpty():boolean {\n return this.lat.isEmpty();\n }\n\n// Return true if the rectangle is full, i.e. it contains all points.\n public isFull():boolean {\n // console.log(this.lat.toString());\n // console.log(S2LatLngRect.fullLat().toString());\n return this.lat.equals(S2LatLngRect.fullLat()) && this.lng.isFull();\n }\n\n /**\n * Return true if lng_.lo() > lng_.hi(), i.e. the rectangle crosses the 180\n * degree latitude line.\n */\n public isInverted():boolean {\n return this.lng.isInverted();\n }\n\n /** Return the k-th vertex of the rectangle (k = 0,1,2,3) in CCW order. */\n public getVertex(k:number):S2LatLng {\n // Return the points in CCW order (SW, SE, NE, NW).\n switch (k) {\n case 0:\n return this.lo();\n case 1:\n return new S2LatLng(this.lat.lo, this.lng.hi);\n case 2:\n return this.hi();\n case 3:\n return new S2LatLng(this.lat.hi, this.lng.lo);\n default:\n throw new Error(\"Invalid vertex index.\");\n }\n }\n\n /**\n * Return the center of the rectangle in latitude-longitude space (in general\n * this is not the center of the region on the sphere).\n */\n public getCenter():S2LatLng {\n return new S2LatLng(this.lat.getCenter(), this.lng.getCenter());\n }\n\n /**\n * Return the minimum distance (measured along the surface of the sphere)\n * from a given point to the rectangle (both its boundary and its interior).\n * The latLng must be valid.\n */\n public getDistanceLL(p:S2LatLng):S1Angle {\n // The algorithm here is the same as in getDistance(S2LagLngRect), only\n // with simplified calculations.\n if (this.isEmpty()) {\n throw new Error();\n }\n if (!p.isValid()) {\n throw new Error('point is not valid');\n }\n\n\n if (this.lng.contains(p.lngRadians)) {\n return new S1Angle(\n Math.max(\n 0.0,\n Math.max(\n p.latRadians - this.lat.hi,\n this.lat.lo - p.latRadians\n )\n )\n );\n }\n\n const interval = new S1Interval(this.lng.hi, this.lng.complement().getCenter());\n let aLng = this.lng.lo;\n if (interval.contains(p.lngRadians)) {\n aLng = this.lng.hi;\n }\n\n const lo = new S2LatLng(this.lat.lo, aLng).toPoint();\n const hi = new S2LatLng(this.lat.hi, aLng).toPoint();\n const loCrossHi = new S2LatLng(0, aLng - S2.M_PI_2).normalized().toPoint();\n return S2EdgeUtil.getDistance(p.toPoint(), lo, hi, loCrossHi);\n }\n\n /**\n * Return the minimum distance (measured along the surface of the sphere) to\n * the given S2LatLngRect. Both S2LatLngRects must be non-empty.\n */\n public getDistanceLLR(other:S2LatLngRect):S1Angle {\n const b = other;\n if (this.isEmpty()) {\n throw new Error();\n }\n if (b.isEmpty()) {\n throw new Error();\n }\n\n\n // First, handle the trivial cases where the longitude intervals overlap.\n if (this.lng.intersects(b.lng)) {\n if (this.lat.intersects(b.lat)) {\n return new S1Angle(0); // Intersection between a and b.\n }\n\n // We found an overlap in the longitude interval, but not in the latitude\n // interval. This means the shortest path travels along some line of\n // longitude connecting the high-latitude of the lower rect with the\n // low-latitude of the higher rect.\n let lo, hi;\n if (this.lat.lo > b.lat.hi) {\n lo = b.lat.hi;\n hi = this.lat.lo;\n } else {\n lo = this.lat.hi;\n hi = b.lat.lo;\n }\n return S1Angle.radians(hi.radians() - lo.radians());\n }\n\n // The longitude intervals don't overlap. In this case, the closest points\n // occur somewhere on the pair of longitudinal edges which are nearest in\n // longitude-space.\n let aLng, bLng;\n const loHi = S1Interval.fromPointPair(this.lng.lo, b.lng.hi);\n const hiLo = S1Interval.fromPointPair(this.lng.hi, b.lng.lo);\n if (loHi.getLength() < (hiLo.getLength())) {\n aLng = this.lng.lo;\n bLng = b.lng.hi;\n } else {\n aLng = this.lng.hi;\n bLng = b.lng.lo;\n }\n\n // The shortest distance between the two longitudinal segments will include\n // at least one segment endpoint. We could probably narrow this down further\n // to a single point-edge distance by comparing the relative latitudes of the\n // endpoints, but for the sake of clarity, we'll do all four point-edge\n // distance tests.\n const aLo = new S2LatLng(this.lat.lo, aLng).toPoint();\n const aHi = new S2LatLng(this.lat.hi, aLng).toPoint();\n const aLoCrossHi = new S2LatLng(0, aLng.radians().minus(S2.M_PI_2)).normalized().toPoint();\n const bLo = new S2LatLng(b.lat.lo, bLng).toPoint();\n const bHi = new S2LatLng(b.lat.hi, bLng).toPoint();\n const bLoCrossHi = new S2LatLng(0, bLng.radians().minus(S2.M_PI_2)).normalized().toPoint();\n\n return S1Angle.min(S2EdgeUtil.getDistance(aLo, bLo, bHi, bLoCrossHi),\n S1Angle.min(S2EdgeUtil.getDistance(aHi, bLo, bHi, bLoCrossHi),\n S1Angle.min(S2EdgeUtil.getDistance(bLo, aLo, aHi, aLoCrossHi),\n S2EdgeUtil.getDistance(bHi, aLo, aHi, aLoCrossHi))));\n }\n\n /**\n * Return the width and height of this rectangle in latitude-longitude space.\n * Empty rectangles have a negative width and height.\n */\n public getSize():S2LatLng {\n return new S2LatLng(this.lat.getLength(), this.lng.getLength());\n }\n\n /**\n * More efficient version of Contains() that accepts a S2LatLng rather than an\n * S2Point.\n */\n public containsLL(ll:S2LatLng):boolean {\n // assert (ll.isValid());\n return (this.lat.contains(ll.latRadians) && this.lng.contains(ll.lngRadians));\n\n }\n\n /**\n * Return true if and only if the given point is contained in the interior of\n * the region (i.e. the region excluding its boundary). The point 'p' does not\n * need to be normalized.\n */\n public interiorContainsP(p:S2Point):boolean {\n return this.interiorContainsLL(S2LatLng.fromPoint(p));\n }\n\n /**\n * More efficient version of InteriorContains() that accepts a S2LatLng rather\n * than an S2Point.\n */\n public interiorContainsLL(ll:S2LatLng):boolean {\n // assert (ll.isValid());\n return (this.lat.interiorContains(ll.latRadians) && this.lng\n .interiorContains(ll.lngRadians));\n }\n\n /**\n * Return true if and only if the rectangle contains the given other\n * rectangle.\n */\n public containsLLR(other:S2LatLngRect):boolean {\n return this.lat.containsI(other.lat) && this.lng.containsI(other.lng);\n }\n\n /**\n * Return true if and only if the interior of this rectangle contains all\n * points of the given other rectangle (including its boundary).\n */\n public interiorContainsLLR(other:S2LatLngRect):boolean {\n return (this.lat.interiorContainsI(other.lat) && this.lng\n .interiorContainsI(other.lng));\n }\n\n /** Return true if this rectangle and the given other rectangle have any\n points in common. */\n public intersectsLLR(other:S2LatLngRect):boolean {\n return this.lat.intersects(other.lat) && this.lng.intersects(other.lng);\n }\n\n /**\n * Returns true if this rectangle intersects the given cell. (This is an exact\n * test and may be fairly expensive, see also MayIntersect below.)\n */\n public intersects(cell:S2Cell):boolean {\n // First we eliminate the cases where one region completely contains the\n // other. Once these are disposed of, then the regions will intersect\n // if and only if their boundaries intersect.\n\n if (this.isEmpty()) {\n return false;\n }\n if (this.containsP(cell.getCenterRaw())) {\n return true;\n }\n if (cell.contains(this.getCenter().toPoint())) {\n return true;\n }\n\n // Quick rejection test (not required for correctness).\n if (!this.intersectsLLR(cell.getRectBound())) {\n return false;\n }\n\n // Now check whether the boundaries intersect. Unfortunately, a\n // latitude-longitude rectangle does not have straight edges -- two edges\n // are curved, and at least one of them is concave.\n\n // Precompute the cell vertices as points and latitude-longitudes.\n const cellV = new Array<S2Point>(4);\n const cellLl = new Array<S2LatLng>(4);\n for (let i = 0; i < 4; ++i) {\n cellV[i] = cell.getVertex(i); // Must be normalized.\n cellLl[i] = S2LatLng.fromPoint(cellV[i]);\n if (this.containsLL(cellLl[i])) {\n return true; // Quick acceptance test.\n }\n }\n\n for (let i = 0; i < 4; ++i) {\n const edgeLng = S1Interval.fromPointPair(\n cellLl[i].lngRadians, cellLl[(i + 1) & 3].lngRadians);\n if (!this.lng.intersects(edgeLng)) {\n continue;\n }\n\n const a = cellV[i];\n const b = cellV[(i + 1) & 3];\n if (edgeLng.contains(this.lng.lo)) {\n if (S2LatLngRect.intersectsLngEdge(a, b, this.lat, this.lng.lo)) {\n return true;\n }\n }\n if (edgeLng.contains(this.lng.hi)) {\n if (S2LatLngRect.intersectsLngEdge(a, b, this.lat, this.lng.hi)) {\n return true;\n }\n }\n if (S2LatLngRect.intersectsLatEdge(a, b, this.lat.lo, this.lng)) {\n return true;\n }\n if (S2LatLngRect.intersectsLatEdge(a, b, this.lat.hi, this.lng)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Return true if and only if the interior of this rectangle intersects any\n * point (including the boundary) of the given other rectangle.\n */\n public interiorIntersects(other:S2LatLngRect):boolean {\n return (this.lat.interiorIntersects(other.lat) && this.lng\n .interiorIntersects(other.lng));\n }\n\n public addPoint(p:S2Point):S2LatLngRect {\n return this.addPointLL(S2LatLng.fromPoint(p));\n }\n\n// Increase the size of the bounding rectangle to include the given point.\n// The rectangle is expanded by the minimum amount possible.\n public addPointLL(ll:S2LatLng):S2LatLngRect {\n const newLat = this.lat.addPoint(ll.latRadians);\n const newLng = this.lng.addPoint(ll.lngRadians);\n return new S2LatLngRect(newLat, newLng);\n }\n\n /**\n * Return a rectangle that contains all points whose latitude distance from\n * this rectangle is at most margin.lat, and whose longitude distance from\n * this rectangle is at most margin.lng. In particular, latitudes are\n * clamped while longitudes are wrapped. Note that any expansion of an empty\n * interval remains empty, and both components of the given margin must be\n * non-negative.\n *\n * NOTE: If you are trying to grow a rectangle by a certain *distance* on the\n * sphere (e.g. 5km), use the ConvolveWithCap() method instead.\n */\n public expanded(margin:S2LatLng):S2LatLngRect {\n // assert (margin.latRadians >= 0 && margin.lngRadians >= 0);\n if (this.isEmpty()) {\n return this;\n }\n return new S2LatLngRect(\n this.lat\n .expanded(margin.latRadians)\n .intersection(\n S2LatLngRect.fullLat()\n ),\n this.lng.expanded(margin.lngRadians)\n );\n }\n\n public polarClosure(): S2LatLngRect {\n if (this.lat.lo == -S2.M_PI_2 || this.lat.hi == S2.M_PI_2) {\n return new S2LatLngRect(this.lat, S1Interval.full());\n } else {\n return this;\n }\n }\n\n /**\n * Return the smallest rectangle containing the union of this rectangle and\n * the given rectangle.\n */\n public union(other:S2LatLngRect):S2LatLngRect {\n return new S2LatLngRect(this.lat.union(other.lat), this.lng.union(other.lng));\n }\n\n /**\n * Return the smallest rectangle containing the intersection of this rectangle\n * and the given rectangle. Note that the region of intersection may consist\n * of two disjoint rectangles, in which case a single rectangle spanning both\n * of them is returned.\n */\n public intersection(other:S2LatLngRect):S2LatLngRect {\n const intersectLat = this.lat.intersection(other.lat);\n const intersectLng = this.lng.intersection(other.lng);\n if (intersectLat.isEmpty() || intersectLng.isEmpty()) {\n // The lat/lng ranges must either be both empty or both non-empty.\n return S2LatLngRect.empty();\n }\n return new S2LatLngRect(intersectLat, intersectLng);\n }\n\n//\n// /**\n// * Return a rectangle that contains the convolution of this rectangle with a\n// * cap of the given angle. This expands the rectangle by a fixed distance (as\n// * opposed to growing the rectangle in latitude-longitude space). The returned\n// * rectangle includes all points whose minimum distance to the original\n// * rectangle is at most the given angle.\n// */\n// public S2LatLngRect convolveWithCap(/*S1Angle*/ angle) {\n// // The most straightforward approach is to build a cap centered on each\n// // vertex and take the union of all the bounding rectangles (including the\n// // original rectangle; this is necessary for very large rectangles).\n//\n// // Optimization: convert the angle to a height exactly once.\n// S2Cap cap = S2Cap.fromAxisAngle(new S2Point(1, 0, 0), angle);\n//\n// S2LatLngRect r = this;\n// for (int k = 0; k < 4; ++k) {\n// S2Cap vertexCap = S2Cap.fromAxisHeight(getVertex(k).toPoint(), cap\n// .height());\n// r = r.union(vertexCap.getRectBound());\n// }\n// return r;\n// }\n\n /** Return the surface area of this rectangle on the unit sphere. */\n public area(): number {\n if (this.isEmpty()) {\n return 0;\n }\n\n // This is the size difference of the two spherical caps, multiplied by\n // the longitude ratio.\n //TODO: check if this.lat.hi & this.lat.lo is radians.\n\n return this.lng.getLength() * (Math.sin(this.lat.hi) - Math.abs(Math.sin(this.lat.lo)));\n }\n\n /** Return true if two rectangles contains the same set of points. */\n\n public equals(that: S2LatLngRect):boolean {\n if (!(that instanceof S2LatLngRect)) {\n return false;\n }\n return this.lat.equals(that.lat) && this.lng.equals(that.lng);\n }\n\n /**\n * Return true if the latitude and longitude intervals of the two rectangles\n * are the same up to the given tolerance (see r1interval.h and s1interval.h\n * for details).\n */\n public approxEquals(other:S2LatLngRect, maxError= 1e-15):boolean {\n return (this.lat.approxEquals(other.lat, maxError) && this.lng.approxEquals(\n other.lng, maxError));\n }\n\n// //////////////////////////////////////////////////////////////////////\n// S2Region interface (see {@code S2Region} for details):\n\n\n public clone():S2Region {\n return new S2LatLngRect(this.lat, this.lng);\n }\n\n\n public getCapBound():S2Cap {\n // We consider two possible bounding caps, one whose axis passes through the center of the\n // lat-lng rectangle and one whose axis is the north or south pole. We return the smaller of the\n // two caps.\n if (this.isEmpty()) {\n return S2Cap.empty();\n }\n\n const useSouthPole = this.lat.lo + this.lat.hi < 0;\n const poleZ = useSouthPole ? -1 : 1;\n const poleAngle = useSouthPole ? S2.M_PI_2 + this.lat.hi : S2.M_PI_2 - this.lat.lo;\n const poleCap = S2Cap.fromAxisAngle(new S2Point(0, 0, poleZ), S1Angle.radians(poleAngle));\n\n // For bounding rectangles that span 180 degrees or less in longitude, the maximum cap size is\n // achieved at one of the rectangle vertices. For rectangles that are larger than 180 degrees,\n // we punt and always return a bounding cap centered at one of the two poles.\n const lngSpan = this.lng.hi - this.lng.lo;\n if (Platform.IEEEremainder(lngSpan, 2 * S2.M_PI) >= 0) {\n if (lngSpan < 2 * S2.M_PI) {\n let midCap = S2Cap.fromAxisAngle(this.getCenter().toPoint(), S1Angle.radians(0));\n for (let k = 0; k < 4; ++k) {\n midCap = midCap.addPoint(this.getVertex(k).toPoint());\n }\n if (midCap.height() < poleCap.height()) {\n return midCap;\n }\n }\n }\n return poleCap;\n }\n\n\n public getRectBound():S2LatLngRect {\n return this;\n }\n\n\n public /*boolean*/ containsC(cell:S2Cell):boolean {\n // A latitude-longitude rectangle contains a cell if and only if it contains\n // the cell's bounding rectangle. (This is an exact test.)\n return this.containsLLR(cell.getRectBound());\n }\n\n /**\n * This test is cheap but is NOT exact. Use Intersects() if you want a more\n * accurate and more expensive test. Note that when this method is used by an\n * S2RegionCoverer, the accuracy isn't all that important since if a cell may\n * intersect the region then it is subdivided, and the accuracy of this method\n * goes up as the cells get smaller.\n */\n\n public /*boolean*/ mayIntersectC(cell:S2Cell):boolean {\n // This test is cheap but is NOT exact (see s2latlngrect.h).\n return this.intersectsLLR(cell.getRectBound());\n }\n\n /** The point 'p' does not need to be normalized. */\n public /*boolean*/ containsP(p:S2Point):boolean {\n return this.containsLL(S2LatLng.fromPoint(p));\n }\n\n /**\n * Return true if the edge AB intersects the given edge of constant longitude.\n */\n private static /*boolean*/ intersectsLngEdge(a:S2Point, b:S2Point,\n lat:R1Interval, lng:number) {\n // Return true if the segment AB intersects the given edge of constant\n // longitude. The nice thing about edges of constant longitude is that\n // they are straight lines on the sphere (geodesics).\n\n\n return S2.simpleCrossing(a, b, new S2LatLng(lat.lo, lng)\n .toPoint(), new S2LatLng(lat.hi, lng).toPoint());\n }\n\n /**\n * Return true if the edge AB intersects the given edge of constant latitude.\n */\n private static /*boolean*/ intersectsLatEdge(a:S2Point, b:S2Point, lat:number,\n lng:S1Interval) {\n // Return true if the segment AB intersects the given edge of constant\n // latitude. Unfortunately, lines of constant latitude are curves on\n // the sphere. They can intersect a straight edge in 0, 1, or 2 points.\n // assert (S2.isUnitLength(a) && S2.isUnitLength(b));\n\n // First, compute the normal to the plane AB that points vaguely north.\n let z = S2Point.normalize(S2.robustCrossProd(a, b));\n if (z.z < (0)) {\n z = S2Point.neg(z);\n }\n\n // Extend this to an orthonormal frame (x,y,z) where x is the direction\n // where the great circle through AB achieves its maximium latitude.\n const y = S2Point.normalize(S2.robustCrossProd(z, new S2Point(0, 0, 1)));\n const x = S2Point.crossProd(y, z);\n // assert (S2.isUnitLength(x) && x.z >= 0);\n\n // Compute the angle \"theta\" from the x-axis (in the x-y plane defined\n // above) where the great circle intersects the given line of latitude.\n const sinLat = Math.sin(lat);\n if (Math.abs(sinLat) >= (x.z)) {\n return false; // The great circle does not reach the given latitude.\n }\n // assert (x.z > 0);\n const cosTheta = sinLat / x.z;\n const sinTheta = Math.sqrt(1 - cosTheta * cosTheta);\n const theta = Math.atan2(sinTheta, cosTheta);\n // Math.atan2(sinTheta, cosTheta);\n\n // The candidate intersection points are located +/- theta in the x-y\n // plane. For an intersection to be valid, we need to check that the\n // intersection point is contained in the interior of the edge AB and\n // also that it is contained within the given longitude interval \"lng\".\n\n // Compute the range of theta values spanned by the edge AB.\n const abTheta = S1Interval.fromPointPair(Math.atan2(\n a.dotProd(y), a.dotProd(x)), Math.atan2(b.dotProd(y), b.dotProd(x)));\n\n if (abTheta.contains(theta)) {\n // Check if the intersection point is also in the given \"lng\" interval.\n const isect = S2Point.add(S2Point.mul(x, cosTheta), S2Point.mul(y,\n sinTheta));\n if (lng.contains(Math.atan2(isect.y, isect.x))) {\n return true;\n }\n }\n if (abTheta.contains(theta * -1)) {\n // Check if the intersection point is also in the given \"lng\" interval.\n const intersection = S2Point.sub(S2Point.mul(x, cosTheta), S2Point.mul(y, sinTheta));\n if (lng.contains(Math.atan2(intersection.y, intersection.x))) {\n return true;\n }\n }\n return false;\n\n }\n\n public allVertex() {\n return [\n this.getVertex(0),\n this.getVertex(1),\n this.getVertex(2),\n this.getVertex(3)\n ]\n }\n\n public toGEOJSON() {\n return {\n type: 'Feature',\n geometry: {\n type: 'Polygon',\n coordinates: [this.allVertex().concat(this.getVertex(0)).map(v => [parseFloat(v.lngDegrees.toFixed(5)), parseFloat(v.latDegrees.toFixed(5))])],\n },\n properties: {}\n\n }\n }\n\n public toString():string {\n return \"[Lo=\" + this.lo().toString() + \", Hi=\" + this.hi().toString() + \"]\";\n }\n\n\n}\n","export function checkArgument(condition: boolean, message?: string) {\n if (!condition) {\n throw Error('IllegalArgumentException: ' + (message || ''));\n }\n}\n\nexport function checkState(condition: boolean, message?: string) {\n if (!condition) {\n throw Error('IllegalStateException: ' + (message || ''));\n }\n}","/*\n * Copyright 2014 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n/**\n * S1ChordAngle represents the angle subtended by a chord (i.e., the straight 3D Cartesian line\n * segment connecting two points on the unit sphere). Its representation makes it very efficient for\n * computing and comparing distances, but unlike S1Angle it is only capable of representing angles\n * between 0 and Pi radians. Generally, S1ChordAngle should only be used in loops where many angles\n * need to be calculated and compared. Otherwise it is simpler to use S1Angle.\n *\n * <p>S1ChordAngle also loses some accuracy as the angle approaches Pi radians. Specifically, the\n * representation of (Pi - x) radians can be expected to have an error of about (1e-15 / x), with a\n * maximum error of about 1e-7.\n */\n\nimport { S1Angle } from './S1Angle';\nimport { S2 } from './S2';\nimport { S2Point } from './S2Point';\nimport { checkArgument } from './utils/preconditions';\n\nexport class S1ChordAngle {\n\n /** Max value that can be returned from {@link #getLength2()}. */\n public static MAX_LENGTH2 = 4.0;\n\n /** The zero chord angle. */\n public static ZERO: S1ChordAngle = new S1ChordAngle(0);\n\n /** The chord angle of 90 degrees (a \"right angle\"). */\n public static RIGHT: S1ChordAngle = new S1ChordAngle(2);\n\n /** The chord angle of 180 degrees (a \"straight angle\"). This is the max finite chord angle. */\n public static STRAIGHT: S1ChordAngle = new S1ChordAngle(S1ChordAngle.MAX_LENGTH2);\n\n /**\n * A chord angle larger than any finite chord angle. The only valid operations on {@code INFINITY}\n * are comparisons and {@link S1Angle} conversions.\n */\n public static INFINITY: S1ChordAngle = new S1ChordAngle(Number.POSITIVE_INFINITY);\n\n /**\n * A chord angle smaller than {@link #ZERO}. The only valid operations on {@code NEGATIVE} are\n * comparisons and {@link S1Angle} conversions.\n */\n public static NEGATIVE: S1ChordAngle = new S1ChordAngle(-1);\n\n private length2: number;\n\n /**\n * S1ChordAngles are represented by the squared chord length, which can range from 0 to {@code\n * MAX_LENGTH2}. {@link #INFINITY} uses an infinite squared length.\n */\n public constructor(length2: number) {\n this.length2 = length2;\n checkArgument(this.isValid());\n }\n\n /**\n * Constructs the S1ChordAngle corresponding to the distance between the two given points. The\n * points must be unit length.\n */\n public static fromS2Point(x: S2Point, y: S2Point): S1ChordAngle {\n checkArgument(S2.isUnitLength(x));\n checkArgument(S2.isUnitLength(y));\n // The distance may slightly exceed 4.0 due to roundoff errors.\n const length2 = Math.min(S1ChordAngle.MAX_LENGTH2, x.getDistance2(y));\n return new S1ChordAngle(length2);\n }\n\n /**\n * Returns a new chord angle approximated from {@code angle} (see {@link\n * #getS1AngleConstructorMaxError()} for the max magnitude of the error).\n *\n * <p>Angles outside the range [0, Pi] are handled as follows:\n *\n * <ul>\n * <li>{@link S1Angle#INFINITY} is mapped to {@link #INFINITY}\n * <li>negative angles are mapped to {@link #NEGATIVE}\n * <li>finite angles larger than Pi are mapped to {@link #STRAIGHT}\n * </ul>\n *\n * <p>Note that this operation is relatively expensive and should be avoided. To use {@link\n * S1ChordAngle} effectively, you should structure your code so that input arguments are converted\n * to S1ChordAngles at the beginning of your algorithm, and results are converted back to {@link\n * S1Angle}s only at the end.\n */\n public static fromS1Angle(angle: S1Angle ): S1ChordAngle {\n if (angle.radians < 0) {\n return S1ChordAngle.NEGATIVE;\n } else if (angle.equals(S1Angle.INFINITY)) {\n return S1ChordAngle.INFINITY;\n } else {\n // The chord length is 2 * sin(angle / 2).\n const length = 2 * Math.sin(0.5 * Math.min(Math.PI, angle.radians));\n return new S1ChordAngle(length * length);\n }\n }\n\n /**\n * Construct an S1ChordAngle from the squared chord length. Note that the argument is\n * automatically clamped to a maximum of {@code MAX_LENGTH2} to handle possible roundoff errors.\n * The argument must be non-negative.\n */\n public static fromLength2(length2: number): S1ChordAngle {\n return new S1ChordAngle(Math.min(S1ChordAngle.MAX_LENGTH2, length2));\n }\n\n /** Returns whether the chord distance is exactly 0. */\n public isZero(): boolean {\n return this.length2 == 0;\n }\n\n /** Returns whether the chord distance is negative. */\n public isNegative(): boolean {\n return this.length2 < 0;\n }\n\n /** Returns whether the chord distance is exactly (positive) infinity. */\n public isInfinity(): boolean {\n return this.length2 == Number.POSITIVE_INFINITY;\n }\n\n /** Returns true if the angle is negative or infinity. */\n public isSpecial(): boolean {\n return this.isNegative() || this.isInfinity();\n }\n\n /**\n * Returns true if getLength2() is within the normal range of 0 to 4 (inclusive) or the angle is\n * special.\n */\n public isValid(): boolean {\n return (this.length2 >= 0 && this.length2 <= S1ChordAngle.MAX_LENGTH2) || this.isNegative() || this.isInfinity();\n }\n\n /**\n * Convert the chord angle to an {@link S1Angle}. {@link #INFINITY} is converted to {@link\n * S1Angle#INFINITY}, and {@link #NEGATIVE} is converted to a negative {@link S1Angle}. This\n * operation is relatively expensive.\n */\n public toAngle(): S1Angle {\n if (this.isNegative()) {\n return S1Angle.radians(-1);\n } else if (this.isInfinity()) {\n return S1Angle.INFINITY;\n } else {\n return S1Angle.radians(2 * Math.asin(0.5 * Math.sqrt(this.length2)));\n }\n }\n\n /** The squared length of the chord. (Most clients will not need this.) */\n public getLength2(): number {\n return this.length2;\n }\n\n /**\n * Returns the smallest representable S1ChordAngle larger than this object. This can be used to\n * convert a \"<\" comparison to a \"<=\" comparison.\n *\n * <p>Note the following special cases:\n *\n * <ul>\n * <li>NEGATIVE.successor() == ZERO\n * <li>STRAIGHT.successor() == INFINITY\n * <li>INFINITY.Successor() == INFINITY\n * </ul>\n */\n// public successor(): S1ChordAngle {\n// if (this.length2 >= S1ChordAngle.MAX_LENGTH2) {\n// return S1ChordAngle.INFINITY;\n// }\n// if (this.length2 < 0.0) {\n// return S1ChordAngle.ZERO;\n// }\n// return new S1ChordAngle(Platform.nextAfter(this.length2, 10.0));\n// }\n\n /**\n * As {@link #successor}, but returns the largest representable S1ChordAngle less than this\n * object.\n *\n * <p>Note the following special cases:\n *\n * <ul>\n * <li>INFINITY.predecessor() == STRAIGHT\n * <li>ZERO.predecessor() == NEGATIVE\n * <li>NEGATIVE.predecessor() == NEGATIVE\n * </ul>\n */\n// public predecessor(): S1ChordAngle {\n// if (this.length2 <= 0.0) {\n// return S1ChordAngle.NEGATIVE;\n// }\n// if (this.length2 > S1ChordAngle.MAX_LENGTH2) {\n// return S1ChordAngle.STRAIGHT;\n// }\n// return new S1ChordAngle(Platform.nextAfter(this.length2, -10.0));\n// }\n\n /**\n * Returns a new S1ChordAngle whose chord distance represents the sum of the angular distances\n * represented by the 'a' and 'b' chord angles.\n *\n * <p>Note that this method is much more efficient than converting the chord angles to S1Angles\n * and adding those. It requires only one square root plus a few additions and multiplications.\n */\n public static add(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n checkArgument(!a.isSpecial());\n checkArgument(!b.isSpecial());\n\n // Optimization for the common case where \"b\" is an error tolerance parameter that happens to be\n // set to zero.\n const a2 = a.length2;\n const b2 = b.length2;\n if (b2 == 0) {\n return a;\n }\n\n // Clamp the angle sum to at most 180 degrees.\n if (a2 + b2 >= S1ChordAngle.MAX_LENGTH2) {\n return S1ChordAngle.STRAIGHT;\n }\n\n // Let \"a\" and \"b\" be the (non-squared) chord lengths, and let c = a+b.\n // Let A, B, and C be the corresponding half-angles (a = 2*sin(A), etc).\n // Then the formula below can be derived from c = 2 * sin(A+B) and the relationships\n // sin(A+B) = sin(A)*cos(B) + sin(B)*cos(A)\n // cos(X) = sqrt(1 - sin^2(X)) .\n const x = a2 * (1 - 0.25 * b2); // isValid() => non-negative\n const y = b2 * (1 - 0.25 * a2); // isValid() => non-negative\n return new S1ChordAngle(Math.min(S1ChordAngle.MAX_LENGTH2, x + y + 2 * Math.sqrt(x * y)));\n }\n\n /**\n * Subtract one S1ChordAngle from another.\n *\n * <p>Note that this method is much more efficient than converting the chord angles to S1Angles\n * and adding those. It requires only one square root plus a few additions and multiplications.\n */\n public static sub(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n // See comments in add(S1ChordAngle, S1ChordAngle).\n checkArgument(!a.isSpecial());\n checkArgument(!b.isSpecial());\n const a2 = a.length2;\n const b2 = b.length2;\n if (b2 == 0) {\n return a;\n }\n if (a2 <= b2) {\n return S1ChordAngle.ZERO;\n }\n const x = a2 * (1 - 0.25 * b2);\n const y = b2 * (1 - 0.25 * a2);\n return new S1ChordAngle(Math.max(0.0, x + y - 2 * Math.sqrt(x * y)));\n }\n\n /** Returns the smaller of the given instances. */\n public static min(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n return a.length2 <= b.length2 ? a : b;\n }\n\n /** Returns the larger of the given instances. */\n public static max(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n return a.length2 > b.length2 ? a : b;\n }\n\n /** Returns the square of Math.sin(toAngle().radians()), but computed more efficiently. */\n public static sin2(a: S1ChordAngle): number {\n checkArgument(!a.isSpecial());\n // Let \"a\" be the (non-squared) chord length, and let A be the corresponding half-angle\n // (a = 2*sin(A)). The formula below can be derived from:\n // sin(2*A) = 2 * sin(A) * cos(A)\n // cos^2(A) = 1 - sin^2(A)\n // This is much faster than converting to an angle and computing its sine.\n return a.length2 * (1 - 0.25 * a.length2);\n }\n\n /** Returns Math.sin(toAngle().radians()), but computed more efficiently. */\n public static sin(a: S1ChordAngle): number {\n return Math.sqrt(this.sin2(a));\n }\n\n /** Returns Math.cos(toAngle().radians()), but computed more efficiently. */\n public static cos(a: S1ChordAngle): number {\n // cos(2*A) = cos^2(A) - sin^2(A) = 1 - 2*sin^2(A)\n checkArgument(!a.isSpecial());\n return 1 - 0.5 * a.length2;\n }\n\n /** Returns Math.tan(toAngle().radians()), but computed more efficiently. */\n public static tan(a: S1ChordAngle): number {\n return this.sin(a) / this.cos(a);\n }\n\n /**\n * Returns a new S1ChordAngle that has been adjusted by the given error bound (which can be\n * positive or negative). {@code error} should be the value returned by one of the error bound\n * methods below. For example:\n *\n * <pre>\n * {@code S1ChordAngle a = new S1ChordAngle(x, y);}\n * {@code S1ChordAngle a1 = a.plusError(a.getS2PointConstructorMaxError());}\n * </pre>\n *\n * <p>If this {@link #isSpecial}, we return {@code this}.\n */\n public plusError(error: number): S1ChordAngle {\n return this.isSpecial() ? this : S1ChordAngle.fromLength2(Math.max(0.0, Math.min(S1ChordAngle.MAX_LENGTH2, this.length2 + error)));\n }\n\n /** Returns the error in {@link #fromS1Angle}. */\n public getS1AngleConstructorMaxError(): number {\n return S2.DBL_EPSILON * this.length2;\n }\n\n /**\n * There is a relative error of {@code 2.5 * DBL_EPSILON} when computing the squared distance,\n * plus a relative error of {@code 2 * DBL_EPSILON} and an absolute error of {@code 16 *\n * DBL_EPSILON^2} because the lengths of the input points may differ from 1 by up to {@code 2 *\n * DBL_EPSILON} each. (This is the maximum length error in {@link S2Point#normalize}).\n */\n public getS2PointConstructorMaxError(): number {\n return (4.5 * S2.DBL_EPSILON * this.length2) + (16 * S2.DBL_EPSILON * S2.DBL_EPSILON);\n }\n\n /** Returns the string of the closest {@link S1Angle} to this chord distance. */\n\n public toString(): string {\n return this.toAngle().toString();\n }\n\n public compareTo(that: S1ChordAngle): number {\n return this.length2 - that.length2\n }\n\n public equals(that: S1ChordAngle): boolean {\n return this.compareTo(that) === 0;\n }\n}","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport {S2Region} from \"./S2Region\";\nimport {S2} from \"./S2\";\nimport {S2Point} from \"./S2Point\";\nimport {S1Angle} from \"./S1Angle\";\nimport {S2LatLngRect} from \"./S2LatLngRect\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {R1Interval} from \"./R1Interval\";\nimport {S1Interval} from \"./S1Interval\";\nimport {S2Cell} from \"./S2Cell\";\nimport {S1ChordAngle} from \"./S1ChordAngle\";\nimport { Platform } from './Platform';\n\n/**\n * This class represents a spherical cap, i.e. a portion of a sphere cut off by\n * a plane. The cap is defined by its axis and height. This representation has\n * good numerical accuracy for very small caps (unlike the (axis,\n * min-distance-from-origin) representation), and is also efficient for\n * containment tests (unlike the (axis, angle) representation).\n *\n * Here are some useful relationships between the cap height (h), the cap\n * opening angle (theta), the maximum chord length from the cap's center (d),\n * and the radius of cap's base (a). All formulas assume a unit radius.\n *\n * h = 1 - cos(theta) = 2 sin^2(theta/2) d^2 = 2 h = a^2 + h^2\n *\n */\nexport class S2Cap implements S2Region {\n\n\n /**\n * Multiply a positive number by this constant to ensure that the result of a\n * floating point operation is at least as large as the true\n * infinite-precision result.\n */\n private static ROUND_UP = 1 / Number(1n << 52n) + 1;\n\n public axis: S2Point;\n public radius: S1ChordAngle;\n\n\n /**\n * Create a cap given its axis and the cap height, i.e. the maximum projected\n * distance along the cap axis from the cap center. 'axis' should be a\n * unit-length vector.\n */\n constructor(axis:S2Point, radius: S1ChordAngle) {\n this.axis = axis;\n this.radius = radius;\n // assert (isValid());\n }\n\n public static fromAxisChord(center: S2Point, radius: S1ChordAngle): S2Cap {\n return new S2Cap(center, radius);\n }\n\n /**\n * Create a cap given its axis and the cap height, i.e. the maximum projected distance along the\n * cap axis from the cap center. 'axis' should be a unit-length vector.\n */\n public static fromAxisHeight(axis: S2Point, height: number): S2Cap {\n // assert (S2.isUnitLength(axis));\n return new S2Cap(axis, S1ChordAngle.fromLength2(2 * height));\n }\n\n /**\n * Create a cap given its axis and the cap opening angle, i.e. maximum angle\n * between the axis and a point on the cap. 'axis' should be a unit-length\n * vector, and 'angle' should be between 0 and 180 degrees.\n */\n public static fromAxisAngle(axis:S2Point, angle:S1Angle): S2Cap {\n // The \"min\" calculation below is necessary to handle S1Angle.INFINITY.\n // assert (S2.isUnitLength(axis));\n\n return this.fromAxisChord(\n axis, S1ChordAngle.fromS1Angle(S1Angle.radians(Math.min(angle.radians, S2.M_PI))));\n }\n\n /**\n * Create a cap given its axis and its area in steradians. 'axis' should be a unit-length vector,\n * and 'area' should be between 0 and 4 * M_PI.\n */\n public static fromAxisArea(axis:S2Point, area:number):S2Cap {\n // assert (S2.isUnitLength(axis));\n return new S2Cap(axis, S1ChordAngle.fromLength2(area / S2.M_PI));\n }\n\n /** Return an empty cap, i.e. a cap that contains no points. */\n public static empty(): S2Cap {\n return new S2Cap(S2Point.X_POS, S1ChordAngle.NEGATIVE);\n }\n\n /** Return a full cap, i.e. a cap that contains all points. */\n public static full(): S2Cap {\n return new S2Cap(S2Point.X_POS, S1ChordAngle.STRAIGHT);\n }\n\n getCapBound():S2Cap {\n return this;\n }\n\n public height(): number {\n return 0.5 * this.radius.getLength2();\n }\n\n public area() {\n return 2 * S2.M_PI * Math.max(0.0, this.height());\n }\n\n /**\n * Returns the cap radius as an S1Angle. Since the cap angle is stored internally as an\n * S1ChordAngle, this method requires a trigonometric operation and may yield a slightly different\n * result than the value passed to {@link #fromAxisAngle(S2Point, S1Angle)}.\n */\n public angle():S1Angle {\n return this.radius.toAngle();\n }\n\n /**\n * Returns true if the axis is {@link S2#isUnitLength unit length}, and the angle is less than Pi.\n *\n * <p>Negative angles or heights are valid, and represent empty caps.\n */\n public isValid():boolean {\n return S2.isUnitLength(this.axis) && this.radius.getLength2() <= 4;\n }\n\n /** Return true if the cap is empty, i.e. it contains no points. */\n public isEmpty():boolean {\n return this.radius.isNegative();\n }\n\n /** Return true if the cap is full, i.e. it contains all points. */\n public isFull():boolean {\n return S1ChordAngle.STRAIGHT.equals(this.radius);\n }\n\n /**\n * Return the complement of the interior of the cap. A cap and its complement have the same\n * boundary but do not share any interior points. The complement operator is not a bijection,\n * since the complement of a singleton cap (containing a single point) is the same as the\n * complement of an empty cap.\n */\n public complement():S2Cap {\n // The complement of a full cap is an empty cap, not a singleton.\n // Also make sure that the complement of an empty cap is full.\n if (this.isFull()) {\n return S2Cap.empty();\n }\n if (this.isEmpty()) {\n return S2Cap.full();\n }\n return S2Cap.fromAxisChord(S2Point.neg(this.axis), S1ChordAngle.fromLength2(4 - this.radius.getLength2()));\n\n }\n\n /**\n * Return true if and only if this cap contains the given other cap (in a set\n * containment sense, e.g. every cap contains the empty cap).\n */\n public containsCap(other:S2Cap):boolean {\n if (this.isFull() || other.isEmpty()) {\n return true;\n } else {\n const axialDistance = S1ChordAngle.fromS2Point(this.axis, other.axis);\n return this.radius.compareTo(S1ChordAngle.add(axialDistance, other.radius)) >= 0;\n }\n }\n\n /**\n * Return true if and only if the interior of this cap intersects the given other cap. (This\n * relationship is not symmetric, since only the interior of this cap is used.)\n */\n public interiorIntersects(other:S2Cap):boolean {\n // Interior(X) intersects Y if and only if Complement(Interior(X))\n // does not contain Y.\n return !this.complement().containsCap(other);\n }\n\n /**\n * Return true if and only if the given point is contained in the interior of the region (i.e. the\n * region excluding its boundary). 'p' should be a unit-length vector.\n */\n public interiorContains(p:S2Point):boolean {\n // assert (S2.isUnitLength(p));\n return this.isFull() || S1ChordAngle.fromS2Point(this.axis, p).compareTo(this.radius) < 0;\n }\n\n /**\n * Increase the cap radius if necessary to include the given point. If the cap is empty the axis\n * is set to the given point, but otherwise it is left unchanged.\n *\n * @param p must be {@link S2#isUnitLength unit length}\n */\n public addPoint(p:S2Point):S2Cap {\n // assert (S2.isUnitLength(p));\n if (this.isEmpty()) {\n return new S2Cap(p, S1ChordAngle.ZERO);\n } else {\n // After adding p to this cap, we require that the result contains p. However we don't need to\n // do anything special to achieve this because contains() does exactly the same distance\n // calculation that we do here.\n return new S2Cap(\n this.axis, S1ChordAngle.fromLength2(Math.max(this.radius.getLength2(), this.axis.getDistance2(p))));\n }\n }\n\n// Increase the cap height if necessary to include \"other\". If the current\n// cap is empty it is set to the given other cap.\n public addCap(other:S2Cap):S2Cap {\n if (this.isEmpty()) {\n return other;\n } else if (other.isEmpty()) {\n return this;\n } else {\n // We round up the distance to ensure that the cap is actually contained.\n // TODO(user): Do some error analysis in order to guarantee this.\n const dist = S1ChordAngle.add(S1ChordAngle.fromS2Point(this.axis, other.axis), other.radius);\n const roundedUp = dist.plusError(S2.DBL_EPSILON * dist.getLength2());\n return new S2Cap(this.axis, S1ChordAngle.max(this.radius, roundedUp));\n }\n }\n\n// //////////////////////////////////////////////////////////////////////\n// S2Region interface (see {@code S2Region} for details):\n public getRectBound():S2LatLngRect {\n if (this.isEmpty()) {\n return S2LatLngRect.empty();\n }\n if (this.isFull()) {\n return S2LatLngRect.full();\n }\n\n // Convert the axis to a (lat,lng) pair, and compute the cap angle.\n const axisLatLng = S2LatLng.fromPoint(this.axis);\n const capAngle = this.angle().radians;\n\n let allLongitudes = false;\n const lat = [];\n const lng = [];\n lng[0] = -S2.M_PI;\n lng[1] = S2.M_PI;\n\n // Check whether cap includes the south pole.\n lat[0] = axisLatLng.lat().radians - capAngle;\n if (lat[0] <= -S2.M_PI_2) {\n lat[0] = -S2.M_PI_2;\n allLongitudes = true;\n }\n // Check whether cap includes the north pole.\n lat[1] = axisLatLng.lat().radians + capAngle;\n if (lat[1] >= S2.M_PI_2) {\n lat[1] = S2.M_PI_2;\n allLongitudes = true;\n }\n if (!allLongitudes) {\n // Compute the range of longitudes covered by the cap. We use the law\n // of sines for spherical triangles. Consider the triangle ABC where\n // A is the north pole, B is the center of the cap, and C is the point\n // of tangency between the cap boundary and a line of longitude. Then\n // C is a right angle, and letting a,b,c denote the sides opposite A,B,C,\n // we have sin(a)/sin(A) = sin(c)/sin(C), or sin(A) = sin(a)/sin(c).\n // Here \"a\" is the cap angle, and \"c\" is the colatitude (90 degrees\n // minus the latitude). This formula also works for negative latitudes.\n const sinA = S1ChordAngle.sin(this.radius);\n const sinC = Math.cos(axisLatLng.lat().radians);\n if (sinA <= sinC) {\n const angleA = Math.asin(sinA / sinC);\n lng[0] = Platform.IEEEremainder(axisLatLng.lng().radians - angleA, 2 * S2.M_PI);\n lng[1] = Platform.IEEEremainder(axisLatLng.lng().radians + angleA, 2 * S2.M_PI);\n }\n }\n return new S2LatLngRect(new R1Interval(lat[0], lat[1]), new S1Interval(lng[0], lng[1]));\n }\n\n // public mayIntersectC(cell:S2Cell):boolean {\n // const toRet = this._mayIntersectC(cell);\n // console.log(\"intersects? \",toRet, cell.id.pos().toString(16), cell.level);\n // return toRet;\n // }\n public mayIntersectC(cell:S2Cell):boolean {\n // If the cap contains any cell vertex, return true.\n const vertices:S2Point[] = new Array(4);\n for (let k = 0; k < 4; ++k) {\n vertices[k] = cell.getVertex(k);\n if (this.contains(vertices[k])) {\n return true;\n }\n }\n return this.intersects(cell, vertices);\n }\n\n /**\n * Return true if the cap intersects 'cell', given that the cap vertices have\n * alrady been checked.\n */\n public intersects(cell:S2Cell, vertices:S2Point[]): boolean {\n // Return true if this cap intersects any point of 'cell' excluding its\n // vertices (which are assumed to already have been checked).\n\n // If the cap is a hemisphere or larger, the cell and the complement of the\n // cap are both convex. Therefore since no vertex of the cell is contained,\n // no other interior point of the cell is contained either.\n if (this.radius.compareTo(S1ChordAngle.RIGHT) >= 0) {\n return false;\n }\n\n // We need to check for empty caps due to the axis check just below.\n if (this.isEmpty()) {\n return false;\n }\n\n // Optimization: return true if the cell contains the cap axis. (This\n // allows half of the edge checks below to be skipped.)\n if (cell.contains(this.axis)) {\n return true;\n }\n\n // At this point we know that the cell does not contain the cap axis,\n // and the cap does not contain any cell vertex. The only way that they\n // can intersect is if the cap intersects the interior of some edge.\n\n const sin2Angle = S1ChordAngle.sin2(this.radius);\n for (let k = 0; k < 4; ++k) {\n const edge = cell.getEdgeRaw(k);\n const dot = this.axis.dotProd(edge);\n if (dot > 0) {\n // The axis is in the interior half-space defined by the edge. We don't\n // need to consider these edges, since if the cap intersects this edge\n // then it also intersects the edge on the opposite side of the cell\n // (because we know the axis is not contained with the cell).\n continue;\n }\n // The Norm2() factor is necessary because \"edge\" is not normalized.\n if (dot * dot > sin2Angle * edge.norm2()) {\n return false; // Entire cap is on the exterior side of this edge.\n }\n // Otherwise, the great circle containing this edge intersects\n // the interior of the cap. We just need to check whether the point\n // of closest approach occurs between the two edge endpoints.\n const dir = S2Point.crossProd(edge, this.axis);\n if (dir.dotProd(vertices[k]) < 0 && dir.dotProd(vertices[(k + 1) & 3]) > 0) {\n return true;\n }\n }\n return false;\n }\n\n public contains(p:S2Point):boolean {\n // The point 'p' should be a unit-length vector.\n // assert (S2.isUnitLength(p));\n return S1ChordAngle.fromS2Point(this.axis, p).compareTo(this.radius) <= 0;\n }\n\n public containsC(cell: S2Cell): boolean {\n // If the cap does not contain all cell vertices, return false.\n // We check the vertices before taking the Complement() because we can't\n // accurately represent the complement of a very small cap (a height\n // of 2-epsilon is rounded off to 2).\n const vertices = [];\n for (let k = 0; k < 4; ++k) {\n vertices[k] = cell.getVertex(k);\n if (!this.contains(vertices[k])) {\n return false;\n }\n }\n // Otherwise, return true if the complement of the cap does not intersect\n // the cell. (This test is slightly conservative, because technically we\n // want Complement().InteriorIntersects() here.)\n return !this.complement().intersects(cell, vertices);\n }\n\n//\n// /** Return true if two caps are identical. */\n// public equals(that:Object ):boolean {\n//\n// if (!(that instanceof S2Cap)) {\n// return false;\n// }\n//\n// S2Cap other = (S2Cap) that;\n// return (this.axis.equals(other.axis) && this.height == other.height)\n// || (isEmpty() && other.isEmpty()) || (isFull() && other.isFull());\n//\n// }\n//\n// @Override\n// public int hashCode() {\n// if (isFull()) {\n// return 17;\n// } else if (isEmpty()) {\n// return 37;\n// }\n// int result = 17;\n// result = 37 * result + this.axis.hashCode();\n// long heightBits = Double.doubleToLongBits(this.height);\n// result = 37 * result + (int) ((heightBits >>> 32) ^ heightBits);\n// return result;\n// }\n\n// /////////////////////////////////////////////////////////////////////\n// The following static methods are convenience functions for assertions\n// and testing purposes only.\n\n /**\n * Return true if the cap axis and height differ by at most \"max_error\" from\n * the given cap \"other\".\n */\n public approxEquals(other:S2Cap, maxError = 1e-14):boolean {\n const r2 = this.radius.getLength2();\n const otherR2 = other.radius.getLength2();\n\n return (S2.approxEqualsPointError(this.axis, other.axis, maxError) && Math.abs(r2 - otherR2) <= maxError)\n || (this.isEmpty() && otherR2 <= maxError)\n || (other.isEmpty() && r2 <= maxError)\n || (this.isFull() && otherR2 >= 2 - maxError)\n || (other.isFull() && r2 >= 2 - maxError);\n }\n\n public toString():string {\n return \"[Point = \" + this.axis + \" Radius = \" + this.radius + \"]\";\n }\n\n public toGEOJSON(){\n return this.getRectBound().toGEOJSON();\n }\n}\n","/**\n * Utility helpers for unsigned 64-bit bigint arithmetic.\n *\n * All values stored in S2CellId.id are guaranteed to be in [0, 2^64-1].\n * Use u64() to mask any operation that can produce an out-of-range value\n * (addition, subtraction, multiplication, shift-left, bitwise-not, negation).\n */\n\n/** Mask a bigint value to the unsigned 64-bit range [0, 2^64-1]. */\nexport function u64(n: bigint): bigint {\n return BigInt.asUintN(64, n);\n}\n\n/** Extract the lower 32 bits as an unsigned JS number [0, 2^32-1]. */\nexport function low32(n: bigint): number {\n return Number(n & 0xFFFF_FFFFn);\n}\n\n/**\n * Extract the lower 32 bits as a signed JS number [-2^31, 2^31-1].\n * Equivalent to Java Long.getLowBits().\n */\nexport function low32s(n: bigint): number {\n return Number(BigInt.asIntN(32, n));\n}\n\n/** Maximum value of a uint64: 2^64 - 1 */\nexport const UINT64_MAX = 0xFFFF_FFFF_FFFF_FFFFn;\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n/**\n * This class specifies the details of how the cube faces are projected onto the\n * unit sphere. This includes getting the face ordering and orientation correct\n * so that sequentially increasing cell ids follow a continuous space-filling\n * curve over the entire sphere, and defining the transformation from cell-space\n * to cube-space (see s2.h) in order to make the cells more uniform in size.\n *\n *\n * We have implemented three different projections from cell-space (s,t) to\n * cube-space (u,v): linear, quadratic, and tangent. They have the following\n * tradeoffs:\n *\n * Linear - This is the fastest transformation, but also produces the least\n * uniform cell sizes. Cell areas vary by a factor of about 5.2, with the\n * largest cells at the center of each face and the smallest cells in the\n * corners.\n *\n * Tangent - Transforming the coordinates via atan() makes the cell sizes more\n * uniform. The areas vary by a maximum ratio of 1.4 as opposed to a maximum\n * ratio of 5.2. However, each call to atan() is about as expensive as all of\n * the other calculations combined when converting from points to cell ids, i.e.\n * it reduces performance by a factor of 3.\n *\n * Quadratic - This is an approximation of the tangent projection that is much\n * faster and produces cells that are almost as uniform in size. It is about 3\n * times faster than the tangent projection for converting cell ids to points,\n * and 2 times faster for converting points to cell ids. Cell areas vary by a\n * maximum ratio of about 2.1.\n *\n * Here is a table comparing the cell uniformity using each projection. \"Area\n * ratio\" is the maximum ratio over all subdivision levels of the largest cell\n * area to the smallest cell area at that level, \"edge ratio\" is the maximum\n * ratio of the longest edge of any cell to the shortest edge of any cell at the\n * same level, and \"diag ratio\" is the ratio of the longest diagonal of any cell\n * to the shortest diagonal of any cell at the same level. \"ToPoint\" and\n * \"FromPoint\" are the times in microseconds required to convert cell ids to and\n * from points (unit vectors) respectively.\n *\n * Area Edge Diag ToPoint FromPoint Ratio Ratio Ratio (microseconds)\n * ------------------------------------------------------- Linear: 5.200 2.117\n * 2.959 0.103 0.123 Tangent: 1.414 1.414 1.704 0.290 0.306 Quadratic: 2.082\n * 1.802 1.932 0.116 0.161\n *\n * The worst-case cell aspect ratios are about the same with all three\n * projections. The maximum ratio of the longest edge to the shortest edge\n * within the same cell is about 1.4 and the maximum ratio of the diagonals\n * within the same cell is about 1.7.\n *\n * This data was produced using s2cell_unittest and s2cellid_unittest.\n *\n */\nimport { S2, S2Metric } from \"./S2\";\nimport { S2CellId } from \"./S2CellId\";\nimport { S2Point } from \"./S2Point\";\nimport { R2Vector } from \"./R2Vector\";\n\n\n\nexport type UvTransformFunction = (x: number, y: number, z: number) => number\nexport type XyzTransformFunction = (u: number, v: number) => number\n\nexport type UvTransform = {\n xyzToU: UvTransformFunction,\n xyzToV: UvTransformFunction\n};\n\nexport type XyzTransform = {\n uvToX: XyzTransformFunction,\n uvToY: XyzTransformFunction,\n uvToZ: XyzTransformFunction,\n}\n\nexport class S2Projections {\n\n public static MIN_WIDTH = new S2Metric(1, 2 * S2.M_SQRT2 / 3); // 0.943\n public static AVG_AREA = new S2Metric(2, 4 * S2.M_PI / 6); // ~2.094\n public static MAX_LEVEL = 30;\n\n private static FACE_UVW_AXES: S2Point[][] = [\n [S2Point.Y_POS, S2Point.Z_POS, S2Point.X_POS],\n [S2Point.X_NEG, S2Point.Z_POS, S2Point.Y_POS],\n [S2Point.X_NEG, S2Point.Y_NEG, S2Point.Z_POS],\n [S2Point.Z_NEG, S2Point.Y_NEG, S2Point.X_NEG],\n [S2Point.Z_NEG, S2Point.X_POS, S2Point.Y_NEG],\n [S2Point.Y_POS, S2Point.X_POS, S2Point.Z_NEG]\n ];\n\n private static UV_TRANSFORMS: UvTransform[] = [\n {\n xyzToU: function xyzToU(x: number, y: number, _z: number) {\n return y / x;\n },\n\n xyzToV: function xyzToV(x: number, _y: number, z: number) {\n return z / x;\n },\n },\n\n {\n xyzToU: function xyzToU(x: number, y: number, _z: number) {\n return -x / y;\n },\n\n xyzToV: function xyzToV(_x: number, y: number, z: number) {\n return z / y;\n },\n },\n\n {\n xyzToU: function xyzToU(x: number, _y: number, z: number) {\n return -x / z;\n },\n\n xyzToV: function xyzToV(_x: number, y: number, z: number) {\n return -y / z;\n },\n },\n\n {\n xyzToU: function xyzToU(x: number, _y: number, z: number) {\n return z / x;\n },\n\n xyzToV: function xyzToV(x: number, y: number, _z: number) {\n return y / x;\n },\n },\n\n {\n xyzToU: function xyzToU(_x: number, y: number, z: number) {\n return z / y;\n },\n\n xyzToV: function xyzToV(x: number, y: number, _z: number) {\n return -x / y;\n },\n },\n\n {\n xyzToU: function xyzToU(_x: number, y: number, z: number) {\n return -y / z;\n },\n\n xyzToV: function xyzToV(x: number, _y: number, z: number) {\n return -x / z;\n },\n }\n ];\n\n private static XYZ_TRANSFORMS: XyzTransform[] = [\n {\n uvToX: function uvToX(_u: number, _v: number): number {\n return 1;\n },\n\n\n uvToY: function uvToY(u: number, _v: number): number {\n return u;\n },\n\n\n uvToZ: function uvToZ(_u: number, v: number): number {\n return v;\n },\n },\n {\n uvToX: function uvToX(u: number, _v: number): number {\n return -u;\n },\n\n\n uvToY: function uvToY(_u: number, _v: number): number {\n return 1;\n },\n\n\n uvToZ: function uvToZ(_u: number, v: number): number {\n return v;\n },\n },\n {\n uvToX: function uvToX(u: number, _v: number): number {\n return -u;\n },\n\n\n uvToY: function uvToY(_u: number, v: number): number {\n return -v;\n },\n\n\n uvToZ: function uvToZ(_u: number, _v: number): number {\n return 1;\n },\n },\n {\n uvToX: function uvToX(_u: number, _v: number): number {\n return -1;\n },\n\n\n uvToY: function uvToY(_u: number, v: number): number {\n return -v;\n },\n\n\n uvToZ: function uvToZ(u: number, _v: number): number {\n return -u;\n },\n },\n {\n uvToX: function uvToX(_u: number, v: number): number {\n return v;\n },\n\n\n uvToY: function uvToY(_u: number, _v: number): number {\n return -1;\n },\n\n\n uvToZ: function uvToZ(u: number, _v: number): number {\n return -u;\n },\n },\n {\n uvToX: function uvToX(_u: number, v: number): number {\n return v;\n },\n\n\n uvToY: function uvToY(u: number, _v: number): number {\n return u;\n },\n\n\n uvToZ: function uvToZ(_u: number, _v: number): number {\n return -1;\n },\n }\n ];\n\n /**\n * The maximum value of an si- or ti-coordinate. The range of valid (si,ti) values is\n * [0..MAX_SiTi].\n */\n public static MAX_SITI = 1n << BigInt(S2Projections.MAX_LEVEL + 1)\n\n public static getUNorm(face: number, u: number): S2Point {\n switch (face) {\n case 0:\n return new S2Point(u, -1, 0);\n case 1:\n return new S2Point(1, u, 0);\n case 2:\n return new S2Point(1, 0, u);\n case 3:\n return new S2Point(-u, 0, 1);\n case 4:\n return new S2Point(0, -u, 1);\n default:\n return new S2Point(0, -1, -u);\n }\n }\n\n public static getVNorm(face: number, v: number): S2Point {\n switch (face) {\n case 0:\n return new S2Point(-v, 0, 1);\n case 1:\n return new S2Point(0, -v, 1);\n case 2:\n return new S2Point(0, -1, -v);\n case 3:\n return new S2Point(v, -1, 0);\n case 4:\n return new S2Point(1, v, 0);\n default:\n return new S2Point(1, 0, v);\n }\n }\n\n public static getUAxis(face: number): S2Point {\n return S2Projections.getUVWAxis(face, 0);\n }\n\n public static getVAxis(face: number): S2Point {\n return S2Projections.getUVWAxis(face, 1);\n }\n\n public static getNorm(face: number): S2Point {\n return S2Projections.getUVWAxis(face, 2);\n }\n\n /** Returns the given axis of the given face (u=0, v=1, w=2). */\n static getUVWAxis(face: number, axis: number): S2Point {\n return S2Projections.FACE_UVW_AXES[face][axis];\n }\n\n /**\n * Convert (face, si, ti) coordinates (see s2.h) to a direction vector (not\n * necessarily unit length).\n */\n public static faceSiTiToXYZ(face: number, si: number, ti: number): S2Point {\n const u = R2Vector.singleStTOUV(this.siTiToSt(si));\n const v = R2Vector.singleStTOUV(this.siTiToSt(ti));\n\n return this.faceUvToXyz(face, u, v)\n }\n\n public static faceUvToXyz(face: number, u: number, v: number): S2Point {\n const t = this.faceToXyzTransform(face)\n return new S2Point(t.uvToX(u, v), t.uvToY(u, v), t.uvToZ(u, v));\n }\n\n public static faceXyzToUv(face: number, p: S2Point): R2Vector {\n if (face < 3) {\n if (p.get(face) <= 0) {\n return null;\n }\n } else {\n if (p.get(face - 3) >= 0) {\n return null;\n }\n }\n return S2Projections.validFaceXyzToUv(face, p);\n }\n\n public static validFaceXyzToUv(face: number, p: S2Point ): R2Vector {\n const t = S2Projections.faceToUvTransform(face);\n return new R2Vector(t.xyzToU(p.x, p.y, p.z), t.xyzToV(p.x, p.y, p.z));\n }\n\n public static ijToStMin(i: number): number {\n // assert (i >= 0 && i <= S2CellId.MAX_SIZE);\n return (1.0 / S2CellId.MAX_SIZE) * i;\n }\n\n public static stToIj(s: number): number {\n return Math.max(\n 0, Math.min(S2CellId.MAX_SIZE - 1, Math.round(S2CellId.MAX_SIZE * s - 0.5)));\n }\n\n public static siTiToSt(si: number): number {\n return 1.0 / Number(this.MAX_SITI) * si;\n }\n\n public static ijToUV(ij: number, cellSize: number): number {\n return R2Vector.singleStTOUV(S2Projections.ijToStMin(ij & -cellSize));\n }\n\n static xyzToFaceP(p: S2Point): number {\n return this.xyzToFace(p.x, p.y, p.z)\n }\n\n static xyzToFace(x: number, y: number, z: number): number {\n switch (S2Point.largestAbsComponent(x, y, z)) {\n case 0:\n return (x < 0) ? 3 : 0;\n case 1:\n return (y < 0) ? 4 : 1;\n default:\n return (z < 0) ? 5 : 2;\n }\n }\n\n public static faceToUvTransform(face: number): UvTransform {\n return S2Projections.UV_TRANSFORMS[face];\n }\n\n public static faceToXyzTransform(face: number): XyzTransform {\n // We map illegal face indices to the largest face index to preserve legacy behavior, i.e., we\n // do not (yet) want to throw an index out of bounds exception. Note that S2CellId.face() is\n // guaranteed to return a non-negative face index even for invalid S2 cells, so it is sufficient\n // to just map all face indices greater than 5 to a face index of 5.\n //\n // TODO(bjj): Remove this legacy behavior.\n return S2Projections.XYZ_TRANSFORMS[Math.min(5, face)];\n }\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { u64, low32s, UINT64_MAX } from './uint64';\nimport { S2Point } from \"./S2Point\";\nimport { R2Vector } from \"./R2Vector\";\nimport { S2 } from \"./S2\";\nimport { MutableInteger } from \"./MutableInteger\";\nimport { S2LatLng } from \"./S2LatLng\";\nimport { S2Projections, UvTransform } from './S2Projections';\n\n/**\n * An S2CellId is a 64-bit unsigned integer that uniquely identifies a cell in\n * the S2 cell decomposition. It has the following format:\n *\n * <pre>\n * id = [face][face_pos]\n * </pre>\n *\n * face: a 3-bit number (range 0..5) encoding the cube face.\n *\n * face_pos: a 61-bit number encoding the position of the center of this cell\n * along the Hilbert curve over this face (see the Wiki pages for details).\n *\n * Sequentially increasing cell ids follow a continuous space-filling curve over\n * the entire sphere. They have the following properties:\n * - The id of a cell at level k consists of a 3-bit face number followed by k\n * bit pairs that recursively select one of the four children of each cell. The\n * next bit is always 1, and all other bits are 0. Therefore, the level of a\n * cell is determined by the position of its lowest-numbered bit that is turned\n * on (for a cell at level k, this position is 2 * (MAX_LEVEL - k).)\n * - The id of a parent cell is at the midpoint of the range of ids spanned by\n * its children (or by its descendants at any level).\n *\n * Leaf cells are often used to represent points on the unit sphere, and this\n * class provides methods for converting directly between these two\n * representations. For cells that represent 2D regions rather than discrete\n * point, it is better to use the S2Cell class.\n *\n * v4 CHANGE: S2CellId.id is now a native bigint (unsigned uint64).\n * The constructor accepts both bigint and string (signed or unsigned decimal).\n */\nexport class S2CellId {\n\n // Although only 60 bits are needed to represent the index of a leaf\n // cell, we need an extra bit in order to represent the position of\n // the center of the leaf cell along the Hilbert curve.\n public static FACE_BITS = 3;\n public static NUM_FACES = 6;\n public static MAX_LEVEL = 30; // Valid levels: 0..MAX_LEVEL\n public static POS_BITS = 2 * S2CellId.MAX_LEVEL + 1; // 61\n public static MAX_SIZE = 1 << S2CellId.MAX_LEVEL; // 2^30\n\n /** Maximum unsigned 64-bit value (sentinel). */\n public static MAX_UNSIGNED: bigint = UINT64_MAX;\n\n // The following lookup tables are used to convert efficiently between an\n // (i,j) cell index and the corresponding position along the Hilbert curve.\n public static LOOKUP_BITS = 4;\n private static SWAP_MASK = 0x01;\n private static INVERT_MASK = 0x02;\n\n private static I_SHIFT = 33;\n private static J_SHIFT = 2;\n\n private static J_MASK = (1n << 31n) - 1n; // 2^31 - 1\n\n private static SI_SHIFT = 32;\n private static ORIENTATION_MASK = 3n;\n\n private static TI_MASK = 0xFFFF_FFFFn; // lower 32 bits\n\n /** LOOKUP_POS[10-bit key] = 10-bit value (stored as bigint) */\n public static LOOKUP_POS: bigint[] = [];\n /** LOOKUP_IJ[10-bit key] = 10-bit value */\n public static LOOKUP_IJ: number[] = [];\n\n /**\n * This is the offset required to wrap around from the beginning of the\n * Hilbert curve to the end or vice versa; see next_wrap() and prev_wrap().\n */\n private static WRAP_OFFSET: bigint =\n BigInt(S2CellId.NUM_FACES) << BigInt(S2CellId.POS_BITS);\n\n /**\n * The 64-bit unsigned cell ID.\n * v4: changed from Long to bigint. Always in [0, 2^64-1].\n */\n public id: bigint;\n\n /**\n * Construct an S2CellId from a bigint or decimal string.\n *\n * The string may be signed (\"-6533045114107854848\") or unsigned\n * (\"11913698959601696768\"); both are handled via BigInt.asUintN(64, ...).\n */\n constructor(id: bigint | string) {\n if (typeof id === 'string') {\n // BigInt() parses the signed decimal, asUintN reinterprets as unsigned.\n this.id = BigInt.asUintN(64, BigInt(id));\n } else {\n this.id = BigInt.asUintN(64, id);\n }\n }\n\n // -------------------------------------------------------------------------\n // Migration helpers (v3 → v4 compatibility)\n // -------------------------------------------------------------------------\n\n /**\n * Construct an S2CellId from a **signed**-decimal string produced by Java's\n * Long.toString() or the v3 Long-based API. Equivalent to `new S2CellId(s)`\n * but makes the intent explicit.\n *\n * @example\n * S2CellId.fromSignedDecimalString('-6533045114107854848')\n */\n public static fromSignedDecimalString(s: string): S2CellId {\n return new S2CellId(BigInt.asUintN(64, BigInt(s)));\n }\n\n /**\n * Return this cell id as a signed-decimal string, matching the output of\n * Java's Long.toString() and the v3 Long-based API.\n *\n * @example\n * cellId.toSignedDecimalString() // '-6533045114107854848'\n */\n public toSignedDecimalString(): string {\n return BigInt.asIntN(64, this.id).toString();\n }\n\n /**\n * Return this cell id as an unsigned-decimal string (same as `this.id.toString()`).\n *\n * @example\n * cellId.toUnsignedDecimalString() // '11913698959601696768'\n */\n public toUnsignedDecimalString(): string {\n return this.id.toString();\n }\n\n // -------------------------------------------------------------------------\n // Core geometry\n // -------------------------------------------------------------------------\n\n /** Which cube face this cell belongs to, in the range 0..5. */\n get face(): number {\n return Number(this.id >> BigInt(S2CellId.POS_BITS));\n }\n\n /** Return the lowest-numbered bit that is on for this cell. */\n public lowestOnBit(): bigint {\n return S2CellId.lowestOnBit(this.id);\n }\n\n static lowestOnBit(id: bigint): bigint {\n // id & (-id) using two's-complement unsigned arithmetic\n return id & u64(-id);\n }\n\n /** Return an invalid cell id (id == 0). */\n public static none(): S2CellId {\n return new S2CellId(0n);\n }\n\n /**\n * Returns an invalid cell id guaranteed to be larger than any valid cell id.\n * Useful for creating indexes.\n */\n public static sentinel(): S2CellId {\n return new S2CellId(UINT64_MAX);\n }\n\n private getBits1(\n i: MutableInteger,\n j: MutableInteger,\n k: number,\n bits: number,\n ): number {\n const nbits =\n k === 7\n ? S2CellId.MAX_LEVEL - 7 * S2CellId.LOOKUP_BITS\n : S2CellId.LOOKUP_BITS;\n\n const shift = k * 2 * S2CellId.LOOKUP_BITS + 1;\n const mask = (1 << (2 * nbits)) - 1;\n bits += (Number((this.id >> BigInt(shift)) & BigInt(mask))) << 2;\n\n bits = S2CellId.LOOKUP_IJ[bits];\n i.val =\n i.val +\n ((bits >> (S2CellId.LOOKUP_BITS + 2)) << (k * S2CellId.LOOKUP_BITS));\n j.val =\n j.val +\n (((bits >> 2) & ((1 << S2CellId.LOOKUP_BITS) - 1)) <<\n (k * S2CellId.LOOKUP_BITS));\n\n bits &= S2.SWAP_MASK | S2.INVERT_MASK;\n return bits;\n }\n\n /** Return the lowest-numbered bit that is on for cells at the given level. */\n public static lowestOnBitForLevel(level: number): bigint {\n return 1n << BigInt(2 * (S2CellId.MAX_LEVEL - level));\n }\n\n /**\n * @deprecated use `toIJOrientation` instead\n */\n public toFaceIJOrientation(\n pi: MutableInteger,\n pj: MutableInteger,\n orientation: MutableInteger,\n ): number {\n const face = this.face;\n let bits = face & S2.SWAP_MASK;\n\n for (let k = 7; k >= 0; --k) {\n bits = this.getBits1(pi, pj, k, bits);\n }\n\n if (orientation != null) {\n if ((0x1111111111111110n & this.lowestOnBit()) !== 0n) {\n bits ^= S2.SWAP_MASK;\n }\n orientation.val = bits;\n }\n return face;\n }\n\n /**\n * Return a packed bigint encoding (i << I_SHIFT | j << J_SHIFT | orientation).\n * Use getI(), getJ(), getOrientation() to unpack.\n */\n public toIJOrientation(): bigint {\n const face = this.face;\n let bits = face & S2.SWAP_MASK;\n\n let i = 0;\n let j = 0;\n for (let k = 7; k >= 0; --k) {\n const nbits =\n k === 7\n ? S2CellId.MAX_LEVEL - 7 * S2CellId.LOOKUP_BITS\n : S2CellId.LOOKUP_BITS;\n\n const shift = k * 2 * S2CellId.LOOKUP_BITS + 1;\n const mask = (1 << (2 * nbits)) - 1;\n bits += (Number((this.id >> BigInt(shift)) & BigInt(mask))) << 2;\n\n bits = S2CellId.LOOKUP_IJ[bits];\n i += (bits >> (S2CellId.LOOKUP_BITS + 2)) << (k * S2CellId.LOOKUP_BITS);\n j +=\n ((bits >> 2) & ((1 << S2CellId.LOOKUP_BITS) - 1)) <<\n (k * S2CellId.LOOKUP_BITS);\n\n bits &= S2.SWAP_MASK | S2.INVERT_MASK;\n }\n\n if ((0x1111111111111110n & this.lowestOnBit()) !== 0n) {\n bits ^= S2.SWAP_MASK;\n }\n\n const orientation = bits;\n return (\n (BigInt(i) << BigInt(S2CellId.I_SHIFT)) |\n (BigInt(j) << BigInt(S2CellId.J_SHIFT)) |\n BigInt(orientation)\n );\n }\n\n public getI(): number {\n return S2CellId.getI(this.toIJOrientation());\n }\n\n static getI(ijo: bigint): number {\n return Number(ijo >> BigInt(S2CellId.I_SHIFT));\n }\n\n public getJ(): number {\n return S2CellId.getJ(this.toIJOrientation());\n }\n\n static getJ(ijo: bigint): number {\n return Number((ijo >> BigInt(S2CellId.J_SHIFT)) & S2CellId.J_MASK);\n }\n\n static getOrientation(ijo: bigint): number {\n return Number(ijo & S2CellId.ORIENTATION_MASK);\n }\n\n /** Return true if this is a leaf cell (level() == MAX_LEVEL). */\n public isLeaf(): boolean {\n return (this.id & 1n) !== 0n;\n }\n\n /**\n * Return the cell at the given level (which must be ≤ the current level).\n */\n public parentL(level: number): S2CellId {\n const newLsb = S2CellId.lowestOnBitForLevel(level);\n return new S2CellId((this.id & u64(-newLsb)) | newLsb);\n }\n\n public parent(): S2CellId {\n const oldLsb = this.lowestOnBit();\n const newLsb = oldLsb << 2n;\n return new S2CellId((this.id & u64(-newLsb)) | newLsb);\n }\n\n /**\n * Return a cell given its face (range 0..5), 61-bit Hilbert curve position\n * within that face, and level (range 0..MAX_LEVEL).\n *\n * v4: `pos` is now `bigint` (was `Long`).\n */\n public static fromFacePosLevel(\n face: number,\n pos: bigint,\n level: number,\n ): S2CellId {\n return new S2CellId(\n (BigInt(face) << BigInt(S2CellId.POS_BITS)) + (pos | 1n),\n ).parentL(level);\n }\n\n public static fromFace(face: number): S2CellId {\n return new S2CellId(S2CellId.fromFaceAsBigInt(face));\n }\n\n public static fromPoint(p: S2Point): S2CellId {\n const face = S2Projections.xyzToFaceP(p);\n const t: UvTransform = S2Projections.faceToUvTransform(face);\n const i = S2Projections.stToIj(\n R2Vector.singleUVToST(t.xyzToU(p.x, p.y, p.z)),\n );\n const j = S2Projections.stToIj(\n R2Vector.singleUVToST(t.xyzToV(p.x, p.y, p.z)),\n );\n return this.fromFaceIJ(face, i, j);\n }\n\n public getCenterUV(): R2Vector {\n const center = this.getCenterSiTi();\n return new R2Vector(\n R2Vector.singleStTOUV(\n S2Projections.siTiToSt(S2CellId.getSi(center)),\n ),\n R2Vector.singleStTOUV(\n S2Projections.siTiToSt(S2CellId.getTi(center)),\n ),\n );\n }\n\n public toPoint(): S2Point {\n return S2Point.normalize(this.toPointRaw());\n }\n\n /**\n * Returns packed (si << 32 | ti) as a bigint.\n * v4: return type changed from Long to bigint.\n */\n getCenterSiTi(): bigint {\n const ijo = this.toIJOrientation();\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n const delta = this.isLeaf()\n ? 1\n : ((i ^ (low32s(this.id) >>> 2)) & 1) !== 0\n ? 2\n : 0;\n\n return (\n (BigInt(2 * i + delta) << BigInt(S2CellId.SI_SHIFT)) |\n (S2CellId.TI_MASK & BigInt(2 * j + delta))\n );\n }\n\n static getSi(center: bigint): number {\n return Number(center >> BigInt(S2CellId.SI_SHIFT));\n }\n\n static getTi(center: bigint): number {\n return Number(center & S2CellId.TI_MASK);\n }\n\n public toPointRaw(): S2Point {\n const center = this.getCenterSiTi();\n return S2Projections.faceSiTiToXYZ(\n this.face,\n S2CellId.getSi(center),\n S2CellId.getTi(center),\n );\n }\n\n public toLatLng(): S2LatLng {\n return S2LatLng.fromPoint(this.toPointRaw());\n }\n\n /** Return true if id() represents a valid cell. */\n public isValid(): boolean {\n return (\n this.face < S2CellId.NUM_FACES &&\n (this.lowestOnBit() & 0x1555555555555555n) !== 0n\n );\n }\n\n /**\n * The position of the cell center along the Hilbert curve over this face,\n * in the range 0..(2**kPosBits-1).\n *\n * v4: return type changed from Long to bigint.\n */\n public pos(): bigint {\n return this.id & (UINT64_MAX >> BigInt(S2CellId.FACE_BITS));\n }\n\n /** Return the subdivision level of the cell (range 0..MAX_LEVEL). */\n public level(): number {\n if (this.isLeaf()) {\n return S2CellId.MAX_LEVEL;\n }\n // Fast path using lower 32 bits\n let x = low32s(this.id); // signed 32-bit lower half (equiv. to Java getLowBits())\n let level = -1;\n if (x !== 0) {\n level += 16;\n } else {\n x = low32s(this.id >> 32n);\n }\n // We only need to look at even-numbered bits to determine the level.\n x &= -x; // isolate lowest set bit\n if ((x & 0x00005555) !== 0) {\n level += 8;\n }\n if ((x & 0x00550055) !== 0) {\n level += 4;\n }\n if ((x & 0x05050505) !== 0) {\n level += 2;\n }\n if ((x & 0x11111111) !== 0) {\n level += 1;\n }\n return level;\n }\n\n public getSizeIJ(): number {\n return S2CellId.getSizeIJ(this.level());\n }\n\n static getSizeIJ(level: number): number {\n return 1 << (S2.MAX_LEVEL - level);\n }\n\n public getSizeST(): number {\n return S2CellId.getSizeST(this.level());\n }\n\n static getSizeST(level: number): number {\n return S2Projections.ijToStMin(S2CellId.getSizeIJ(level));\n }\n\n public isFace(): boolean {\n return this.level() === 0;\n }\n\n public childPosition(level: number): number {\n return Number(\n (this.id >> BigInt(2 * (S2CellId.MAX_LEVEL - level) + 1)) & 3n,\n );\n }\n\n public rangeMin(): S2CellId {\n // id - (lowestOnBit() - 1)\n return new S2CellId(u64(this.id - this.lowestOnBit() + 1n));\n }\n\n public rangeMax(): S2CellId {\n // id + (lowestOnBit() - 1)\n return new S2CellId(this.id + this.lowestOnBit() - 1n);\n }\n\n public contains(other: S2CellId): boolean {\n return (\n other.greaterOrEquals(this.rangeMin()) &&\n other.lessOrEquals(this.rangeMax())\n );\n }\n\n public intersects(other: S2CellId): boolean {\n return (\n other.rangeMin().lessOrEquals(this.rangeMax()) &&\n other.rangeMax().greaterOrEquals(this.rangeMin())\n );\n }\n\n public childBegin(): S2CellId {\n return new S2CellId(S2CellId.childBeginAsBigInt(this.id));\n }\n\n public childBeginL(level: number): S2CellId {\n return new S2CellId(S2CellId.childBeginAsBigIntL(this.id, level));\n }\n\n public childEnd(): S2CellId {\n return new S2CellId(S2CellId.childEndAsBigInt(this.id));\n }\n\n public childEndL(level: number): S2CellId {\n return new S2CellId(S2CellId.childEndAsBigIntL(this.id, level));\n }\n\n private static childBeginAsBigInt(id: bigint): bigint {\n const oldLsb = S2CellId.lowestOnBit(id);\n return u64(id - oldLsb + (oldLsb >> 2n));\n }\n\n private static childBeginAsBigIntL(id: bigint, level: number): bigint {\n return u64(\n id - S2CellId.lowestOnBit(id) + S2CellId.lowestOnBitForLevel(level),\n );\n }\n\n private static childEndAsBigInt(id: bigint): bigint {\n const oldLsb = S2CellId.lowestOnBit(id);\n return u64(id + oldLsb + (oldLsb >> 2n));\n }\n\n private static childEndAsBigIntL(id: bigint, level: number): bigint {\n return u64(\n id + S2CellId.lowestOnBit(id) + S2CellId.lowestOnBitForLevel(level),\n );\n }\n\n private static fromFaceAsBigInt(face: number): bigint {\n return (\n (BigInt(face) << BigInt(S2CellId.POS_BITS)) +\n S2CellId.lowestOnBitForLevel(0)\n );\n }\n\n /** Return the next cell at the same level along the Hilbert curve. */\n public next(): S2CellId {\n return new S2CellId(u64(this.id + (this.lowestOnBit() << 1n)));\n }\n\n /** Return the previous cell at the same level along the Hilbert curve. */\n public prev(): S2CellId {\n return new S2CellId(u64(this.id - (this.lowestOnBit() << 1n)));\n }\n\n public nextWrap(): S2CellId {\n const n = this.next();\n if (n.id < S2CellId.WRAP_OFFSET) {\n return n;\n }\n return new S2CellId(u64(n.id - S2CellId.WRAP_OFFSET));\n }\n\n public prevWrap(): S2CellId {\n const p = this.prev();\n if (p.id < S2CellId.WRAP_OFFSET) {\n return p;\n }\n return new S2CellId(p.id + S2CellId.WRAP_OFFSET);\n }\n\n static begin(level: number): S2CellId {\n return S2CellId.fromFacePosLevel(0, 0n, 0).childBeginL(level);\n }\n\n static end(level: number): S2CellId {\n return S2CellId.fromFacePosLevel(5, 0n, 0).childEndL(level);\n }\n\n /**\n * Decodes a cell id from a compact hex token string.\n * The maximum token length is 16 hex characters.\n */\n public static fromToken(token: string): S2CellId {\n if (token == null) {\n throw new Error('Null string in S2CellId.fromToken');\n }\n if (token.length === 0) {\n throw new Error('Empty string in S2CellId.fromToken');\n }\n if (token.length > 16 || token === 'X') {\n return S2CellId.none();\n }\n // Pad with trailing zeros to 16 hex chars, then parse as 64-bit unsigned.\n const padded = token.padEnd(16, '0');\n return new S2CellId(BigInt('0x' + padded));\n }\n\n /**\n * Encodes the cell id to a compact hex token string.\n * Cells at lower levels are encoded into fewer characters.\n */\n public toToken(): string {\n if (this.id === 0n) {\n return 'X';\n }\n const hex = this.id.toString(16).padStart(16, '0');\n let len = 16;\n while (len > 0 && hex[len - 1] === '0') {\n len--;\n }\n return hex.substring(0, len);\n }\n\n public getEdgeNeighbors(): S2CellId[] {\n const level = this.level();\n const size = this.getSizeIJ();\n const face = this.face;\n\n const ijo = this.toIJOrientation();\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n\n return [\n S2CellId.fromFaceIJSame(face, i, j - size, j - size >= 0).parentL(\n level,\n ),\n S2CellId.fromFaceIJSame(\n face,\n i + size,\n j,\n i + size < S2CellId.MAX_SIZE,\n ).parentL(level),\n S2CellId.fromFaceIJSame(\n face,\n i,\n j + size,\n j + size < S2CellId.MAX_SIZE,\n ).parentL(level),\n S2CellId.fromFaceIJSame(face, i - size, j, i - size >= 0).parentL(\n level,\n ),\n ];\n }\n\n public getVertexNeighbors(level: number): S2CellId[] {\n const ijo = this.toIJOrientation();\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n\n const halfsize = S2CellId.getSizeIJ(level + 1);\n const size = halfsize << 1;\n let isame: boolean, jsame: boolean;\n let ioffset: number, joffset: number;\n\n if ((i & halfsize) !== 0) {\n ioffset = size;\n isame = i + size < S2CellId.MAX_SIZE;\n } else {\n ioffset = -size;\n isame = i - size >= 0;\n }\n if ((j & halfsize) !== 0) {\n joffset = size;\n jsame = j + size < S2CellId.MAX_SIZE;\n } else {\n joffset = -size;\n jsame = j - size >= 0;\n }\n\n const face = this.face;\n const toRet: S2CellId[] = [this.parentL(level)];\n toRet.push(\n S2CellId.fromFaceIJSame(face, i + ioffset, j, isame).parentL(level),\n );\n toRet.push(\n S2CellId.fromFaceIJSame(face, i, j + joffset, jsame).parentL(level),\n );\n if (isame || jsame) {\n toRet.push(\n S2CellId.fromFaceIJSame(\n face,\n i + ioffset,\n j + joffset,\n isame && jsame,\n ).parentL(level),\n );\n }\n return toRet;\n }\n\n public getAllNeighbors(nbrLevel: number): S2CellId[] {\n const ijo = this.toIJOrientation();\n\n const size = this.getSizeIJ();\n const face = this.face;\n const i = S2CellId.getI(ijo) & -size;\n const j = S2CellId.getJ(ijo) & -size;\n\n const nbrSize = S2CellId.getSizeIJ(nbrLevel);\n\n const output: S2CellId[] = [];\n for (let k = -nbrSize; ; k += nbrSize) {\n let sameFace: boolean;\n if (k < 0) {\n sameFace = j + k >= 0;\n } else if (k >= size) {\n sameFace = j + k < S2CellId.MAX_SIZE;\n } else {\n sameFace = true;\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i + k,\n j - nbrSize,\n j - size >= 0,\n ).parentL(nbrLevel),\n );\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i + k,\n j + size,\n j + size < S2CellId.MAX_SIZE,\n ).parentL(nbrLevel),\n );\n }\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i - nbrSize,\n j + k,\n sameFace && i - size >= 0,\n ).parentL(nbrLevel),\n );\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i + size,\n j + k,\n sameFace && i + size < S2CellId.MAX_SIZE,\n ).parentL(nbrLevel),\n );\n if (k >= size) {\n break;\n }\n }\n return output;\n }\n\n // ///////////////////////////////////////////////////////////////////\n // Low-level methods.\n\n public static fromFaceIJ(face: number, i: number, j: number): S2CellId {\n // n[1] holds the high 32 bits, n[0] holds the low 32 bits.\n const n: bigint[] = [0n, BigInt(face) << BigInt(S2CellId.POS_BITS - 33)];\n\n let bits = face & S2CellId.SWAP_MASK;\n\n for (let k = 7; k >= 0; --k) {\n bits = S2CellId.getBits(n, i, j, k, bits);\n }\n\n // Combine halves, shift left 1, set leaf bit.\n return new S2CellId(((n[1] << 32n) | n[0]) << 1n | 1n);\n }\n\n private static getBits(\n n: bigint[],\n i: number,\n j: number,\n k: number,\n bits: number,\n ): number {\n const mask = (1 << S2CellId.LOOKUP_BITS) - 1; // 15\n bits += ((i >> (k * S2CellId.LOOKUP_BITS)) & mask) << (S2CellId.LOOKUP_BITS + 2);\n bits += ((j >> (k * S2CellId.LOOKUP_BITS)) & mask) << 2;\n\n const lookupBits = S2CellId.LOOKUP_POS[bits]; // bigint\n n[k >> 2] =\n n[k >> 2] |\n ((lookupBits >> 2n) <<\n BigInt((k & 3) * 2 * S2CellId.LOOKUP_BITS));\n\n return Number(lookupBits) & (S2CellId.SWAP_MASK | S2CellId.INVERT_MASK);\n }\n\n private static stToIJ(s: number): number {\n const m = S2CellId.MAX_SIZE / 2;\n return Math.max(0, Math.min(m * 2 - 1, Math.round(m * s + m - 0.5)));\n }\n\n private static fromFaceIJWrap(face: number, i: number, j: number): S2CellId {\n i = Math.max(-1, Math.min(S2CellId.MAX_SIZE, i));\n j = Math.max(-1, Math.min(S2CellId.MAX_SIZE, j));\n\n const kScale = 1 / S2CellId.MAX_SIZE;\n // Plain number arithmetic: values fit in 32-bit int\n const s = kScale * (2 * i + 1 - S2CellId.MAX_SIZE);\n const t = kScale * (2 * j + 1 - S2CellId.MAX_SIZE);\n\n const p = new R2Vector(s, t).toPoint(face);\n face = p.toFace();\n const st = p.toR2Vector(face);\n return S2CellId.fromFaceIJ(\n face,\n S2CellId.stToIJ(st.x),\n S2CellId.stToIJ(st.y),\n );\n }\n\n public static fromFaceIJSame(\n face: number,\n i: number,\n j: number,\n sameFace: boolean,\n ): S2CellId {\n return sameFace\n ? S2CellId.fromFaceIJ(face, i, j)\n : S2CellId.fromFaceIJWrap(face, i, j);\n }\n\n // -------------------------------------------------------------------------\n // Unsigned comparison helpers (trivial now that bigint is always positive)\n // -------------------------------------------------------------------------\n\n /** Returns true if x1 < x2 (unsigned comparison). */\n public static unsignedLongLessThan(x1: bigint, x2: bigint): boolean {\n return x1 < x2;\n }\n\n /** Returns true if x1 > x2 (unsigned comparison). */\n public static unsignedLongGreaterThan(x1: bigint, x2: bigint): boolean {\n return x1 > x2;\n }\n\n public lessThan(x: S2CellId): boolean {\n return this.id < x.id;\n }\n\n public greaterThan(x: S2CellId): boolean {\n return this.id > x.id;\n }\n\n public lessOrEquals(x: S2CellId): boolean {\n return this.id <= x.id;\n }\n\n public greaterOrEquals(x: S2CellId): boolean {\n return this.id >= x.id;\n }\n\n public toString(): string {\n return (\n '(face=' +\n this.face +\n ', pos=' +\n this.pos().toString(16) +\n ', level=' +\n this.level() +\n ')'\n );\n }\n\n public compareTo(that: S2CellId): number {\n return this.id < that.id ? -1 : this.id > that.id ? 1 : 0;\n }\n\n public equals(that: S2CellId): boolean {\n return this.id === that.id;\n }\n\n /**\n * Binary search in a sorted S2CellId array.\n * Returns index if found, or -(insertionPoint+1) if not found.\n *\n * v4: `_id` accepts bigint, string, or S2CellId (was Long, string, or S2CellId).\n */\n public static binarySearch(\n ids: S2CellId[],\n _id: bigint | string | S2CellId,\n low = 0,\n ): number {\n let id: S2CellId;\n if (_id instanceof S2CellId) {\n id = _id;\n } else {\n id = new S2CellId(_id as bigint | string);\n }\n let high = ids.length - 1;\n\n while (low <= high) {\n const mid = (low + high) >>> 1;\n const midVal = ids[mid];\n const cmp = midVal.compareTo(id);\n\n if (cmp < 0) low = mid + 1;\n else if (cmp > 0) high = mid - 1;\n else return mid;\n }\n return -(low + 1);\n }\n\n public static indexedBinarySearch(\n ids: S2CellId[],\n id: bigint | string | S2CellId,\n low = 0,\n ): number {\n const toRet = this.binarySearch(ids, id, low);\n return toRet >= 0 ? toRet : -(toRet + 1);\n }\n}\n\n// -------------------------------------------------------------------------\n// Lookup table initialisation\n// -------------------------------------------------------------------------\n\nfunction initLookupCell(\n level: number,\n i: number,\n j: number,\n origOrientation: number,\n pos: bigint,\n orientation: number,\n): void {\n if (level === S2CellId.LOOKUP_BITS) {\n const ij = (i << S2CellId.LOOKUP_BITS) + j;\n S2CellId.LOOKUP_POS[(ij << 2) + origOrientation] =\n (pos << 2n) + BigInt(orientation);\n S2CellId.LOOKUP_IJ[Number((pos << 2n) + BigInt(origOrientation))] =\n (ij << 2) + orientation;\n } else {\n level++;\n i <<= 1;\n j <<= 1;\n pos = pos << 2n;\n for (let subPos = 0; subPos < 4; subPos++) {\n const ij = S2.POS_TO_IJ[orientation][subPos];\n const orientationMask = S2.POS_TO_ORIENTATION[subPos];\n initLookupCell(\n level,\n i + (ij >>> 1),\n j + (ij & 1),\n origOrientation,\n pos + BigInt(subPos),\n orientation ^ orientationMask,\n );\n }\n }\n}\n\ninitLookupCell(0, 0, 0, 0, 0n, 0);\ninitLookupCell(0, 0, 0, S2.SWAP_MASK, 0n, S2.SWAP_MASK);\ninitLookupCell(0, 0, 0, S2.INVERT_MASK, 0n, S2.INVERT_MASK);\ninitLookupCell(\n 0,\n 0,\n 0,\n S2.SWAP_MASK | S2.INVERT_MASK,\n 0n,\n S2.SWAP_MASK | S2.INVERT_MASK,\n);\n","/**\n * Transitional utilities for consumers migrating from nodes2-ts v3 (Long-based API)\n * to v4 (bigint-based API).\n *\n * These helpers make it easy to work with signed-decimal cell ID strings that\n * older code or Java S2 libraries produce (e.g. \"-6533045114107854848\") alongside\n * the new unsigned bigint representation.\n */\n\nimport { S2CellId } from './S2CellId';\n\n/**\n * Convert a signed-decimal string (as produced by Java's Long.toString()) to an\n * unsigned 64-bit bigint.\n *\n * @example\n * signedDecimalToUnsigned('-6533045114107854848')\n * // => 11913698959601696768n\n */\nexport function signedDecimalToUnsigned(s: string): bigint {\n return BigInt.asUintN(64, BigInt(s));\n}\n\n/**\n * Convert an unsigned 64-bit bigint back to a signed-decimal string, as Java's\n * Long.toString() would produce.\n *\n * @example\n * unsignedToSignedDecimal(11913698959601696768n)\n * // => '-6533045114107854848'\n */\nexport function unsignedToSignedDecimal(id: bigint): string {\n return BigInt.asIntN(64, id).toString();\n}\n\n/**\n * Convenience: convert a signed-decimal S2 cell ID string (from Java) to its\n * token representation.\n *\n * @example\n * signedDecimalTokenMap('-6533045114107854848')\n * // => 'a555f6151'\n */\nexport function signedDecimalTokenMap(signedId: string): string {\n return new S2CellId(signedDecimalToUnsigned(signedId)).toToken();\n}\n","export class MutableInteger {\n\n constructor(public val:number) {\n }\n}","import {S2CellId} from \"./S2CellId\";\nimport {S2Point} from \"./S2Point\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {S2Projections} from \"./S2Projections\";\nimport {R2Vector} from \"./R2Vector\";\nimport {S2} from \"./S2\";\nimport {S2LatLngRect} from \"./S2LatLngRect\";\nimport {R1Interval} from \"./R1Interval\";\nimport {S1Interval} from \"./S1Interval\";\nimport {S2Cap} from \"./S2Cap\";\nexport class S2Cell {\n private static MAX_CELL_SIZE = 1 << S2CellId.MAX_LEVEL;\n\n private _face:number;\n private _level:number;\n private _orientation:number;\n\n private uMin: number;\n private uMax: number;\n private vMin: number;\n private vMax: number;\n\n constructor(private cellID?:S2CellId) {\n if (cellID != null) {\n this.init(cellID)\n }\n }\n\n get id():S2CellId {\n return this.cellID;\n }\n\n\n public static fromFace(face: number): S2Cell {\n return new S2Cell(S2CellId.fromFace(face));\n }\n\n// This is a static method in order to provide named parameters.\n public static fromFacePosLevel(face:number, pos:number, level:number):S2Cell {\n return new S2Cell(S2CellId.fromFacePosLevel(face, BigInt(pos), level));\n }\n\n// Convenience methods.\n public static fromPoint(p:S2Point):S2Cell {\n return new S2Cell(S2CellId.fromPoint(p))\n }\n\n public static fromLatLng(ll:S2LatLng):S2Cell {\n return new S2Cell(S2CellId.fromPoint(ll.toPoint()));\n }\n\n\n public isLeaf():boolean {\n return this._level == S2CellId.MAX_LEVEL;\n }\n\n public getVertex(k:number):S2Point {\n return S2Point.normalize(this.getVertexRaw(k));\n }\n\n /**\n * Return the k-th vertex of the cell (k = 0,1,2,3). Vertices are returned in\n * CCW order. The points returned by GetVertexRaw are not necessarily unit\n * length.\n */\n public getVertexRaw(k:number):S2Point {\n // Vertices are returned in the order SW, SE, NE, NW.\n return S2Projections.faceUvToXyz(\n this._face, ((k >> 1) ^ (k & 1)) == 0 ? this.uMin : this.uMax, (k >> 1) == 0 ? this.vMin : this.vMax);\n }\n\n public getEdge(k:number):S2Point {\n return S2Point.normalize(this.getEdgeRaw(k));\n }\n\n public getEdgeRaw(k:number):S2Point {\n switch (k) {\n case 0:\n return S2Projections.getVNorm(this._face, this.vMin); // South\n case 1:\n return S2Projections.getUNorm(this._face, this.uMax); // East\n case 2:\n return S2Point.neg(S2Projections.getVNorm(this._face, this.vMax)); // North\n default:\n return S2Point.neg(S2Projections.getUNorm(this._face, this.uMin)); // West\n }\n }\n\n\n /**\n * Return the inward-facing normal of the great circle passing through the\n * edge from vertex k to vertex k+1 (mod 4). The normals returned by\n * GetEdgeRaw are not necessarily unit length.\n *\n * If this is not a leaf cell, set children[0..3] to the four children of\n * this cell (in traversal order) and return true. Otherwise returns false.\n * This method is equivalent to the following:\n *\n * for (pos=0, id=child_begin(); id != child_end(); id = id.next(), ++pos)\n * children[i] = S2Cell(id);\n *\n * except that it is more than two times faster.\n */\n public subdivide():S2Cell[] {\n // This function is equivalent to just iterating over the child cell ids\n // and calling the S2Cell constructor, but it is about 2.5 times faster.\n\n if (this.id.isLeaf()) {\n return null;\n }\n \n const children:S2Cell[] = new Array(4);\n for (let i = 0; i < 4; ++i) {\n children[i] = new S2Cell();\n }\n\n // Create four children with the appropriate bounds.\n let id = this.id.childBegin();\n const mid = this.getCenterUV();\n const uMid = mid.x;\n const vMid = mid.y;\n\n for (let pos = 0; pos < 4; ++pos, id = id.next()) {\n const child = children[pos];\n child._face = this.face;\n child._level = this.level + 1;\n child._orientation = this.orientation ^ S2.POS_TO_ORIENTATION[pos];\n child.cellID = id;\n // We want to split the cell in half in \"u\" and \"v\". To decide which\n // side to set equal to the midpoint value, we look at cell's (i,j)\n // position within its parent. The index for \"i\" is in bit 1 of ij.\n const ij = S2.POS_TO_IJ[this.orientation][pos];\n // The dimension 0 index (i/u) is in bit 1 of ij.\n if ((ij & 0x2) != 0) {\n child.uMin = uMid;\n child.uMax = this.uMax;\n } else {\n child.uMin = this.uMin;\n child.uMax = uMid;\n }\n // The dimension 1 index (j/v) is in bit 0 of ij.\n if ((ij & 0x1) != 0) {\n child.vMin = vMid;\n child.vMax = this.vMax;\n } else {\n child.vMin = this.vMin;\n child.vMax = vMid;\n }\n }\n return children;\n }\n\n /**\n * Return the direction vector corresponding to the center in (s,t)-space of\n * the given cell. This is the point at which the cell is divided into four\n * subcells; it is not necessarily the centroid of the cell in (u,v)-space or\n * (x,y,z)-space. The point returned by GetCenterRaw is not necessarily unit\n * length.\n */\n public getCenter():S2Point {\n return S2Point.normalize(this.getCenterRaw());\n }\n\n public getCenterRaw():S2Point {\n return this.cellID.toPointRaw();\n }\n\n /**\n * Return the center of the cell in (u,v) coordinates (see {@code\n * S2Projections}). Note that the center of the cell is defined as the point\n * at which it is recursively subdivided into four children; in general, it is\n * not at the midpoint of the (u,v) rectangle covered by the cell\n */\n public getCenterUV():R2Vector {\n return this.cellID.getCenterUV();\n }\n\n /**\n * Return the average area of cells at this level. This is accurate to within\n * a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to\n * compute.\n */\n public static averageArea(level):number {\n return S2Projections.AVG_AREA.getValue(level);\n }\n\n /**\n * Return the average area of cells at this level. This is accurate to within\n * a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to\n * compute.\n */\n public averageArea():number {\n return S2Projections.AVG_AREA.getValue(this._level);\n }\n\n /**\n * Return the approximate area of this cell. This method is accurate to within\n * 3% percent for all cell sizes and accurate to within 0.1% for cells at\n * level 5 or higher (i.e. 300km square or smaller). It is moderately cheap to\n * compute.\n */\n public approxArea():number {\n\n // All cells at the first two levels have the same area.\n if (this._level < 2) {\n return this.averageArea();\n }\n\n // First, compute the approximate area of the cell when projected\n // perpendicular to its normal. The cross product of its diagonals gives\n // the normal, and the length of the normal is twice the projected area.\n const flatArea = S2Point.crossProd(\n S2Point.sub(this.getVertex(2), this.getVertex(0)),\n S2Point.sub(this.getVertex(3), this.getVertex(1))\n ).norm() * 0.5;\n // double flatArea = 0.5 * S2Point.crossProd(\n // S2Point.sub(getVertex(2), getVertex(0)), S2Point.sub(getVertex(3), getVertex(1))).norm();\n\n // Now, compensate for the curvature of the cell surface by pretending\n // that the cell is shaped like a spherical cap. The ratio of the\n // area of a spherical cap to the area of its projected disc turns out\n // to be 2 / (1 + sqrt(1 - r*r)) where \"r\" is the radius of the disc.\n // For example, when r=0 the ratio is 1, and when r=1 the ratio is 2.\n // Here we set Pi*r*r == flat_area to find the equivalent disc.\n return flatArea *2 / (Math.sqrt((Math.min(flatArea * S2.M_1_PI, 1) * -1)+1)+1);\n }\n\n//\n// /**\n// * Return the area of this cell as accurately as possible. This method is more\n// * expensive but it is accurate to 6 digits of precision even for leaf cells\n// * (whose area is approximately 1e-18).\n// */\n public exactArea() {\n const v0 = this.getVertex(0);\n const v1 = this.getVertex(1);\n const v2 = this.getVertex(2);\n const v3 = this.getVertex(3);\n return S2.area(v0, v1, v2) + (S2.area(v0, v2, v3));\n }\n\n// //////////////////////////////////////////////////////////////////////\n// S2Region interface (see {@code S2Region} for details):\n\n\n public getCapBound():S2Cap {\n // Use the cell center in (u,v)-space as the cap axis. This vector is\n // very close to GetCenter() and faster to compute. Neither one of these\n // vectors yields the bounding cap with minimal surface area, but they\n // are both pretty close.\n //\n // It's possible to show that the two vertices that are furthest from\n // the (u,v)-origin never determine the maximum cap size (this is a\n // possible future optimization).\n const uv = this.getCenterUV();\n const center = S2Point.normalize(S2Projections.faceUvToXyz(this._face, uv.x, uv.y));\n let cap = S2Cap.fromAxisHeight(center, 0);\n for (let k = 0; k < 4; ++k) {\n cap = cap.addPoint(this.getVertex(k));\n }\n return cap;\n }\n\n// We grow the bounds slightly to make sure that the bounding rectangle\n// also contains the normalized versions of the vertices. Note that the\n// maximum result magnitude is Pi, with a floating-point exponent of 1.\n// Therefore adding or subtracting 2**-51 will always change the result.\n// private static MAX_ERROR = S2.toDecimal(1.0).dividedBy(S2.toDecimal(new Long(1).shiftLeft(51).toString()));\n private static MAX_ERROR = 1 / Number(1n << 51n);\n\n// The 4 cells around the equator extend to +/-45 degrees latitude at the\n// midpoints of their top and bottom edges. The two cells covering the\n// poles extend down to +/-35.26 degrees at their vertices.\n// adding kMaxError (as opposed to the C version) because of asin and atan2\n// roundoff errors\n private static POLE_MIN_LAT = Math.asin(Math.sqrt(1/3)) - S2Cell.MAX_ERROR;\n// 35.26 degrees\n\n\n private getPoint(i: number, j: number): S2Point {\n return S2Projections.faceUvToXyz(this._face, i == 0 ? this.uMin : this.uMax, j == 0 ? this.vMin : this.vMax);\n }\n\n public getRectBound():S2LatLngRect {\n if (this._level > 0) {\n // Except for cells at level 0, the latitude and longitude extremes are\n // attained at the vertices. Furthermore, the latitude range is\n // determined by one pair of diagonally opposite vertices and the\n // longitude range is determined by the other pair.\n //\n // We first determine which corner (i,j) of the cell has the largest\n // absolute latitude. To maximize latitude, we want to find the point in\n // the cell that has the largest absolute z-coordinate and the smallest\n // absolute x- and y-coordinates. To do this we look at each coordinate\n // (u and v), and determine whether we want to minimize or maximize that\n // coordinate based on the axis direction and the cell's (u,v) quadrant.\n const u = this.uMin + this.uMax;\n const v = this.vMin + this.vMax;\n const i = S2Projections.getUAxis(this._face).z == 0 ? (u < 0 ? 1 : 0) : (u > 0 ? 1 : 0);\n const j = S2Projections.getVAxis(this._face).z == 0 ? (v < 0 ? 1 : 0) : (v > 0 ? 1 : 0);\n\n const lat = R1Interval.fromPointPair(\n S2LatLng.latitude(this.getPoint(i, j)).radians,\n S2LatLng.latitude(this.getPoint(1 - i, 1 - j)).radians);\n \n const lng = S1Interval.fromPointPair(\n S2LatLng.longitude(this.getPoint(i, 1 - j)).radians,\n S2LatLng.longitude(this.getPoint(1 - i, j)).radians);\n\n \n // DBL_EPSILON\n return new S2LatLngRect(lat, lng)\n .expanded(S2LatLng.fromRadians(S2.DBL_EPSILON, S2.DBL_EPSILON))\n .polarClosure();\n }\n\n\n // The face centers are the +X, +Y, +Z, -X, -Y, -Z axes in that order.\n // assert (S2Projections.getNorm(face).get(face % 3) == ((face < 3) ? 1 : -1));\n switch (this._face) {\n case 0:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(-S2.M_PI_4, S2.M_PI_4));\n case 1:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(S2.M_PI_4, 3 * S2.M_PI_4));\n case 2:\n return new S2LatLngRect(\n new R1Interval(S2Cell.POLE_MIN_LAT, S2.M_PI_2), new S1Interval(-S2.M_PI, S2.M_PI));\n case 3:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(3 * S2.M_PI_4, -3 * S2.M_PI_4));\n case 4:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(-3 * S2.M_PI_4, -S2.M_PI_4));\n default:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_2, -S2Cell.POLE_MIN_LAT), new S1Interval(-S2.M_PI, S2.M_PI));\n }\n\n }\n\n\n public mayIntersectC(cell:S2Cell):boolean {\n return this.cellID.intersects(cell.cellID);\n }\n\n public contains(p:S2Point):boolean {\n // We can't just call XYZtoFaceUV, because for points that lie on the\n // boundary between two faces (i.e. u or v is +1/-1) we need to return\n // true for both adjacent cells.\n\n const uvPoint = S2Projections.faceXyzToUv(this._face, p);\n if (uvPoint == null) {\n return false;\n }\n return (uvPoint.x >= this.uMin\n && uvPoint.x <= this.uMax\n && uvPoint.y >= this.vMin\n && uvPoint.y <= this.vMax);\n }\n\n// The point 'p' does not need to be normalized.\n\n public containsC(cell:S2Cell):boolean {\n return this.cellID.contains(cell.cellID);\n }\n\n private init(id:S2CellId) {\n this.cellID = id;\n this._face = id.face\n\n const ijo = id.toIJOrientation();\n\n this._orientation = S2CellId.getOrientation(ijo);\n this._level = id.level();\n\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n const cellSize = id.getSizeIJ();\n\n this.uMin = S2Projections.ijToUV(i, cellSize);\n this.uMax = S2Projections.ijToUV(i + cellSize, cellSize);\n this.vMin = S2Projections.ijToUV(j, cellSize);\n this.vMax = S2Projections.ijToUV(j + cellSize, cellSize);\n\n // for (let d = 0; d < 2; ++d) {\n // // Compute the cell bounds in scaled (i,j) coordinates.\n // const sijLo = (ij[d].val & -cellSize) * 2 - S2Cell.MAX_CELL_SIZE;\n // const sijHi = sijLo + cellSize * 2;\n\n // const s = 1/S2Cell.MAX_CELL_SIZE;\n // this._uv[d][0] = R2Vector.singleStTOUV(s * (sijLo))\n // //S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * sijLo);\n // this._uv[d][1] = R2Vector.singleStTOUV(s * (sijHi));\n // //S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * sijHi);\n // }\n }\n\n get face(): number {\n return this._face;\n }\n\n get orientation(): number {\n return this._orientation;\n }\n\n get level(): number {\n return this._level;\n }\n\n\n// Return the latitude or longitude of the cell vertex given by (i,j),\n// where \"i\" and \"j\" are either 0 or 1.\n\n public toString():string {\n return \"[\" + this._face + \", \" + this._level + \", \" + this.orientation + \", \" + this.cellID + \"]\";\n }\n\n public toGEOJSON() {\n const coords = [this.getVertex(0),this.getVertex(1),this.getVertex(2),this.getVertex(3),this.getVertex(0)]\n .map(v => S2LatLng.fromPoint(v))\n .map(v => ([v.lngDegrees, v.latDegrees]))\n\n // const rectJSON = this.getRectBound().toGEOJSON();\n return {\n type: 'Feature',\n geometry: {\n type:'Polygon',\n coordinates: [coords]\n },\n properties: {},\n title: `Cell: ${this.id.toToken()} lvl: ${this._level}`\n };\n // rectJSON.title = `Cell: ${this.id.toToken()}`;\n // return rectJSON;\n }\n\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { u64 } from './uint64';\nimport { S2Region } from \"./S2Region\";\nimport { S2CellId } from \"./S2CellId\";\nimport { S2Cell } from \"./S2Cell\";\nimport { S1Angle } from \"./S1Angle\";\nimport { S2Projections } from \"./S2Projections\";\nimport { S2LatLngRect } from \"./S2LatLngRect\";\nimport { S2Point } from \"./S2Point\";\nimport { S2Cap } from \"./S2Cap\";\nimport { S1ChordAngle } from './S1ChordAngle';\n\n/**\n * An S2CellUnion is a region consisting of cells of various sizes.\n */\nexport class S2CellUnion implements S2Region {\n\n /** The CellIds that form the Union */\n private cellIds: S2CellId[] = [];\n\n /**\n * Populates a cell union with the given S2CellIds or 64-bit cell ids, and\n * then calls Normalize().\n *\n * v4: `cellIds` accepts `bigint[] | string[]` (was `Long[] | string[]`).\n */\n public initFromIds(cellIds: bigint[] | string[]) {\n this.initRawIds(cellIds);\n this.normalize();\n }\n\n public initFromCellIds(cellIds: S2CellId[]) {\n this.initRawCellIds(cellIds);\n this.normalize();\n }\n\n public initSwap(cellIds: S2CellId[]) {\n this.initRawSwap(cellIds);\n this.normalize();\n }\n\n public initRawCellIds(cellIds: S2CellId[]) {\n this.cellIds = cellIds;\n }\n\n public initRawIds(cellIds: bigint[] | string[]) {\n const size = cellIds.length;\n this.cellIds = [];\n for (let i = 0; i < size; i++) {\n this.cellIds.push(new S2CellId(cellIds[i] as bigint | string));\n }\n }\n\n public initRawSwap(cellIds: S2CellId[]) {\n this.cellIds = [].concat(cellIds);\n }\n\n public size(): number {\n return this.cellIds.length;\n }\n\n public cellId(i: number): S2CellId {\n return this.cellIds[i];\n }\n\n public getCellIds(): S2CellId[] {\n return this.cellIds;\n }\n\n public denormalize(minLevel: number, levelMod: number): S2CellId[] {\n const output: S2CellId[] = [];\n for (let i = 0; i < this.cellIds.length; i++) {\n const id = this.cellIds[i];\n const level = id.level();\n let newLevel = Math.max(minLevel, level);\n if (levelMod > 1) {\n newLevel += (S2CellId.MAX_LEVEL - (newLevel - minLevel)) % levelMod;\n newLevel = Math.min(S2CellId.MAX_LEVEL, newLevel);\n }\n if (newLevel === level) {\n output.push(id);\n } else {\n const end = id.childEndL(newLevel);\n for (\n let iid = id.childBeginL(newLevel);\n !iid.equals(end);\n iid = iid.next()\n ) {\n output.push(iid);\n }\n }\n }\n return output;\n }\n\n public pack() {\n throw new Error('useless');\n }\n\n containsC(cell: S2Cell): boolean {\n return this.containsCell(cell);\n }\n\n mayIntersectC(cell: S2Cell): boolean {\n return this.mayIntersectCell(cell);\n }\n\n public contains(id: S2CellId): boolean {\n let pos = S2CellId.binarySearch(this.cellIds, id.id);\n if (pos < 0) {\n pos = -pos - 1;\n }\n if (pos < this.cellIds.length && this.cellIds[pos].rangeMin().lessOrEquals(id)) {\n return true;\n }\n return pos !== 0 && this.cellIds[pos - 1].rangeMax().greaterOrEquals(id);\n }\n\n public intersects(id: S2CellId): boolean {\n let pos = S2CellId.binarySearch(this.cellIds, id.id);\n if (pos < 0) {\n pos = -pos - 1;\n }\n if (\n pos < this.cellIds.length &&\n this.cellIds[pos].rangeMin().lessOrEquals(id.rangeMax())\n ) {\n return true;\n }\n return (\n pos !== 0 && this.cellIds[pos - 1].rangeMax().greaterOrEquals(id.rangeMin())\n );\n }\n\n public containsUnion(that: S2CellUnion): boolean {\n for (let i = 0; i < that.cellIds.length; i++) {\n if (!this.contains(that.cellIds[i])) {\n return false;\n }\n }\n return true;\n }\n\n public containsCell(cell: S2Cell): boolean {\n return this.contains(cell.id);\n }\n\n public intersectsUnion(that: S2CellUnion): boolean {\n for (let i = 0; i < that.cellIds.length; i++) {\n if (this.intersects(that.cellIds[i])) {\n return true;\n }\n }\n return false;\n }\n\n public getUnion(x: S2CellUnion, y: S2CellUnion) {\n this.cellIds = [].concat(x.cellIds).concat(y.cellIds);\n this.normalize();\n }\n\n public getIntersection(x: S2CellUnion, id: S2CellId) {\n this.cellIds = [];\n if (x.contains(id)) {\n this.cellIds.push(id);\n } else {\n let pos = S2CellId.binarySearch(x.cellIds, id.rangeMin().id);\n if (pos < 0) {\n pos = -pos - 1;\n }\n const idmax = id.rangeMax();\n const size = x.cellIds.length;\n while (pos < size && x.cellIds[pos].lessOrEquals(idmax)) {\n this.cellIds.push(x.cellIds[pos++]);\n }\n }\n }\n\n public getIntersectionUU(x: S2CellUnion, y: S2CellUnion) {\n this.cellIds = [];\n\n let i = 0;\n let j = 0;\n\n while (i < x.cellIds.length && j < y.cellIds.length) {\n const imin = x.cellId(i).rangeMin();\n const jmin = y.cellId(j).rangeMin();\n\n if (imin.greaterThan(jmin)) {\n if (x.cellId(i).lessOrEquals(y.cellId(j).rangeMax())) {\n this.cellIds.push(x.cellId(i++));\n } else {\n j = S2CellId.indexedBinarySearch(y.cellIds, imin, j + 1);\n if (x.cellId(i).lessOrEquals(y.cellId(j - 1).rangeMax())) {\n --j;\n }\n }\n } else if (jmin.greaterThan(imin)) {\n if (y.cellId(j).lessOrEquals(x.cellId(i).rangeMax())) {\n this.cellIds.push(y.cellId(j++));\n } else {\n i = S2CellId.indexedBinarySearch(x.cellIds, jmin, i + 1);\n if (y.cellId(j).lessOrEquals(x.cellId(i - 1).rangeMax())) {\n --i;\n }\n }\n } else {\n if (x.cellId(i).lessThan(y.cellId(j))) {\n this.cellIds.push(x.cellId(i++));\n } else {\n this.cellIds.push(y.cellId(j++));\n }\n }\n }\n }\n\n public expand(level: number) {\n let output: S2CellId[] = [];\n const levelLsb = S2CellId.lowestOnBitForLevel(level); // bigint\n\n let i = this.size() - 1;\n do {\n let id = this.cellId(i);\n if (id.lowestOnBit() < levelLsb) {\n id = id.parentL(level);\n while (i > 0 && id.contains(this.cellId(i - 1))) {\n --i;\n }\n }\n output.push(id);\n output = output.concat(id.getAllNeighbors(level));\n } while (--i >= 0);\n this.initSwap(output);\n }\n\n public expandA(minRadius: S1Angle, maxLevelDiff: number) {\n let minLevel = S2CellId.MAX_LEVEL;\n for (let i = 0; i < this.cellIds.length; i++) {\n minLevel = Math.min(minLevel, this.cellId(i).level());\n }\n const radiusLevel = S2Projections.MIN_WIDTH.getMaxLevel(minRadius.radians);\n if (\n radiusLevel === 0 &&\n minRadius.radians > S2Projections.MIN_WIDTH.getValue(0)\n ) {\n this.expand(0);\n }\n this.expand(Math.min(minLevel + maxLevelDiff, radiusLevel));\n }\n\n public getCapBound(): S2Cap {\n if (this.cellIds.length === 0) {\n return S2Cap.empty();\n }\n let centroid = new S2Point(0, 0, 0);\n this.cellIds.forEach(id => {\n const area = S2Cell.averageArea(id.level());\n centroid = S2Point.add(centroid, S2Point.mul(id.toPoint(), area));\n });\n\n if (centroid.equals(S2Point.ORIGIN)) {\n centroid = S2Point.X_POS;\n } else {\n centroid = S2Point.normalize(centroid);\n }\n\n let cap = S2Cap.fromAxisChord(centroid, S1ChordAngle.ZERO);\n this.cellIds.forEach(id => {\n cap = cap.addCap(new S2Cell(id).getCapBound());\n });\n return cap;\n }\n\n public getRectBound(): S2LatLngRect {\n let bound = S2LatLngRect.empty();\n this.cellIds.forEach(id => {\n bound = bound.union(new S2Cell(id).getRectBound());\n });\n return bound;\n }\n\n public mayIntersectCell(cell: S2Cell): boolean {\n return this.intersects(cell.id);\n }\n\n public containsPoint(p: S2Point): boolean {\n return this.contains(S2CellId.fromPoint(p));\n }\n\n /**\n * The number of leaf cells covered by the union.\n *\n * v4: return type changed from Long to bigint.\n */\n public leafCellsCovered(): bigint {\n let numLeaves = 0n;\n this.cellIds.forEach((id: S2CellId) => {\n const invertedLevel = S2CellId.MAX_LEVEL - id.level();\n numLeaves += 1n << BigInt(invertedLevel << 1);\n });\n return numLeaves;\n }\n\n /**\n * Approximate area by summing the average area of each contained cell.\n *\n * v4: uses Number(bigint) instead of Long.toNumber().\n */\n public averageBasedArea(): number {\n return (\n Number(this.leafCellsCovered()) *\n S2Projections.AVG_AREA.getValue(S2CellId.MAX_LEVEL)\n );\n }\n\n public approxArea(): number {\n let area = 0;\n this.cellIds.forEach(id => {\n area += new S2Cell(id).approxArea();\n });\n return area;\n }\n\n public exactArea(): number {\n let area = 0;\n this.cellIds.forEach(id => {\n area += new S2Cell(id).exactArea();\n });\n return area;\n }\n\n public normalize(): boolean {\n const output: S2CellId[] = [];\n\n this.cellIds.sort((a, b) => a.compareTo(b));\n\n this.cellIds.forEach(id => {\n let size = output.length;\n if (output.length !== 0 && output[size - 1].contains(id)) {\n return;\n }\n\n while (\n output.length !== 0 &&\n id.contains(output[output.length - 1])\n ) {\n output.splice(output.length - 1, 1);\n }\n\n while (output.length >= 3) {\n size = output.length;\n // XOR of the four cell IDs must be zero for them to be siblings.\n if (\n (output[size - 3].id ^\n output[size - 2].id ^\n output[size - 1].id) !==\n id.id\n ) {\n break;\n }\n\n // Build a mask that blocks the two bits encoding the child position.\n let mask: bigint = id.lowestOnBit() << 1n;\n mask = u64(~(mask + (mask << 1n)));\n\n const idMasked = id.id & mask;\n if (\n (output[size - 3].id & mask) !== idMasked ||\n (output[size - 2].id & mask) !== idMasked ||\n (output[size - 1].id & mask) !== idMasked ||\n id.isFace()\n ) {\n break;\n }\n\n // Replace four children by their parent cell.\n output.splice(size - 3);\n id = id.parent();\n }\n output.push(id);\n });\n\n if (output.length < this.size()) {\n this.initRawSwap(output);\n return true;\n }\n return false;\n }\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {S2Cell} from \"./S2Cell\";\nimport {S2Region} from \"./S2Region\";\nimport {S2CellId} from \"./S2CellId\";\nimport {S2CellUnion} from \"./S2CellUnion\";\nimport {S2Projections} from \"./S2Projections\";\nimport { S2Point } from \"./S2Point\";\n/**\n * An S2RegionCoverer is a class that allows arbitrary regions to be\n * approximated as unions of cells (S2CellUnion). This is useful for\n * implementing various sorts of search and precomputation operations.\n *\n * Typical usage: {@code S2RegionCoverer coverer; coverer.setMaxCells(5); S2Cap\n * cap = S2Cap.fromAxisAngle(...); S2CellUnion covering;\n * coverer.getCovering(cap, covering); * }\n *\n * This yields a cell union of at most 5 cells that is guaranteed to cover the\n * given cap (a disc-shaped region on the sphere).\n *\n * The approximation algorithm is not optimal but does a pretty good job in\n * practice. The output does not always use the maximum number of cells allowed,\n * both because this would not always yield a better approximation, and because\n * max_cells() is a limit on how much work is done exploring the possible\n * covering as well as a limit on the final output size.\n *\n * One can also generate interior coverings, which are sets of cells which are\n * entirely contained within a region. Interior coverings can be empty, even for\n * non-empty regions, if there are no cells that satisfy the provided\n * constraints and are contained by the region. Note that for performance\n * reasons, it is wise to specify a max_level when computing interior coverings\n * - otherwise for regions with small or zero area, the algorithm may spend a\n * lot of time subdividing cells all the way to leaf level to try to find\n * contained cells.\n *\n * This class is thread-unsafe. Simultaneous calls to any of the getCovering\n * methods will conflict and produce unpredictable results.\n *\n */\nexport class S2RegionCoverer {\n\n /**\n * By default, the covering uses at most 8 cells at any level. This gives a\n * reasonable tradeoff between the number of cells used and the accuracy of\n * the approximation (see table below).\n */\n public static DEFAULT_MAX_CELLS = 8;\n\n private static FACE_CELLS:S2Cell[] = [0, 1, 2, 3, 4, 5].map(face => S2Cell.fromFace(face));\n\n\n private minLevel:number;\n private maxLevel:number;\n private levelMod:number;\n private maxCells:number;\n\n// True if we're computing an interior covering.\n private interiorCovering:boolean;\n\n// Counter of number of candidates created, for performance evaluation.\n private candidatesCreatedCounter:number;\n\n /**\n * We save a temporary copy of the pointer passed to GetCovering() in order to\n * avoid passing this parameter around internally. It is only used (and only\n * valid) for the duration of a single GetCovering() call.\n */\n protected region:S2Region;\n\n /**\n * A temporary variable used by GetCovering() that holds the cell ids that\n * have been added to the covering so far.\n */\n protected result:S2CellId[];\n\n\n /**\n * We keep the candidates in a priority queue. We specify a vector to hold the\n * queue entries since for some reason priority_queue<> uses a deque by\n * default.\n */\n private candidateQueue:PriorityQueue<QueueEntry>;\n\n /**\n * Default constructor, sets all fields to default values.\n */\n public constructor() {\n this.minLevel = 0;\n this.maxLevel = S2CellId.MAX_LEVEL;\n this.levelMod = 1;\n this.maxCells = S2RegionCoverer.DEFAULT_MAX_CELLS;\n this.region = null;\n this.result = [];\n this.candidateQueue = new PriorityQueue<QueueEntry>();\n }\n\n// Set the minimum and maximum cell level to be used. The default is to use\n// all cell levels. Requires: max_level() >= min_level().\n//\n// To find the cell level corresponding to a given physical distance, use\n// the S2Cell metrics defined in s2.h. For example, to find the cell\n// level that corresponds to an average edge length of 10km, use:\n//\n// int level = S2::kAvgEdge.GetClosestLevel(\n// geostore::S2Earth::KmToRadians(length_km));\n//\n// Note: min_level() takes priority over max_cells(), i.e. cells below the\n// given level will never be used even if this causes a large number of\n// cells to be returned.\n\n /**\n * Sets the minimum level to be used.\n */\n public setMinLevel(minLevel:number):S2RegionCoverer {\n // assert (minLevel >= 0 && minLevel <= S2CellId.MAX_LEVEL);\n this.minLevel = Math.max(0, Math.min(S2CellId.MAX_LEVEL, minLevel));\n return this;\n }\n\n /**\n * Sets the maximum level to be used.\n */\n public setMaxLevel(maxLevel:number):S2RegionCoverer {\n // assert (maxLevel >= 0 && maxLevel <= S2CellId.MAX_LEVEL);\n this.maxLevel = Math.max(0, Math.min(S2CellId.MAX_LEVEL, maxLevel));\n return this;\n }\n\n /**\n * If specified, then only cells where (level - min_level) is a multiple of\n * \"level_mod\" will be used (default 1). This effectively allows the branching\n * factor of the S2CellId hierarchy to be increased. Currently the only\n * parameter values allowed are 1, 2, or 3, corresponding to branching factors\n * of 4, 16, and 64 respectively.\n */\n public setLevelMod(levelMod:number):S2RegionCoverer {\n // assert (levelMod >= 1 && levelMod <= 3);\n this.levelMod = Math.max(1, Math.min(3, levelMod));\n return this;\n }\n\n /**\n * Sets the maximum desired number of cells in the approximation (defaults to\n * kDefaultMaxCells). Note the following:\n *\n * <ul>\n * <li>For any setting of max_cells(), up to 6 cells may be returned if that\n * is the minimum number of cells required (e.g. if the region intersects all\n * six face cells). Up to 3 cells may be returned even for very tiny convex\n * regions if they happen to be located at the intersection of three cube\n * faces.\n *\n * <li>For any setting of max_cells(), an arbitrary number of cells may be\n * returned if min_level() is too high for the region being approximated.\n *\n * <li>If max_cells() is less than 4, the area of the covering may be\n * arbitrarily large compared to the area of the original region even if the\n * region is convex (e.g. an S2Cap or S2LatLngRect).\n * </ul>\n *\n * Accuracy is measured by dividing the area of the covering by the area of\n * the original region. The following table shows the median and worst case\n * values for this area ratio on a test case consisting of 100,000 spherical\n * caps of random size (generated using s2regioncoverer_unittest):\n *\n * <pre>\n * max_cells: 3 4 5 6 8 12 20 100 1000\n * median ratio: 5.33 3.32 2.73 2.34 1.98 1.66 1.42 1.11 1.01\n * worst case: 215518 14.41 9.72 5.26 3.91 2.75 1.92 1.20 1.02\n * </pre>\n */\n public setMaxCells(maxCells:number):S2RegionCoverer {\n this.maxCells = maxCells;\n return this;\n }\n\n public getMinLevel(): number {\n return this.minLevel;\n }\n\n public getMaxLevel(): number {\n return this.maxLevel;\n }\n\n public getMaxCells(): number {\n return this.maxCells;\n }\n\n public getLevelMod(): number {\n return this.levelMod;\n }\n\n /**\n * Computes a list of cell ids that covers the given region and satisfies the\n * various restrictions specified above.\n *\n * @param region The region to cover\n * @param covering The list filled in by this method\n */\n public getCoveringCells(region:S2Region):S2CellId[] {\n // Rather than just returning the raw list of cell ids generated by\n // GetCoveringInternal(), we construct a cell union and then denormalize it.\n // This has the effect of replacing four child cells with their parent\n // whenever this does not violate the covering parameters specified\n // (min_level, level_mod, etc). This strategy significantly reduces the\n // number of cells returned in many cases, and it is cheap compared to\n // computing the covering in the first place.\n const tmp = this.getCoveringUnion(region);\n return tmp.denormalize(this.minLevel, this.levelMod);\n }\n\n /**\n * Computes a list of cell ids that is contained within the given region and\n * satisfies the various restrictions specified above.\n *\n * @param region The region to fill\n * @param interior The list filled in by this method\n */\n public getInteriorCoveringCells(region:S2Region):S2CellId[] {\n const tmp = this.getInteriorCoveringUnion(region);\n return tmp.denormalize(this.minLevel, this.levelMod);\n }\n\n /**\n * Return a normalized cell union that covers the given region and satisfies\n * the restrictions *EXCEPT* for min_level() and level_mod(). These criteria\n * cannot be satisfied using a cell union because cell unions are\n * automatically normalized by replacing four child cells with their parent\n * whenever possible. (Note that the list of cell ids passed to the cell union\n * constructor does in fact satisfy all the given restrictions.)\n */\n public getCoveringUnion(region:S2Region, covering:S2CellUnion = new S2CellUnion()):S2CellUnion {\n this.interiorCovering = false;\n this.getCoveringInternal(region);\n covering.initSwap(this.result);\n this.result = [];\n return covering;\n }\n\n /**\n * Return a normalized cell union that is contained within the given region\n * and satisfies the restrictions *EXCEPT* for min_level() and level_mod().\n */\n public getInteriorCoveringUnion(region:S2Region, covering:S2CellUnion=new S2CellUnion()):S2CellUnion {\n this.interiorCovering = true;\n this.getCoveringInternal(region);\n covering.initSwap(this.result);\n this.result = [];\n return covering;\n }\n\n /**\n * Given a connected region and a starting point, return a set of cells at the given level that\n * cover the region.\n */\n public static getSimpleCovering(region: S2Region, start: S2Point, level: number): S2CellId[] {\n return this.floodFill(region, S2CellId.fromPoint(start).parentL(level));\n }\n\n /**\n * If the cell intersects the given region, return a new candidate with no\n * children, otherwise return null. Also marks the candidate as \"terminal\" if\n * it should not be expanded further.\n */\n private newCandidate(cell:S2Cell):Candidate {\n if (!this.region.mayIntersectC(cell)) {\n return null;\n }\n\n let isTerminal = false;\n if (cell.level >= this.minLevel) {\n if (this.interiorCovering) {\n if (this.region.containsC(cell)) {\n isTerminal = true;\n } else if (cell.level + this.levelMod > this.maxLevel) {\n return null;\n }\n } else {\n if (cell.level + this.levelMod > this.maxLevel || this.region.containsC(cell)) {\n isTerminal = true;\n }\n }\n }\n\n const candidate = new Candidate();\n candidate.cell = cell;\n candidate.isTerminal = isTerminal;\n candidate.numChildren = 0;\n if (!isTerminal) {\n candidate.children = [];\n const numOfChildren = 1 << this.maxChildrenShift();\n for (let i = 0; i < numOfChildren; i++) {\n candidate.children.push(new Candidate())\n }\n }\n this.candidatesCreatedCounter++;\n return candidate;\n }\n\n /** Return the log base 2 of the maximum number of children of a candidate. */\n private maxChildrenShift():number {\n return 2 * this.levelMod;\n }\n\n /**\n * Process a candidate by either adding it to the result list or expanding its\n * children and inserting it into the priority queue. Passing an argument of\n * NULL does nothing.\n */\n private addCandidate(candidate:Candidate) {\n if (candidate == null) {\n return;\n }\n\n if (candidate.isTerminal) {\n this.result.push(candidate.cell.id);\n return;\n }\n // assert (candidate.numChildren == 0);\n\n // Expand one level at a time until we hit min_level_ to ensure that\n // we don't skip over it.\n const numLevels = (candidate.cell.level < this.minLevel) ? 1 : this.levelMod;\n\n const numTerminals = this.expandChildren(candidate, candidate.cell, numLevels);\n\n if (candidate.numChildren == 0) {\n // Do nothing\n } else if (!this.interiorCovering && numTerminals == 1 << this.maxChildrenShift()\n && candidate.cell.level >= this.minLevel) {\n // Optimization: add the parent cell rather than all of its children.\n // We can't do this for interior coverings, since the children just\n // intersect the region, but may not be contained by it - we need to\n // subdivide them further.\n candidate.isTerminal = true;\n this.addCandidate(candidate);\n\n } else {\n // We negate the priority so that smaller absolute priorities are returned\n // first. The heuristic is designed to refine the largest cells first,\n // since those are where we have the largest potential gain. Among cells\n // at the same level, we prefer the cells with the smallest number of\n // intersecting children. Finally, we prefer cells that have the smallest\n // number of children that cannot be refined any further.\n const priority = -((((candidate.cell.level << this.maxChildrenShift()) + candidate.numChildren)\n << this.maxChildrenShift()) + numTerminals);\n\n this.candidateQueue.add(new QueueEntry(priority, candidate));\n // logger.info(\"Push: \" + candidate.cell.id() + \" (\" + priority + \") \");\n }\n }\n\n /**\n * Populate the children of \"candidate\" by expanding the given number of\n * levels from the given cell. Returns the number of children that were marked\n * \"terminal\".\n */\n private expandChildren(candidate:Candidate, cell:S2Cell, numLevels:number):number {\n numLevels--;\n\n const childCells = cell.subdivide();\n\n let numTerminals = 0;\n for (let i = 0; i < 4; ++i) {\n if (numLevels > 0) {\n if (this.region.mayIntersectC(childCells[i])) {\n numTerminals += this.expandChildren(candidate, childCells[i], numLevels);\n }\n continue;\n }\n const child = this.newCandidate(childCells[i]);\n\n if (child != null) {\n candidate.children[candidate.numChildren++] = child;\n if (child.isTerminal) {\n ++numTerminals;\n }\n }\n }\n\n\n return numTerminals;\n }\n\n /** Computes a set of initial candidates that cover the given region. */\n private getInitialCandidates() {\n // Optimization: if at least 4 cells are desired (the normal case),\n // start with a 4-cell covering of the region's bounding cap. This\n // lets us skip quite a few levels of refinement when the region to\n // be covered is relatively small.\n if (this.maxCells >= 4) {\n // Find the maximum level such that the bounding cap contains at most one\n // cell vertex at that level.\n const cap = this.region.getCapBound();\n let level =\n Math.min(\n S2Projections.MIN_WIDTH.getMaxLevel(2 * cap.angle().radians),\n Math.min(this.maxLevel, S2CellId.MAX_LEVEL - 1));\n if (this.levelMod > 1 && level > this.minLevel) {\n level -= (level - this.minLevel) % this.levelMod;\n }\n\n // We don't bother trying to optimize the level == 0 case, since more than\n // four face cells may be required.\n if (level > 0) {\n // Find the leaf cell containing the cap axis, and determine which\n // subcell of the parent cell contains it.\n \n const id = S2CellId.fromPoint(cap.axis);\n const base = id.getVertexNeighbors(level);\n for (let i = 0; i < base.length; ++i) {\n this.addCandidate(this.newCandidate(new S2Cell(base[i])));\n }\n return;\n }\n }\n // Default: start with all six cube faces.\n for (let face = 0; face < 6; ++face) {\n this.addCandidate(this.newCandidate(S2RegionCoverer.FACE_CELLS[face]));\n }\n }\n\n /** Generates a covering and stores it in result. */\n private getCoveringInternal(region:S2Region) {\n // Strategy: Start with the 6 faces of the cube. Discard any\n // that do not intersect the shape. Then repeatedly choose the\n // largest cell that intersects the shape and subdivide it.\n //\n // result contains the cells that will be part of the output, while the\n // priority queue contains cells that we may still subdivide further. Cells\n // that are entirely contained within the region are immediately added to\n // the output, while cells that do not intersect the region are immediately\n // discarded.\n // Therefore pq_ only contains cells that partially intersect the region.\n // Candidates are prioritized first according to cell size (larger cells\n // first), then by the number of intersecting children they have (fewest\n // children first), and then by the number of fully contained children\n // (fewest children first).\n\n if (!(this.candidateQueue.size() == 0 && this.result.length == 0)) {\n throw new Error('preconditions are not satisfied')\n }\n // Preconditions.checkState(this.candidateQueue.isEmpty() && this.result.isEmpty());\n\n this.region = region;\n this.candidatesCreatedCounter = 0;\n\n this.getInitialCandidates();\n\n while (this.candidateQueue.size() !== 0 && (!this.interiorCovering || this.result.length < this.maxCells)) {\n const candidate = this.candidateQueue.poll().candidate;\n if (this.interiorCovering || candidate.cell.level < this.minLevel || candidate.numChildren == 1\n || this.result.length + this.candidateQueue.size() + candidate.numChildren <= this.maxCells) {\n // Expand this candidate into its children.\n for (let i = 0; i < candidate.numChildren; ++i) {\n if (!this.interiorCovering || this.result.length < this.maxCells) {\n this.addCandidate(candidate.children[i]);\n }\n }\n } else {\n candidate.isTerminal = true;\n this.addCandidate(candidate);\n }\n }\n\n this.candidateQueue.clear();\n this.region = null;\n }\n\n /**\n * Given a region and a starting cell, return the set of all the edge-connected cells at the same\n * level that intersect \"region\". The output cells are returned in arbitrary order.\n */\n private static floodFill(region: S2Region, start: S2CellId): S2CellId[] {\n const all = new Set<string>();\n const frontier: S2CellId[] = [];\n const output: S2CellId[] = [];\n\n all.add(start.toToken());\n frontier.push(start);\n while (frontier.length !== 0) {\n const id = frontier.pop();\n if (!region.mayIntersectC(new S2Cell(id))) {\n continue;\n }\n output.push(id);\n\n const neighbors: S2CellId[] = id.getEdgeNeighbors();\n for (let edge = 0; edge < 4; ++edge) {\n const nbr = neighbors[edge];\n if (!all.has(nbr.toToken())) {\n frontier.push(nbr);\n all.add(nbr.toToken());\n }\n }\n }\n\n return output;\n }\n}\n\n\nclass Candidate {\n public cell:S2Cell;\n public isTerminal:boolean; // Cell should not be expanded further.\n public numChildren:number; // Number of children that intersect the region.\n public children:Candidate[]; // Actual size may be 0, 4, 16, or 64\n // elements.\n\n public toString() {\n return `isTerminal: ${this.isTerminal} - Cell: ${this.cell.toString()}`;\n }\n}\n\ninterface Comparable<T> {\n compare(other:T):number;\n}\nclass PriorityQueue<T extends Comparable<T>> {\n public items:T[];\n\n constructor() {\n this.clear();\n }\n\n add(item:T) {\n this.items.push(item);\n this.items.sort((a, b) => a.compare(b));\n }\n\n clear() {\n this.items = [];\n }\n\n size() {\n return this.items.length;\n }\n\n poll():T {\n return this.items.splice(0, 1)[0];\n }\n}\n\nclass QueueEntry implements Comparable<QueueEntry> {\n compare(other:QueueEntry):number {\n return this.id < other.id ? 1 : (this.id > other.id ? -1 : 0);\n }\n\n public constructor(public id:number, public candidate:Candidate) {\n\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,WAAN,MAAM,UAAS;AAAA,EAGpB,YAAY,IAAW,IAAW;AAChC,SAAK,KAAK;AACV,SAAK,KAAK;AAAA,EACZ;AAAA,EAEA,IAAI,IAAI;AACN,WAAO,KAAK;AAAA,EACd;AAAA,EAEA,IAAI,IAAI;AACN,WAAO,KAAK;AAAA,EACd;AAAA,EAGO,IAAI,OAAc;AACvB,QAAI,QAAQ,KAAK,QAAQ,GAAG;AAC1B,YAAM,IAAI,MAAM,6BAA6B,KAAK,EAAE;AAAA,IACtD;AACA,WAAO,SAAS,IAAI,KAAK,KAAK,KAAK;AAAA,EACrC;AAAA,EAEA,OAAO,c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C1B,CAAC;AACL,WAAO;AAAA,EACT;AACF;","names":[]}
|
|
1
|
+
{"version":3,"sources":["../src/export.ts","../src/R2Vector.ts","../src/S2Point.ts","../src/Platform.ts","../src/S2Metric.ts","../src/S2.ts","../src/S1Angle.ts","../src/Interval.ts","../src/S1Interval.ts","../src/R1Interval.ts","../src/S2LatLng.ts","../src/S2EdgeUtil.ts","../src/S2LatLngRect.ts","../src/utils/preconditions.ts","../src/S1ChordAngle.ts","../src/S2Cap.ts","../src/uint64.ts","../src/S2Projections.ts","../src/S2CellId.ts","../src/compat.ts","../src/MutableInteger.ts","../src/S2Cell.ts","../src/S2CellUnion.ts","../src/S2RegionCoverer.ts"],"sourcesContent":["import {S2Region} from \"./S2Region\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {S2Cap} from \"./S2Cap\";\nimport {S2} from \"./S2\";\nimport {S2CellId} from \"./S2CellId\";\nimport {S2Projections} from \"./S2Projections\";\nexport * from './uint64';\nexport * from './compat';\nexport * from './Interval';\nexport * from './MutableInteger';\nexport * from './R1Interval';\nexport * from './R2Vector';\nexport * from './S1Angle';\nexport * from './S1Interval';\nexport * from './S2';\nexport * from './S2Cap';\nexport * from './S2Cell';\nexport * from './S2CellId';\nexport * from './S2CellUnion';\n// export * from './S2EdgeIndex';\n// export * from './S2EdgeUtil';\nexport * from './S2LatLng';\nexport * from './S2LatLngRect';\n// export * from './S2Loop';\nexport * from './S2Point';\nexport * from './S2Projections';\nexport * from './S2Region';\nexport * from './S2RegionCoverer';\n\nexport class Utils {\n\n /**\n * Atomically updates the maximum cell level across all S2 classes.\n *\n * This sets the `MAX_LEVEL` field on `S2`, `S2CellId`, and `S2Projections`\n * in one call, keeping them in sync.\n *\n * **What changes:**\n * - `S2Cell.MAX_CELL_SIZE` (derived via getter from `S2CellId.MAX_LEVEL`)\n * - `S2Projections.MAX_SITI` (derived via getter)\n * - `S2CellId.getSizeIJ()` / `S2CellId.getSizeST()` size calculations\n * - Default max-level caps in `S2RegionCoverer` and `S2Metric`\n * - `S2CellId.isLeaf()` / `level()` detection of the leaf level\n *\n * **What does NOT change:**\n * - `S2CellId.POS_BITS` (always 61) — the 64-bit S2 cell ID bit layout is\n * a fixed canonical format; changing it breaks encoding/decoding.\n * - `S2CellId.MAX_SIZE` (always 2^30) — the Hilbert-curve grid resolution.\n * - `S2CellId.WRAP_OFFSET` — derived from the fixed `POS_BITS`.\n *\n * For shorter cell tokens, use `parentL(desiredLevel)` or set\n * `S2RegionCoverer.maxLevel`; `toToken()` naturally produces compact hex\n * strings for lower-level cells (e.g. level 10 → 6 hex chars).\n *\n * @param level — integer in [1, 30]\n */\n static setMaxLevel(level: number): void {\n if (!Number.isInteger(level) || level < 1 || level > 30) {\n throw new RangeError(\n `MAX_LEVEL must be an integer in [1, 30], got ${level}`\n );\n }\n S2.MAX_LEVEL = level;\n S2CellId.MAX_LEVEL = level;\n S2Projections.MAX_LEVEL = level;\n }\n\n /**\n * Calculates a region covering a circle\n * NOTE: The current implementation uses S2Cap while S2Loop would be better (S2Loop is not implemented yet)\n * @param center\n * @param radiusInKM\n * @param points the number of points to calculate. The higher the better precision\n * @returns {S2Region}\n */\n static calcRegionFromCenterRadius(center:S2LatLng, radiusInKM:number, points=16):S2Region {\n const pointsAtDistance = center.pointsAtDistance(radiusInKM, points);\n let s2Cap = S2Cap.empty().addPoint(center.toPoint());\n // It would be probably enough to add one of the points/2 pair of opposite points in the circle such\n // as (0, points/2). but since this is just a temporary solution lets stick with this as it\n // will come handy when implementing S2Loop.\n pointsAtDistance\n .map(p => p.toPoint())\n .forEach(p => {\n s2Cap = s2Cap.addPoint(p);\n });\n return s2Cap;\n }\n}\n","import {S2Point} from \"./S2Point\";\n/**\n * R2Vector represents a vector in the two-dimensional space. It defines the\n * basic geometrical operations for 2D vectors, e.g. cross product, addition,\n * norm, comparison etc.\n *\n */\nexport class R2Vector {\n private _x: number;\n private _y: number;\n constructor(_x:number, _y:number) {\n this._x = _x;\n this._y = _y;\n }\n\n get x() {\n return this._x;\n }\n\n get y() {\n return this._y;\n }\n\n\n public get(index:number) {\n if (index < 0 || index > 1) {\n throw new Error(`Index out fo bounds error ${index}`);\n }\n return index == 0 ? this._x : this._y;\n }\n\n static fromPointFace(p:S2Point, face:number): R2Vector {\n return p.toR2Vector(face);\n }\n public static add(p1:R2Vector, p2:R2Vector):R2Vector {\n return new R2Vector(p1._x + (p2._x), p1._y + (p2._y));\n }\n\n public static mul(p:R2Vector, m:number):R2Vector {\n return new R2Vector(m * (p._x), m * (p._y));\n }\n\n public norm2() {\n return this.x * this.x + this.y * this.y;\n }\n\n public static dotProd(p1:R2Vector, p2:R2Vector) {\n return p1.x * (p2.x) + (p1.y * (p2.y));\n }\n\n public dotProd(that:R2Vector) {\n return R2Vector.dotProd(this, that);\n }\n\n public crossProd(that:R2Vector) {\n return this.x*(that.y) - (this.y*(that.x));\n }\n\n public lessThan(vb:R2Vector):boolean {\n if (this.x < (vb.x)) {\n return true;\n }\n if (vb.x < (this.x)) {\n return false;\n }\n if (this.y < (vb.y)) {\n return true;\n }\n return false;\n }\n\n//\n// @Override\n// public boolean equals(Object that) {\n// if (!(that instanceof R2Vector)) {\n// return false;\n// }\n// R2Vector thatPoint = (R2Vector) that;\n// return this.x == thatPoint.x && this.y == thatPoint.y;\n// }\n\n// /**\n// * Calcualates hashcode based on stored coordinates. Since we want +0.0 and\n// * -0.0 to be treated the same, we ignore the sign of the coordinates.\n// */\n// @Override\n// public int hashCode() {\n// long value = 17;\n// value += 37 * value + Double.doubleToLongBits(Math.abs(x));\n// value += 37 * value + Double.doubleToLongBits(Math.abs(y));\n// return (int) (value ^ (value >>> 32));\n// }\n//\n\n public static fromSTVector(stVector: R2Vector):R2Vector{\n return new R2Vector(\n R2Vector.singleStTOUV(stVector.x),\n R2Vector.singleStTOUV(stVector.y)\n );\n\n }\n\n // from S2Projections.stToUV (QUADRATIC)\n public static singleStTOUV(s:number): number {\n if (s >= 0.5) {\n return (1 / 3) * (4 * s * s - 1);\n } else {\n return (1 / 3) * (1 - 4 * (1 - s) * (1 - s));\n }\n\n }\n public static singleUVToST(u:number): number {\n if (u >= 0) {\n return 0.5 * Math.sqrt(1 + 3 * u);\n } else {\n return 1 - 0.5 * Math.sqrt(1 - 3 * u);\n }\n }\n\n /**\n * To be used only if this vector is representing uv.\n * @param face\n * @returns {S2Point}\n */\n public toPoint(face:number) {\n switch (face) {\n case 0:\n return new S2Point(1, this.x, this.y);\n case 1:\n return new S2Point(this.x * -1 , 1, this.y);\n case 2:\n return new S2Point(this.x * -1, this.y * -1, 1);\n case 3:\n return new S2Point(-1, this.y * -1, this.x * -1);\n case 4:\n return new S2Point(this.y, -1, this.x * -1);\n default:\n return new S2Point(this.y, this.x, -1);\n }\n }\n\n public toSt(which: number) {\n return which == 0?R2Vector.singleUVToST(this.x): R2Vector.singleUVToST(this.y);\n }\n public toString():string {\n return \"(\" + this.x.toString() + \", \" + this.y.toString() + \")\";\n }\n\n}\n","/*\n * Copyright 2006 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {R2Vector} from \"./R2Vector\";\n\n///re\n/**\n * An S2Point represents a point on the unit sphere as a 3D vector. Usually\n * points are normalized to be unit length, but some methods do not require\n * this.\n *\n */\nexport class S2Point {\n\n /** Origin of the coordinate system, [0,0,0]. */\n public static ORIGIN = new S2Point(0, 0, 0);\n\n /** Direction of the x-axis. */\n public static X_POS = new S2Point(1, 0, 0);\n\n /** Opposite direction of the x-axis. */\n public static X_NEG = new S2Point(-1, 0, 0);\n\n /** Direction of the y-axis. */\n public static Y_POS = new S2Point(0, 1, 0);\n\n /** Opposite direction of the y-axis. */\n public static Y_NEG = new S2Point(0, -1, 0);\n\n /** Direction of the z-axis. */\n public static Z_POS = new S2Point(0, 0, 1);\n\n /** Opposite direction of the z-axis. */\n public static Z_NEG = new S2Point(0, 0, -1);\n\n public x: number;\n public y: number;\n public z: number;\n constructor(x:number, y:number, z:number) {\n this.x = (x);\n this.y = (y);\n this.z = (z);\n // this.y = typeof(y) === 'number'?new Decimal(y):y as Decimal;\n // this.z = typeof(z) === 'number'?new Decimal(z):z as Decimal;\n }\n\n static minus(p1:S2Point, p2:S2Point) {\n return S2Point.sub(p1, p2);\n }\n\n static neg(p: S2Point) {\n return new S2Point(p.x * -1, p.y*-1, p.z*-1);\n }\n\n public norm2() {\n return Math.pow(this.x, 2) + Math.pow(this.y, 2) + Math.pow(this.z, 2);\n }\n\n public norm() {\n return Math.sqrt(this.norm2());\n }\n\n\n static crossProd(p1:S2Point, p2:S2Point):S2Point {\n return new S2Point(\n p1.y* (p2.z) - (p1.z* (p2.y)),\n p1.z* (p2.x) - (p1.x* (p2.z)),\n // p1.z * p2.x - p1.x * p2.z,\n p1.x* (p2.y) - (p1.y* (p2.x))\n // p1.x * p2.y - p1.y * p2.x\n );\n }\n\n static add(p1:S2Point, p2:S2Point):S2Point {\n return new S2Point(p1.x + p2.x, p1.y + p2.y, p1.z + p2.z);\n }\n\n static sub(p1:S2Point, p2:S2Point):S2Point {\n return new S2Point(p1.x - p2.x, p1.y - p2.y, p1.z - p2.z);\n }\n\n public dotProd(that:S2Point) {\n return this.x*(that.x) +(this.y * that.y) + (this.z* (that.z));\n }\n\n public static mul(p, m: number):S2Point {\n return new S2Point(m* (p.x), m* (p.y) , m* (p.z));\n }\n\n public static div(p:S2Point, m:number):S2Point {\n return new S2Point(p.x / (m), p.y / (m), p.z / (m));\n }\n\n /**\n * Returns the distance in 3D coordinates from this to that.\n *\n * <p>Equivalent to {@code a.sub(b).norm()}, but significantly faster.\n *\n * <p>If ordering points by angle, this is faster than {@link #norm}, and much faster than {@link\n * #angle}, but consider using {@link S1ChordAngle}.\n */ \n public getDistance(that: S2Point): number {\n return Math.sqrt(this.getDistance2(that));\n }\n\n /**\n * Returns the square of the distance in 3D coordinates from this to that.\n *\n * <p>Equivalent to {@code getDistance(that)<sup>2</sup>}, but significantly faster.\n *\n * <p>If ordering points by angle, this is much faster than {@link #angle}, but consider using\n * {@link S1ChordAngle}.\n */\n public getDistance2(that: S2Point): number {\n const dx = this.x - that.x;\n const dy = this.y - that.y;\n const dz = this.z - that.z;\n return dx * dx + dy * dy + dz * dz;\n }\n\n /** return a vector orthogonal to this one */\n public ortho():S2Point {\n const k = this.largestAbsComponent();\n let temp;\n if (k == 1) {\n temp = new S2Point(1,0,0);\n } else if (k == 2) {\n temp = new S2Point(0,1,0);\n } else {\n temp = new S2Point(0,0,1);\n }\n return S2Point.normalize(S2Point.crossProd(this, temp));\n }\n\n /** Return the index of the largest component fabs */\n public largestAbsComponent():number {\n return S2Point.largestAbsComponent(this.x, this.y, this.z);\n }\n\n public static largestAbsComponent(x: number, y: number, z: number): number {\n const absX = Math.abs(x);\n const absY = Math.abs(y);\n const absZ = Math.abs(z);\n if (absX > absY) {\n if (absX > absZ) {\n return 0;\n } else {\n return 2;\n }\n } else {\n if (absY > absZ) {\n return 1;\n } else {\n return 2;\n }\n }\n }\n\n public get(axis: number): number {\n return (axis == 0) ? this.x : (axis == 1) ? this.y : this.z;\n }\n\n public static fabs(p:S2Point):S2Point {\n return new S2Point(Math.abs(p.x), Math.abs(p.y), Math.abs(p.z));\n }\n\n /** Returns a copy of 'p' rescaled to be unit-length. */\n public static normalize(p:S2Point) {\n let norm = p.norm();\n\n if (norm != 0) {\n norm = 1 / norm;\n }\n return S2Point.mul(p, norm);\n }\n\n axis(axis:number) {\n return (axis == 0) ? this.x : (axis == 1) ? this.y : this.z;\n }\n\n /** Return the angle between two vectors in radians */\n public angle(va) {\n return Math.atan2(S2Point.crossProd(this, va).norm(), this.dotProd(va));\n }\n\n /**\n * Compare two vectors, return true if all their components are within a\n * difference of margin.\n */\n aequal(that:S2Point, margin:number):boolean {\n return this.x - Math.abs(that.x) < (margin) &&\n this.y - Math.abs(that.y) < (margin) &&\n this.z - Math.abs(that.z) < (margin);\n }\n\n equals(that:S2Point):boolean {\n if (!(that instanceof S2Point)) {\n return false;\n }\n return this.x == (that.x) && this.y==(that.y) && this.z==(that.z);\n }\n\n public lessThan(vb:S2Point):boolean {\n if (this.x < (vb.x)) {\n return true;\n }\n if (vb.x < (this.x)) {\n return false;\n }\n if (this.y < (vb.y)) {\n return true;\n }\n if (vb.y < (this.y)) {\n return false;\n }\n if (this.z < (vb.z)) {\n return true;\n }\n return false;\n }\n\n public compareTo(other:S2Point):number {\n return (this.lessThan(other) ? -1 : (this.equals(other) ? 0 : 1));\n }\n\n\n toFace():number {\n let face = this.largestAbsComponent();\n if (this.axis(face) < (0)) {\n face += 3;\n }\n return face;\n }\n\n toR2Vector(face:number = this.toFace()):R2Vector {\n let u;\n let v;\n switch (face) {\n case 0:\n u = this.y / (this.x);\n v = this.z / (this.x);\n break;\n case 1:\n u = (this.x * -1) / (this.y);\n v = this.z / (this.y);\n break;\n case 2:\n u = (this.x * -1) / (this.z);\n v = (this.y * -1) / (this.z);\n break;\n case 3:\n u = this.z / (this.x);\n v = this.y / (this.x);\n break;\n case 4:\n u = this.z / (this.y);\n v = (this.x * -1) / (this.y);\n break;\n case 5:\n u = (this.y * -1) / (this.z);\n v = (this.x * -1) / (this.z);\n break;\n default:\n throw new Error('Invalid face');\n }\n return new R2Vector(u, v);\n }\n\n\n toString():string {\n return `Point(${this.x}, ${this.y}, ${this.z})`;\n }\n}\n","const exponentBuffer = new ArrayBuffer(8);\nconst exponentView = new DataView(exponentBuffer);\n\nfunction getFloat64Exponent(value: number): number {\n exponentView.setFloat64(0, value, false);\n const highWord = exponentView.getUint32(0, false);\n return ((highWord & 0x7ff00000) >>> 20) - 1023;\n}\n\nexport class Platform {\n public static IEEEremainder(f1: number, f2: number): number {\n // let r = f1 % f2;\n\n // if (isNaN(r) || r == (f2) || r <= (Math.abs(f2) / 2)) {\n // return r;\n // } else {\n // return (f1 >= (0) ? 1 : -1) * (r - f2);\n // }\n\n if (Number.isNaN(f1)) {\n return f1;\n }\n\n if (Number.isNaN(f2)) {\n return f2\n }\n\n if ((f2 === Number.POSITIVE_INFINITY || f2 === Number.NEGATIVE_INFINITY) && Number.isFinite(f1)) {\n return f1;\n }\n\n return f1 - (Math.round(f1 / f2) * f2);\n }\n\n /**\n * If v is non-zero, return an integer {@code exp} such that\n * {@code (0.5 <= |v|*2^(-exp) < 1)}. If v is zero, return 0.\n *\n * <p>Note that this arguably a bad definition of exponent because it makes\n * {@code exp(9) == 4}. In decimal this would be like saying that the\n * exponent of 1234 is 4, when in scientific 'exponent' notation 1234 is\n * {@code 1.234 x 10^3}.\n *\n * TODO(dbeaumont): Replace this with \"DoubleUtils.getExponent(v) - 1\" ?\n */\n public static getExponent(v:number ):number {\n // if (v == 0) {\n // return 0;\n // }\n // // IT should always be ((int)log(2,v))+1;\n // const start = Math.floor(Math.log(v)/Math.log(2));\n // for(let i= start; i<start+10; i++) {\n // const curVal = Math.abs(v) * Math.pow(2,-i);\n // if (curVal >= 0.5 && curVal < 1 ) {\n // return i;\n // }\n // }\n // throw new Error('method not written yet');\n // // return (int)((S2.EXPONENT_MASK & bits) >> S2.EXPONENT_SHIFT) - 1022;\n return getFloat64Exponent(v);\n }\n}\n","import { Platform } from \"./Platform\";\nimport {S2} from \"./S2\";\n/**\n * Defines an area or a length cell metric.\n */\nexport class S2Metric {\n private _dim:number;\n private _deriv:number;\n\n /**\n * Defines a cell metric of the given dimension (1 == length, 2 == area).\n */\n public constructor(_dim:number, _deriv:number) {\n this._dim = _dim;\n this._deriv = _deriv;\n\n }\n\n deriv() {\n return this._deriv;\n }\n\n dim() {\n return this._dim;\n }\n\n /** Return the value of a metric for cells at the given level. */\n public getValue(level:number):number {\n return this.deriv() * Math.pow(2, -this.dim() * level)\n }\n\n /**\n * Return the level at which the metric has approximately the given value.\n * For example, S2::kAvgEdge.GetClosestLevel(0.1) returns the level at which\n * the average cell edge length is approximately 0.1. The return value is\n * always a valid level.\n */\n public getClosestLevel(/*double*/value:number):number {\n return this.getMinLevel((this.dim() == 1 ? S2.M_SQRT2 : 2) * value);\n }\n\n /**\n * Return the minimum level such that the metric is at most the given value,\n * or S2CellId::kMaxLevel if there is no such level. For example,\n * S2::kMaxDiag.GetMinLevel(0.1) returns the minimum level such that all\n * cell diagonal lengths are 0.1 or smaller. The return value is always a\n * valid level.\n */\n public getMinLevel(value:number /*double*/):number /*int*/ {\n if (value <= 0) {\n return S2.MAX_LEVEL;\n }\n\n // This code is equivalent to computing a floating-point \"level\"\n // value and rounding up.\n // let exponent = Platform.getExponent(value / ((1 << this.dim()) * this.deriv()));\n const exponent = Platform.getExponent(this.deriv() / value);\n // let level = Math.max(0,\n // Math.min(S2.MAX_LEVEL, -((exponent - 1) >> (this.dim() - 1))));\n const level = Math.max(0, Math.min(S2.MAX_LEVEL, -(exponent >> (this.dim() - 1))));\n\n // assert (level == S2CellId.MAX_LEVEL || getValue(level) <= value);\n // assert (level == 0 || getValue(level - 1) > value);\n return level;\n }\n\n /**\n * Return the maximum level such that the metric is at least the given\n * value, or zero if there is no such level. For example,\n * S2.kMinWidth.GetMaxLevel(0.1) returns the maximum level such that all\n * cells have a minimum width of 0.1 or larger. The return value is always a\n * valid level.\n */\n public getMaxLevel(value:number /*double*/):number {\n if (value <= 0) {\n return S2.MAX_LEVEL;\n }\n\n // This code is equivalent to computing a floating-point \"level\"\n // value and rounding down.\n const exponent = Platform.getExponent(this.deriv() / value);\n const level = Math.max(0, Math.min(S2.MAX_LEVEL, exponent >> (this.dim() - 1)));\n\n // assert (level == 0 || getValue(level) >= value);\n // assert (level == S2CellId.MAX_LEVEL || getValue(level + 1) < value);\n return level;\n }\n}\n","import {S2Point} from \"./S2Point\";\nimport {S2Metric} from \"./S2Metric\";\nimport { Platform } from \"./Platform\";\n\nexport class S2 {\n\n public static M_PI = Math.PI;\n public static M_1_PI = 1.0 / Math.PI;\n public static M_PI_2 = Math.PI / 2.0;\n public static M_PI_4 = Math.PI / 4.0;\n public static M_SQRT2 = Math.sqrt(2);\n public static M_E = Math.E;\n // the axis directions are reversed).\n public static SWAP_MASK = 0x01;\n public static INVERT_MASK = 0x02;\n\n /** Mapping from cell orientation + Hilbert traversal to IJ-index. */\n public static POS_TO_ORIENTATION = [S2.SWAP_MASK, 0, 0, S2.INVERT_MASK + S2.SWAP_MASK];\n public static DBL_EPSILON = 2 * Number.EPSILON;\n\n public static POS_TO_IJ = [\n // 0 1 2 3\n [0, 1, 3, 2], // canonical order: (0,0), (0,1), (1,1), (1,0)\n [0, 2, 3, 1], // axes swapped: (0,0), (1,0), (1,1), (0,1)\n [3, 2, 0, 1], // bits inverted: (1,1), (1,0), (0,0), (0,1)\n [3, 1, 0, 2], // swapped & inverted: (1,1), (0,1), (0,0), (1,0)\n ];\n static MAX_LEVEL = 30;\n\n public static IEEEremainder(f1:number, f2:number): number {\n return Platform.IEEEremainder(f1, f2);\n }\n\n /**\n * Return true if the given point is approximately unit length (this is mainly\n * useful for assertions).\n */\n public static isUnitLength(p:S2Point):boolean {\n return Math.abs(p.norm2() - 1) <= (1e-15);\n }\n\n /**\n * If v is non-zero, return an integer {@code exp} such that\n * {@code (0.5 <= |v|*2^(-exp) < 1)}. If v is zero, return 0.\n *\n * <p>Note that this arguably a bad definition of exponent because it makes\n * {@code exp(9) == 4}. In decimal this would be like saying that the\n * exponent of 1234 is 4, when in scientific 'exponent' notation 1234 is\n * {@code 1.234 x 10^3}.\n *\n * TODO(dbeaumont): Replace this with \"DoubleUtils.getExponent(v) - 1\" ?\n */\n static exp(v:number /*double*/):number {\n return Platform.getExponent(v);\n }\n\n /**\n * Return a vector \"c\" that is orthogonal to the given unit-length vectors \"a\"\n * and \"b\". This function is similar to a.CrossProd(b) except that it does a\n * better job of ensuring orthogonality when \"a\" is nearly parallel to \"b\",\n * and it returns a non-zero result even when a == b or a == -b.\n *\n * It satisfies the following properties (RCP == RobustCrossProd):\n *\n * (1) RCP(a,b) != 0 for all a, b (2) RCP(b,a) == -RCP(a,b) unless a == b or\n * a == -b (3) RCP(-a,b) == -RCP(a,b) unless a == b or a == -b (4) RCP(a,-b)\n * == -RCP(a,b) unless a == b or a == -b\n */\n static robustCrossProd(a:S2Point, b:S2Point):S2Point {\n // The direction of a.CrossProd(b) becomes unstable as (a + b) or (a - b)\n // approaches zero. This leads to situations where a.CrossProd(b) is not\n // very orthogonal to \"a\" and/or \"b\". We could fix this using Gram-Schmidt,\n // but we also want b.RobustCrossProd(a) == -b.RobustCrossProd(a).\n //\n // The easiest fix is to just compute the cross product of (b+a) and (b-a).\n // Given that \"a\" and \"b\" are unit-length, this has good orthogonality to\n // \"a\" and \"b\" even if they differ only in the lowest bit of one component.\n\n // assert (isUnitLength(a) && isUnitLength(b));\n const x = S2Point.crossProd(S2Point.add(b, a), S2Point.sub(b, a));\n if (!x.equals(new S2Point(0, 0, 0))) {\n return x;\n }\n // The only result that makes sense mathematically is to return zero, but\n // we find it more convenient to return an arbitrary orthogonal vector.\n return a.ortho();\n }\n\n /**\n * Return the area of triangle ABC. The method used is about twice as\n * expensive as Girard's formula, but it is numerically stable for both large\n * and very small triangles. The points do not need to be normalized. The area\n * is always positive.\n *\n * The triangle area is undefined if it contains two antipodal points, and\n * becomes numerically unstable as the length of any edge approaches 180\n * degrees.\n */\n static area(a:S2Point, b:S2Point, c:S2Point) {\n // This method is based on l'Huilier's theorem,\n //\n // tan(E/4) = sqrt(tan(s/2) tan((s-a)/2) tan((s-b)/2) tan((s-c)/2))\n //\n // where E is the spherical excess of the triangle (i.e. its area),\n // a, b, c, are the side lengths, and\n // s is the semiperimeter (a + b + c) / 2 .\n //\n // The only significant source of error using l'Huilier's method is the\n // cancellation error of the terms (s-a), (s-b), (s-c). This leads to a\n // *relative* error of about 1e-16 * s / min(s-a, s-b, s-c). This compares\n // to a relative error of about 1e-15 / E using Girard's formula, where E is\n // the true area of the triangle. Girard's formula can be even worse than\n // this for very small triangles, e.g. a triangle with a true area of 1e-30\n // might evaluate to 1e-5.\n //\n // So, we prefer l'Huilier's formula unless dmin < s * (0.1 * E), where\n // dmin = min(s-a, s-b, s-c). This basically includes all triangles\n // except for extremely long and skinny ones.\n //\n // Since we don't know E, we would like a conservative upper bound on\n // the triangle area in terms of s and dmin. It's possible to show that\n // E <= k1 * s * sqrt(s * dmin), where k1 = 2*sqrt(3)/Pi (about 1).\n // Using this, it's easy to show that we should always use l'Huilier's\n // method if dmin >= k2 * s^5, where k2 is about 1e-2. Furthermore,\n // if dmin < k2 * s^5, the triangle area is at most k3 * s^4, where\n // k3 is about 0.1. Since the best case error using Girard's formula\n // is about 1e-15, this means that we shouldn't even consider it unless\n // s >= 3e-4 or so.\n\n // We use volatile doubles to force the compiler to truncate all of these\n // quantities to 64 bits. Otherwise it may compute a value of dmin > 0\n // simply because it chose to spill one of the intermediate values to\n // memory but not one of the others.\n const sa = b.angle(c);\n const sb = c.angle(a);\n const sc = a.angle(b);\n const s = sa+ (sb)+ (sc) * (0.5);\n // 0.5 * (sa + sb + sc);\n if (s >= (3e-4)) {\n // Consider whether Girard's formula might be more accurate.\n const s2 = s * 2;\n const dmin = s - Math.max(\n sa,\n sb,\n sc\n );\n if (dmin < (s2 * s2 * (s) * (1e-2))) {\n // This triangle is skinny enough to consider Girard's formula.\n const area = S2.girardArea(a, b, c);\n if (dmin < (s * (area * (0.1)))) {\n return area;\n }\n }\n }\n // Use l'Huilier's formula.\n return 4 * (\n Math.atan(\n Math.sqrt(\n Math.max(\n 0.0,\n Math.tan(s * (0.5))\n * (Math.tan(s - (sa) * (0.5)))\n * (Math.tan(s - (sb) * (0.5)))\n * (Math.tan(s - (sc) * (0.5)))\n )\n )\n )\n )\n }\n\n\n /**\n * Return the area of the triangle computed using Girard's formula. This is\n * slightly faster than the Area() method above is not accurate for very small\n * triangles.\n */\n static girardArea(a:S2Point, b:S2Point, c:S2Point) {\n // This is equivalent to the usual Girard's formula but is slightly\n // more accurate, faster to compute, and handles a == b == c without\n // a special case.\n\n const ab = S2Point.crossProd(a, b);\n const bc = S2Point.crossProd(b, c);\n const ac = S2Point.crossProd(a, c);\n return Math.max(\n 0,\n ab.angle(ac) - ab.angle(bc) + bc.angle(ac)\n );\n }\n\n /**\n * Return true if the points A, B, C are strictly counterclockwise. Return\n * false if the points are clockwise or colinear (i.e. if they are all\n * contained on some great circle).\n *\n * Due to numerical errors, situations may arise that are mathematically\n * impossible, e.g. ABC may be considered strictly CCW while BCA is not.\n * However, the implementation guarantees the following:\n *\n * If SimpleCCW(a,b,c), then !SimpleCCW(c,b,a) for all a,b,c.\n *\n * In other words, ABC and CBA are guaranteed not to be both CCW\n */\n public static simpleCCW(a:S2Point, b:S2Point, c:S2Point):boolean {\n // We compute the signed volume of the parallelepiped ABC. The usual\n // formula for this is (AxB).C, but we compute it here using (CxA).B\n // in order to ensure that ABC and CBA are not both CCW. This follows\n // from the following identities (which are true numerically, not just\n // mathematically):\n //\n // (1) x.CrossProd(y) == -(y.CrossProd(x))\n // (2) (-x).DotProd(y) == -(x.DotProd(y))\n\n return S2Point.crossProd(c, a).dotProd(b) > 0;\n }\n\n /**\n *\n * Return true if edge AB crosses CD at a point that is interior to both\n * edges. Properties:\n *\n * (1) SimpleCrossing(b,a,c,d) == SimpleCrossing(a,b,c,d) (2)\n * SimpleCrossing(c,d,a,b) == SimpleCrossing(a,b,c,d)\n */\n public static simpleCrossing(a:S2Point, b:S2Point, c:S2Point, d:S2Point):boolean {\n // We compute SimpleCCW() for triangles ACB, CBD, BDA, and DAC. All\n // of these triangles need to have the same orientation (CW or CCW)\n // for an intersection to exist. Note that this is slightly more\n // restrictive than the corresponding definition for planar edges,\n // since we need to exclude pairs of line segments that would\n // otherwise \"intersect\" by crossing two antipodal points.\n\n const ab = S2Point.crossProd(a, b);\n const cd = S2Point.crossProd(c, d);\n const acb = ab.dotProd(c) * -1;\n const cbd = cd.dotProd(b) * -1;\n const bda = ab.dotProd(d);\n const dac = cd.dotProd(a);\n\n return (acb * (cbd) > (0)) && (cbd * (bda) > (0)) && (bda * (dac) > (0));\n }\n\n public static approxEqualsPointError(a: S2Point, b: S2Point, maxError: number): boolean {\n return a.angle(b) <= maxError;\n }\n\n public static approxEqualsPoint(a: S2Point, b: S2Point): boolean {\n return this.approxEqualsPointError(a, b, 1e-15);\n }\n\n public static approxEqualsNumberError(a: number, b: number, maxError: number): boolean {\n return Math.abs(a - b) <= maxError;\n }\n\n public static approxEqualsNumber(a: number, b: number): boolean {\n return this.approxEqualsNumberError(a, b, 1e-15);\n }\n\n static Metric = S2Metric\n}\n\nexport { S2Metric };\n","import {S2Point} from \"./S2Point\";\n\nexport class S1Angle {\n public static INFINITY: S1Angle = new S1Angle(Number.POSITIVE_INFINITY);\n public static ZERO: S1Angle = new S1Angle(0);\n\n\n public radians: number;\n constructor(radians: number) {\n this.radians = radians;\n }\n\n\n public degrees() {\n return this.radians * 180 / Math.PI;\n }\n\n //\n // public long e5() {\n // return Math.round(degrees() * 1e5);\n // }\n //\n // public long e6() {\n // return Math.round(degrees() * 1e6);\n // }\n //\n // public long e7() {\n // return Math.round(degrees() * 1e7);\n // }\n\n /**\n * Return the angle between two points, which is also equal to the distance\n * between these points on the unit sphere. The points do not need to be\n * normalized.\n */\n static fromPoints(x: S2Point, y: S2Point) {\n return new S1Angle(x.angle(y));\n }\n\n public lessThan(that: S1Angle): boolean {\n return this.radians < (that.radians);\n }\n\n public greaterThan(that: S1Angle): boolean {\n return this.radians > (that.radians);\n }\n\n public lessOrEquals(that: S1Angle): boolean {\n return this.radians <= (that.radians);\n }\n\n public greaterOrEquals(that: S1Angle): boolean {\n return this.radians >= (that.radians);\n }\n\n public static max(left: S1Angle, right: S1Angle): S1Angle {\n return right.greaterThan(left) ? right : left;\n }\n\n public static min(left: S1Angle, right: S1Angle): S1Angle {\n return right.greaterThan(left) ? left : right;\n }\n\n public static radians(radians: number): S1Angle {\n return new S1Angle(radians);\n }\n\n public static degrees(degrees: number): S1Angle {\n return new S1Angle(degrees * (Math.PI / 180));\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this + a)</code>.\n */\n public add(a: S1Angle): S1Angle {\n return new S1Angle(this.radians + a.radians);\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this - a)</code>.\n */\n public sub(a: S1Angle): S1Angle {\n return new S1Angle(this.radians - a.radians);\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this * m)</code>.\n */\n public mul(m: number): S1Angle {\n return new S1Angle(this.radians * m);\n }\n\n /**\n * Retuns an {@link S1Angle} whose angle is <code>(this / d)</code>.\n */\n public div(d: number): S1Angle {\n return new S1Angle(this.radians / d);\n }\n\n /**\n * Returns the trigonometric cosine of the angle.\n */\n public cos(): number {\n return Math.cos(this.radians);\n }\n\n /**\n * Returns the trigonometric sine of the angle.\n */\n public sin(): number {\n return Math.sin(this.radians);\n }\n\n /**\n * Returns the trigonometric tangent of the angle.\n */\n public tan(): number {\n return Math.tan(this.radians);\n }\n\n /** Returns the distance along the surface of a sphere of the given radius. */\n public distance(radius: number): number {\n return this.radians * radius;\n }\n\n //\n // public static S1Angle e5(long e5) {\n // return degrees(e5 * 1e-5);\n // }\n //\n // public static S1Angle e6(long e6) {\n // // Multiplying by 1e-6 isn't quite as accurate as dividing by 1e6,\n // // but it's about 10 times faster and more than accurate enough.\n // return degrees(e6 * 1e-6);\n // }\n //\n // public static S1Angle e7(long e7) {\n // return degrees(e7 * 1e-7);\n // }\n\n /**\n * Writes the angle in degrees with a \"d\" suffix, e.g. \"17.3745d\". By default\n * 6 digits are printed; this can be changed using setprecision(). Up to 17\n * digits are required to distinguish one angle from another.\n */\n public toString(): string {\n return this.degrees() + \"d\";\n }\n\n public compareTo(that: S1Angle): number {\n return this.radians < that.radians ? -1 : this.radians > that.radians ? 1 : 0;\n }\n\n public equals(that: S1Angle): boolean {\n return this.compareTo(that) === 0;\n }\n}\n","export abstract class Interval {\n public lo: number;\n public hi: number;\n\n constructor(lo:number, hi:number) {\n this.lo = lo;\n this.hi = hi;\n }\n\n /** Return true if the interval is empty, i.e. it contains no points. */\n\n public abstract isEmpty():boolean;\n\n /**\n * Return the center of the interval. For empty intervals, the result is\n * arbitrary.\n */\n public abstract getCenter(): number;\n\n /**\n * Return the length of the interval. The length of an empty interval is\n * negative.\n */\n public abstract getLength(): number;\n\n public abstract contains(p:number):boolean;\n\n public abstract interiorContains(p:number):boolean;\n\n public toString():string {\n return \"[\" + this.lo.toString() + \", \" + this.hi.toString() + \"]\";\n }\n\n\n /**\n * Return true if two intervals contains the same set of points.\n */\n public equals(that: Interval):boolean {\n if (that instanceof Interval) {\n return this.lo == that.lo && this.hi == that.hi;\n }\n return false;\n }\n\n\n}\n","import {Interval} from \"./Interval\";\nimport {S2} from \"./S2\";\nimport { Platform } from './Platform';\nexport class S1Interval extends Interval {\n\n constructor(lo:number, hi:number, checked = false) {\n super(lo, hi);\n if (!checked) {\n if (this.lo == (-S2.M_PI) && this.hi != (S2.M_PI)) {\n this.lo = (S2.M_PI);\n }\n if (this.hi == (-S2.M_PI) && this.lo != (S2.M_PI)) {\n this.hi = (S2.M_PI);\n }\n }\n }\n\n /**\n * An interval is valid if neither bound exceeds Pi in absolute value, and the\n * value -Pi appears only in the Empty() and Full() intervals.\n */\n isValid():boolean {\n return Math.abs(this.lo) <= (S2.M_PI) && Math.abs(this.hi) <= (S2.M_PI)\n && !(this.lo == (-S2.M_PI) && this.hi != (S2.M_PI))\n && !(this.hi == (-S2.M_PI) && this.lo != (S2.M_PI));\n // return (Math.abs(this.lo) <= S2.M_PI && Math.abs(this.hi) <= S2.M_PI\n // && !(this.lo == -S2.M_PI && this.hi != S2.M_PI) && !(this.hi == -S2.M_PI && this.lo != S2.M_PI));\n }\n\n /** Return true if the interval contains all points on the unit circle. */\n isFull() {\n // console.log(this.hi - (this.lo) == (2 * S2.M_PI));\n return this.hi - (this.lo) == (2 * S2.M_PI)\n }\n\n\n /** Return true if the interval is empty, i.e. it contains no points. */\n public isEmpty() {\n return this.lo - (this.hi) == (2 * S2.M_PI);\n }\n\n\n /* Return true if this.lo > this.hi. (This is true for empty intervals.) */\n public isInverted():boolean {\n return this.lo > (this.hi);\n }\n\n\n /**\n * Return the midpoint of the interval. For full and empty intervals, the\n * result is arbitrary.\n */\n public getCenter() {\n const center = (this.lo + this.hi) / 2;\n // let center = 0.5 * (this.lo + this.hi);\n if (!this.isInverted()) {\n return center;\n }\n // Return the center in the range (-Pi, Pi].\n return (center <= (0)) ? (center + (S2.M_PI)) : (center - (S2.M_PI));\n }\n\n\n /**\n * Return the length of the interval. The length of an empty interval is\n * negative.\n */\n public getLength() {\n let length = this.hi - (this.lo);\n if (length >= (0)) {\n return length;\n }\n length = length + (2 * S2.M_PI);\n // Empty intervals have a negative length.\n return (length > (0)) ? length : (-1);\n }\n\n /**\n * Return the complement of the interior of the interval. An interval and its\n * complement have the same boundary but do not share any interior values. The\n * complement operator is not a bijection, since the complement of a singleton\n * interval (containing a single value) is the same as the complement of an\n * empty interval.\n */\n public complement():S1Interval {\n if (this.lo == (this.hi)) {\n return S1Interval.full(); // Singleton.\n }\n return new S1Interval(this.hi, this.lo, true); // Handles\n // empty and\n // full.\n }\n\n /** Return true if the interval (which is closed) contains the point 'p'. */\n public contains(_p:number):boolean {\n let p = (_p);\n // Works for empty, full, and singleton intervals.\n // assert (Math.abs(p) <= S2.M_PI);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n return this.fastContains(p);\n }\n\n /**\n * Return true if the interval (which is closed) contains the point 'p'. Skips\n * the normalization of 'p' from -Pi to Pi.\n *\n */\n public fastContains(_p:number):boolean {\n const p = (_p);\n if (this.isInverted()) {\n return (p>= (this.lo) || p <= (this.hi)) && !this.isEmpty();\n } else {\n return p>= (this.lo) && p <= (this.hi);\n }\n }\n\n /** Return true if the interior of the interval contains the point 'p'. */\n public interiorContains(_p:number):boolean {\n // Works for empty, full, and singleton intervals.\n // assert (Math.abs(p) <= S2.M_PI);\n let p = (_p);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n\n if (this.isInverted()) {\n return p > (this.lo) || p < (this.hi);\n } else {\n return (p > (this.lo) && p < (this.hi)) || this.isFull();\n }\n }\n\n /**\n * Return true if the interval contains the given interval 'y'. Works for\n * empty, full, and singleton intervals.\n */\n public containsI(y:S1Interval):boolean {\n // It might be helpful to compare the structure of these tests to\n // the simpler Contains(number) method above.\n\n if (this.isInverted()) {\n if (y.isInverted()) {\n return y.lo>= (this.lo) && y.hi <= (this.hi);\n }\n return (y.lo>= (this.lo) || y.hi <= (this.hi)) && !this.isEmpty();\n } else {\n if (y.isInverted()) {\n return this.isFull() || y.isEmpty();\n }\n return y.lo>= (this.lo) && y.hi <= (this.hi);\n }\n }\n\n /**\n * Returns true if the interior of this interval contains the entire interval\n * 'y'. Note that x.InteriorContains(x) is true only when x is the empty or\n * full interval, and x.InteriorContains(S1Interval(p,p)) is equivalent to\n * x.InteriorContains(p).\n */\n public interiorContainsI(y:S1Interval):boolean {\n if (this.isInverted()) {\n if (!y.isInverted()) {\n return this.lo > (this.lo) || y.hi < (this.hi);\n }\n return (y.lo > (this.lo) && y.hi < (this.hi)) || y.isEmpty();\n } else {\n if (y.isInverted()) {\n return this.isFull() || y.isEmpty();\n }\n return (y.lo > (this.lo) && y.hi < (this.hi)) || this.isFull();\n }\n }\n\n /**\n * Return true if the two intervals contain any points in common. Note that\n * the point +/-Pi has two representations, so the intervals [-Pi,-3] and\n * [2,Pi] intersect, for example.\n */\n public intersects(y:S1Interval):boolean {\n if (this.isEmpty() || y.isEmpty()) {\n return false;\n }\n if (this.isInverted()) {\n // Every non-empty inverted interval contains Pi.\n return y.isInverted() || y.lo <= (this.hi) || y.hi>= (this.lo);\n } else {\n if (y.isInverted()) {\n return y.lo <= (this.hi) || y.hi>= (this.lo);\n }\n return y.lo <= (this.hi) && y.hi>= (this.lo);\n }\n }\n\n /**\n * Return true if the interior of this interval contains any point of the\n * interval 'y' (including its boundary). Works for empty, full, and singleton\n * intervals.\n */\n public interiorIntersects(y:S1Interval):boolean {\n if (this.isEmpty() || y.isEmpty() || this.lo == (this.hi)) {\n return false;\n }\n if (this.isInverted()) {\n return y.isInverted() || y.lo < (this.hi) || y.hi > (this.lo);\n } else {\n if (y.isInverted()) {\n return y.lo < (this.hi) || y.hi > (this.lo);\n }\n return (y.lo < (this.hi) && y.hi > (this.lo)) || this.isFull();\n }\n }\n\n /**\n * Expand the interval by the minimum amount necessary so that it contains the\n * given point \"p\" (an angle in the range [-Pi, Pi]).\n */\n public addPoint(_p:number):S1Interval {\n let p = (_p);\n // assert (Math.abs(p) <= S2.M_PI);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n\n if (this.fastContains(p)) {\n return new S1Interval(this.lo, this.hi);\n }\n\n if (this.isEmpty()) {\n return S1Interval.fromPoint(p);\n } else {\n // Compute distance from p to each endpoint.\n const dlo = S1Interval.positiveDistance(p, this.lo);\n const dhi = S1Interval.positiveDistance(this.hi, p);\n if (dlo < (dhi)) {\n return new S1Interval(p, this.hi);\n } else {\n return new S1Interval(this.lo, p);\n }\n // Adding a point can never turn a non-full interval into a full one.\n }\n }\n\n /**\n * Return an interval that contains all points within a distance \"radius\" of\n * a point in this interval. Note that the expansion of an empty interval is\n * always empty. The radius must be non-negative.\n */\n public expanded(radius:number):S1Interval {\n // assert (radius >= 0);\n if (this.isEmpty()) {\n return this;\n }\n\n // Check whether this interval will be full after expansion, allowing\n // for a 1-bit rounding error when computing each endpoint.\n if (this.getLength() + (radius * 2)>= (2*S2.M_PI-1e-15)) {\n return S1Interval.full();\n }\n\n // NOTE(dbeaumont): Should this remainder be 2 * M_PI or just M_PI ??\n let lo = Platform.IEEEremainder(this.lo - (radius), 2 * S2.M_PI);\n const hi = Platform.IEEEremainder(this.hi + (radius), 2 * S2.M_PI);\n\n if (lo == (-S2.M_PI)) {\n lo = (S2.M_PI);\n }\n return new S1Interval(lo, hi);\n }\n\n /**\n * Return the smallest interval that contains this interval and the given\n * interval \"y\".\n */\n public union(y:S1Interval):S1Interval {\n // The y.is_full() case is handled correctly in all cases by the code\n // below, but can follow three separate code paths depending on whether\n // this interval is inverted, is non-inverted but contains Pi, or neither.\n\n if (y.isEmpty()) {\n return this;\n }\n if (this.fastContains(y.lo)) {\n if (this.fastContains(y.hi)) {\n // Either this interval contains y, or the union of the two\n // intervals is the Full() interval.\n if (this.containsI(y)) {\n return this; // is_full() code path\n }\n return S1Interval.full();\n }\n return new S1Interval(this.lo, this.hi, true);\n }\n if (this.fastContains(y.hi)) {\n return new S1Interval(y.lo, this.hi, true);\n }\n\n // This interval contains neither endpoint of y. This means that either y\n // contains all of this interval, or the two intervals are disjoint.\n if (this.isEmpty() || y.fastContains(this.lo)) {\n return y;\n }\n\n // Check which pair of endpoints are closer together.\n const dlo = S1Interval.positiveDistance(y.hi, this.lo);\n const dhi = S1Interval.positiveDistance(this.hi, y.lo);\n if (dlo < dhi) {\n return new S1Interval(y.lo, this.hi, true);\n } else {\n return new S1Interval(this.lo, y.hi, true);\n }\n }\n\n /**\n * Return the smallest interval that contains the intersection of this\n * interval with \"y\". Note that the region of intersection may consist of two\n * disjoint intervals.\n */\n public intersection(y:S1Interval):S1Interval {\n // The y.is_full() case is handled correctly in all cases by the code\n // below, but can follow three separate code paths depending on whether\n // this interval is inverted, is non-inverted but contains Pi, or neither.\n\n if (y.isEmpty()) {\n return S1Interval.empty();\n }\n if (this.fastContains(y.lo)) {\n if (this.fastContains(y.hi)) {\n // Either this interval contains y, or the region of intersection\n // consists of two disjoint subintervals. In either case, we want\n // to return the shorter of the two original intervals.\n if (y.getLength() < (this.getLength())) {\n return y; // is_full() code path\n }\n return this;\n }\n return new S1Interval(y.lo, this.hi, true);\n }\n if (this.fastContains(y.hi)) {\n return new S1Interval(this.lo, y.hi, true);\n }\n\n // This interval contains neither endpoint of y. This means that either y\n // contains all of this interval, or the two intervals are disjoint.\n\n if (y.fastContains(this.lo)) {\n return this; // is_empty() okay here\n }\n // assert (!intersects(y));\n return S1Interval.empty();\n }\n\n /**\n * Return true if the length of the symmetric difference between the two\n * intervals is at most the given tolerance.\n */\n public approxEquals(y:S1Interval, maxError=1e-9):boolean {\n if (this.isEmpty()) {\n return y.getLength() <= (maxError);\n }\n if (y.isEmpty()) {\n return this.getLength() <= (maxError);\n }\n\n return Math.abs(Platform.IEEEremainder(y.lo - (this.lo), 2 * S2.M_PI))\n + (Math.abs(Platform.IEEEremainder(y.hi - (this.hi), 2 * S2.M_PI)))\n <= (maxError);\n }\n\n\n\n static empty():S1Interval {\n return new S1Interval(S2.M_PI, -S2.M_PI, true);\n }\n\n static full():S1Interval {\n return new S1Interval(-S2.M_PI, S2.M_PI, true);\n }\n\n static fromPoint(_p:number):S1Interval {\n let p = (_p);\n if (p == (-S2.M_PI)) {\n p = (S2.M_PI);\n }\n return new S1Interval(p, p, true);\n }\n\n\n /**\n * Convenience method to construct the minimal interval containing the two\n * given points. This is equivalent to starting with an empty interval and\n * calling AddPoint() twice, but it is more efficient.\n */\n static fromPointPair(_p1:number, _p2:number):S1Interval {\n // assert (Math.abs(p1) <= S2.M_PI && Math.abs(p2) <= S2.M_PI);\n let p1 = (_p1);\n let p2 = (_p2);\n if (p1 == (-S2.M_PI)) {\n p1 = (S2.M_PI);\n }\n if (p2 == (-S2.M_PI)) {\n p2 = (S2.M_PI);\n }\n if (S1Interval.positiveDistance(p1, p2) <= (S2.M_PI)) {\n return new S1Interval(p1, p2, true);\n } else {\n return new S1Interval(p2, p1, true);\n }\n }\n\n /**\n * Compute the distance from \"a\" to \"b\" in the range [0, 2*Pi). This is\n * equivalent to (drem(b - a - S2.M_PI, 2 * S2.M_PI) + S2.M_PI), except that\n * it is more numerically stable (it does not lose precision for very small\n * positive distances).\n */\n public static positiveDistance(_a:number, _b:number): number {\n const a = (_a);\n const b = (_b);\n const d = b - (a);\n if (d >= (0)) {\n return d;\n }\n // We want to ensure that if b == Pi and a == (-Pi + eps),\n // the return result is approximately 2*Pi and not zero.\n return b + (S2.M_PI) - (a - (S2.M_PI));\n }\n\n}\n","import {Interval} from \"./Interval\";\n/**\n * An R1Interval represents a closed interval on a unit circle (also known as a\n * 1-dimensional sphere). It is capable of representing the empty interval\n * (containing no points), the full interval (containing all points), and\n * zero-length intervals (containing a single point).\n *\n * Points are represented by the angle they make with the positive x-axis in\n * the range [-Pi, Pi]. An interval is represented by its lower and upper bounds\n * (both inclusive, since the interval is closed). The lower bound may be\n * greater than the upper bound, in which case the interval is \"inverted\" (i.e.\n * it passes through the point (-1, 0)).\n *\n * Note that the point (-1, 0) has two valid representations, Pi and -Pi. The\n * normalized representation of this point internally is Pi, so that endpoints\n * of normal intervals are in the range (-Pi, Pi]. However, we take advantage of\n * the point -Pi to construct two special intervals: the Full() interval is\n * [-Pi, Pi], and the Empty() interval is [Pi, -Pi].\n *\n */\n\nexport class R1Interval extends Interval {\n\n /** Return true if the interval is empty, i.e. it contains no points. */\n public isEmpty() {\n return this.lo > this.hi;\n }\n\n public getCenter() {\n return (this.lo + this.hi)/2;\n }\n\n public getLength() {\n return this.hi - this.lo;\n }\n\n public contains(p:number):boolean {\n return p >= this.lo && p <= this.hi;\n\n }\n\n /** Return true if the interior of the interval contains the point 'p'. */\n public interiorContains(p:number):boolean {\n return p > this.lo && p < this.hi;\n }\n\n /**\n * Return true if the interval contains the given interval 'y'. Works for\n * empty, full, and singleton intervals.\n */\n public containsI(y:R1Interval):boolean {\n if (y.isEmpty()) {\n return true;\n }\n return y.lo >= this.lo && y.hi <= this.hi;\n }\n\n\n public interiorContainsI(y:R1Interval):boolean {\n if (y.isEmpty()) {\n return true;\n }\n return y.lo > this.lo && y.hi < this.hi;\n }\n\n /**\n * Return true if this interval intersects the given interval, i.e. if they\n * have any points in common.\n */\n public intersects(y:R1Interval):boolean {\n if (this.lo <= y.lo) {\n return y.lo <= (this.hi) && y.lo <= (y.hi);\n } else {\n return this.lo <= (y.hi) && this.lo <= (this.hi);\n }\n }\n\n /**\n * Return true if the interior of this interval intersects any point of the\n * given interval (including its boundary).\n */\n public interiorIntersects(y:R1Interval):boolean {\n return y.lo < (this.hi) && this.lo < (y.hi) && this.lo < (this.hi) && y.lo <= (y.hi);\n }\n\n /** Expand the interval so that it contains the given point \"p\". */\n public addPoint(p:number):R1Interval {\n if (this.isEmpty()) {\n return R1Interval.fromPoint(p);\n } else if (p < (this.lo)) {\n return new R1Interval(p, this.hi);\n } else if (p > (this.hi)) {\n return new R1Interval(this.lo, p);\n } else {\n return new R1Interval(this.lo, this.hi);\n }\n }\n\n /**\n * Return an interval that contains all points with a distance \"radius\" of a\n * point in this interval. Note that the expansion of an empty interval is\n * always empty.\n */\n public expanded(radius:number):R1Interval {\n // assert (radius >= 0);\n if (this.isEmpty()) {\n return this;\n }\n return new R1Interval(this.lo - radius, this.hi + radius);\n }\n\n /**\n * Return the smallest interval that contains this interval and the given\n * interval \"y\".\n */\n public union(y:R1Interval):R1Interval {\n if (this.isEmpty()) {\n return y;\n }\n if (y.isEmpty()) {\n return this;\n }\n return new R1Interval(\n Math.min(this.lo, y.lo),\n Math.max(this.hi, y.hi)\n );\n }\n\n /**\n * Return the intersection of this interval with the given interval. Empty\n * intervals do not need to be special-cased.\n */\n public intersection(y:R1Interval):R1Interval {\n return new R1Interval(\n Math.max(this.lo, y.lo),\n Math.min(this.hi, y.hi)\n );\n }\n\n /**\n * Return true if the length of the symmetric difference between the two\n * intervals is at most the given tolerance.\n */\n public approxEquals(y:R1Interval, maxError=1e-15):boolean {\n if (this.isEmpty()) {\n return y.getLength() <= (maxError);\n }\n if (y.isEmpty()) {\n return this.getLength() <= ( maxError);\n }\n return Math.abs(y.lo - (this.lo)) + Math.abs(y.hi - this.hi) <= (maxError);\n }\n\n\n\n static empty():R1Interval {\n return new R1Interval(1, 0);\n }\n\n\n static fromPoint(p:number):R1Interval {\n return new R1Interval(p, p);\n }\n\n /**\n * Convenience method to construct the minimal interval containing the two\n * given points. This is equivalent to starting with an empty interval and\n * calling AddPoint() twice, but it is more efficient.\n */\n static fromPointPair(p1:number, p2:number):R1Interval {\n if (p1 <= (p2)) {\n return new R1Interval(p1, p2);\n } else {\n return new R1Interval(p2, p1);\n }\n }\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {S1Angle} from \"./S1Angle\";\nimport {S2Point} from \"./S2Point\";\nimport {S2} from \"./S2\";\nimport { Platform } from \"./Platform\";\n/**\n * This class represents a point on the unit sphere as a pair of\n * latitude-longitude coordinates. Like the rest of the \"geometry\" package, the\n * intent is to represent spherical geometry as a mathematical abstraction, so\n * functions that are specifically related to the Earth's geometry (e.g.\n * easting/northing conversions) should be put elsewhere.\n *\n */\nexport class S2LatLng {\n\n /**\n * Approximate \"effective\" radius of the Earth in meters.\n */\n public static EARTH_RADIUS_METERS = 6367000.0;\n\n /** The center point the lat/lng coordinate system. */\n public static CENTER = new S2LatLng(0.0, 0.0);\n\n public latRadians: number;\n public lngRadians: number;\n\n constructor(latRadians:number, lngRadians:number) {\n this.latRadians = latRadians;\n this.lngRadians = lngRadians;\n }\n\n get latDegrees() {\n return new S1Angle(this.latRadians).degrees();\n }\n\n get lngDegrees() {\n return new S1Angle(this.lngRadians).degrees();\n }\n\n// Clamps the latitude to the range [-90, 90] degrees, and adds or subtracts\n // a multiple of 360 degrees to the longitude if necessary to reduce it to\n // the range [-180, 180].\n /** Convert an S2LatLng to the equivalent unit-length vector (S2Point). */\n public toPoint():S2Point {\n const phi = this.latRadians;\n const theta = this.lngRadians;\n const cosphi = Math.cos(phi);\n\n return new S2Point(\n Math.cos(theta) * (cosphi),\n Math.sin(theta)* (cosphi),\n Math.sin(phi));\n }\n\n /**\n * Returns a new S2LatLng based on this instance for which {@link #isValid()}\n * will be {@code true}.\n * <ul>\n * <li>Latitude is clipped to the range {@code [-90, 90]}\n * <li>Longitude is normalized to be in the range {@code [-180, 180]}\n * </ul>\n * <p>If the current point is valid then the returned point will have the same\n * coordinates.\n */\n public normalized():S2LatLng {\n // drem(x, 2 * S2.M_PI) reduces its argument to the range\n // [-S2.M_PI, Math.atan2PI] inclusive, which is what we want here.\n return new S2LatLng(\n Math.max(\n -S2.M_PI_2,\n Math.min(\n S2.M_PI_2,\n this.latRadians\n )\n ),\n Platform.IEEEremainder(\n this.lngRadians,\n 2* (S2.M_PI)\n )\n );\n }\n\n public static fromDegrees(latDegrees:number, lngDegrees:number):S2LatLng {\n return new S2LatLng(S1Angle.degrees(latDegrees).radians, S1Angle.degrees(lngDegrees).radians);\n }\n\n public static fromRadians(latRadians:number, lngRadians:number):S2LatLng {\n return new S2LatLng(latRadians, lngRadians);\n }\n\n static fromPoint(p:S2Point) {\n return new S2LatLng(\n S2LatLng.latitude(p).radians,\n S2LatLng.longitude(p).radians\n );\n }\n\n /** Returns the latitude of this point as a new S1Angle. */\n public lat(): S1Angle {\n return S1Angle.radians(this.latRadians);\n }\n\n /** Returns the longitude of this point as a new S1Angle. */\n public lng(): S1Angle {\n return S1Angle.radians(this.lngRadians);\n }\n\n /**\n * Return true if the latitude is between -90 and 90 degrees inclusive and the\n * longitude is between -180 and 180 degrees inclusive.\n */\n public isValid():boolean {\n return Math.abs(this.latRadians) <= (S2.M_PI_2) &&\n Math.abs(this.lngRadians) <= (S2.M_PI);\n\n }\n\n\n /**\n * Scales this point by the given scaling factor.\n * Note that there is no guarantee that the new point will be <em>valid</em>.\n */\n public mul(m:number):S2LatLng {\n return new S2LatLng(this.latRadians* (m), this.lngRadians* (m));\n }\n\n public static latitude(p:S2Point) {\n // We use atan2 rather than asin because the input vector is not necessarily\n // unit length, and atan2 is much more accurate than asin near the poles.\n return new S1Angle(Math.atan2(p.z, Math.sqrt(p.x * p.x + p.y * p.y)));\n }\n\n public static longitude(p:S2Point):S1Angle {\n // Note that atan2(0, 0) is defined to be zero.\n return new S1Angle(Math.atan2(p.y, p.x));\n }\n\n equals(other:S2LatLng):boolean {\n return other.latRadians === this.latRadians && other.lngRadians === this.lngRadians;\n }\n\n pointAtDistance(distanceInKM:number, bearingRadians:number) {\n const distanceInM = distanceInKM * 1000;\n const distanceToRadius = distanceInM / (S2LatLng.EARTH_RADIUS_METERS);\n\n const newLat = Math.asin(Math.sin(this.latRadians) * Math.cos(distanceToRadius)\n + (\n Math.cos(this.latRadians) * Math.sin(distanceToRadius) * Math.cos(bearingRadians)\n ));\n const newLng = this.lngRadians + Math.atan2(\n Math.sin(bearingRadians)\n * (Math.sin(distanceToRadius))\n * (Math.cos(this.latRadians)),\n Math.cos(distanceToRadius) - (Math.sin(this.latRadians) * Math.sin(newLat)\n )\n );\n return new S2LatLng(newLat, newLng);\n }\n\n /**\n * Generates n LatLngs given a distance in km and the number of points wanted.\n * Generated points will be returned in a Clockwise order starting from North.\n * @param _distanceInKm\n * @param nPoints\n * @returns {S2LatLng[]}\n */\n pointsAtDistance(_distanceInKm:number, nPoints=4):S2LatLng[] {\n return [... new Array(nPoints)] // create an array filled of undefined!\n .map((p, idx) => 360 / nPoints * idx)\n .map(bearingDegree => S1Angle.degrees(bearingDegree).radians)\n .map(bearingRadians => this.pointAtDistance(_distanceInKm, bearingRadians));\n\n }\n\n getEarthDistance(other:S2LatLng) {\n return this.getDistance(other).radians * (S2LatLng.EARTH_RADIUS_METERS);\n }\n\n getDistance(other:S2LatLng):S1Angle {\n // This implements the Haversine formula, which is numerically stable for\n // small distances but only gets about 8 digits of precision for very large\n // distances (e.g. antipodal points). Note that 8 digits is still accurate\n // to within about 10cm for a sphere the size of the Earth.\n //\n // This could be fixed with another sin() and cos() below, but at that point\n // you might as well just convert both arguments to S2Points and compute the\n // distance that way (which gives about 15 digits of accuracy for all\n // distances).\n\n const lat1 = this.latRadians;\n const lat2 = other.latRadians\n const lng1 = this.lngRadians;\n const lng2 = other.lngRadians;\n const dLat = Math.sin(0.5 * (lat2 - lat1));\n const dLng = Math.sin(0.5 * (lng2 - lng1));\n const x = dLat * dLat + dLng * dLng * Math.cos(lat1) * Math.cos(lat2)\n\n return S1Angle.radians(2 * Math.asin(Math.sqrt(Math.min(1.0, x))));\n // Return the distance (measured along the surface of the sphere) to the\n // given S2LatLng. This is mathematically equivalent to:\n //\n // S1Angle::FromRadians(ToPoint().Angle(o.ToPoint())\n //\n // but this implementation is slightly more efficient.\n }\n\n public toString():string {\n return \"(\" + this.latRadians + \", \" + this.lngRadians + \")\";\n }\n\n public toStringDegrees():string {\n return \"(\" + this.latDegrees + \", \" + this.lngDegrees + \")\";\n }\n\n public toGEOJSON() {\n return {\n type: 'Feature',\n geometry: {\n type: \"Point\",\n coordinates: [this.lngDegrees, this.latDegrees]\n },\n properties: {}\n\n }\n }\n}\n","/*\n * Copyright 2006 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport {S2Point} from \"./S2Point\";\nimport {S2} from \"./S2\";\nimport {S1Angle} from \"./S1Angle\";\n\n/**\n * This class contains various utility functions related to edges. It collects\n * together common code that is needed to implement polygonal geometry such as\n * polylines, loops, and general polygons.\n *\n */\nexport class S2EdgeUtil {\n// /**\n// * IEEE floating-point operations have a maximum error of 0.5 ULPS (units in\n// * the last place). For double-precision numbers, this works out to 2**-53\n// * (about 1.11e-16) times the magnitude of the result. It is possible to\n// * analyze the calculation done by getIntersection() and work out the\n// * worst-case rounding error. I have done a rough version of this, and my\n// * estimate is that the worst case distance from the intersection point X to\n// * the great circle through (a0, a1) is about 12 ULPS, or about 1.3e-15. This\n// * needs to be increased by a factor of (1/0.866) to account for the\n// * edgeSpliceFraction() in S2PolygonBuilder. Note that the maximum error\n// * measured by the unittest in 1,000,000 trials is less than 3e-16.\n// */\n// public static final S1Angle DEFAULT_INTERSECTION_TOLERANCE = S1Angle.radians(1.5e-15);\n//\n// /**\n// * This class allows a vertex chain v0, v1, v2, ... to be efficiently tested\n// * for intersection with a given fixed edge AB.\n// */\n// public static class EdgeCrosser {\n// // The fields below are all constant.\n//\n// private final S2Point a;\n// private final S2Point b;\n// private final S2Point aCrossB;\n//\n// // The fields below are updated for each vertex in the chain.\n//\n// // Previous vertex in the vertex chain.\n// private S2Point c;\n// // The orientation of the triangle ACB.\n// private int acb;\n//\n// /**\n// * AB is the given fixed edge, and C is the first vertex of the vertex\n// * chain. All parameters must point to fixed storage that persists for the\n// * lifetime of the EdgeCrosser object.\n// */\n// public EdgeCrosser(S2Point a, S2Point b, S2Point c) {\n// this.a = a;\n// this.b = b;\n// this.aCrossB = S2Point.crossProd(a, b);\n// restartAt(c);\n// }\n//\n// /**\n// * Call this function when your chain 'jumps' to a new place.\n// */\n// public void restartAt(S2Point c) {\n// this.c = c;\n// this.acb = -S2.robustCCW(this.a, this.b, c, this.aCrossB);\n// }\n//\n// /**\n// * This method is equivalent to calling the S2EdgeUtil.robustCrossing()\n// * function (defined below) on the edges AB and CD. It returns +1 if there\n// * is a crossing, -1 if there is no crossing, and 0 if two points from\n// * different edges are the same. Returns 0 or -1 if either edge is\n// * degenerate. As a side effect, it saves vertex D to be used as the next\n// * vertex C.\n// */\n// public int robustCrossing(S2Point d) {\n// // For there to be an edge crossing, the triangles ACB, CBD, BDA, DAC must\n// // all be oriented the same way (CW or CCW). We keep the orientation\n// // of ACB as part of our state. When each new point D arrives, we\n// // compute the orientation of BDA and check whether it matches ACB.\n// // This checks whether the points C and D are on opposite sides of the\n// // great circle through AB.\n//\n// // Recall that robustCCW is invariant with respect to rotating its\n// // arguments, i.e. ABC has the same orientation as BDA.\n// int bda = S2.robustCCW(this.a, this.b, d, this.aCrossB);\n// int result;\n//\n// if (bda == -this.acb && bda != 0) {\n// // Most common case -- triangles have opposite orientations.\n// result = -1;\n// } else if ((bda & this.acb) == 0) {\n// // At least one value is zero -- two vertices are identical.\n// result = 0;\n// } else {\n// // assert (bda == acb && bda != 0);\n// result = robustCrossingInternal(d); // Slow path.\n// }\n// // Now save the current vertex D as the next vertex C, and also save the\n// // orientation of the new triangle ACB (which is opposite to the current\n// // triangle BDA).\n// this.c = d;\n// this.acb = -bda;\n// return result;\n// }\n//\n// /**\n// * This method is equivalent to the S2EdgeUtil.edgeOrVertexCrossing() method\n// * defined below. It is similar to robustCrossing, but handles cases where\n// * two vertices are identical in a way that makes it easy to implement\n// * point-in-polygon containment tests.\n// */\n// public boolean edgeOrVertexCrossing(S2Point d) {\n// // We need to copy c since it is clobbered by robustCrossing().\n// S2Point c2 = new S2Point(this.c.get(0), this.c.get(1), this.c.get(2));\n//\n// int crossing = robustCrossing(d);\n// if (crossing < 0) {\n// return false;\n// }\n// if (crossing > 0) {\n// return true;\n// }\n//\n// return vertexCrossing(this.a, this.b, c2, d);\n// }\n//\n// /**\n// * This function handles the \"slow path\" of robustCrossing().\n// */\n// private int robustCrossingInternal(S2Point d) {\n// // ACB and BDA have the appropriate orientations, so now we check the\n// // triangles CBD and DAC.\n// S2Point cCrossD = S2Point.crossProd(this.c, d);\n// int cbd = -S2.robustCCW(this.c, d, this.b, cCrossD);\n// if (cbd != this.acb) {\n// return -1;\n// }\n//\n// int dac = S2.robustCCW(this.c, d, this.a, cCrossD);\n// return (dac == this.acb) ? 1 : -1;\n// }\n// }\n//\n// /**\n// * This class computes a bounding rectangle that contains all edges defined by\n// * a vertex chain v0, v1, v2, ... All vertices must be unit length. Note that\n// * the bounding rectangle of an edge can be larger than the bounding rectangle\n// * of its endpoints, e.g. consider an edge that passes through the north pole.\n// */\n// public static class RectBounder {\n// // The previous vertex in the chain.\n// private S2Point a;\n//\n// // The corresponding latitude-longitude.\n// private S2LatLng aLatLng;\n//\n// // The current bounding rectangle.\n// private S2LatLngRect bound;\n//\n// public RectBounder() {\n// this.bound = S2LatLngRect.empty();\n// }\n//\n// /**\n// * This method is called to add each vertex to the chain. 'b' must point to\n// * fixed storage that persists for the lifetime of the RectBounder.\n// */\n// public void addPoint(S2Point b) {\n// // assert (S2.isUnitLength(b));\n//\n// S2LatLng bLatLng = new S2LatLng(b);\n//\n// if (this.bound.isEmpty()) {\n// this.bound = this.bound.addPoint(bLatLng);\n// } else {\n// // We can't just call bound.addPoint(bLatLng) here, since we need to\n// // ensure that all the longitudes between \"a\" and \"b\" are included.\n// this.bound = this.bound.union(S2LatLngRect.fromPointPair(this.aLatLng, bLatLng));\n//\n// // Check whether the min/max latitude occurs in the edge interior.\n// // We find the normal to the plane containing AB, and then a vector\n// // \"dir\" in this plane that also passes through the equator. We use\n// // RobustCrossProd to ensure that the edge normal is accurate even\n// // when the two points are very close together.\n// S2Point aCrossB = S2.robustCrossProd(this.a, b);\n// S2Point dir = S2Point.crossProd(aCrossB, new S2Point(0, 0, 1));\n// double da = dir.dotProd(this.a);\n// double db = dir.dotProd(b);\n//\n// if (da * db < 0) {\n// // Minimum/maximum latitude occurs in the edge interior. This affects\n// // the latitude bounds but not the longitude bounds.\n// double absLat = Math.acos(Math.abs(aCrossB.get(2) / aCrossB.norm()));\n// R1Interval lat = this.bound.lat();\n// if (da < 0) {\n// // It's possible that absLat < lat.lo() due to numerical errors.\n// lat = new R1Interval(lat.lo(), Math.max(absLat, this.bound.lat().hi()));\n// } else {\n// lat = new R1Interval(Math.min(-absLat, this.bound.lat().lo()), lat.hi());\n// }\n// this.bound = new S2LatLngRect(lat, this.bound.lng());\n// }\n// }\n// this.a = b;\n// this.aLatLng = bLatLng;\n// }\n//\n// /**\n// * Return the bounding rectangle of the edge chain that connects the\n// * vertices defined so far.\n// */\n// public S2LatLngRect getBound() {\n// return this.bound;\n// }\n//\n// }\n//\n// /**\n// * The purpose of this class is to find edges that intersect a given XYZ\n// * bounding box. It can be used as an efficient rejection test when attempting to\n// * find edges that intersect a given region. It accepts a vertex chain v0, v1,\n// * v2, ... and returns a boolean value indicating whether each edge intersects\n// * the specified bounding box.\n// *\n// * We use XYZ intervals instead of something like longitude intervals because\n// * it is cheap to collect from S2Point lists and any slicing strategy should\n// * give essentially equivalent results. See S2Loop for an example of use.\n// */\n// public static class XYZPruner {\n// private S2Point lastVertex;\n//\n// // The region to be tested against.\n// private boolean boundSet;\n// private double xmin;\n// private double ymin;\n// private double zmin;\n// private double xmax;\n// private double ymax;\n// private double zmax;\n// private double maxDeformation;\n//\n// public XYZPruner() {\n// this.boundSet = false;\n// }\n//\n// /**\n// * Accumulate a bounding rectangle from provided edges.\n// *\n// * @param from start of edge\n// * @param to end of edge.\n// */\n// public void addEdgeToBounds(S2Point from, S2Point to) {\n// if (!this.boundSet) {\n// this.boundSet = true;\n// this.xmin = this.xmax = from.x;\n// this.ymin = this.ymax = from.y;\n// this.zmin = this.zmax = from.z;\n// }\n// this.xmin = Math.min(this.xmin, Math.min(to.x, from.x));\n// this.ymin = Math.min(this.ymin, Math.min(to.y, from.y));\n// this.zmin = Math.min(this.zmin, Math.min(to.z, from.z));\n// this.xmax = Math.max(this.xmax, Math.max(to.x, from.x));\n// this.ymax = Math.max(this.ymax, Math.max(to.y, from.y));\n// this.zmax = Math.max(this.zmax, Math.max(to.z, from.z));\n//\n// // Because our arcs are really geodesics on the surface of the earth\n// // an edge can have intermediate points outside the xyz bounds implicit\n// // in the end points. Based on the length of the arc we compute a\n// // generous bound for the maximum amount of deformation. For small edges\n// // it will be very small but for some large arcs (ie. from (1N,90W) to\n// // (1N,90E) the path can be wildly deformed. I did a bunch of\n// // experiments with geodesics to get safe bounds for the deformation.\n// double approxArcLen =\n// Math.abs(from.x - to.x) + Math.abs(from.y - to.y) + Math.abs(from.z - to.z);\n// if (approxArcLen < 0.025) { // less than 2 degrees\n// this.maxDeformation = Math.max(this.maxDeformation, approxArcLen * 0.0025);\n// } else if (approxArcLen < 1.0) { // less than 90 degrees\n// this.maxDeformation = Math.max(this.maxDeformation, approxArcLen * 0.11);\n// } else {\n// this.maxDeformation = approxArcLen * 0.5;\n// }\n// }\n//\n// public void setFirstIntersectPoint(S2Point v0) {\n// this.xmin = this.xmin - this.maxDeformation;\n// this.ymin = this.ymin - this.maxDeformation;\n// this.zmin = this.zmin - this.maxDeformation;\n// this.xmax = this.xmax + this.maxDeformation;\n// this.ymax = this.ymax + this.maxDeformation;\n// this.zmax = this.zmax + this.maxDeformation;\n// this.lastVertex = v0;\n// }\n//\n// /**\n// * Returns true if the edge going from the last point to this point passes\n// * through the pruner bounding box, otherwise returns false. So the\n// * method returns false if we are certain there is no intersection, but it\n// * may return true when there turns out to be no intersection.\n// */\n// public boolean intersects(S2Point v1) {\n// boolean result = true;\n//\n// if ((v1.x < this.xmin && this.lastVertex.x < this.xmin) || (v1.x > this.xmax && this.lastVertex.x > this.xmax)) {\n// result = false;\n// } else if ((v1.y < this.ymin && this.lastVertex.y < this.ymin) || (v1.y > this.ymax && this.lastVertex.y > this.ymax)) {\n// result = false;\n// } else if ((v1.z < this.zmin && this.lastVertex.z < this.zmin) || (v1.z > this.zmax && this.lastVertex.z > this.zmax)) {\n// result = false;\n// }\n//\n// this.lastVertex = v1;\n// return result;\n// }\n// }\n//\n// /**\n// * The purpose of this class is to find edges that intersect a given longitude\n// * interval. It can be used as an efficient rejection test when attempting to\n// * find edges that intersect a given region. It accepts a vertex chain v0, v1,\n// * v2, ... and returns a boolean value indicating whether each edge intersects\n// * the specified longitude interval.\n// *\n// * This class is not currently used as the XYZPruner is preferred for\n// * S2Loop, but this should be usable in similar circumstances. Be wary\n// * of the cost of atan2() in conversions from S2Point to longitude!\n// */\n// public static class LongitudePruner {\n// // The interval to be tested against.\n// private S1Interval interval;\n//\n// // The longitude of the next v0.\n// private double lng0;\n//\n// /**\n// *'interval' is the longitude interval to be tested against, and 'v0' is\n// * the first vertex of edge chain.\n// */\n// public LongitudePruner(S1Interval interval, S2Point v0) {\n// this.interval = interval;\n// this.lng0 = S2LatLng.longitude(v0).radians();\n// }\n//\n// /**\n// * Returns true if the edge (v0, v1) intersects the given longitude\n// * interval, and then saves 'v1' to be used as the next 'v0'.\n// */\n// public boolean intersects(S2Point v1) {\n// double lng1 = S2LatLng.longitude(v1).radians();\n// boolean result = this.interval.intersects(S1Interval.fromPointPair(this.lng0, lng1));\n// this.lng0 = lng1;\n// return result;\n// }\n// }\n//\n// /**\n// * A wedge relation's test method accepts two edge chains A=(a0,a1,a2) and\n// * B=(b0,b1,b2) where a1==b1, and returns either -1, 0, or 1 to indicate the\n// * relationship between the region to the left of A and the region to the left\n// * of B. Wedge relations are used to determine the local relationship between\n// * two polygons that share a common vertex.\n// *\n// * All wedge relations require that a0 != a2 and b0 != b2. Other degenerate\n// * cases (such as a0 == b2) are handled as expected. The parameter \"ab1\"\n// * denotes the common vertex a1 == b1.\n// */\n// public interface WedgeRelation {\n// int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2);\n// }\n//\n// public static class WedgeContains implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns +1\n// * if the region to the left of A contains the region to the left of B, and\n// * 0 otherwise.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // For A to contain B (where each loop interior is defined to be its left\n// // side), the CCW edge order around ab1 must be a2 b2 b0 a0. We split\n// // this test into two parts that test three vertices each.\n// return S2.orderedCCW(a2, b2, b0, ab1) && S2.orderedCCW(b0, a0, a2, ab1) ? 1 : 0;\n// }\n// }\n//\n// public static class WedgeIntersects implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns -1\n// * if the region to the left of A intersects the region to the left of B,\n// * and 0 otherwise. Note that regions are defined such that points along a\n// * boundary are contained by one side or the other, not both. So for\n// * example, if A,B,C are distinct points ordered CCW around a vertex O, then\n// * the wedges BOA, AOC, and COB do not intersect.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // For A not to intersect B (where each loop interior is defined to be\n// // its left side), the CCW edge order around ab1 must be a0 b2 b0 a2.\n// // Note that it's important to write these conditions as negatives\n// // (!OrderedCCW(a,b,c,o) rather than Ordered(c,b,a,o)) to get correct\n// // results when two vertices are the same.\n// return (S2.orderedCCW(a0, b2, b0, ab1) && S2.orderedCCW(b0, a2, a0, ab1) ? 0 : -1);\n// }\n// }\n//\n// public static class WedgeContainsOrIntersects implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns +1\n// * if A contains B, 0 if A and B are disjoint, and -1 if A intersects but\n// * does not contain B.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // This is similar to WedgeContainsOrCrosses, except that we want to\n// // distinguish cases (1) [A contains B], (3) [A and B are disjoint],\n// // and (2,4,5,6) [A intersects but does not contain B].\n//\n// if (S2.orderedCCW(a0, a2, b2, ab1)) {\n// // We are in case 1, 5, or 6, or case 2 if a2 == b2.\n// return S2.orderedCCW(b2, b0, a0, ab1) ? 1 : -1; // Case 1 vs. 2,5,6.\n// }\n// // We are in cases 2, 3, or 4.\n// if (!S2.orderedCCW(a2, b0, b2, ab1)) {\n// return 0; // Case 3.\n// }\n//\n// // We are in case 2 or 4, or case 3 if a2 == b0.\n// return (a2.equals(b0)) ? 0 : -1; // Case 3 vs. 2,4.\n// }\n// }\n//\n// public static class WedgeContainsOrCrosses implements WedgeRelation {\n// /**\n// * Given two edge chains (see WedgeRelation above), this function returns +1\n// * if A contains B, 0 if B contains A or the two wedges do not intersect,\n// * and -1 if the edge chains A and B cross each other (i.e. if A intersects\n// * both the interior and exterior of the region to the left of B). In\n// * degenerate cases where more than one of these conditions is satisfied,\n// * the maximum possible result is returned. For example, if A == B then the\n// * result is +1.\n// */\n// @Override\n// public int test(S2Point a0, S2Point ab1, S2Point a2, S2Point b0, S2Point b2) {\n// // There are 6 possible edge orderings at a shared vertex (all\n// // of these orderings are circular, i.e. abcd == bcda):\n// //\n// // (1) a2 b2 b0 a0: A contains B\n// // (2) a2 a0 b0 b2: B contains A\n// // (3) a2 a0 b2 b0: A and B are disjoint\n// // (4) a2 b0 a0 b2: A and B intersect in one wedge\n// // (5) a2 b2 a0 b0: A and B intersect in one wedge\n// // (6) a2 b0 b2 a0: A and B intersect in two wedges\n// //\n// // In cases (4-6), the boundaries of A and B cross (i.e. the boundary\n// // of A intersects the interior and exterior of B and vice versa).\n// // Thus we want to distinguish cases (1), (2-3), and (4-6).\n// //\n// // Note that the vertices may satisfy more than one of the edge\n// // orderings above if two or more vertices are the same. The tests\n// // below are written so that we take the most favorable\n// // interpretation, i.e. preferring (1) over (2-3) over (4-6). In\n// // particular note that if orderedCCW(a,b,c,o) returns true, it may be\n// // possible that orderedCCW(c,b,a,o) is also true (if a == b or b == c).\n//\n// if (S2.orderedCCW(a0, a2, b2, ab1)) {\n// // The cases with this vertex ordering are 1, 5, and 6,\n// // although case 2 is also possible if a2 == b2.\n// if (S2.orderedCCW(b2, b0, a0, ab1)) {\n// return 1; // Case 1 (A contains B)\n// }\n//\n// // We are in case 5 or 6, or case 2 if a2 == b2.\n// return (a2.equals(b2)) ? 0 : -1; // Case 2 vs. 5,6.\n// }\n// // We are in case 2, 3, or 4.\n// return S2.orderedCCW(a0, b0, a2, ab1) ? 0 : -1; // Case 2,3 vs. 4.\n// }\n// }\n//\n// /**\n// * Return true if edge AB crosses CD at a point that is interior to both\n// * edges. Properties:\n// *\n// * (1) simpleCrossing(b,a,c,d) == simpleCrossing(a,b,c,d) (2)\n// * simpleCrossing(c,d,a,b) == simpleCrossing(a,b,c,d)\n// */\n// public static boolean simpleCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// // We compute simpleCCW() for triangles ACB, CBD, BDA, and DAC. All\n// // of these triangles need to have the same orientation (CW or CCW)\n// // for an intersection to exist. Note that this is slightly more\n// // restrictive than the corresponding definition for planar edges,\n// // since we need to exclude pairs of line segments that would\n// // otherwise \"intersect\" by crossing two antipodal points.\n//\n// S2Point ab = S2Point.crossProd(a, b);\n// double acb = -(ab.dotProd(c));\n// double bda = ab.dotProd(d);\n// if (acb * bda <= 0) {\n// return false;\n// }\n//\n// S2Point cd = S2Point.crossProd(c, d);\n// double cbd = -(cd.dotProd(b));\n// double dac = cd.dotProd(a);\n// return (acb * cbd > 0) && (acb * dac > 0);\n// }\n//\n// /**\n// * Like SimpleCrossing, except that points that lie exactly on a line are\n// * arbitrarily classified as being on one side or the other (according to the\n// * rules of S2.robustCCW). It returns +1 if there is a crossing, -1 if there\n// * is no crossing, and 0 if any two vertices from different edges are the\n// * same. Returns 0 or -1 if either edge is degenerate. Properties of\n// * robustCrossing:\n// *\n// * (1) robustCrossing(b,a,c,d) == robustCrossing(a,b,c,d) (2)\n// * robustCrossing(c,d,a,b) == robustCrossing(a,b,c,d) (3)\n// * robustCrossing(a,b,c,d) == 0 if a==c, a==d, b==c, b==d (3)\n// * robustCrossing(a,b,c,d) <= 0 if a==b or c==d\n// *\n// * Note that if you want to check an edge against a *chain* of other edges,\n// * it is much more efficient to use an EdgeCrosser (above).\n// */\n// public static int robustCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// // For there to be a crossing, the triangles ACB, CBD, BDA, DAC must\n// // all have the same orientation (clockwise or counterclockwise).\n// //\n// // First we compute the orientation of ACB and BDA. We permute the\n// // arguments to robustCCW so that we can reuse the cross-product of A and B.\n// // Recall that when the arguments to robustCCW are permuted, the sign of the\n// // result changes according to the sign of the permutation. Thus ACB and\n// // ABC are oppositely oriented, while BDA and ABD are the same.\n// S2Point aCrossB = S2Point.crossProd(a, b);\n// int acb = -S2.robustCCW(a, b, c, aCrossB);\n// int bda = S2.robustCCW(a, b, d, aCrossB);\n//\n// // If any two vertices are the same, the result is degenerate.\n// if ((bda & acb) == 0) {\n// return 0;\n// }\n//\n// // If ABC and BDA have opposite orientations (the most common case),\n// // there is no crossing.\n// if (bda != acb) {\n// return -1;\n// }\n//\n// // Otherwise we compute the orientations of CBD and DAC, and check whether\n// // their orientations are compatible with the other two triangles.\n// S2Point cCrossD = S2Point.crossProd(c, d);\n// int cbd = -S2.robustCCW(c, d, b, cCrossD);\n// if (cbd != acb) {\n// return -1;\n// }\n//\n// int dac = S2.robustCCW(c, d, a, cCrossD);\n// return (dac == acb) ? 1 : -1;\n// }\n//\n// /**\n// * Given two edges AB and CD where at least two vertices are identical (i.e.\n// * robustCrossing(a,b,c,d) == 0), this function defines whether the two edges\n// * \"cross\" in a such a way that point-in-polygon containment tests can be\n// * implemented by counting the number of edge crossings. The basic rule is\n// * that a \"crossing\" occurs if AB is encountered after CD during a CCW sweep\n// * around the shared vertex starting from a fixed reference point.\n// *\n// * Note that according to this rule, if AB crosses CD then in general CD does\n// * not cross AB. However, this leads to the correct result when counting\n// * polygon edge crossings. For example, suppose that A,B,C are three\n// * consecutive vertices of a CCW polygon. If we now consider the edge\n// * crossings of a segment BP as P sweeps around B, the crossing number changes\n// * parity exactly when BP crosses BA or BC.\n// *\n// * Useful properties of VertexCrossing (VC):\n// *\n// * (1) VC(a,a,c,d) == VC(a,b,c,c) == false (2) VC(a,b,a,b) == VC(a,b,b,a) ==\n// * true (3) VC(a,b,c,d) == VC(a,b,d,c) == VC(b,a,c,d) == VC(b,a,d,c) (3) If\n// * exactly one of a,b equals one of c,d, then exactly one of VC(a,b,c,d) and\n// * VC(c,d,a,b) is true\n// *\n// * It is an error to call this method with 4 distinct vertices.\n// */\n// public static boolean vertexCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// // If A == B or C == D there is no intersection. We need to check this\n// // case first in case 3 or more input points are identical.\n// if (a.equals(b) || c.equals(d)) {\n// return false;\n// }\n//\n// // If any other pair of vertices is equal, there is a crossing if and only\n// // if orderedCCW() indicates that the edge AB is further CCW around the\n// // shared vertex than the edge CD.\n// if (a.equals(d)) {\n// return S2.orderedCCW(S2.ortho(a), c, b, a);\n// }\n// if (b.equals(c)) {\n// return S2.orderedCCW(S2.ortho(b), d, a, b);\n// }\n// if (a.equals(c)) {\n// return S2.orderedCCW(S2.ortho(a), d, b, a);\n// }\n// if (b.equals(d)) {\n// return S2.orderedCCW(S2.ortho(b), c, a, b);\n// }\n//\n// // assert (false);\n// return false;\n// }\n//\n// /**\n// * A convenience function that calls robustCrossing() to handle cases where\n// * all four vertices are distinct, and VertexCrossing() to handle cases where\n// * two or more vertices are the same. This defines a crossing function such\n// * that point-in-polygon containment tests can be implemented by simply\n// * counting edge crossings.\n// */\n// public static boolean edgeOrVertexCrossing(S2Point a, S2Point b, S2Point c, S2Point d) {\n// int crossing = robustCrossing(a, b, c, d);\n// if (crossing < 0) {\n// return false;\n// }\n// if (crossing > 0) {\n// return true;\n// }\n// return vertexCrossing(a, b, c, d);\n// }\n//\n// static class CloserResult {\n// private double dmin2;\n// private S2Point vmin;\n//\n// public double getDmin2() {\n// return this.dmin2;\n// }\n//\n// public S2Point getVmin() {\n// return this.vmin;\n// }\n//\n// public CloserResult(double dmin2, S2Point vmin) {\n// this.dmin2 = dmin2;\n// this.vmin = vmin;\n// }\n//\n// public void replaceIfCloser(S2Point x, S2Point y) {\n// // If the squared distance from x to y is less than dmin2, then replace\n// // vmin by y and update dmin2 accordingly.\n// double d2 = S2Point.minus(x, y).norm2();\n// if (d2 < this.dmin2 || (d2 == this.dmin2 && y.lessThan(this.vmin))) {\n// this.dmin2 = d2;\n// this.vmin = y;\n// }\n// }\n// }\n//\n// /*\n// * Given two edges AB and CD such that robustCrossing() is true, return their\n// * intersection point. Useful properties of getIntersection (GI):\n// *\n// * (1) GI(b,a,c,d) == GI(a,b,d,c) == GI(a,b,c,d) (2) GI(c,d,a,b) ==\n// * GI(a,b,c,d)\n// *\n// * The returned intersection point X is guaranteed to be close to the edges AB\n// * and CD, but if the edges intersect at a very small angle then X may not be\n// * close to the true mathematical intersection point P. See the description of\n// * \"DEFAULT_INTERSECTION_TOLERANCE\" below for details.\n// */\n// public static S2Point getIntersection(S2Point a0, S2Point a1, S2Point b0, S2Point b1) {\n// Preconditions.checkArgument(robustCrossing(a0, a1, b0, b1) > 0,\n// \"Input edges a0a1 and b0b1 muct have a true robustCrossing.\");\n//\n// // We use robustCrossProd() to get accurate results even when two endpoints\n// // are close together, or when the two line segments are nearly parallel.\n// S2Point aNorm = S2Point.normalize(S2.robustCrossProd(a0, a1));\n// S2Point bNorm = S2Point.normalize(S2.robustCrossProd(b0, b1));\n// S2Point x = S2Point.normalize(S2.robustCrossProd(aNorm, bNorm));\n//\n// // Make sure the intersection point is on the correct side of the sphere.\n// // Since all vertices are unit length, and edges are less than 180 degrees,\n// // (a0 + a1) and (b0 + b1) both have positive dot product with the\n// // intersection point. We use the sum of all vertices to make sure that the\n// // result is unchanged when the edges are reversed or exchanged.\n// if (x.dotProd(S2Point.add(S2Point.add(a0, a1), S2Point.add(b0, b1))) < 0) {\n// x = S2Point.neg(x);\n// }\n//\n// // The calculation above is sufficient to ensure that \"x\" is within\n// // DEFAULT_INTERSECTION_TOLERANCE of the great circles through (a0,a1) and\n// // (b0,b1).\n// // However, if these two great circles are very close to parallel, it is\n// // possible that \"x\" does not lie between the endpoints of the given line\n// // segments. In other words, \"x\" might be on the great circle through\n// // (a0,a1) but outside the range covered by (a0,a1). In this case we do\n// // additional clipping to ensure that it does.\n//\n// if (S2.orderedCCW(a0, x, a1, aNorm) && S2.orderedCCW(b0, x, b1, bNorm)) {\n// return x;\n// }\n//\n// // Find the acceptable endpoint closest to x and return it. An endpoint is\n// // acceptable if it lies between the endpoints of the other line segment.\n// CloserResult r = new CloserResult(10, x);\n// if (S2.orderedCCW(b0, a0, b1, bNorm)) {\n// r.replaceIfCloser(x, a0);\n// }\n// if (S2.orderedCCW(b0, a1, b1, bNorm)) {\n// r.replaceIfCloser(x, a1);\n// }\n// if (S2.orderedCCW(a0, b0, a1, aNorm)) {\n// r.replaceIfCloser(x, b0);\n// }\n// if (S2.orderedCCW(a0, b1, a1, aNorm)) {\n// r.replaceIfCloser(x, b1);\n// }\n// return r.getVmin();\n// }\n//\n// /**\n// * Given a point X and an edge AB, return the distance ratio AX / (AX + BX).\n// * If X happens to be on the line segment AB, this is the fraction \"t\" such\n// * that X == Interpolate(A, B, t). Requires that A and B are distinct.\n// */\n// public static double getDistanceFraction(S2Point x, S2Point a0, S2Point a1) {\n// Preconditions.checkArgument(!a0.equals(a1));\n// double d0 = x.angle(a0);\n// double d1 = x.angle(a1);\n// return d0 / (d0 + d1);\n// }\n//\n// /**\n// * Return the minimum distance from X to any point on the edge AB. The result\n// * is very accurate for small distances but may have some numerical error if\n// * the distance is large (approximately Pi/2 or greater). The case A == B is\n// * handled correctly. Note: x, a and b must be of unit length. Throws\n// * IllegalArgumentException if this is not the case.\n// */\n// public static getDistance(x:S2Point , a:S2Point , b:S2Point ):S1Angle {\n// return this.getDistance(x, a, b, S2.robustCrossProd(a, b));\n// }\n\n/**\n * A slightly more efficient version of getDistance() where the cross product\n * of the two endpoints has been precomputed. The cross product does not need\n * to be normalized, but should be computed using S2.robustCrossProd() for the\n * most accurate results.\n */\npublic static getDistance(x:S2Point , a:S2Point , b:S2Point , aCrossB:S2Point=S2.robustCrossProd(a,b) ):S1Angle {\n // Preconditions.checkArgument(S2.isUnitLength(x));\n // Preconditions.checkArgument(S2.isUnitLength(a));\n // Preconditions.checkArgument(S2.isUnitLength(b));\n\n // There are three cases. If X is located in the spherical wedge defined by\n // A, B, and the axis A x B, then the closest point is on the segment AB.\n // Otherwise the closest point is either A or B; the dividing line between\n // these two cases is the great circle passing through (A x B) and the\n // midpoint of AB.\n\n if (S2.simpleCCW(aCrossB, a, x) && S2.simpleCCW(x, b, aCrossB)) {\n // The closest point to X lies on the segment AB. We compute the distance\n // to the corresponding great circle. The result is accurate for small\n // distances but not necessarily for large distances (approaching Pi/2).\n\n const sinDist = Math.abs(x.dotProd(aCrossB)) / ( aCrossB.norm());\n return new S1Angle(Math.asin(Math.min(1.0, sinDist)));\n }\n\n // Otherwise, the closest point is either A or B. The cheapest method is\n // just to compute the minimum of the two linear (as opposed to spherical)\n // distances and convert the result to an angle. Again, this method is\n // accurate for small but not large distances (approaching Pi).\n\n const linearDist2 = Math.min(S2Point.minus(x, a).norm2(), S2Point.minus(x, b).norm2());\n return new S1Angle(\n Math.asin(\n Math.min(\n 1.0,\n Math.sqrt(linearDist2) * 0.5\n )\n ) * 2\n );\n}\n//\n// /**\n// * Returns the point on edge AB closest to X. x, a and b must be of unit\n// * length. Throws IllegalArgumentException if this is not the case.\n// *\n// */\n// public static S2Point getClosestPoint(S2Point x, S2Point a, S2Point b) {\n// Preconditions.checkArgument(S2.isUnitLength(x));\n// Preconditions.checkArgument(S2.isUnitLength(a));\n// Preconditions.checkArgument(S2.isUnitLength(b));\n//\n// S2Point crossProd = S2.robustCrossProd(a, b);\n// // Find the closest point to X along the great circle through AB.\n// S2Point p = S2Point.minus(x, S2Point.mul(crossProd, x.dotProd(crossProd) / crossProd.norm2()));\n//\n// // If p is on the edge AB, then it's the closest point.\n// if (S2.simpleCCW(crossProd, a, p) && S2.simpleCCW(p, b, crossProd)) {\n// return S2Point.normalize(p);\n// }\n// // Otherwise, the closest point is either A or B.\n// return S2Point.minus(x, a).norm2() <= S2Point.minus(x, b).norm2() ? a : b;\n// }\n//\n// /** Constructor is private so that this class is never instantiated. */\n// private S2EdgeUtil() {\n// }\n}\n","import {S1Interval} from \"./S1Interval\";\nimport {R1Interval} from \"./R1Interval\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {S2Region} from \"./S2Region\";\nimport {S2} from \"./S2\";\nimport {S2Point} from \"./S2Point\";\nimport {S1Angle} from \"./S1Angle\";\nimport {S2Cell} from \"./S2Cell\";\nimport {S2EdgeUtil} from \"./S2EdgeUtil\";\nimport {S2Cap} from \"./S2Cap\";\nimport { Platform } from \"./Platform\";\n\nexport class S2LatLngRect implements S2Region {\n constructor(public lat:R1Interval, public lng:S1Interval) {\n\n }\n\n static fromLatLng(lo:S2LatLng, hi:S2LatLng):S2LatLngRect {\n return new S2LatLngRect(\n new R1Interval(\n lo.latRadians,\n hi.latRadians\n ),\n new S1Interval(\n lo.lngRadians,\n hi.lngRadians\n )\n );\n }\n\n\n /** The canonical empty rectangle */\n public static empty():S2LatLngRect {\n return new S2LatLngRect(R1Interval.empty(), S1Interval.empty());\n }\n\n /** The canonical full rectangle. */\n public static full():S2LatLngRect {\n return new S2LatLngRect(S2LatLngRect.fullLat(), S1Interval.full());\n }\n\n /** The full allowable range of latitudes. */\n public static fullLat() {\n return new R1Interval(-S2.M_PI_2, S2.M_PI_2);\n }\n\n\n /**\n * Construct a rectangle from a center point (in lat-lng space) and size in\n * each dimension. If size.lng is greater than 360 degrees it is clamped,\n * and latitudes greater than +/- 90 degrees are also clamped. So for example,\n * FromCenterSize((80,170),(20,20)) -> (lo=(60,150),hi=(90,-170)).\n */\n public static fromCenterSize(center:S2LatLng, size:S2LatLng) {\n return S2LatLngRect.fromPoint(center).expanded(size.mul(0.5));\n }\n\n /** Convenience method to construct a rectangle containing a single point. */\n public static fromPoint(p:S2LatLng):S2LatLngRect {\n // assert (p.isValid());\n return S2LatLngRect.fromLatLng(p, p);\n }\n\n /**\n * Convenience method to construct the minimal bounding rectangle containing\n * the two given points. This is equivalent to starting with an empty\n * rectangle and calling AddPoint() twice. Note that it is different than the\n * S2LatLngRect(lo, hi) constructor, where the first point is always used as\n * the lower-left corner of the resulting rectangle.\n */\n public static fromPointPair(p1:S2LatLng, p2:S2LatLng):S2LatLngRect {\n // assert (p1.isValid() && p2.isValid());\n return new S2LatLngRect(R1Interval.fromPointPair(p1.latRadians, p2\n .latRadians), S1Interval.fromPointPair(p1.lngRadians, p2.lngRadians));\n }\n\n /**\n * Return a latitude-longitude rectangle that contains the edge from \"a\" to\n * \"b\". Both points must be unit-length. Note that the bounding rectangle of\n * an edge can be larger than the bounding rectangle of its endpoints.\n */\n public static fromEdge(a:S2Point, b:S2Point):S2LatLngRect {\n // assert (S2.isUnitLength(a) && S2.isUnitLength(b));\n const r = S2LatLngRect.fromPointPair(S2LatLng.fromPoint(a), S2LatLng.fromPoint(b));\n\n // Check whether the min/max latitude occurs in the edge interior.\n // We find the normal to the plane containing AB, and then a vector \"dir\" in\n // this plane that also passes through the equator. We use RobustCrossProd\n // to ensure that the edge normal is accurate even when the two points are\n // very close together.\n const ab = S2.robustCrossProd(a, b);\n const dir = S2Point.crossProd(ab, new S2Point(0, 0, 1));\n const da = dir.dotProd(a);\n const db = dir.dotProd(b);\n if (da * db >= 0) {\n // Minimum and maximum latitude are attained at the vertices.\n return r;\n }\n // Minimum/maximum latitude occurs in the edge interior. This affects the\n // latitude bounds but not the longitude bounds.\n const absLat = Math.acos(ab.z / Math.abs(ab.norm()));\n if (da < 0) {\n return new S2LatLngRect(new R1Interval(r.lat.lo, absLat), r.lng);\n } else {\n return new S2LatLngRect(new R1Interval(-absLat, r.lat.hi), r.lng);\n }\n }\n\n /**\n * Return true if the rectangle is valid, which essentially just means that\n * the latitude bounds do not exceed Pi/2 in absolute value and the longitude\n * bounds do not exceed Pi in absolute value.\n *\n */\n public isValid():boolean {\n // The lat/lng ranges must either be both empty or both non-empty.\n return (Math.abs(this.lat.lo) <= S2.M_PI_2 && Math.abs(this.lat.hi) <= (S2.M_PI_2)\n && this.lng.isValid() && this.lat.isEmpty() == this.lng.isEmpty());\n }\n\n public lo():S2LatLng {\n return new S2LatLng(this.lat.lo, this.lng.lo);\n }\n\n public hi():S2LatLng {\n return new S2LatLng(this.lat.hi, this.lng.hi);\n }\n\n public latLo(): S1Angle {\n return S1Angle.radians(this.lat.lo);\n }\n\n public latHi(): S1Angle {\n return S1Angle.radians(this.lat.hi);\n }\n\n public lngLo(): S1Angle {\n return S1Angle.radians(this.lng.lo);\n }\n\n public lngHi(): S1Angle {\n return S1Angle.radians(this.lng.hi);\n }\n\n /**\n * Return true if the rectangle is empty, i.e. it contains no points at all.\n */\n public isEmpty():boolean {\n return this.lat.isEmpty();\n }\n\n// Return true if the rectangle is full, i.e. it contains all points.\n public isFull():boolean {\n // console.log(this.lat.toString());\n // console.log(S2LatLngRect.fullLat().toString());\n return this.lat.equals(S2LatLngRect.fullLat()) && this.lng.isFull();\n }\n\n /**\n * Return true if lng_.lo() > lng_.hi(), i.e. the rectangle crosses the 180\n * degree latitude line.\n */\n public isInverted():boolean {\n return this.lng.isInverted();\n }\n\n /** Return the k-th vertex of the rectangle (k = 0,1,2,3) in CCW order. */\n public getVertex(k:number):S2LatLng {\n // Return the points in CCW order (SW, SE, NE, NW).\n switch (k) {\n case 0:\n return this.lo();\n case 1:\n return new S2LatLng(this.lat.lo, this.lng.hi);\n case 2:\n return this.hi();\n case 3:\n return new S2LatLng(this.lat.hi, this.lng.lo);\n default:\n throw new Error(\"Invalid vertex index.\");\n }\n }\n\n /**\n * Return the center of the rectangle in latitude-longitude space (in general\n * this is not the center of the region on the sphere).\n */\n public getCenter():S2LatLng {\n return new S2LatLng(this.lat.getCenter(), this.lng.getCenter());\n }\n\n /**\n * Return the minimum distance (measured along the surface of the sphere)\n * from a given point to the rectangle (both its boundary and its interior).\n * The latLng must be valid.\n */\n public getDistanceLL(p:S2LatLng):S1Angle {\n // The algorithm here is the same as in getDistance(S2LagLngRect), only\n // with simplified calculations.\n if (this.isEmpty()) {\n throw new Error();\n }\n if (!p.isValid()) {\n throw new Error('point is not valid');\n }\n\n\n if (this.lng.contains(p.lngRadians)) {\n return new S1Angle(\n Math.max(\n 0.0,\n Math.max(\n p.latRadians - this.lat.hi,\n this.lat.lo - p.latRadians\n )\n )\n );\n }\n\n const interval = new S1Interval(this.lng.hi, this.lng.complement().getCenter());\n let aLng = this.lng.lo;\n if (interval.contains(p.lngRadians)) {\n aLng = this.lng.hi;\n }\n\n const lo = new S2LatLng(this.lat.lo, aLng).toPoint();\n const hi = new S2LatLng(this.lat.hi, aLng).toPoint();\n const loCrossHi = new S2LatLng(0, aLng - S2.M_PI_2).normalized().toPoint();\n return S2EdgeUtil.getDistance(p.toPoint(), lo, hi, loCrossHi);\n }\n\n /**\n * Return the minimum distance (measured along the surface of the sphere) to\n * the given S2LatLngRect. Both S2LatLngRects must be non-empty.\n */\n public getDistanceLLR(other:S2LatLngRect):S1Angle {\n const b = other;\n if (this.isEmpty()) {\n throw new Error();\n }\n if (b.isEmpty()) {\n throw new Error();\n }\n\n\n // First, handle the trivial cases where the longitude intervals overlap.\n if (this.lng.intersects(b.lng)) {\n if (this.lat.intersects(b.lat)) {\n return new S1Angle(0); // Intersection between a and b.\n }\n\n // We found an overlap in the longitude interval, but not in the latitude\n // interval. This means the shortest path travels along some line of\n // longitude connecting the high-latitude of the lower rect with the\n // low-latitude of the higher rect.\n let lo, hi;\n if (this.lat.lo > b.lat.hi) {\n lo = b.lat.hi;\n hi = this.lat.lo;\n } else {\n lo = this.lat.hi;\n hi = b.lat.lo;\n }\n return S1Angle.radians(hi.radians() - lo.radians());\n }\n\n // The longitude intervals don't overlap. In this case, the closest points\n // occur somewhere on the pair of longitudinal edges which are nearest in\n // longitude-space.\n let aLng, bLng;\n const loHi = S1Interval.fromPointPair(this.lng.lo, b.lng.hi);\n const hiLo = S1Interval.fromPointPair(this.lng.hi, b.lng.lo);\n if (loHi.getLength() < (hiLo.getLength())) {\n aLng = this.lng.lo;\n bLng = b.lng.hi;\n } else {\n aLng = this.lng.hi;\n bLng = b.lng.lo;\n }\n\n // The shortest distance between the two longitudinal segments will include\n // at least one segment endpoint. We could probably narrow this down further\n // to a single point-edge distance by comparing the relative latitudes of the\n // endpoints, but for the sake of clarity, we'll do all four point-edge\n // distance tests.\n const aLo = new S2LatLng(this.lat.lo, aLng).toPoint();\n const aHi = new S2LatLng(this.lat.hi, aLng).toPoint();\n const aLoCrossHi = new S2LatLng(0, aLng.radians().minus(S2.M_PI_2)).normalized().toPoint();\n const bLo = new S2LatLng(b.lat.lo, bLng).toPoint();\n const bHi = new S2LatLng(b.lat.hi, bLng).toPoint();\n const bLoCrossHi = new S2LatLng(0, bLng.radians().minus(S2.M_PI_2)).normalized().toPoint();\n\n return S1Angle.min(S2EdgeUtil.getDistance(aLo, bLo, bHi, bLoCrossHi),\n S1Angle.min(S2EdgeUtil.getDistance(aHi, bLo, bHi, bLoCrossHi),\n S1Angle.min(S2EdgeUtil.getDistance(bLo, aLo, aHi, aLoCrossHi),\n S2EdgeUtil.getDistance(bHi, aLo, aHi, aLoCrossHi))));\n }\n\n /**\n * Return the width and height of this rectangle in latitude-longitude space.\n * Empty rectangles have a negative width and height.\n */\n public getSize():S2LatLng {\n return new S2LatLng(this.lat.getLength(), this.lng.getLength());\n }\n\n /**\n * More efficient version of Contains() that accepts a S2LatLng rather than an\n * S2Point.\n */\n public containsLL(ll:S2LatLng):boolean {\n // assert (ll.isValid());\n return (this.lat.contains(ll.latRadians) && this.lng.contains(ll.lngRadians));\n\n }\n\n /**\n * Return true if and only if the given point is contained in the interior of\n * the region (i.e. the region excluding its boundary). The point 'p' does not\n * need to be normalized.\n */\n public interiorContainsP(p:S2Point):boolean {\n return this.interiorContainsLL(S2LatLng.fromPoint(p));\n }\n\n /**\n * More efficient version of InteriorContains() that accepts a S2LatLng rather\n * than an S2Point.\n */\n public interiorContainsLL(ll:S2LatLng):boolean {\n // assert (ll.isValid());\n return (this.lat.interiorContains(ll.latRadians) && this.lng\n .interiorContains(ll.lngRadians));\n }\n\n /**\n * Return true if and only if the rectangle contains the given other\n * rectangle.\n */\n public containsLLR(other:S2LatLngRect):boolean {\n return this.lat.containsI(other.lat) && this.lng.containsI(other.lng);\n }\n\n /**\n * Return true if and only if the interior of this rectangle contains all\n * points of the given other rectangle (including its boundary).\n */\n public interiorContainsLLR(other:S2LatLngRect):boolean {\n return (this.lat.interiorContainsI(other.lat) && this.lng\n .interiorContainsI(other.lng));\n }\n\n /** Return true if this rectangle and the given other rectangle have any\n points in common. */\n public intersectsLLR(other:S2LatLngRect):boolean {\n return this.lat.intersects(other.lat) && this.lng.intersects(other.lng);\n }\n\n /**\n * Returns true if this rectangle intersects the given cell. (This is an exact\n * test and may be fairly expensive, see also MayIntersect below.)\n */\n public intersects(cell:S2Cell):boolean {\n // First we eliminate the cases where one region completely contains the\n // other. Once these are disposed of, then the regions will intersect\n // if and only if their boundaries intersect.\n\n if (this.isEmpty()) {\n return false;\n }\n if (this.containsP(cell.getCenterRaw())) {\n return true;\n }\n if (cell.contains(this.getCenter().toPoint())) {\n return true;\n }\n\n // Quick rejection test (not required for correctness).\n if (!this.intersectsLLR(cell.getRectBound())) {\n return false;\n }\n\n // Now check whether the boundaries intersect. Unfortunately, a\n // latitude-longitude rectangle does not have straight edges -- two edges\n // are curved, and at least one of them is concave.\n\n // Precompute the cell vertices as points and latitude-longitudes.\n const cellV = new Array<S2Point>(4);\n const cellLl = new Array<S2LatLng>(4);\n for (let i = 0; i < 4; ++i) {\n cellV[i] = cell.getVertex(i); // Must be normalized.\n cellLl[i] = S2LatLng.fromPoint(cellV[i]);\n if (this.containsLL(cellLl[i])) {\n return true; // Quick acceptance test.\n }\n }\n\n for (let i = 0; i < 4; ++i) {\n const edgeLng = S1Interval.fromPointPair(\n cellLl[i].lngRadians, cellLl[(i + 1) & 3].lngRadians);\n if (!this.lng.intersects(edgeLng)) {\n continue;\n }\n\n const a = cellV[i];\n const b = cellV[(i + 1) & 3];\n if (edgeLng.contains(this.lng.lo)) {\n if (S2LatLngRect.intersectsLngEdge(a, b, this.lat, this.lng.lo)) {\n return true;\n }\n }\n if (edgeLng.contains(this.lng.hi)) {\n if (S2LatLngRect.intersectsLngEdge(a, b, this.lat, this.lng.hi)) {\n return true;\n }\n }\n if (S2LatLngRect.intersectsLatEdge(a, b, this.lat.lo, this.lng)) {\n return true;\n }\n if (S2LatLngRect.intersectsLatEdge(a, b, this.lat.hi, this.lng)) {\n return true;\n }\n }\n return false;\n }\n\n /**\n * Return true if and only if the interior of this rectangle intersects any\n * point (including the boundary) of the given other rectangle.\n */\n public interiorIntersects(other:S2LatLngRect):boolean {\n return (this.lat.interiorIntersects(other.lat) && this.lng\n .interiorIntersects(other.lng));\n }\n\n public addPoint(p:S2Point):S2LatLngRect {\n return this.addPointLL(S2LatLng.fromPoint(p));\n }\n\n// Increase the size of the bounding rectangle to include the given point.\n// The rectangle is expanded by the minimum amount possible.\n public addPointLL(ll:S2LatLng):S2LatLngRect {\n const newLat = this.lat.addPoint(ll.latRadians);\n const newLng = this.lng.addPoint(ll.lngRadians);\n return new S2LatLngRect(newLat, newLng);\n }\n\n /**\n * Return a rectangle that contains all points whose latitude distance from\n * this rectangle is at most margin.lat, and whose longitude distance from\n * this rectangle is at most margin.lng. In particular, latitudes are\n * clamped while longitudes are wrapped. Note that any expansion of an empty\n * interval remains empty, and both components of the given margin must be\n * non-negative.\n *\n * NOTE: If you are trying to grow a rectangle by a certain *distance* on the\n * sphere (e.g. 5km), use the ConvolveWithCap() method instead.\n */\n public expanded(margin:S2LatLng):S2LatLngRect {\n // assert (margin.latRadians >= 0 && margin.lngRadians >= 0);\n if (this.isEmpty()) {\n return this;\n }\n return new S2LatLngRect(\n this.lat\n .expanded(margin.latRadians)\n .intersection(\n S2LatLngRect.fullLat()\n ),\n this.lng.expanded(margin.lngRadians)\n );\n }\n\n public polarClosure(): S2LatLngRect {\n if (this.lat.lo == -S2.M_PI_2 || this.lat.hi == S2.M_PI_2) {\n return new S2LatLngRect(this.lat, S1Interval.full());\n } else {\n return this;\n }\n }\n\n /**\n * Return the smallest rectangle containing the union of this rectangle and\n * the given rectangle.\n */\n public union(other:S2LatLngRect):S2LatLngRect {\n return new S2LatLngRect(this.lat.union(other.lat), this.lng.union(other.lng));\n }\n\n /**\n * Return the smallest rectangle containing the intersection of this rectangle\n * and the given rectangle. Note that the region of intersection may consist\n * of two disjoint rectangles, in which case a single rectangle spanning both\n * of them is returned.\n */\n public intersection(other:S2LatLngRect):S2LatLngRect {\n const intersectLat = this.lat.intersection(other.lat);\n const intersectLng = this.lng.intersection(other.lng);\n if (intersectLat.isEmpty() || intersectLng.isEmpty()) {\n // The lat/lng ranges must either be both empty or both non-empty.\n return S2LatLngRect.empty();\n }\n return new S2LatLngRect(intersectLat, intersectLng);\n }\n\n//\n// /**\n// * Return a rectangle that contains the convolution of this rectangle with a\n// * cap of the given angle. This expands the rectangle by a fixed distance (as\n// * opposed to growing the rectangle in latitude-longitude space). The returned\n// * rectangle includes all points whose minimum distance to the original\n// * rectangle is at most the given angle.\n// */\n// public S2LatLngRect convolveWithCap(/*S1Angle*/ angle) {\n// // The most straightforward approach is to build a cap centered on each\n// // vertex and take the union of all the bounding rectangles (including the\n// // original rectangle; this is necessary for very large rectangles).\n//\n// // Optimization: convert the angle to a height exactly once.\n// S2Cap cap = S2Cap.fromAxisAngle(new S2Point(1, 0, 0), angle);\n//\n// S2LatLngRect r = this;\n// for (int k = 0; k < 4; ++k) {\n// S2Cap vertexCap = S2Cap.fromAxisHeight(getVertex(k).toPoint(), cap\n// .height());\n// r = r.union(vertexCap.getRectBound());\n// }\n// return r;\n// }\n\n /** Return the surface area of this rectangle on the unit sphere. */\n public area(): number {\n if (this.isEmpty()) {\n return 0;\n }\n\n // This is the size difference of the two spherical caps, multiplied by\n // the longitude ratio.\n //TODO: check if this.lat.hi & this.lat.lo is radians.\n\n return this.lng.getLength() * (Math.sin(this.lat.hi) - Math.abs(Math.sin(this.lat.lo)));\n }\n\n /** Return true if two rectangles contains the same set of points. */\n\n public equals(that: S2LatLngRect):boolean {\n if (!(that instanceof S2LatLngRect)) {\n return false;\n }\n return this.lat.equals(that.lat) && this.lng.equals(that.lng);\n }\n\n /**\n * Return true if the latitude and longitude intervals of the two rectangles\n * are the same up to the given tolerance (see r1interval.h and s1interval.h\n * for details).\n */\n public approxEquals(other:S2LatLngRect, maxError= 1e-15):boolean {\n return (this.lat.approxEquals(other.lat, maxError) && this.lng.approxEquals(\n other.lng, maxError));\n }\n\n// //////////////////////////////////////////////////////////////////////\n// S2Region interface (see {@code S2Region} for details):\n\n\n public clone():S2Region {\n return new S2LatLngRect(this.lat, this.lng);\n }\n\n\n public getCapBound():S2Cap {\n // We consider two possible bounding caps, one whose axis passes through the center of the\n // lat-lng rectangle and one whose axis is the north or south pole. We return the smaller of the\n // two caps.\n if (this.isEmpty()) {\n return S2Cap.empty();\n }\n\n const useSouthPole = this.lat.lo + this.lat.hi < 0;\n const poleZ = useSouthPole ? -1 : 1;\n const poleAngle = useSouthPole ? S2.M_PI_2 + this.lat.hi : S2.M_PI_2 - this.lat.lo;\n const poleCap = S2Cap.fromAxisAngle(new S2Point(0, 0, poleZ), S1Angle.radians(poleAngle));\n\n // For bounding rectangles that span 180 degrees or less in longitude, the maximum cap size is\n // achieved at one of the rectangle vertices. For rectangles that are larger than 180 degrees,\n // we punt and always return a bounding cap centered at one of the two poles.\n const lngSpan = this.lng.hi - this.lng.lo;\n if (Platform.IEEEremainder(lngSpan, 2 * S2.M_PI) >= 0) {\n if (lngSpan < 2 * S2.M_PI) {\n let midCap = S2Cap.fromAxisAngle(this.getCenter().toPoint(), S1Angle.radians(0));\n for (let k = 0; k < 4; ++k) {\n midCap = midCap.addPoint(this.getVertex(k).toPoint());\n }\n if (midCap.height() < poleCap.height()) {\n return midCap;\n }\n }\n }\n return poleCap;\n }\n\n\n public getRectBound():S2LatLngRect {\n return this;\n }\n\n\n public /*boolean*/ containsC(cell:S2Cell):boolean {\n // A latitude-longitude rectangle contains a cell if and only if it contains\n // the cell's bounding rectangle. (This is an exact test.)\n return this.containsLLR(cell.getRectBound());\n }\n\n /**\n * This test is cheap but is NOT exact. Use Intersects() if you want a more\n * accurate and more expensive test. Note that when this method is used by an\n * S2RegionCoverer, the accuracy isn't all that important since if a cell may\n * intersect the region then it is subdivided, and the accuracy of this method\n * goes up as the cells get smaller.\n */\n\n public /*boolean*/ mayIntersectC(cell:S2Cell):boolean {\n // This test is cheap but is NOT exact (see s2latlngrect.h).\n return this.intersectsLLR(cell.getRectBound());\n }\n\n /** The point 'p' does not need to be normalized. */\n public /*boolean*/ containsP(p:S2Point):boolean {\n return this.containsLL(S2LatLng.fromPoint(p));\n }\n\n /**\n * Return true if the edge AB intersects the given edge of constant longitude.\n */\n private static /*boolean*/ intersectsLngEdge(a:S2Point, b:S2Point,\n lat:R1Interval, lng:number) {\n // Return true if the segment AB intersects the given edge of constant\n // longitude. The nice thing about edges of constant longitude is that\n // they are straight lines on the sphere (geodesics).\n\n\n return S2.simpleCrossing(a, b, new S2LatLng(lat.lo, lng)\n .toPoint(), new S2LatLng(lat.hi, lng).toPoint());\n }\n\n /**\n * Return true if the edge AB intersects the given edge of constant latitude.\n */\n private static /*boolean*/ intersectsLatEdge(a:S2Point, b:S2Point, lat:number,\n lng:S1Interval) {\n // Return true if the segment AB intersects the given edge of constant\n // latitude. Unfortunately, lines of constant latitude are curves on\n // the sphere. They can intersect a straight edge in 0, 1, or 2 points.\n // assert (S2.isUnitLength(a) && S2.isUnitLength(b));\n\n // First, compute the normal to the plane AB that points vaguely north.\n let z = S2Point.normalize(S2.robustCrossProd(a, b));\n if (z.z < (0)) {\n z = S2Point.neg(z);\n }\n\n // Extend this to an orthonormal frame (x,y,z) where x is the direction\n // where the great circle through AB achieves its maximium latitude.\n const y = S2Point.normalize(S2.robustCrossProd(z, new S2Point(0, 0, 1)));\n const x = S2Point.crossProd(y, z);\n // assert (S2.isUnitLength(x) && x.z >= 0);\n\n // Compute the angle \"theta\" from the x-axis (in the x-y plane defined\n // above) where the great circle intersects the given line of latitude.\n const sinLat = Math.sin(lat);\n if (Math.abs(sinLat) >= (x.z)) {\n return false; // The great circle does not reach the given latitude.\n }\n // assert (x.z > 0);\n const cosTheta = sinLat / x.z;\n const sinTheta = Math.sqrt(1 - cosTheta * cosTheta);\n const theta = Math.atan2(sinTheta, cosTheta);\n // Math.atan2(sinTheta, cosTheta);\n\n // The candidate intersection points are located +/- theta in the x-y\n // plane. For an intersection to be valid, we need to check that the\n // intersection point is contained in the interior of the edge AB and\n // also that it is contained within the given longitude interval \"lng\".\n\n // Compute the range of theta values spanned by the edge AB.\n const abTheta = S1Interval.fromPointPair(Math.atan2(\n a.dotProd(y), a.dotProd(x)), Math.atan2(b.dotProd(y), b.dotProd(x)));\n\n if (abTheta.contains(theta)) {\n // Check if the intersection point is also in the given \"lng\" interval.\n const isect = S2Point.add(S2Point.mul(x, cosTheta), S2Point.mul(y,\n sinTheta));\n if (lng.contains(Math.atan2(isect.y, isect.x))) {\n return true;\n }\n }\n if (abTheta.contains(theta * -1)) {\n // Check if the intersection point is also in the given \"lng\" interval.\n const intersection = S2Point.sub(S2Point.mul(x, cosTheta), S2Point.mul(y, sinTheta));\n if (lng.contains(Math.atan2(intersection.y, intersection.x))) {\n return true;\n }\n }\n return false;\n\n }\n\n public allVertex() {\n return [\n this.getVertex(0),\n this.getVertex(1),\n this.getVertex(2),\n this.getVertex(3)\n ]\n }\n\n public toGEOJSON() {\n return {\n type: 'Feature',\n geometry: {\n type: 'Polygon',\n coordinates: [this.allVertex().concat(this.getVertex(0)).map(v => [parseFloat(v.lngDegrees.toFixed(5)), parseFloat(v.latDegrees.toFixed(5))])],\n },\n properties: {}\n\n }\n }\n\n public toString():string {\n return \"[Lo=\" + this.lo().toString() + \", Hi=\" + this.hi().toString() + \"]\";\n }\n\n\n}\n","export function checkArgument(condition: boolean, message?: string) {\n if (!condition) {\n throw Error('IllegalArgumentException: ' + (message || ''));\n }\n}\n\nexport function checkState(condition: boolean, message?: string) {\n if (!condition) {\n throw Error('IllegalStateException: ' + (message || ''));\n }\n}","/*\n * Copyright 2014 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n/**\n * S1ChordAngle represents the angle subtended by a chord (i.e., the straight 3D Cartesian line\n * segment connecting two points on the unit sphere). Its representation makes it very efficient for\n * computing and comparing distances, but unlike S1Angle it is only capable of representing angles\n * between 0 and Pi radians. Generally, S1ChordAngle should only be used in loops where many angles\n * need to be calculated and compared. Otherwise it is simpler to use S1Angle.\n *\n * <p>S1ChordAngle also loses some accuracy as the angle approaches Pi radians. Specifically, the\n * representation of (Pi - x) radians can be expected to have an error of about (1e-15 / x), with a\n * maximum error of about 1e-7.\n */\n\nimport { S1Angle } from './S1Angle';\nimport { S2 } from './S2';\nimport { S2Point } from './S2Point';\nimport { checkArgument } from './utils/preconditions';\n\nexport class S1ChordAngle {\n\n /** Max value that can be returned from {@link #getLength2()}. */\n public static MAX_LENGTH2 = 4.0;\n\n /** The zero chord angle. */\n public static ZERO: S1ChordAngle = new S1ChordAngle(0);\n\n /** The chord angle of 90 degrees (a \"right angle\"). */\n public static RIGHT: S1ChordAngle = new S1ChordAngle(2);\n\n /** The chord angle of 180 degrees (a \"straight angle\"). This is the max finite chord angle. */\n public static STRAIGHT: S1ChordAngle = new S1ChordAngle(S1ChordAngle.MAX_LENGTH2);\n\n /**\n * A chord angle larger than any finite chord angle. The only valid operations on {@code INFINITY}\n * are comparisons and {@link S1Angle} conversions.\n */\n public static INFINITY: S1ChordAngle = new S1ChordAngle(Number.POSITIVE_INFINITY);\n\n /**\n * A chord angle smaller than {@link #ZERO}. The only valid operations on {@code NEGATIVE} are\n * comparisons and {@link S1Angle} conversions.\n */\n public static NEGATIVE: S1ChordAngle = new S1ChordAngle(-1);\n\n private length2: number;\n\n /**\n * S1ChordAngles are represented by the squared chord length, which can range from 0 to {@code\n * MAX_LENGTH2}. {@link #INFINITY} uses an infinite squared length.\n */\n public constructor(length2: number) {\n this.length2 = length2;\n checkArgument(this.isValid());\n }\n\n /**\n * Constructs the S1ChordAngle corresponding to the distance between the two given points. The\n * points must be unit length.\n */\n public static fromS2Point(x: S2Point, y: S2Point): S1ChordAngle {\n checkArgument(S2.isUnitLength(x));\n checkArgument(S2.isUnitLength(y));\n // The distance may slightly exceed 4.0 due to roundoff errors.\n const length2 = Math.min(S1ChordAngle.MAX_LENGTH2, x.getDistance2(y));\n return new S1ChordAngle(length2);\n }\n\n /**\n * Returns a new chord angle approximated from {@code angle} (see {@link\n * #getS1AngleConstructorMaxError()} for the max magnitude of the error).\n *\n * <p>Angles outside the range [0, Pi] are handled as follows:\n *\n * <ul>\n * <li>{@link S1Angle#INFINITY} is mapped to {@link #INFINITY}\n * <li>negative angles are mapped to {@link #NEGATIVE}\n * <li>finite angles larger than Pi are mapped to {@link #STRAIGHT}\n * </ul>\n *\n * <p>Note that this operation is relatively expensive and should be avoided. To use {@link\n * S1ChordAngle} effectively, you should structure your code so that input arguments are converted\n * to S1ChordAngles at the beginning of your algorithm, and results are converted back to {@link\n * S1Angle}s only at the end.\n */\n public static fromS1Angle(angle: S1Angle ): S1ChordAngle {\n if (angle.radians < 0) {\n return S1ChordAngle.NEGATIVE;\n } else if (angle.equals(S1Angle.INFINITY)) {\n return S1ChordAngle.INFINITY;\n } else {\n // The chord length is 2 * sin(angle / 2).\n const length = 2 * Math.sin(0.5 * Math.min(Math.PI, angle.radians));\n return new S1ChordAngle(length * length);\n }\n }\n\n /**\n * Construct an S1ChordAngle from the squared chord length. Note that the argument is\n * automatically clamped to a maximum of {@code MAX_LENGTH2} to handle possible roundoff errors.\n * The argument must be non-negative.\n */\n public static fromLength2(length2: number): S1ChordAngle {\n return new S1ChordAngle(Math.min(S1ChordAngle.MAX_LENGTH2, length2));\n }\n\n /** Returns whether the chord distance is exactly 0. */\n public isZero(): boolean {\n return this.length2 == 0;\n }\n\n /** Returns whether the chord distance is negative. */\n public isNegative(): boolean {\n return this.length2 < 0;\n }\n\n /** Returns whether the chord distance is exactly (positive) infinity. */\n public isInfinity(): boolean {\n return this.length2 == Number.POSITIVE_INFINITY;\n }\n\n /** Returns true if the angle is negative or infinity. */\n public isSpecial(): boolean {\n return this.isNegative() || this.isInfinity();\n }\n\n /**\n * Returns true if getLength2() is within the normal range of 0 to 4 (inclusive) or the angle is\n * special.\n */\n public isValid(): boolean {\n return (this.length2 >= 0 && this.length2 <= S1ChordAngle.MAX_LENGTH2) || this.isNegative() || this.isInfinity();\n }\n\n /**\n * Convert the chord angle to an {@link S1Angle}. {@link #INFINITY} is converted to {@link\n * S1Angle#INFINITY}, and {@link #NEGATIVE} is converted to a negative {@link S1Angle}. This\n * operation is relatively expensive.\n */\n public toAngle(): S1Angle {\n if (this.isNegative()) {\n return S1Angle.radians(-1);\n } else if (this.isInfinity()) {\n return S1Angle.INFINITY;\n } else {\n return S1Angle.radians(2 * Math.asin(0.5 * Math.sqrt(this.length2)));\n }\n }\n\n /** The squared length of the chord. (Most clients will not need this.) */\n public getLength2(): number {\n return this.length2;\n }\n\n /**\n * Returns the smallest representable S1ChordAngle larger than this object. This can be used to\n * convert a \"<\" comparison to a \"<=\" comparison.\n *\n * <p>Note the following special cases:\n *\n * <ul>\n * <li>NEGATIVE.successor() == ZERO\n * <li>STRAIGHT.successor() == INFINITY\n * <li>INFINITY.Successor() == INFINITY\n * </ul>\n */\n// public successor(): S1ChordAngle {\n// if (this.length2 >= S1ChordAngle.MAX_LENGTH2) {\n// return S1ChordAngle.INFINITY;\n// }\n// if (this.length2 < 0.0) {\n// return S1ChordAngle.ZERO;\n// }\n// return new S1ChordAngle(Platform.nextAfter(this.length2, 10.0));\n// }\n\n /**\n * As {@link #successor}, but returns the largest representable S1ChordAngle less than this\n * object.\n *\n * <p>Note the following special cases:\n *\n * <ul>\n * <li>INFINITY.predecessor() == STRAIGHT\n * <li>ZERO.predecessor() == NEGATIVE\n * <li>NEGATIVE.predecessor() == NEGATIVE\n * </ul>\n */\n// public predecessor(): S1ChordAngle {\n// if (this.length2 <= 0.0) {\n// return S1ChordAngle.NEGATIVE;\n// }\n// if (this.length2 > S1ChordAngle.MAX_LENGTH2) {\n// return S1ChordAngle.STRAIGHT;\n// }\n// return new S1ChordAngle(Platform.nextAfter(this.length2, -10.0));\n// }\n\n /**\n * Returns a new S1ChordAngle whose chord distance represents the sum of the angular distances\n * represented by the 'a' and 'b' chord angles.\n *\n * <p>Note that this method is much more efficient than converting the chord angles to S1Angles\n * and adding those. It requires only one square root plus a few additions and multiplications.\n */\n public static add(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n checkArgument(!a.isSpecial());\n checkArgument(!b.isSpecial());\n\n // Optimization for the common case where \"b\" is an error tolerance parameter that happens to be\n // set to zero.\n const a2 = a.length2;\n const b2 = b.length2;\n if (b2 == 0) {\n return a;\n }\n\n // Clamp the angle sum to at most 180 degrees.\n if (a2 + b2 >= S1ChordAngle.MAX_LENGTH2) {\n return S1ChordAngle.STRAIGHT;\n }\n\n // Let \"a\" and \"b\" be the (non-squared) chord lengths, and let c = a+b.\n // Let A, B, and C be the corresponding half-angles (a = 2*sin(A), etc).\n // Then the formula below can be derived from c = 2 * sin(A+B) and the relationships\n // sin(A+B) = sin(A)*cos(B) + sin(B)*cos(A)\n // cos(X) = sqrt(1 - sin^2(X)) .\n const x = a2 * (1 - 0.25 * b2); // isValid() => non-negative\n const y = b2 * (1 - 0.25 * a2); // isValid() => non-negative\n return new S1ChordAngle(Math.min(S1ChordAngle.MAX_LENGTH2, x + y + 2 * Math.sqrt(x * y)));\n }\n\n /**\n * Subtract one S1ChordAngle from another.\n *\n * <p>Note that this method is much more efficient than converting the chord angles to S1Angles\n * and adding those. It requires only one square root plus a few additions and multiplications.\n */\n public static sub(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n // See comments in add(S1ChordAngle, S1ChordAngle).\n checkArgument(!a.isSpecial());\n checkArgument(!b.isSpecial());\n const a2 = a.length2;\n const b2 = b.length2;\n if (b2 == 0) {\n return a;\n }\n if (a2 <= b2) {\n return S1ChordAngle.ZERO;\n }\n const x = a2 * (1 - 0.25 * b2);\n const y = b2 * (1 - 0.25 * a2);\n return new S1ChordAngle(Math.max(0.0, x + y - 2 * Math.sqrt(x * y)));\n }\n\n /** Returns the smaller of the given instances. */\n public static min(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n return a.length2 <= b.length2 ? a : b;\n }\n\n /** Returns the larger of the given instances. */\n public static max(a: S1ChordAngle, b: S1ChordAngle): S1ChordAngle {\n return a.length2 > b.length2 ? a : b;\n }\n\n /** Returns the square of Math.sin(toAngle().radians()), but computed more efficiently. */\n public static sin2(a: S1ChordAngle): number {\n checkArgument(!a.isSpecial());\n // Let \"a\" be the (non-squared) chord length, and let A be the corresponding half-angle\n // (a = 2*sin(A)). The formula below can be derived from:\n // sin(2*A) = 2 * sin(A) * cos(A)\n // cos^2(A) = 1 - sin^2(A)\n // This is much faster than converting to an angle and computing its sine.\n return a.length2 * (1 - 0.25 * a.length2);\n }\n\n /** Returns Math.sin(toAngle().radians()), but computed more efficiently. */\n public static sin(a: S1ChordAngle): number {\n return Math.sqrt(this.sin2(a));\n }\n\n /** Returns Math.cos(toAngle().radians()), but computed more efficiently. */\n public static cos(a: S1ChordAngle): number {\n // cos(2*A) = cos^2(A) - sin^2(A) = 1 - 2*sin^2(A)\n checkArgument(!a.isSpecial());\n return 1 - 0.5 * a.length2;\n }\n\n /** Returns Math.tan(toAngle().radians()), but computed more efficiently. */\n public static tan(a: S1ChordAngle): number {\n return this.sin(a) / this.cos(a);\n }\n\n /**\n * Returns a new S1ChordAngle that has been adjusted by the given error bound (which can be\n * positive or negative). {@code error} should be the value returned by one of the error bound\n * methods below. For example:\n *\n * <pre>\n * {@code S1ChordAngle a = new S1ChordAngle(x, y);}\n * {@code S1ChordAngle a1 = a.plusError(a.getS2PointConstructorMaxError());}\n * </pre>\n *\n * <p>If this {@link #isSpecial}, we return {@code this}.\n */\n public plusError(error: number): S1ChordAngle {\n return this.isSpecial() ? this : S1ChordAngle.fromLength2(Math.max(0.0, Math.min(S1ChordAngle.MAX_LENGTH2, this.length2 + error)));\n }\n\n /** Returns the error in {@link #fromS1Angle}. */\n public getS1AngleConstructorMaxError(): number {\n return S2.DBL_EPSILON * this.length2;\n }\n\n /**\n * There is a relative error of {@code 2.5 * DBL_EPSILON} when computing the squared distance,\n * plus a relative error of {@code 2 * DBL_EPSILON} and an absolute error of {@code 16 *\n * DBL_EPSILON^2} because the lengths of the input points may differ from 1 by up to {@code 2 *\n * DBL_EPSILON} each. (This is the maximum length error in {@link S2Point#normalize}).\n */\n public getS2PointConstructorMaxError(): number {\n return (4.5 * S2.DBL_EPSILON * this.length2) + (16 * S2.DBL_EPSILON * S2.DBL_EPSILON);\n }\n\n /** Returns the string of the closest {@link S1Angle} to this chord distance. */\n\n public toString(): string {\n return this.toAngle().toString();\n }\n\n public compareTo(that: S1ChordAngle): number {\n return this.length2 - that.length2\n }\n\n public equals(that: S1ChordAngle): boolean {\n return this.compareTo(that) === 0;\n }\n}","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\nimport {S2Region} from \"./S2Region\";\nimport {S2} from \"./S2\";\nimport {S2Point} from \"./S2Point\";\nimport {S1Angle} from \"./S1Angle\";\nimport {S2LatLngRect} from \"./S2LatLngRect\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {R1Interval} from \"./R1Interval\";\nimport {S1Interval} from \"./S1Interval\";\nimport {S2Cell} from \"./S2Cell\";\nimport {S1ChordAngle} from \"./S1ChordAngle\";\nimport { Platform } from './Platform';\n\n/**\n * This class represents a spherical cap, i.e. a portion of a sphere cut off by\n * a plane. The cap is defined by its axis and height. This representation has\n * good numerical accuracy for very small caps (unlike the (axis,\n * min-distance-from-origin) representation), and is also efficient for\n * containment tests (unlike the (axis, angle) representation).\n *\n * Here are some useful relationships between the cap height (h), the cap\n * opening angle (theta), the maximum chord length from the cap's center (d),\n * and the radius of cap's base (a). All formulas assume a unit radius.\n *\n * h = 1 - cos(theta) = 2 sin^2(theta/2) d^2 = 2 h = a^2 + h^2\n *\n */\nexport class S2Cap implements S2Region {\n\n\n /**\n * Multiply a positive number by this constant to ensure that the result of a\n * floating point operation is at least as large as the true\n * infinite-precision result.\n */\n private static ROUND_UP = 1 / Number(1n << 52n) + 1;\n\n public axis: S2Point;\n public radius: S1ChordAngle;\n\n\n /**\n * Create a cap given its axis and the cap height, i.e. the maximum projected\n * distance along the cap axis from the cap center. 'axis' should be a\n * unit-length vector.\n */\n constructor(axis:S2Point, radius: S1ChordAngle) {\n this.axis = axis;\n this.radius = radius;\n // assert (isValid());\n }\n\n public static fromAxisChord(center: S2Point, radius: S1ChordAngle): S2Cap {\n return new S2Cap(center, radius);\n }\n\n /**\n * Create a cap given its axis and the cap height, i.e. the maximum projected distance along the\n * cap axis from the cap center. 'axis' should be a unit-length vector.\n */\n public static fromAxisHeight(axis: S2Point, height: number): S2Cap {\n // assert (S2.isUnitLength(axis));\n return new S2Cap(axis, S1ChordAngle.fromLength2(2 * height));\n }\n\n /**\n * Create a cap given its axis and the cap opening angle, i.e. maximum angle\n * between the axis and a point on the cap. 'axis' should be a unit-length\n * vector, and 'angle' should be between 0 and 180 degrees.\n */\n public static fromAxisAngle(axis:S2Point, angle:S1Angle): S2Cap {\n // The \"min\" calculation below is necessary to handle S1Angle.INFINITY.\n // assert (S2.isUnitLength(axis));\n\n return this.fromAxisChord(\n axis, S1ChordAngle.fromS1Angle(S1Angle.radians(Math.min(angle.radians, S2.M_PI))));\n }\n\n /**\n * Create a cap given its axis and its area in steradians. 'axis' should be a unit-length vector,\n * and 'area' should be between 0 and 4 * M_PI.\n */\n public static fromAxisArea(axis:S2Point, area:number):S2Cap {\n // assert (S2.isUnitLength(axis));\n return new S2Cap(axis, S1ChordAngle.fromLength2(area / S2.M_PI));\n }\n\n /** Return an empty cap, i.e. a cap that contains no points. */\n public static empty(): S2Cap {\n return new S2Cap(S2Point.X_POS, S1ChordAngle.NEGATIVE);\n }\n\n /** Return a full cap, i.e. a cap that contains all points. */\n public static full(): S2Cap {\n return new S2Cap(S2Point.X_POS, S1ChordAngle.STRAIGHT);\n }\n\n getCapBound():S2Cap {\n return this;\n }\n\n public height(): number {\n return 0.5 * this.radius.getLength2();\n }\n\n public area() {\n return 2 * S2.M_PI * Math.max(0.0, this.height());\n }\n\n /**\n * Returns the cap radius as an S1Angle. Since the cap angle is stored internally as an\n * S1ChordAngle, this method requires a trigonometric operation and may yield a slightly different\n * result than the value passed to {@link #fromAxisAngle(S2Point, S1Angle)}.\n */\n public angle():S1Angle {\n return this.radius.toAngle();\n }\n\n /**\n * Returns true if the axis is {@link S2#isUnitLength unit length}, and the angle is less than Pi.\n *\n * <p>Negative angles or heights are valid, and represent empty caps.\n */\n public isValid():boolean {\n return S2.isUnitLength(this.axis) && this.radius.getLength2() <= 4;\n }\n\n /** Return true if the cap is empty, i.e. it contains no points. */\n public isEmpty():boolean {\n return this.radius.isNegative();\n }\n\n /** Return true if the cap is full, i.e. it contains all points. */\n public isFull():boolean {\n return S1ChordAngle.STRAIGHT.equals(this.radius);\n }\n\n /**\n * Return the complement of the interior of the cap. A cap and its complement have the same\n * boundary but do not share any interior points. The complement operator is not a bijection,\n * since the complement of a singleton cap (containing a single point) is the same as the\n * complement of an empty cap.\n */\n public complement():S2Cap {\n // The complement of a full cap is an empty cap, not a singleton.\n // Also make sure that the complement of an empty cap is full.\n if (this.isFull()) {\n return S2Cap.empty();\n }\n if (this.isEmpty()) {\n return S2Cap.full();\n }\n return S2Cap.fromAxisChord(S2Point.neg(this.axis), S1ChordAngle.fromLength2(4 - this.radius.getLength2()));\n\n }\n\n /**\n * Return true if and only if this cap contains the given other cap (in a set\n * containment sense, e.g. every cap contains the empty cap).\n */\n public containsCap(other:S2Cap):boolean {\n if (this.isFull() || other.isEmpty()) {\n return true;\n } else {\n const axialDistance = S1ChordAngle.fromS2Point(this.axis, other.axis);\n return this.radius.compareTo(S1ChordAngle.add(axialDistance, other.radius)) >= 0;\n }\n }\n\n /**\n * Return true if and only if the interior of this cap intersects the given other cap. (This\n * relationship is not symmetric, since only the interior of this cap is used.)\n */\n public interiorIntersects(other:S2Cap):boolean {\n // Interior(X) intersects Y if and only if Complement(Interior(X))\n // does not contain Y.\n return !this.complement().containsCap(other);\n }\n\n /**\n * Return true if and only if the given point is contained in the interior of the region (i.e. the\n * region excluding its boundary). 'p' should be a unit-length vector.\n */\n public interiorContains(p:S2Point):boolean {\n // assert (S2.isUnitLength(p));\n return this.isFull() || S1ChordAngle.fromS2Point(this.axis, p).compareTo(this.radius) < 0;\n }\n\n /**\n * Increase the cap radius if necessary to include the given point. If the cap is empty the axis\n * is set to the given point, but otherwise it is left unchanged.\n *\n * @param p must be {@link S2#isUnitLength unit length}\n */\n public addPoint(p:S2Point):S2Cap {\n // assert (S2.isUnitLength(p));\n if (this.isEmpty()) {\n return new S2Cap(p, S1ChordAngle.ZERO);\n } else {\n // After adding p to this cap, we require that the result contains p. However we don't need to\n // do anything special to achieve this because contains() does exactly the same distance\n // calculation that we do here.\n return new S2Cap(\n this.axis, S1ChordAngle.fromLength2(Math.max(this.radius.getLength2(), this.axis.getDistance2(p))));\n }\n }\n\n// Increase the cap height if necessary to include \"other\". If the current\n// cap is empty it is set to the given other cap.\n public addCap(other:S2Cap):S2Cap {\n if (this.isEmpty()) {\n return other;\n } else if (other.isEmpty()) {\n return this;\n } else {\n // We round up the distance to ensure that the cap is actually contained.\n // TODO(user): Do some error analysis in order to guarantee this.\n const dist = S1ChordAngle.add(S1ChordAngle.fromS2Point(this.axis, other.axis), other.radius);\n const roundedUp = dist.plusError(S2.DBL_EPSILON * dist.getLength2());\n return new S2Cap(this.axis, S1ChordAngle.max(this.radius, roundedUp));\n }\n }\n\n// //////////////////////////////////////////////////////////////////////\n// S2Region interface (see {@code S2Region} for details):\n public getRectBound():S2LatLngRect {\n if (this.isEmpty()) {\n return S2LatLngRect.empty();\n }\n if (this.isFull()) {\n return S2LatLngRect.full();\n }\n\n // Convert the axis to a (lat,lng) pair, and compute the cap angle.\n const axisLatLng = S2LatLng.fromPoint(this.axis);\n const capAngle = this.angle().radians;\n\n let allLongitudes = false;\n const lat = [];\n const lng = [];\n lng[0] = -S2.M_PI;\n lng[1] = S2.M_PI;\n\n // Check whether cap includes the south pole.\n lat[0] = axisLatLng.lat().radians - capAngle;\n if (lat[0] <= -S2.M_PI_2) {\n lat[0] = -S2.M_PI_2;\n allLongitudes = true;\n }\n // Check whether cap includes the north pole.\n lat[1] = axisLatLng.lat().radians + capAngle;\n if (lat[1] >= S2.M_PI_2) {\n lat[1] = S2.M_PI_2;\n allLongitudes = true;\n }\n if (!allLongitudes) {\n // Compute the range of longitudes covered by the cap. We use the law\n // of sines for spherical triangles. Consider the triangle ABC where\n // A is the north pole, B is the center of the cap, and C is the point\n // of tangency between the cap boundary and a line of longitude. Then\n // C is a right angle, and letting a,b,c denote the sides opposite A,B,C,\n // we have sin(a)/sin(A) = sin(c)/sin(C), or sin(A) = sin(a)/sin(c).\n // Here \"a\" is the cap angle, and \"c\" is the colatitude (90 degrees\n // minus the latitude). This formula also works for negative latitudes.\n const sinA = S1ChordAngle.sin(this.radius);\n const sinC = Math.cos(axisLatLng.lat().radians);\n if (sinA <= sinC) {\n const angleA = Math.asin(sinA / sinC);\n lng[0] = Platform.IEEEremainder(axisLatLng.lng().radians - angleA, 2 * S2.M_PI);\n lng[1] = Platform.IEEEremainder(axisLatLng.lng().radians + angleA, 2 * S2.M_PI);\n }\n }\n return new S2LatLngRect(new R1Interval(lat[0], lat[1]), new S1Interval(lng[0], lng[1]));\n }\n\n // public mayIntersectC(cell:S2Cell):boolean {\n // const toRet = this._mayIntersectC(cell);\n // console.log(\"intersects? \",toRet, cell.id.pos().toString(16), cell.level);\n // return toRet;\n // }\n public mayIntersectC(cell:S2Cell):boolean {\n // If the cap contains any cell vertex, return true.\n const vertices:S2Point[] = new Array(4);\n for (let k = 0; k < 4; ++k) {\n vertices[k] = cell.getVertex(k);\n if (this.contains(vertices[k])) {\n return true;\n }\n }\n return this.intersects(cell, vertices);\n }\n\n /**\n * Return true if the cap intersects 'cell', given that the cap vertices have\n * alrady been checked.\n */\n public intersects(cell:S2Cell, vertices:S2Point[]): boolean {\n // Return true if this cap intersects any point of 'cell' excluding its\n // vertices (which are assumed to already have been checked).\n\n // If the cap is a hemisphere or larger, the cell and the complement of the\n // cap are both convex. Therefore since no vertex of the cell is contained,\n // no other interior point of the cell is contained either.\n if (this.radius.compareTo(S1ChordAngle.RIGHT) >= 0) {\n return false;\n }\n\n // We need to check for empty caps due to the axis check just below.\n if (this.isEmpty()) {\n return false;\n }\n\n // Optimization: return true if the cell contains the cap axis. (This\n // allows half of the edge checks below to be skipped.)\n if (cell.contains(this.axis)) {\n return true;\n }\n\n // At this point we know that the cell does not contain the cap axis,\n // and the cap does not contain any cell vertex. The only way that they\n // can intersect is if the cap intersects the interior of some edge.\n\n const sin2Angle = S1ChordAngle.sin2(this.radius);\n for (let k = 0; k < 4; ++k) {\n const edge = cell.getEdgeRaw(k);\n const dot = this.axis.dotProd(edge);\n if (dot > 0) {\n // The axis is in the interior half-space defined by the edge. We don't\n // need to consider these edges, since if the cap intersects this edge\n // then it also intersects the edge on the opposite side of the cell\n // (because we know the axis is not contained with the cell).\n continue;\n }\n // The Norm2() factor is necessary because \"edge\" is not normalized.\n if (dot * dot > sin2Angle * edge.norm2()) {\n return false; // Entire cap is on the exterior side of this edge.\n }\n // Otherwise, the great circle containing this edge intersects\n // the interior of the cap. We just need to check whether the point\n // of closest approach occurs between the two edge endpoints.\n const dir = S2Point.crossProd(edge, this.axis);\n if (dir.dotProd(vertices[k]) < 0 && dir.dotProd(vertices[(k + 1) & 3]) > 0) {\n return true;\n }\n }\n return false;\n }\n\n public contains(p:S2Point):boolean {\n // The point 'p' should be a unit-length vector.\n // assert (S2.isUnitLength(p));\n return S1ChordAngle.fromS2Point(this.axis, p).compareTo(this.radius) <= 0;\n }\n\n public containsC(cell: S2Cell): boolean {\n // If the cap does not contain all cell vertices, return false.\n // We check the vertices before taking the Complement() because we can't\n // accurately represent the complement of a very small cap (a height\n // of 2-epsilon is rounded off to 2).\n const vertices = [];\n for (let k = 0; k < 4; ++k) {\n vertices[k] = cell.getVertex(k);\n if (!this.contains(vertices[k])) {\n return false;\n }\n }\n // Otherwise, return true if the complement of the cap does not intersect\n // the cell. (This test is slightly conservative, because technically we\n // want Complement().InteriorIntersects() here.)\n return !this.complement().intersects(cell, vertices);\n }\n\n//\n// /** Return true if two caps are identical. */\n// public equals(that:Object ):boolean {\n//\n// if (!(that instanceof S2Cap)) {\n// return false;\n// }\n//\n// S2Cap other = (S2Cap) that;\n// return (this.axis.equals(other.axis) && this.height == other.height)\n// || (isEmpty() && other.isEmpty()) || (isFull() && other.isFull());\n//\n// }\n//\n// @Override\n// public int hashCode() {\n// if (isFull()) {\n// return 17;\n// } else if (isEmpty()) {\n// return 37;\n// }\n// int result = 17;\n// result = 37 * result + this.axis.hashCode();\n// long heightBits = Double.doubleToLongBits(this.height);\n// result = 37 * result + (int) ((heightBits >>> 32) ^ heightBits);\n// return result;\n// }\n\n// /////////////////////////////////////////////////////////////////////\n// The following static methods are convenience functions for assertions\n// and testing purposes only.\n\n /**\n * Return true if the cap axis and height differ by at most \"max_error\" from\n * the given cap \"other\".\n */\n public approxEquals(other:S2Cap, maxError = 1e-14):boolean {\n const r2 = this.radius.getLength2();\n const otherR2 = other.radius.getLength2();\n\n return (S2.approxEqualsPointError(this.axis, other.axis, maxError) && Math.abs(r2 - otherR2) <= maxError)\n || (this.isEmpty() && otherR2 <= maxError)\n || (other.isEmpty() && r2 <= maxError)\n || (this.isFull() && otherR2 >= 2 - maxError)\n || (other.isFull() && r2 >= 2 - maxError);\n }\n\n public toString():string {\n return \"[Point = \" + this.axis + \" Radius = \" + this.radius + \"]\";\n }\n\n public toGEOJSON(){\n return this.getRectBound().toGEOJSON();\n }\n}\n","/**\n * Utility helpers for unsigned 64-bit bigint arithmetic.\n *\n * All values stored in S2CellId.id are guaranteed to be in [0, 2^64-1].\n * Use u64() to mask any operation that can produce an out-of-range value\n * (addition, subtraction, multiplication, shift-left, bitwise-not, negation).\n */\n\n/** Mask a bigint value to the unsigned 64-bit range [0, 2^64-1]. */\nexport function u64(n: bigint): bigint {\n return BigInt.asUintN(64, n);\n}\n\n/** Extract the lower 32 bits as an unsigned JS number [0, 2^32-1]. */\nexport function low32(n: bigint): number {\n return Number(n & 0xFFFF_FFFFn);\n}\n\n/**\n * Extract the lower 32 bits as a signed JS number [-2^31, 2^31-1].\n * Equivalent to Java Long.getLowBits().\n */\nexport function low32s(n: bigint): number {\n return Number(BigInt.asIntN(32, n));\n}\n\n/** Maximum value of a uint64: 2^64 - 1 */\nexport const UINT64_MAX = 0xFFFF_FFFF_FFFF_FFFFn;\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\n\n/**\n * This class specifies the details of how the cube faces are projected onto the\n * unit sphere. This includes getting the face ordering and orientation correct\n * so that sequentially increasing cell ids follow a continuous space-filling\n * curve over the entire sphere, and defining the transformation from cell-space\n * to cube-space (see s2.h) in order to make the cells more uniform in size.\n *\n *\n * We have implemented three different projections from cell-space (s,t) to\n * cube-space (u,v): linear, quadratic, and tangent. They have the following\n * tradeoffs:\n *\n * Linear - This is the fastest transformation, but also produces the least\n * uniform cell sizes. Cell areas vary by a factor of about 5.2, with the\n * largest cells at the center of each face and the smallest cells in the\n * corners.\n *\n * Tangent - Transforming the coordinates via atan() makes the cell sizes more\n * uniform. The areas vary by a maximum ratio of 1.4 as opposed to a maximum\n * ratio of 5.2. However, each call to atan() is about as expensive as all of\n * the other calculations combined when converting from points to cell ids, i.e.\n * it reduces performance by a factor of 3.\n *\n * Quadratic - This is an approximation of the tangent projection that is much\n * faster and produces cells that are almost as uniform in size. It is about 3\n * times faster than the tangent projection for converting cell ids to points,\n * and 2 times faster for converting points to cell ids. Cell areas vary by a\n * maximum ratio of about 2.1.\n *\n * Here is a table comparing the cell uniformity using each projection. \"Area\n * ratio\" is the maximum ratio over all subdivision levels of the largest cell\n * area to the smallest cell area at that level, \"edge ratio\" is the maximum\n * ratio of the longest edge of any cell to the shortest edge of any cell at the\n * same level, and \"diag ratio\" is the ratio of the longest diagonal of any cell\n * to the shortest diagonal of any cell at the same level. \"ToPoint\" and\n * \"FromPoint\" are the times in microseconds required to convert cell ids to and\n * from points (unit vectors) respectively.\n *\n * Area Edge Diag ToPoint FromPoint Ratio Ratio Ratio (microseconds)\n * ------------------------------------------------------- Linear: 5.200 2.117\n * 2.959 0.103 0.123 Tangent: 1.414 1.414 1.704 0.290 0.306 Quadratic: 2.082\n * 1.802 1.932 0.116 0.161\n *\n * The worst-case cell aspect ratios are about the same with all three\n * projections. The maximum ratio of the longest edge to the shortest edge\n * within the same cell is about 1.4 and the maximum ratio of the diagonals\n * within the same cell is about 1.7.\n *\n * This data was produced using s2cell_unittest and s2cellid_unittest.\n *\n */\nimport { S2, S2Metric } from \"./S2\";\nimport { S2CellId } from \"./S2CellId\";\nimport { S2Point } from \"./S2Point\";\nimport { R2Vector } from \"./R2Vector\";\n\n\n\nexport type UvTransformFunction = (x: number, y: number, z: number) => number\nexport type XyzTransformFunction = (u: number, v: number) => number\n\nexport type UvTransform = {\n xyzToU: UvTransformFunction,\n xyzToV: UvTransformFunction\n};\n\nexport type XyzTransform = {\n uvToX: XyzTransformFunction,\n uvToY: XyzTransformFunction,\n uvToZ: XyzTransformFunction,\n}\n\nexport class S2Projections {\n\n public static MIN_WIDTH = new S2Metric(1, 2 * S2.M_SQRT2 / 3); // 0.943\n public static AVG_AREA = new S2Metric(2, 4 * S2.M_PI / 6); // ~2.094\n public static MAX_LEVEL = 30;\n\n private static FACE_UVW_AXES: S2Point[][] = [\n [S2Point.Y_POS, S2Point.Z_POS, S2Point.X_POS],\n [S2Point.X_NEG, S2Point.Z_POS, S2Point.Y_POS],\n [S2Point.X_NEG, S2Point.Y_NEG, S2Point.Z_POS],\n [S2Point.Z_NEG, S2Point.Y_NEG, S2Point.X_NEG],\n [S2Point.Z_NEG, S2Point.X_POS, S2Point.Y_NEG],\n [S2Point.Y_POS, S2Point.X_POS, S2Point.Z_NEG]\n ];\n\n private static UV_TRANSFORMS: UvTransform[] = [\n {\n xyzToU: function xyzToU(x: number, y: number, _z: number) {\n return y / x;\n },\n\n xyzToV: function xyzToV(x: number, _y: number, z: number) {\n return z / x;\n },\n },\n\n {\n xyzToU: function xyzToU(x: number, y: number, _z: number) {\n return -x / y;\n },\n\n xyzToV: function xyzToV(_x: number, y: number, z: number) {\n return z / y;\n },\n },\n\n {\n xyzToU: function xyzToU(x: number, _y: number, z: number) {\n return -x / z;\n },\n\n xyzToV: function xyzToV(_x: number, y: number, z: number) {\n return -y / z;\n },\n },\n\n {\n xyzToU: function xyzToU(x: number, _y: number, z: number) {\n return z / x;\n },\n\n xyzToV: function xyzToV(x: number, y: number, _z: number) {\n return y / x;\n },\n },\n\n {\n xyzToU: function xyzToU(_x: number, y: number, z: number) {\n return z / y;\n },\n\n xyzToV: function xyzToV(x: number, y: number, _z: number) {\n return -x / y;\n },\n },\n\n {\n xyzToU: function xyzToU(_x: number, y: number, z: number) {\n return -y / z;\n },\n\n xyzToV: function xyzToV(x: number, _y: number, z: number) {\n return -x / z;\n },\n }\n ];\n\n private static XYZ_TRANSFORMS: XyzTransform[] = [\n {\n uvToX: function uvToX(_u: number, _v: number): number {\n return 1;\n },\n\n\n uvToY: function uvToY(u: number, _v: number): number {\n return u;\n },\n\n\n uvToZ: function uvToZ(_u: number, v: number): number {\n return v;\n },\n },\n {\n uvToX: function uvToX(u: number, _v: number): number {\n return -u;\n },\n\n\n uvToY: function uvToY(_u: number, _v: number): number {\n return 1;\n },\n\n\n uvToZ: function uvToZ(_u: number, v: number): number {\n return v;\n },\n },\n {\n uvToX: function uvToX(u: number, _v: number): number {\n return -u;\n },\n\n\n uvToY: function uvToY(_u: number, v: number): number {\n return -v;\n },\n\n\n uvToZ: function uvToZ(_u: number, _v: number): number {\n return 1;\n },\n },\n {\n uvToX: function uvToX(_u: number, _v: number): number {\n return -1;\n },\n\n\n uvToY: function uvToY(_u: number, v: number): number {\n return -v;\n },\n\n\n uvToZ: function uvToZ(u: number, _v: number): number {\n return -u;\n },\n },\n {\n uvToX: function uvToX(_u: number, v: number): number {\n return v;\n },\n\n\n uvToY: function uvToY(_u: number, _v: number): number {\n return -1;\n },\n\n\n uvToZ: function uvToZ(u: number, _v: number): number {\n return -u;\n },\n },\n {\n uvToX: function uvToX(_u: number, v: number): number {\n return v;\n },\n\n\n uvToY: function uvToY(u: number, _v: number): number {\n return u;\n },\n\n\n uvToZ: function uvToZ(_u: number, _v: number): number {\n return -1;\n },\n }\n ];\n\n /**\n * The maximum value of an si- or ti-coordinate. The range of valid (si,ti) values is\n * [0..MAX_SiTi].\n */\n public static get MAX_SITI(): bigint {\n return 1n << BigInt(S2Projections.MAX_LEVEL + 1);\n }\n\n public static getUNorm(face: number, u: number): S2Point {\n switch (face) {\n case 0:\n return new S2Point(u, -1, 0);\n case 1:\n return new S2Point(1, u, 0);\n case 2:\n return new S2Point(1, 0, u);\n case 3:\n return new S2Point(-u, 0, 1);\n case 4:\n return new S2Point(0, -u, 1);\n default:\n return new S2Point(0, -1, -u);\n }\n }\n\n public static getVNorm(face: number, v: number): S2Point {\n switch (face) {\n case 0:\n return new S2Point(-v, 0, 1);\n case 1:\n return new S2Point(0, -v, 1);\n case 2:\n return new S2Point(0, -1, -v);\n case 3:\n return new S2Point(v, -1, 0);\n case 4:\n return new S2Point(1, v, 0);\n default:\n return new S2Point(1, 0, v);\n }\n }\n\n public static getUAxis(face: number): S2Point {\n return S2Projections.getUVWAxis(face, 0);\n }\n\n public static getVAxis(face: number): S2Point {\n return S2Projections.getUVWAxis(face, 1);\n }\n\n public static getNorm(face: number): S2Point {\n return S2Projections.getUVWAxis(face, 2);\n }\n\n /** Returns the given axis of the given face (u=0, v=1, w=2). */\n static getUVWAxis(face: number, axis: number): S2Point {\n return S2Projections.FACE_UVW_AXES[face][axis];\n }\n\n /**\n * Convert (face, si, ti) coordinates (see s2.h) to a direction vector (not\n * necessarily unit length).\n */\n public static faceSiTiToXYZ(face: number, si: number, ti: number): S2Point {\n const u = R2Vector.singleStTOUV(this.siTiToSt(si));\n const v = R2Vector.singleStTOUV(this.siTiToSt(ti));\n\n return this.faceUvToXyz(face, u, v)\n }\n\n public static faceUvToXyz(face: number, u: number, v: number): S2Point {\n const t = this.faceToXyzTransform(face)\n return new S2Point(t.uvToX(u, v), t.uvToY(u, v), t.uvToZ(u, v));\n }\n\n public static faceXyzToUv(face: number, p: S2Point): R2Vector {\n if (face < 3) {\n if (p.get(face) <= 0) {\n return null;\n }\n } else {\n if (p.get(face - 3) >= 0) {\n return null;\n }\n }\n return S2Projections.validFaceXyzToUv(face, p);\n }\n\n public static validFaceXyzToUv(face: number, p: S2Point ): R2Vector {\n const t = S2Projections.faceToUvTransform(face);\n return new R2Vector(t.xyzToU(p.x, p.y, p.z), t.xyzToV(p.x, p.y, p.z));\n }\n\n public static ijToStMin(i: number): number {\n // assert (i >= 0 && i <= S2CellId.MAX_SIZE);\n return (1.0 / S2CellId.MAX_SIZE) * i;\n }\n\n public static stToIj(s: number): number {\n return Math.max(\n 0, Math.min(S2CellId.MAX_SIZE - 1, Math.round(S2CellId.MAX_SIZE * s - 0.5)));\n }\n\n public static siTiToSt(si: number): number {\n return 1.0 / Number(this.MAX_SITI) * si;\n }\n\n public static ijToUV(ij: number, cellSize: number): number {\n return R2Vector.singleStTOUV(S2Projections.ijToStMin(ij & -cellSize));\n }\n\n static xyzToFaceP(p: S2Point): number {\n return this.xyzToFace(p.x, p.y, p.z)\n }\n\n static xyzToFace(x: number, y: number, z: number): number {\n switch (S2Point.largestAbsComponent(x, y, z)) {\n case 0:\n return (x < 0) ? 3 : 0;\n case 1:\n return (y < 0) ? 4 : 1;\n default:\n return (z < 0) ? 5 : 2;\n }\n }\n\n public static faceToUvTransform(face: number): UvTransform {\n return S2Projections.UV_TRANSFORMS[face];\n }\n\n public static faceToXyzTransform(face: number): XyzTransform {\n // We map illegal face indices to the largest face index to preserve legacy behavior, i.e., we\n // do not (yet) want to throw an index out of bounds exception. Note that S2CellId.face() is\n // guaranteed to return a non-negative face index even for invalid S2 cells, so it is sufficient\n // to just map all face indices greater than 5 to a face index of 5.\n //\n // TODO(bjj): Remove this legacy behavior.\n return S2Projections.XYZ_TRANSFORMS[Math.min(5, face)];\n }\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { u64, low32s, UINT64_MAX } from './uint64';\nimport { S2Point } from \"./S2Point\";\nimport { R2Vector } from \"./R2Vector\";\nimport { S2 } from \"./S2\";\nimport { MutableInteger } from \"./MutableInteger\";\nimport { S2LatLng } from \"./S2LatLng\";\nimport { S2Projections, UvTransform } from './S2Projections';\n\n/**\n * An S2CellId is a 64-bit unsigned integer that uniquely identifies a cell in\n * the S2 cell decomposition. It has the following format:\n *\n * <pre>\n * id = [face][face_pos]\n * </pre>\n *\n * face: a 3-bit number (range 0..5) encoding the cube face.\n *\n * face_pos: a 61-bit number encoding the position of the center of this cell\n * along the Hilbert curve over this face (see the Wiki pages for details).\n *\n * Sequentially increasing cell ids follow a continuous space-filling curve over\n * the entire sphere. They have the following properties:\n * - The id of a cell at level k consists of a 3-bit face number followed by k\n * bit pairs that recursively select one of the four children of each cell. The\n * next bit is always 1, and all other bits are 0. Therefore, the level of a\n * cell is determined by the position of its lowest-numbered bit that is turned\n * on (for a cell at level k, this position is 2 * (MAX_LEVEL - k).)\n * - The id of a parent cell is at the midpoint of the range of ids spanned by\n * its children (or by its descendants at any level).\n *\n * Leaf cells are often used to represent points on the unit sphere, and this\n * class provides methods for converting directly between these two\n * representations. For cells that represent 2D regions rather than discrete\n * point, it is better to use the S2Cell class.\n *\n * v4 CHANGE: S2CellId.id is now a native bigint (unsigned uint64).\n * The constructor accepts bigint, string (signed or unsigned decimal), or number.\n */\nexport class S2CellId {\n\n // Although only 60 bits are needed to represent the index of a leaf\n // cell, we need an extra bit in order to represent the position of\n // the center of the leaf cell along the Hilbert curve.\n public static FACE_BITS = 3;\n public static NUM_FACES = 6;\n public static MAX_LEVEL = 30; // Valid levels: 0..MAX_LEVEL\n /**\n * The number of bits used by a position along the Hilbert curve over all\n * faces (range 1..2*MAX_LEVEL+1). This is a fixed constant encoding the\n * canonical 64-bit S2 cell ID layout; it must NEVER be derived from a\n * mutable MAX_LEVEL.\n */\n public static readonly POS_BITS = 2 * 30 + 1; // = 61\n /**\n * The maximum coordinate value for an (i,j) cell index. Equal to 2^30.\n * Fixed constant matching the 30-level S2 grid.\n */\n public static readonly MAX_SIZE = 1 << 30; // = 1073741824\n\n /** Maximum unsigned 64-bit value (sentinel). */\n public static MAX_UNSIGNED: bigint = UINT64_MAX;\n\n // The following lookup tables are used to convert efficiently between an\n // (i,j) cell index and the corresponding position along the Hilbert curve.\n public static LOOKUP_BITS = 4;\n private static SWAP_MASK = 0x01;\n private static INVERT_MASK = 0x02;\n\n private static I_SHIFT = 33;\n private static J_SHIFT = 2;\n\n private static J_MASK = (1n << 31n) - 1n; // 2^31 - 1\n\n private static SI_SHIFT = 32;\n private static ORIENTATION_MASK = 3n;\n\n private static TI_MASK = 0xFFFF_FFFFn; // lower 32 bits\n\n /** LOOKUP_POS[10-bit key] = 10-bit value (stored as bigint) */\n public static LOOKUP_POS: bigint[] = [];\n /** LOOKUP_IJ[10-bit key] = 10-bit value */\n public static LOOKUP_IJ: number[] = [];\n\n /**\n * This is the offset required to wrap around from the beginning of the\n * Hilbert curve to the end or vice versa; see next_wrap() and prev_wrap().\n */\n /**\n * Precomputed wrap offset. Fixed constant; must not be derived from a\n * mutable POS_BITS.\n */\n private static readonly WRAP_OFFSET: bigint =\n BigInt(S2CellId.NUM_FACES) << BigInt(S2CellId.POS_BITS);\n\n /**\n * The 64-bit unsigned cell ID.\n * v4: changed from Long to bigint. Always in [0, 2^64-1].\n */\n public id: bigint;\n\n /**\n * Construct an S2CellId from a bigint, decimal string, or number.\n *\n * The string may be signed (\"-6533045114107854848\") or unsigned\n * (\"11913698959601696768\"); both are handled via BigInt.asUintN(64, ...).\n *\n * Numbers must be finite integers within the safe-integer range\n * (|n| ≤ Number.MAX_SAFE_INTEGER = 2^53 − 1). Values outside that range\n * may have silently lost precision in JS before reaching this constructor,\n * so a RangeError is thrown. Use a bigint literal for large cell IDs\n * (e.g. `-9182983676231680000n`).\n *\n * @throws {TypeError} if `id` is a non-integer or non-finite number.\n * @throws {RangeError} if `id` exceeds safe-integer precision (> 2^53 − 1).\n */\n constructor(id: bigint | string | number) {\n if (typeof id === 'string') {\n // BigInt() parses the signed decimal, asUintN reinterprets as unsigned.\n this.id = BigInt.asUintN(64, BigInt(id));\n } else if (typeof id === 'number') {\n if (!Number.isInteger(id) || !isFinite(id)) {\n throw new TypeError(`S2CellId: non-integer or non-finite number: ${id}`);\n }\n if (!Number.isSafeInteger(id)) {\n throw new RangeError(\n `S2CellId: number ${id} exceeds safe integer precision (> 2^53). ` +\n `Use a bigint literal instead, e.g. ${BigInt(id)}n`\n );\n }\n this.id = BigInt.asUintN(64, BigInt(id));\n } else {\n this.id = BigInt.asUintN(64, id);\n }\n }\n\n // -------------------------------------------------------------------------\n // Migration helpers (v3 → v4 compatibility)\n // -------------------------------------------------------------------------\n\n /**\n * Construct an S2CellId from a **signed**-decimal string produced by Java's\n * Long.toString() or the v3 Long-based API. Equivalent to `new S2CellId(s)`\n * but makes the intent explicit.\n *\n * @example\n * S2CellId.fromSignedDecimalString('-6533045114107854848')\n */\n public static fromSignedDecimalString(s: string): S2CellId {\n return new S2CellId(BigInt.asUintN(64, BigInt(s)));\n }\n\n /**\n * Return this cell id as a signed-decimal string, matching the output of\n * Java's Long.toString() and the v3 Long-based API.\n *\n * @example\n * cellId.toSignedDecimalString() // '-6533045114107854848'\n */\n public toSignedDecimalString(): string {\n return BigInt.asIntN(64, this.id).toString();\n }\n\n /**\n * Return this cell id as an unsigned-decimal string (same as `this.id.toString()`).\n *\n * @example\n * cellId.toUnsignedDecimalString() // '11913698959601696768'\n */\n public toUnsignedDecimalString(): string {\n return this.id.toString();\n }\n\n // -------------------------------------------------------------------------\n // Core geometry\n // -------------------------------------------------------------------------\n\n /** Which cube face this cell belongs to, in the range 0..5. */\n get face(): number {\n return Number(this.id >> BigInt(S2CellId.POS_BITS));\n }\n\n /** Return the lowest-numbered bit that is on for this cell. */\n public lowestOnBit(): bigint {\n return S2CellId.lowestOnBit(this.id);\n }\n\n static lowestOnBit(id: bigint): bigint {\n // id & (-id) using two's-complement unsigned arithmetic\n return id & u64(-id);\n }\n\n /** Return an invalid cell id (id == 0). */\n public static none(): S2CellId {\n return new S2CellId(0n);\n }\n\n /**\n * Returns an invalid cell id guaranteed to be larger than any valid cell id.\n * Useful for creating indexes.\n */\n public static sentinel(): S2CellId {\n return new S2CellId(UINT64_MAX);\n }\n\n private getBits1(\n i: MutableInteger,\n j: MutableInteger,\n k: number,\n bits: number,\n ): number {\n const nbits =\n k === 7\n ? S2CellId.MAX_LEVEL - 7 * S2CellId.LOOKUP_BITS\n : S2CellId.LOOKUP_BITS;\n\n const shift = k * 2 * S2CellId.LOOKUP_BITS + 1;\n const mask = (1 << (2 * nbits)) - 1;\n bits += (Number((this.id >> BigInt(shift)) & BigInt(mask))) << 2;\n\n bits = S2CellId.LOOKUP_IJ[bits];\n i.val =\n i.val +\n ((bits >> (S2CellId.LOOKUP_BITS + 2)) << (k * S2CellId.LOOKUP_BITS));\n j.val =\n j.val +\n (((bits >> 2) & ((1 << S2CellId.LOOKUP_BITS) - 1)) <<\n (k * S2CellId.LOOKUP_BITS));\n\n bits &= S2.SWAP_MASK | S2.INVERT_MASK;\n return bits;\n }\n\n /** Return the lowest-numbered bit that is on for cells at the given level. */\n public static lowestOnBitForLevel(level: number): bigint {\n return 1n << BigInt(2 * (S2CellId.MAX_LEVEL - level));\n }\n\n /**\n * @deprecated use `toIJOrientation` instead\n */\n public toFaceIJOrientation(\n pi: MutableInteger,\n pj: MutableInteger,\n orientation: MutableInteger,\n ): number {\n const face = this.face;\n let bits = face & S2.SWAP_MASK;\n\n for (let k = 7; k >= 0; --k) {\n bits = this.getBits1(pi, pj, k, bits);\n }\n\n if (orientation != null) {\n if ((0x1111111111111110n & this.lowestOnBit()) !== 0n) {\n bits ^= S2.SWAP_MASK;\n }\n orientation.val = bits;\n }\n return face;\n }\n\n /**\n * Return a packed bigint encoding (i << I_SHIFT | j << J_SHIFT | orientation).\n * Use getI(), getJ(), getOrientation() to unpack.\n */\n public toIJOrientation(): bigint {\n const face = this.face;\n let bits = face & S2.SWAP_MASK;\n\n let i = 0;\n let j = 0;\n for (let k = 7; k >= 0; --k) {\n const nbits =\n k === 7\n ? S2CellId.MAX_LEVEL - 7 * S2CellId.LOOKUP_BITS\n : S2CellId.LOOKUP_BITS;\n\n const shift = k * 2 * S2CellId.LOOKUP_BITS + 1;\n const mask = (1 << (2 * nbits)) - 1;\n bits += (Number((this.id >> BigInt(shift)) & BigInt(mask))) << 2;\n\n bits = S2CellId.LOOKUP_IJ[bits];\n i += (bits >> (S2CellId.LOOKUP_BITS + 2)) << (k * S2CellId.LOOKUP_BITS);\n j +=\n ((bits >> 2) & ((1 << S2CellId.LOOKUP_BITS) - 1)) <<\n (k * S2CellId.LOOKUP_BITS);\n\n bits &= S2.SWAP_MASK | S2.INVERT_MASK;\n }\n\n if ((0x1111111111111110n & this.lowestOnBit()) !== 0n) {\n bits ^= S2.SWAP_MASK;\n }\n\n const orientation = bits;\n return (\n (BigInt(i) << BigInt(S2CellId.I_SHIFT)) |\n (BigInt(j) << BigInt(S2CellId.J_SHIFT)) |\n BigInt(orientation)\n );\n }\n\n public getI(): number {\n return S2CellId.getI(this.toIJOrientation());\n }\n\n static getI(ijo: bigint): number {\n return Number(ijo >> BigInt(S2CellId.I_SHIFT));\n }\n\n public getJ(): number {\n return S2CellId.getJ(this.toIJOrientation());\n }\n\n static getJ(ijo: bigint): number {\n return Number((ijo >> BigInt(S2CellId.J_SHIFT)) & S2CellId.J_MASK);\n }\n\n static getOrientation(ijo: bigint): number {\n return Number(ijo & S2CellId.ORIENTATION_MASK);\n }\n\n /** Return true if this is a leaf cell (level() == MAX_LEVEL). */\n public isLeaf(): boolean {\n return (this.id & 1n) !== 0n;\n }\n\n /**\n * Return the cell at the given level (which must be ≤ the current level).\n */\n public parentL(level: number): S2CellId {\n const newLsb = S2CellId.lowestOnBitForLevel(level);\n return new S2CellId((this.id & u64(-newLsb)) | newLsb);\n }\n\n public parent(): S2CellId {\n const oldLsb = this.lowestOnBit();\n const newLsb = oldLsb << 2n;\n return new S2CellId((this.id & u64(-newLsb)) | newLsb);\n }\n\n /**\n * Return a cell given its face (range 0..5), 61-bit Hilbert curve position\n * within that face, and level (range 0..MAX_LEVEL).\n *\n * v4: `pos` is now `bigint` (was `Long`).\n */\n public static fromFacePosLevel(\n face: number,\n pos: bigint,\n level: number,\n ): S2CellId {\n return new S2CellId(\n (BigInt(face) << BigInt(S2CellId.POS_BITS)) + (pos | 1n),\n ).parentL(level);\n }\n\n public static fromFace(face: number): S2CellId {\n return new S2CellId(S2CellId.fromFaceAsBigInt(face));\n }\n\n public static fromPoint(p: S2Point): S2CellId {\n const face = S2Projections.xyzToFaceP(p);\n const t: UvTransform = S2Projections.faceToUvTransform(face);\n const i = S2Projections.stToIj(\n R2Vector.singleUVToST(t.xyzToU(p.x, p.y, p.z)),\n );\n const j = S2Projections.stToIj(\n R2Vector.singleUVToST(t.xyzToV(p.x, p.y, p.z)),\n );\n return this.fromFaceIJ(face, i, j);\n }\n\n public getCenterUV(): R2Vector {\n const center = this.getCenterSiTi();\n return new R2Vector(\n R2Vector.singleStTOUV(\n S2Projections.siTiToSt(S2CellId.getSi(center)),\n ),\n R2Vector.singleStTOUV(\n S2Projections.siTiToSt(S2CellId.getTi(center)),\n ),\n );\n }\n\n public toPoint(): S2Point {\n return S2Point.normalize(this.toPointRaw());\n }\n\n /**\n * Returns packed (si << 32 | ti) as a bigint.\n * v4: return type changed from Long to bigint.\n */\n getCenterSiTi(): bigint {\n const ijo = this.toIJOrientation();\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n const delta = this.isLeaf()\n ? 1\n : ((i ^ (low32s(this.id) >>> 2)) & 1) !== 0\n ? 2\n : 0;\n\n return (\n (BigInt(2 * i + delta) << BigInt(S2CellId.SI_SHIFT)) |\n (S2CellId.TI_MASK & BigInt(2 * j + delta))\n );\n }\n\n static getSi(center: bigint): number {\n return Number(center >> BigInt(S2CellId.SI_SHIFT));\n }\n\n static getTi(center: bigint): number {\n return Number(center & S2CellId.TI_MASK);\n }\n\n public toPointRaw(): S2Point {\n const center = this.getCenterSiTi();\n return S2Projections.faceSiTiToXYZ(\n this.face,\n S2CellId.getSi(center),\n S2CellId.getTi(center),\n );\n }\n\n public toLatLng(): S2LatLng {\n return S2LatLng.fromPoint(this.toPointRaw());\n }\n\n /** Return true if id() represents a valid cell. */\n public isValid(): boolean {\n return (\n this.face < S2CellId.NUM_FACES &&\n (this.lowestOnBit() & 0x1555555555555555n) !== 0n\n );\n }\n\n /**\n * The position of the cell center along the Hilbert curve over this face,\n * in the range 0..(2**kPosBits-1).\n *\n * v4: return type changed from Long to bigint.\n */\n public pos(): bigint {\n return this.id & (UINT64_MAX >> BigInt(S2CellId.FACE_BITS));\n }\n\n /** Return the subdivision level of the cell (range 0..MAX_LEVEL). */\n public level(): number {\n if (this.isLeaf()) {\n return S2CellId.MAX_LEVEL;\n }\n // Fast path using lower 32 bits\n let x = low32s(this.id); // signed 32-bit lower half (equiv. to Java getLowBits())\n let level = -1;\n if (x !== 0) {\n level += 16;\n } else {\n x = low32s(this.id >> 32n);\n }\n // We only need to look at even-numbered bits to determine the level.\n x &= -x; // isolate lowest set bit\n if ((x & 0x00005555) !== 0) {\n level += 8;\n }\n if ((x & 0x00550055) !== 0) {\n level += 4;\n }\n if ((x & 0x05050505) !== 0) {\n level += 2;\n }\n if ((x & 0x11111111) !== 0) {\n level += 1;\n }\n return level;\n }\n\n public getSizeIJ(): number {\n return S2CellId.getSizeIJ(this.level());\n }\n\n static getSizeIJ(level: number): number {\n return 1 << (S2.MAX_LEVEL - level);\n }\n\n public getSizeST(): number {\n return S2CellId.getSizeST(this.level());\n }\n\n static getSizeST(level: number): number {\n return S2Projections.ijToStMin(S2CellId.getSizeIJ(level));\n }\n\n public isFace(): boolean {\n return this.level() === 0;\n }\n\n public childPosition(level: number): number {\n return Number(\n (this.id >> BigInt(2 * (S2CellId.MAX_LEVEL - level) + 1)) & 3n,\n );\n }\n\n public rangeMin(): S2CellId {\n // id - (lowestOnBit() - 1)\n return new S2CellId(u64(this.id - this.lowestOnBit() + 1n));\n }\n\n public rangeMax(): S2CellId {\n // id + (lowestOnBit() - 1)\n return new S2CellId(this.id + this.lowestOnBit() - 1n);\n }\n\n public contains(other: S2CellId): boolean {\n return (\n other.greaterOrEquals(this.rangeMin()) &&\n other.lessOrEquals(this.rangeMax())\n );\n }\n\n public intersects(other: S2CellId): boolean {\n return (\n other.rangeMin().lessOrEquals(this.rangeMax()) &&\n other.rangeMax().greaterOrEquals(this.rangeMin())\n );\n }\n\n public childBegin(): S2CellId {\n return new S2CellId(S2CellId.childBeginAsBigInt(this.id));\n }\n\n public childBeginL(level: number): S2CellId {\n return new S2CellId(S2CellId.childBeginAsBigIntL(this.id, level));\n }\n\n public childEnd(): S2CellId {\n return new S2CellId(S2CellId.childEndAsBigInt(this.id));\n }\n\n public childEndL(level: number): S2CellId {\n return new S2CellId(S2CellId.childEndAsBigIntL(this.id, level));\n }\n\n private static childBeginAsBigInt(id: bigint): bigint {\n const oldLsb = S2CellId.lowestOnBit(id);\n return u64(id - oldLsb + (oldLsb >> 2n));\n }\n\n private static childBeginAsBigIntL(id: bigint, level: number): bigint {\n return u64(\n id - S2CellId.lowestOnBit(id) + S2CellId.lowestOnBitForLevel(level),\n );\n }\n\n private static childEndAsBigInt(id: bigint): bigint {\n const oldLsb = S2CellId.lowestOnBit(id);\n return u64(id + oldLsb + (oldLsb >> 2n));\n }\n\n private static childEndAsBigIntL(id: bigint, level: number): bigint {\n return u64(\n id + S2CellId.lowestOnBit(id) + S2CellId.lowestOnBitForLevel(level),\n );\n }\n\n private static fromFaceAsBigInt(face: number): bigint {\n return (\n (BigInt(face) << BigInt(S2CellId.POS_BITS)) +\n S2CellId.lowestOnBitForLevel(0)\n );\n }\n\n /** Return the next cell at the same level along the Hilbert curve. */\n public next(): S2CellId {\n return new S2CellId(u64(this.id + (this.lowestOnBit() << 1n)));\n }\n\n /** Return the previous cell at the same level along the Hilbert curve. */\n public prev(): S2CellId {\n return new S2CellId(u64(this.id - (this.lowestOnBit() << 1n)));\n }\n\n public nextWrap(): S2CellId {\n const n = this.next();\n if (n.id < S2CellId.WRAP_OFFSET) {\n return n;\n }\n return new S2CellId(u64(n.id - S2CellId.WRAP_OFFSET));\n }\n\n public prevWrap(): S2CellId {\n const p = this.prev();\n if (p.id < S2CellId.WRAP_OFFSET) {\n return p;\n }\n return new S2CellId(p.id + S2CellId.WRAP_OFFSET);\n }\n\n static begin(level: number): S2CellId {\n return S2CellId.fromFacePosLevel(0, 0n, 0).childBeginL(level);\n }\n\n static end(level: number): S2CellId {\n return S2CellId.fromFacePosLevel(5, 0n, 0).childEndL(level);\n }\n\n /**\n * Decodes a cell id from a compact hex token string.\n * The maximum token length is 16 hex characters.\n */\n public static fromToken(token: string): S2CellId {\n if (token == null) {\n throw new Error('Null string in S2CellId.fromToken');\n }\n if (token.length === 0) {\n throw new Error('Empty string in S2CellId.fromToken');\n }\n if (token.length > 16 || token === 'X') {\n return S2CellId.none();\n }\n // Pad with trailing zeros to 16 hex chars, then parse as 64-bit unsigned.\n const padded = token.padEnd(16, '0');\n return new S2CellId(BigInt('0x' + padded));\n }\n\n /**\n * Encodes the cell id to a compact hex token string.\n * Cells at lower levels are encoded into fewer characters.\n */\n public toToken(): string {\n if (this.id === 0n) {\n return 'X';\n }\n const hex = this.id.toString(16).padStart(16, '0');\n let len = 16;\n while (len > 0 && hex[len - 1] === '0') {\n len--;\n }\n return hex.substring(0, len);\n }\n\n public getEdgeNeighbors(): S2CellId[] {\n const level = this.level();\n const size = this.getSizeIJ();\n const face = this.face;\n\n const ijo = this.toIJOrientation();\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n\n return [\n S2CellId.fromFaceIJSame(face, i, j - size, j - size >= 0).parentL(\n level,\n ),\n S2CellId.fromFaceIJSame(\n face,\n i + size,\n j,\n i + size < S2CellId.MAX_SIZE,\n ).parentL(level),\n S2CellId.fromFaceIJSame(\n face,\n i,\n j + size,\n j + size < S2CellId.MAX_SIZE,\n ).parentL(level),\n S2CellId.fromFaceIJSame(face, i - size, j, i - size >= 0).parentL(\n level,\n ),\n ];\n }\n\n public getVertexNeighbors(level: number): S2CellId[] {\n const ijo = this.toIJOrientation();\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n\n const halfsize = S2CellId.getSizeIJ(level + 1);\n const size = halfsize << 1;\n let isame: boolean, jsame: boolean;\n let ioffset: number, joffset: number;\n\n if ((i & halfsize) !== 0) {\n ioffset = size;\n isame = i + size < S2CellId.MAX_SIZE;\n } else {\n ioffset = -size;\n isame = i - size >= 0;\n }\n if ((j & halfsize) !== 0) {\n joffset = size;\n jsame = j + size < S2CellId.MAX_SIZE;\n } else {\n joffset = -size;\n jsame = j - size >= 0;\n }\n\n const face = this.face;\n const toRet: S2CellId[] = [this.parentL(level)];\n toRet.push(\n S2CellId.fromFaceIJSame(face, i + ioffset, j, isame).parentL(level),\n );\n toRet.push(\n S2CellId.fromFaceIJSame(face, i, j + joffset, jsame).parentL(level),\n );\n if (isame || jsame) {\n toRet.push(\n S2CellId.fromFaceIJSame(\n face,\n i + ioffset,\n j + joffset,\n isame && jsame,\n ).parentL(level),\n );\n }\n return toRet;\n }\n\n public getAllNeighbors(nbrLevel: number): S2CellId[] {\n const ijo = this.toIJOrientation();\n\n const size = this.getSizeIJ();\n const face = this.face;\n const i = S2CellId.getI(ijo) & -size;\n const j = S2CellId.getJ(ijo) & -size;\n\n const nbrSize = S2CellId.getSizeIJ(nbrLevel);\n\n const output: S2CellId[] = [];\n for (let k = -nbrSize; ; k += nbrSize) {\n let sameFace: boolean;\n if (k < 0) {\n sameFace = j + k >= 0;\n } else if (k >= size) {\n sameFace = j + k < S2CellId.MAX_SIZE;\n } else {\n sameFace = true;\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i + k,\n j - nbrSize,\n j - size >= 0,\n ).parentL(nbrLevel),\n );\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i + k,\n j + size,\n j + size < S2CellId.MAX_SIZE,\n ).parentL(nbrLevel),\n );\n }\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i - nbrSize,\n j + k,\n sameFace && i - size >= 0,\n ).parentL(nbrLevel),\n );\n output.push(\n S2CellId.fromFaceIJSame(\n face,\n i + size,\n j + k,\n sameFace && i + size < S2CellId.MAX_SIZE,\n ).parentL(nbrLevel),\n );\n if (k >= size) {\n break;\n }\n }\n return output;\n }\n\n // ///////////////////////////////////////////////////////////////////\n // Low-level methods.\n\n public static fromFaceIJ(face: number, i: number, j: number): S2CellId {\n // n[1] holds the high 32 bits, n[0] holds the low 32 bits.\n const n: bigint[] = [0n, BigInt(face) << BigInt(S2CellId.POS_BITS - 33)];\n\n let bits = face & S2CellId.SWAP_MASK;\n\n for (let k = 7; k >= 0; --k) {\n bits = S2CellId.getBits(n, i, j, k, bits);\n }\n\n // Combine halves, shift left 1, set leaf bit.\n return new S2CellId(((n[1] << 32n) | n[0]) << 1n | 1n);\n }\n\n private static getBits(\n n: bigint[],\n i: number,\n j: number,\n k: number,\n bits: number,\n ): number {\n const mask = (1 << S2CellId.LOOKUP_BITS) - 1; // 15\n bits += ((i >> (k * S2CellId.LOOKUP_BITS)) & mask) << (S2CellId.LOOKUP_BITS + 2);\n bits += ((j >> (k * S2CellId.LOOKUP_BITS)) & mask) << 2;\n\n const lookupBits = S2CellId.LOOKUP_POS[bits]; // bigint\n n[k >> 2] =\n n[k >> 2] |\n ((lookupBits >> 2n) <<\n BigInt((k & 3) * 2 * S2CellId.LOOKUP_BITS));\n\n return Number(lookupBits) & (S2CellId.SWAP_MASK | S2CellId.INVERT_MASK);\n }\n\n private static stToIJ(s: number): number {\n const m = S2CellId.MAX_SIZE / 2;\n return Math.max(0, Math.min(m * 2 - 1, Math.round(m * s + m - 0.5)));\n }\n\n private static fromFaceIJWrap(face: number, i: number, j: number): S2CellId {\n i = Math.max(-1, Math.min(S2CellId.MAX_SIZE, i));\n j = Math.max(-1, Math.min(S2CellId.MAX_SIZE, j));\n\n const kScale = 1 / S2CellId.MAX_SIZE;\n // Plain number arithmetic: values fit in 32-bit int\n const s = kScale * (2 * i + 1 - S2CellId.MAX_SIZE);\n const t = kScale * (2 * j + 1 - S2CellId.MAX_SIZE);\n\n const p = new R2Vector(s, t).toPoint(face);\n face = p.toFace();\n const st = p.toR2Vector(face);\n return S2CellId.fromFaceIJ(\n face,\n S2CellId.stToIJ(st.x),\n S2CellId.stToIJ(st.y),\n );\n }\n\n public static fromFaceIJSame(\n face: number,\n i: number,\n j: number,\n sameFace: boolean,\n ): S2CellId {\n return sameFace\n ? S2CellId.fromFaceIJ(face, i, j)\n : S2CellId.fromFaceIJWrap(face, i, j);\n }\n\n // -------------------------------------------------------------------------\n // Unsigned comparison helpers (trivial now that bigint is always positive)\n // -------------------------------------------------------------------------\n\n /** Returns true if x1 < x2 (unsigned comparison). */\n public static unsignedLongLessThan(x1: bigint, x2: bigint): boolean {\n return x1 < x2;\n }\n\n /** Returns true if x1 > x2 (unsigned comparison). */\n public static unsignedLongGreaterThan(x1: bigint, x2: bigint): boolean {\n return x1 > x2;\n }\n\n public lessThan(x: S2CellId): boolean {\n return this.id < x.id;\n }\n\n public greaterThan(x: S2CellId): boolean {\n return this.id > x.id;\n }\n\n public lessOrEquals(x: S2CellId): boolean {\n return this.id <= x.id;\n }\n\n public greaterOrEquals(x: S2CellId): boolean {\n return this.id >= x.id;\n }\n\n public toString(): string {\n return (\n '(face=' +\n this.face +\n ', pos=' +\n this.pos().toString(16) +\n ', level=' +\n this.level() +\n ')'\n );\n }\n\n public compareTo(that: S2CellId): number {\n return this.id < that.id ? -1 : this.id > that.id ? 1 : 0;\n }\n\n public equals(that: S2CellId): boolean {\n return this.id === that.id;\n }\n\n /**\n * Binary search in a sorted S2CellId array.\n * Returns index if found, or -(insertionPoint+1) if not found.\n *\n * v4: `_id` accepts bigint, string, number, or S2CellId (was Long, string, or S2CellId).\n */\n public static binarySearch(\n ids: S2CellId[],\n _id: bigint | string | number | S2CellId,\n low = 0,\n ): number {\n let id: S2CellId;\n if (_id instanceof S2CellId) {\n id = _id;\n } else {\n id = new S2CellId(_id as bigint | string | number);\n }\n let high = ids.length - 1;\n\n while (low <= high) {\n const mid = (low + high) >>> 1;\n const midVal = ids[mid];\n const cmp = midVal.compareTo(id);\n\n if (cmp < 0) low = mid + 1;\n else if (cmp > 0) high = mid - 1;\n else return mid;\n }\n return -(low + 1);\n }\n\n public static indexedBinarySearch(\n ids: S2CellId[],\n id: bigint | string | number | S2CellId,\n low = 0,\n ): number {\n const toRet = this.binarySearch(ids, id, low);\n return toRet >= 0 ? toRet : -(toRet + 1);\n }\n}\n\n// -------------------------------------------------------------------------\n// Lookup table initialisation\n// -------------------------------------------------------------------------\n\nfunction initLookupCell(\n level: number,\n i: number,\n j: number,\n origOrientation: number,\n pos: bigint,\n orientation: number,\n): void {\n if (level === S2CellId.LOOKUP_BITS) {\n const ij = (i << S2CellId.LOOKUP_BITS) + j;\n S2CellId.LOOKUP_POS[(ij << 2) + origOrientation] =\n (pos << 2n) + BigInt(orientation);\n S2CellId.LOOKUP_IJ[Number((pos << 2n) + BigInt(origOrientation))] =\n (ij << 2) + orientation;\n } else {\n level++;\n i <<= 1;\n j <<= 1;\n pos = pos << 2n;\n for (let subPos = 0; subPos < 4; subPos++) {\n const ij = S2.POS_TO_IJ[orientation][subPos];\n const orientationMask = S2.POS_TO_ORIENTATION[subPos];\n initLookupCell(\n level,\n i + (ij >>> 1),\n j + (ij & 1),\n origOrientation,\n pos + BigInt(subPos),\n orientation ^ orientationMask,\n );\n }\n }\n}\n\ninitLookupCell(0, 0, 0, 0, 0n, 0);\ninitLookupCell(0, 0, 0, S2.SWAP_MASK, 0n, S2.SWAP_MASK);\ninitLookupCell(0, 0, 0, S2.INVERT_MASK, 0n, S2.INVERT_MASK);\ninitLookupCell(\n 0,\n 0,\n 0,\n S2.SWAP_MASK | S2.INVERT_MASK,\n 0n,\n S2.SWAP_MASK | S2.INVERT_MASK,\n);\n","/**\n * Transitional utilities for consumers migrating from nodes2-ts v3 (Long-based API)\n * to v4 (bigint-based API).\n *\n * These helpers make it easy to work with signed-decimal cell ID strings that\n * older code or Java S2 libraries produce (e.g. \"-6533045114107854848\") alongside\n * the new unsigned bigint representation.\n */\n\nimport { S2CellId } from './S2CellId';\n\n/**\n * Convert a signed-decimal string (as produced by Java's Long.toString()) to an\n * unsigned 64-bit bigint.\n *\n * @example\n * signedDecimalToUnsigned('-6533045114107854848')\n * // => 11913698959601696768n\n */\nexport function signedDecimalToUnsigned(s: string): bigint {\n return BigInt.asUintN(64, BigInt(s));\n}\n\n/**\n * Convert an unsigned 64-bit bigint back to a signed-decimal string, as Java's\n * Long.toString() would produce.\n *\n * @example\n * unsignedToSignedDecimal(11913698959601696768n)\n * // => '-6533045114107854848'\n */\nexport function unsignedToSignedDecimal(id: bigint): string {\n return BigInt.asIntN(64, id).toString();\n}\n\n/**\n * Convenience: convert a signed-decimal S2 cell ID string (from Java) to its\n * token representation.\n *\n * @example\n * signedDecimalTokenMap('-6533045114107854848')\n * // => 'a555f6151'\n */\nexport function signedDecimalTokenMap(signedId: string): string {\n return new S2CellId(signedDecimalToUnsigned(signedId)).toToken();\n}\n","export class MutableInteger {\n\n constructor(public val:number) {\n }\n}","import {S2CellId} from \"./S2CellId\";\nimport {S2Point} from \"./S2Point\";\nimport {S2LatLng} from \"./S2LatLng\";\nimport {S2Projections} from \"./S2Projections\";\nimport {R2Vector} from \"./R2Vector\";\nimport {S2} from \"./S2\";\nimport {S2LatLngRect} from \"./S2LatLngRect\";\nimport {R1Interval} from \"./R1Interval\";\nimport {S1Interval} from \"./S1Interval\";\nimport {S2Cap} from \"./S2Cap\";\nexport class S2Cell {\n public static get MAX_CELL_SIZE(): number {\n return 1 << S2CellId.MAX_LEVEL;\n }\n\n private _face:number;\n private _level:number;\n private _orientation:number;\n\n private uMin: number;\n private uMax: number;\n private vMin: number;\n private vMax: number;\n\n constructor(private cellID?:S2CellId) {\n if (cellID != null) {\n this.init(cellID)\n }\n }\n\n get id():S2CellId {\n return this.cellID;\n }\n\n\n public static fromFace(face: number): S2Cell {\n return new S2Cell(S2CellId.fromFace(face));\n }\n\n// This is a static method in order to provide named parameters.\n public static fromFacePosLevel(face:number, pos:number, level:number):S2Cell {\n return new S2Cell(S2CellId.fromFacePosLevel(face, BigInt(pos), level));\n }\n\n// Convenience methods.\n public static fromPoint(p:S2Point):S2Cell {\n return new S2Cell(S2CellId.fromPoint(p))\n }\n\n public static fromLatLng(ll:S2LatLng):S2Cell {\n return new S2Cell(S2CellId.fromPoint(ll.toPoint()));\n }\n\n\n public isLeaf():boolean {\n return this._level == S2CellId.MAX_LEVEL;\n }\n\n public getVertex(k:number):S2Point {\n return S2Point.normalize(this.getVertexRaw(k));\n }\n\n /**\n * Return the k-th vertex of the cell (k = 0,1,2,3). Vertices are returned in\n * CCW order. The points returned by GetVertexRaw are not necessarily unit\n * length.\n */\n public getVertexRaw(k:number):S2Point {\n // Vertices are returned in the order SW, SE, NE, NW.\n return S2Projections.faceUvToXyz(\n this._face, ((k >> 1) ^ (k & 1)) == 0 ? this.uMin : this.uMax, (k >> 1) == 0 ? this.vMin : this.vMax);\n }\n\n public getEdge(k:number):S2Point {\n return S2Point.normalize(this.getEdgeRaw(k));\n }\n\n public getEdgeRaw(k:number):S2Point {\n switch (k) {\n case 0:\n return S2Projections.getVNorm(this._face, this.vMin); // South\n case 1:\n return S2Projections.getUNorm(this._face, this.uMax); // East\n case 2:\n return S2Point.neg(S2Projections.getVNorm(this._face, this.vMax)); // North\n default:\n return S2Point.neg(S2Projections.getUNorm(this._face, this.uMin)); // West\n }\n }\n\n\n /**\n * Return the inward-facing normal of the great circle passing through the\n * edge from vertex k to vertex k+1 (mod 4). The normals returned by\n * GetEdgeRaw are not necessarily unit length.\n *\n * If this is not a leaf cell, set children[0..3] to the four children of\n * this cell (in traversal order) and return true. Otherwise returns false.\n * This method is equivalent to the following:\n *\n * for (pos=0, id=child_begin(); id != child_end(); id = id.next(), ++pos)\n * children[i] = S2Cell(id);\n *\n * except that it is more than two times faster.\n */\n public subdivide():S2Cell[] {\n // This function is equivalent to just iterating over the child cell ids\n // and calling the S2Cell constructor, but it is about 2.5 times faster.\n\n if (this.id.isLeaf()) {\n return null;\n }\n \n const children:S2Cell[] = new Array(4);\n for (let i = 0; i < 4; ++i) {\n children[i] = new S2Cell();\n }\n\n // Create four children with the appropriate bounds.\n let id = this.id.childBegin();\n const mid = this.getCenterUV();\n const uMid = mid.x;\n const vMid = mid.y;\n\n for (let pos = 0; pos < 4; ++pos, id = id.next()) {\n const child = children[pos];\n child._face = this.face;\n child._level = this.level + 1;\n child._orientation = this.orientation ^ S2.POS_TO_ORIENTATION[pos];\n child.cellID = id;\n // We want to split the cell in half in \"u\" and \"v\". To decide which\n // side to set equal to the midpoint value, we look at cell's (i,j)\n // position within its parent. The index for \"i\" is in bit 1 of ij.\n const ij = S2.POS_TO_IJ[this.orientation][pos];\n // The dimension 0 index (i/u) is in bit 1 of ij.\n if ((ij & 0x2) != 0) {\n child.uMin = uMid;\n child.uMax = this.uMax;\n } else {\n child.uMin = this.uMin;\n child.uMax = uMid;\n }\n // The dimension 1 index (j/v) is in bit 0 of ij.\n if ((ij & 0x1) != 0) {\n child.vMin = vMid;\n child.vMax = this.vMax;\n } else {\n child.vMin = this.vMin;\n child.vMax = vMid;\n }\n }\n return children;\n }\n\n /**\n * Return the direction vector corresponding to the center in (s,t)-space of\n * the given cell. This is the point at which the cell is divided into four\n * subcells; it is not necessarily the centroid of the cell in (u,v)-space or\n * (x,y,z)-space. The point returned by GetCenterRaw is not necessarily unit\n * length.\n */\n public getCenter():S2Point {\n return S2Point.normalize(this.getCenterRaw());\n }\n\n public getCenterRaw():S2Point {\n return this.cellID.toPointRaw();\n }\n\n /**\n * Return the center of the cell in (u,v) coordinates (see {@code\n * S2Projections}). Note that the center of the cell is defined as the point\n * at which it is recursively subdivided into four children; in general, it is\n * not at the midpoint of the (u,v) rectangle covered by the cell\n */\n public getCenterUV():R2Vector {\n return this.cellID.getCenterUV();\n }\n\n /**\n * Return the average area of cells at this level. This is accurate to within\n * a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to\n * compute.\n */\n public static averageArea(level):number {\n return S2Projections.AVG_AREA.getValue(level);\n }\n\n /**\n * Return the average area of cells at this level. This is accurate to within\n * a factor of 1.7 (for S2_QUADRATIC_PROJECTION) and is extremely cheap to\n * compute.\n */\n public averageArea():number {\n return S2Projections.AVG_AREA.getValue(this._level);\n }\n\n /**\n * Return the approximate area of this cell. This method is accurate to within\n * 3% percent for all cell sizes and accurate to within 0.1% for cells at\n * level 5 or higher (i.e. 300km square or smaller). It is moderately cheap to\n * compute.\n */\n public approxArea():number {\n\n // All cells at the first two levels have the same area.\n if (this._level < 2) {\n return this.averageArea();\n }\n\n // First, compute the approximate area of the cell when projected\n // perpendicular to its normal. The cross product of its diagonals gives\n // the normal, and the length of the normal is twice the projected area.\n const flatArea = S2Point.crossProd(\n S2Point.sub(this.getVertex(2), this.getVertex(0)),\n S2Point.sub(this.getVertex(3), this.getVertex(1))\n ).norm() * 0.5;\n // double flatArea = 0.5 * S2Point.crossProd(\n // S2Point.sub(getVertex(2), getVertex(0)), S2Point.sub(getVertex(3), getVertex(1))).norm();\n\n // Now, compensate for the curvature of the cell surface by pretending\n // that the cell is shaped like a spherical cap. The ratio of the\n // area of a spherical cap to the area of its projected disc turns out\n // to be 2 / (1 + sqrt(1 - r*r)) where \"r\" is the radius of the disc.\n // For example, when r=0 the ratio is 1, and when r=1 the ratio is 2.\n // Here we set Pi*r*r == flat_area to find the equivalent disc.\n return flatArea *2 / (Math.sqrt((Math.min(flatArea * S2.M_1_PI, 1) * -1)+1)+1);\n }\n\n//\n// /**\n// * Return the area of this cell as accurately as possible. This method is more\n// * expensive but it is accurate to 6 digits of precision even for leaf cells\n// * (whose area is approximately 1e-18).\n// */\n public exactArea() {\n const v0 = this.getVertex(0);\n const v1 = this.getVertex(1);\n const v2 = this.getVertex(2);\n const v3 = this.getVertex(3);\n return S2.area(v0, v1, v2) + (S2.area(v0, v2, v3));\n }\n\n// //////////////////////////////////////////////////////////////////////\n// S2Region interface (see {@code S2Region} for details):\n\n\n public getCapBound():S2Cap {\n // Use the cell center in (u,v)-space as the cap axis. This vector is\n // very close to GetCenter() and faster to compute. Neither one of these\n // vectors yields the bounding cap with minimal surface area, but they\n // are both pretty close.\n //\n // It's possible to show that the two vertices that are furthest from\n // the (u,v)-origin never determine the maximum cap size (this is a\n // possible future optimization).\n const uv = this.getCenterUV();\n const center = S2Point.normalize(S2Projections.faceUvToXyz(this._face, uv.x, uv.y));\n let cap = S2Cap.fromAxisHeight(center, 0);\n for (let k = 0; k < 4; ++k) {\n cap = cap.addPoint(this.getVertex(k));\n }\n return cap;\n }\n\n// We grow the bounds slightly to make sure that the bounding rectangle\n// also contains the normalized versions of the vertices. Note that the\n// maximum result magnitude is Pi, with a floating-point exponent of 1.\n// Therefore adding or subtracting 2**-51 will always change the result.\n// private static MAX_ERROR = S2.toDecimal(1.0).dividedBy(S2.toDecimal(new Long(1).shiftLeft(51).toString()));\n private static MAX_ERROR = 1 / Number(1n << 51n);\n\n// The 4 cells around the equator extend to +/-45 degrees latitude at the\n// midpoints of their top and bottom edges. The two cells covering the\n// poles extend down to +/-35.26 degrees at their vertices.\n// adding kMaxError (as opposed to the C version) because of asin and atan2\n// roundoff errors\n private static POLE_MIN_LAT = Math.asin(Math.sqrt(1/3)) - S2Cell.MAX_ERROR;\n// 35.26 degrees\n\n\n private getPoint(i: number, j: number): S2Point {\n return S2Projections.faceUvToXyz(this._face, i == 0 ? this.uMin : this.uMax, j == 0 ? this.vMin : this.vMax);\n }\n\n public getRectBound():S2LatLngRect {\n if (this._level > 0) {\n // Except for cells at level 0, the latitude and longitude extremes are\n // attained at the vertices. Furthermore, the latitude range is\n // determined by one pair of diagonally opposite vertices and the\n // longitude range is determined by the other pair.\n //\n // We first determine which corner (i,j) of the cell has the largest\n // absolute latitude. To maximize latitude, we want to find the point in\n // the cell that has the largest absolute z-coordinate and the smallest\n // absolute x- and y-coordinates. To do this we look at each coordinate\n // (u and v), and determine whether we want to minimize or maximize that\n // coordinate based on the axis direction and the cell's (u,v) quadrant.\n const u = this.uMin + this.uMax;\n const v = this.vMin + this.vMax;\n const i = S2Projections.getUAxis(this._face).z == 0 ? (u < 0 ? 1 : 0) : (u > 0 ? 1 : 0);\n const j = S2Projections.getVAxis(this._face).z == 0 ? (v < 0 ? 1 : 0) : (v > 0 ? 1 : 0);\n\n const lat = R1Interval.fromPointPair(\n S2LatLng.latitude(this.getPoint(i, j)).radians,\n S2LatLng.latitude(this.getPoint(1 - i, 1 - j)).radians);\n \n const lng = S1Interval.fromPointPair(\n S2LatLng.longitude(this.getPoint(i, 1 - j)).radians,\n S2LatLng.longitude(this.getPoint(1 - i, j)).radians);\n\n \n // DBL_EPSILON\n return new S2LatLngRect(lat, lng)\n .expanded(S2LatLng.fromRadians(S2.DBL_EPSILON, S2.DBL_EPSILON))\n .polarClosure();\n }\n\n\n // The face centers are the +X, +Y, +Z, -X, -Y, -Z axes in that order.\n // assert (S2Projections.getNorm(face).get(face % 3) == ((face < 3) ? 1 : -1));\n switch (this._face) {\n case 0:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(-S2.M_PI_4, S2.M_PI_4));\n case 1:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(S2.M_PI_4, 3 * S2.M_PI_4));\n case 2:\n return new S2LatLngRect(\n new R1Interval(S2Cell.POLE_MIN_LAT, S2.M_PI_2), new S1Interval(-S2.M_PI, S2.M_PI));\n case 3:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(3 * S2.M_PI_4, -3 * S2.M_PI_4));\n case 4:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_4, S2.M_PI_4), new S1Interval(-3 * S2.M_PI_4, -S2.M_PI_4));\n default:\n return new S2LatLngRect(\n new R1Interval(-S2.M_PI_2, -S2Cell.POLE_MIN_LAT), new S1Interval(-S2.M_PI, S2.M_PI));\n }\n\n }\n\n\n public mayIntersectC(cell:S2Cell):boolean {\n return this.cellID.intersects(cell.cellID);\n }\n\n public contains(p:S2Point):boolean {\n // We can't just call XYZtoFaceUV, because for points that lie on the\n // boundary between two faces (i.e. u or v is +1/-1) we need to return\n // true for both adjacent cells.\n\n const uvPoint = S2Projections.faceXyzToUv(this._face, p);\n if (uvPoint == null) {\n return false;\n }\n return (uvPoint.x >= this.uMin\n && uvPoint.x <= this.uMax\n && uvPoint.y >= this.vMin\n && uvPoint.y <= this.vMax);\n }\n\n// The point 'p' does not need to be normalized.\n\n public containsC(cell:S2Cell):boolean {\n return this.cellID.contains(cell.cellID);\n }\n\n private init(id:S2CellId) {\n this.cellID = id;\n this._face = id.face\n\n const ijo = id.toIJOrientation();\n\n this._orientation = S2CellId.getOrientation(ijo);\n this._level = id.level();\n\n const i = S2CellId.getI(ijo);\n const j = S2CellId.getJ(ijo);\n const cellSize = id.getSizeIJ();\n\n this.uMin = S2Projections.ijToUV(i, cellSize);\n this.uMax = S2Projections.ijToUV(i + cellSize, cellSize);\n this.vMin = S2Projections.ijToUV(j, cellSize);\n this.vMax = S2Projections.ijToUV(j + cellSize, cellSize);\n\n // for (let d = 0; d < 2; ++d) {\n // // Compute the cell bounds in scaled (i,j) coordinates.\n // const sijLo = (ij[d].val & -cellSize) * 2 - S2Cell.MAX_CELL_SIZE;\n // const sijHi = sijLo + cellSize * 2;\n\n // const s = 1/S2Cell.MAX_CELL_SIZE;\n // this._uv[d][0] = R2Vector.singleStTOUV(s * (sijLo))\n // //S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * sijLo);\n // this._uv[d][1] = R2Vector.singleStTOUV(s * (sijHi));\n // //S2Projections.stToUV((1.0 / S2Cell.MAX_CELL_SIZE) * sijHi);\n // }\n }\n\n get face(): number {\n return this._face;\n }\n\n get orientation(): number {\n return this._orientation;\n }\n\n get level(): number {\n return this._level;\n }\n\n\n// Return the latitude or longitude of the cell vertex given by (i,j),\n// where \"i\" and \"j\" are either 0 or 1.\n\n public toString():string {\n return \"[\" + this._face + \", \" + this._level + \", \" + this.orientation + \", \" + this.cellID + \"]\";\n }\n\n public toGEOJSON() {\n const coords = [this.getVertex(0),this.getVertex(1),this.getVertex(2),this.getVertex(3),this.getVertex(0)]\n .map(v => S2LatLng.fromPoint(v))\n .map(v => ([v.lngDegrees, v.latDegrees]))\n\n // const rectJSON = this.getRectBound().toGEOJSON();\n return {\n type: 'Feature',\n geometry: {\n type:'Polygon',\n coordinates: [coords]\n },\n properties: {},\n title: `Cell: ${this.id.toToken()} lvl: ${this._level}`\n };\n // rectJSON.title = `Cell: ${this.id.toToken()}`;\n // return rectJSON;\n }\n\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\nimport { u64 } from './uint64';\nimport { S2Region } from \"./S2Region\";\nimport { S2CellId } from \"./S2CellId\";\nimport { S2Cell } from \"./S2Cell\";\nimport { S1Angle } from \"./S1Angle\";\nimport { S2Projections } from \"./S2Projections\";\nimport { S2LatLngRect } from \"./S2LatLngRect\";\nimport { S2Point } from \"./S2Point\";\nimport { S2Cap } from \"./S2Cap\";\nimport { S1ChordAngle } from './S1ChordAngle';\n\n/**\n * An S2CellUnion is a region consisting of cells of various sizes.\n */\nexport class S2CellUnion implements S2Region {\n\n /** The CellIds that form the Union */\n private cellIds: S2CellId[] = [];\n\n /**\n * Populates a cell union with the given S2CellIds or 64-bit cell ids, and\n * then calls Normalize().\n *\n * v4: `cellIds` accepts `bigint[] | string[] | number[]` (was `Long[] | string[]`).\n */\n public initFromIds(cellIds: bigint[] | string[] | number[]) {\n this.initRawIds(cellIds);\n this.normalize();\n }\n\n public initFromCellIds(cellIds: S2CellId[]) {\n this.initRawCellIds(cellIds);\n this.normalize();\n }\n\n public initSwap(cellIds: S2CellId[]) {\n this.initRawSwap(cellIds);\n this.normalize();\n }\n\n public initRawCellIds(cellIds: S2CellId[]) {\n this.cellIds = cellIds;\n }\n\n public initRawIds(cellIds: bigint[] | string[] | number[]) {\n const size = cellIds.length;\n this.cellIds = [];\n for (let i = 0; i < size; i++) {\n this.cellIds.push(new S2CellId(cellIds[i] as bigint | string | number));\n }\n }\n\n public initRawSwap(cellIds: S2CellId[]) {\n this.cellIds = [].concat(cellIds);\n }\n\n public size(): number {\n return this.cellIds.length;\n }\n\n public cellId(i: number): S2CellId {\n return this.cellIds[i];\n }\n\n public getCellIds(): S2CellId[] {\n return this.cellIds;\n }\n\n public denormalize(minLevel: number, levelMod: number): S2CellId[] {\n const output: S2CellId[] = [];\n for (let i = 0; i < this.cellIds.length; i++) {\n const id = this.cellIds[i];\n const level = id.level();\n let newLevel = Math.max(minLevel, level);\n if (levelMod > 1) {\n newLevel += (S2CellId.MAX_LEVEL - (newLevel - minLevel)) % levelMod;\n newLevel = Math.min(S2CellId.MAX_LEVEL, newLevel);\n }\n if (newLevel === level) {\n output.push(id);\n } else {\n const end = id.childEndL(newLevel);\n for (\n let iid = id.childBeginL(newLevel);\n !iid.equals(end);\n iid = iid.next()\n ) {\n output.push(iid);\n }\n }\n }\n return output;\n }\n\n public pack() {\n throw new Error('useless');\n }\n\n containsC(cell: S2Cell): boolean {\n return this.containsCell(cell);\n }\n\n mayIntersectC(cell: S2Cell): boolean {\n return this.mayIntersectCell(cell);\n }\n\n public contains(id: S2CellId): boolean {\n let pos = S2CellId.binarySearch(this.cellIds, id.id);\n if (pos < 0) {\n pos = -pos - 1;\n }\n if (pos < this.cellIds.length && this.cellIds[pos].rangeMin().lessOrEquals(id)) {\n return true;\n }\n return pos !== 0 && this.cellIds[pos - 1].rangeMax().greaterOrEquals(id);\n }\n\n public intersects(id: S2CellId): boolean {\n let pos = S2CellId.binarySearch(this.cellIds, id.id);\n if (pos < 0) {\n pos = -pos - 1;\n }\n if (\n pos < this.cellIds.length &&\n this.cellIds[pos].rangeMin().lessOrEquals(id.rangeMax())\n ) {\n return true;\n }\n return (\n pos !== 0 && this.cellIds[pos - 1].rangeMax().greaterOrEquals(id.rangeMin())\n );\n }\n\n public containsUnion(that: S2CellUnion): boolean {\n for (let i = 0; i < that.cellIds.length; i++) {\n if (!this.contains(that.cellIds[i])) {\n return false;\n }\n }\n return true;\n }\n\n public containsCell(cell: S2Cell): boolean {\n return this.contains(cell.id);\n }\n\n public intersectsUnion(that: S2CellUnion): boolean {\n for (let i = 0; i < that.cellIds.length; i++) {\n if (this.intersects(that.cellIds[i])) {\n return true;\n }\n }\n return false;\n }\n\n public getUnion(x: S2CellUnion, y: S2CellUnion) {\n this.cellIds = [].concat(x.cellIds).concat(y.cellIds);\n this.normalize();\n }\n\n public getIntersection(x: S2CellUnion, id: S2CellId) {\n this.cellIds = [];\n if (x.contains(id)) {\n this.cellIds.push(id);\n } else {\n let pos = S2CellId.binarySearch(x.cellIds, id.rangeMin().id);\n if (pos < 0) {\n pos = -pos - 1;\n }\n const idmax = id.rangeMax();\n const size = x.cellIds.length;\n while (pos < size && x.cellIds[pos].lessOrEquals(idmax)) {\n this.cellIds.push(x.cellIds[pos++]);\n }\n }\n }\n\n public getIntersectionUU(x: S2CellUnion, y: S2CellUnion) {\n this.cellIds = [];\n\n let i = 0;\n let j = 0;\n\n while (i < x.cellIds.length && j < y.cellIds.length) {\n const imin = x.cellId(i).rangeMin();\n const jmin = y.cellId(j).rangeMin();\n\n if (imin.greaterThan(jmin)) {\n if (x.cellId(i).lessOrEquals(y.cellId(j).rangeMax())) {\n this.cellIds.push(x.cellId(i++));\n } else {\n j = S2CellId.indexedBinarySearch(y.cellIds, imin, j + 1);\n if (x.cellId(i).lessOrEquals(y.cellId(j - 1).rangeMax())) {\n --j;\n }\n }\n } else if (jmin.greaterThan(imin)) {\n if (y.cellId(j).lessOrEquals(x.cellId(i).rangeMax())) {\n this.cellIds.push(y.cellId(j++));\n } else {\n i = S2CellId.indexedBinarySearch(x.cellIds, jmin, i + 1);\n if (y.cellId(j).lessOrEquals(x.cellId(i - 1).rangeMax())) {\n --i;\n }\n }\n } else {\n if (x.cellId(i).lessThan(y.cellId(j))) {\n this.cellIds.push(x.cellId(i++));\n } else {\n this.cellIds.push(y.cellId(j++));\n }\n }\n }\n }\n\n public expand(level: number) {\n let output: S2CellId[] = [];\n const levelLsb = S2CellId.lowestOnBitForLevel(level); // bigint\n\n let i = this.size() - 1;\n do {\n let id = this.cellId(i);\n if (id.lowestOnBit() < levelLsb) {\n id = id.parentL(level);\n while (i > 0 && id.contains(this.cellId(i - 1))) {\n --i;\n }\n }\n output.push(id);\n output = output.concat(id.getAllNeighbors(level));\n } while (--i >= 0);\n this.initSwap(output);\n }\n\n public expandA(minRadius: S1Angle, maxLevelDiff: number) {\n let minLevel = S2CellId.MAX_LEVEL;\n for (let i = 0; i < this.cellIds.length; i++) {\n minLevel = Math.min(minLevel, this.cellId(i).level());\n }\n const radiusLevel = S2Projections.MIN_WIDTH.getMaxLevel(minRadius.radians);\n if (\n radiusLevel === 0 &&\n minRadius.radians > S2Projections.MIN_WIDTH.getValue(0)\n ) {\n this.expand(0);\n }\n this.expand(Math.min(minLevel + maxLevelDiff, radiusLevel));\n }\n\n public getCapBound(): S2Cap {\n if (this.cellIds.length === 0) {\n return S2Cap.empty();\n }\n let centroid = new S2Point(0, 0, 0);\n this.cellIds.forEach(id => {\n const area = S2Cell.averageArea(id.level());\n centroid = S2Point.add(centroid, S2Point.mul(id.toPoint(), area));\n });\n\n if (centroid.equals(S2Point.ORIGIN)) {\n centroid = S2Point.X_POS;\n } else {\n centroid = S2Point.normalize(centroid);\n }\n\n let cap = S2Cap.fromAxisChord(centroid, S1ChordAngle.ZERO);\n this.cellIds.forEach(id => {\n cap = cap.addCap(new S2Cell(id).getCapBound());\n });\n return cap;\n }\n\n public getRectBound(): S2LatLngRect {\n let bound = S2LatLngRect.empty();\n this.cellIds.forEach(id => {\n bound = bound.union(new S2Cell(id).getRectBound());\n });\n return bound;\n }\n\n public mayIntersectCell(cell: S2Cell): boolean {\n return this.intersects(cell.id);\n }\n\n public containsPoint(p: S2Point): boolean {\n return this.contains(S2CellId.fromPoint(p));\n }\n\n /**\n * The number of leaf cells covered by the union.\n *\n * v4: return type changed from Long to bigint.\n */\n public leafCellsCovered(): bigint {\n let numLeaves = 0n;\n this.cellIds.forEach((id: S2CellId) => {\n const invertedLevel = S2CellId.MAX_LEVEL - id.level();\n numLeaves += 1n << BigInt(invertedLevel << 1);\n });\n return numLeaves;\n }\n\n /**\n * Approximate area by summing the average area of each contained cell.\n *\n * v4: uses Number(bigint) instead of Long.toNumber().\n */\n public averageBasedArea(): number {\n return (\n Number(this.leafCellsCovered()) *\n S2Projections.AVG_AREA.getValue(S2CellId.MAX_LEVEL)\n );\n }\n\n public approxArea(): number {\n let area = 0;\n this.cellIds.forEach(id => {\n area += new S2Cell(id).approxArea();\n });\n return area;\n }\n\n public exactArea(): number {\n let area = 0;\n this.cellIds.forEach(id => {\n area += new S2Cell(id).exactArea();\n });\n return area;\n }\n\n public normalize(): boolean {\n const output: S2CellId[] = [];\n\n this.cellIds.sort((a, b) => a.compareTo(b));\n\n this.cellIds.forEach(id => {\n let size = output.length;\n if (output.length !== 0 && output[size - 1].contains(id)) {\n return;\n }\n\n while (\n output.length !== 0 &&\n id.contains(output[output.length - 1])\n ) {\n output.splice(output.length - 1, 1);\n }\n\n while (output.length >= 3) {\n size = output.length;\n // XOR of the four cell IDs must be zero for them to be siblings.\n if (\n (output[size - 3].id ^\n output[size - 2].id ^\n output[size - 1].id) !==\n id.id\n ) {\n break;\n }\n\n // Build a mask that blocks the two bits encoding the child position.\n let mask: bigint = id.lowestOnBit() << 1n;\n mask = u64(~(mask + (mask << 1n)));\n\n const idMasked = id.id & mask;\n if (\n (output[size - 3].id & mask) !== idMasked ||\n (output[size - 2].id & mask) !== idMasked ||\n (output[size - 1].id & mask) !== idMasked ||\n id.isFace()\n ) {\n break;\n }\n\n // Replace four children by their parent cell.\n output.splice(size - 3);\n id = id.parent();\n }\n output.push(id);\n });\n\n if (output.length < this.size()) {\n this.initRawSwap(output);\n return true;\n }\n return false;\n }\n}\n","/*\n * Copyright 2005 Google Inc.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport {S2Cell} from \"./S2Cell\";\nimport {S2Region} from \"./S2Region\";\nimport {S2CellId} from \"./S2CellId\";\nimport {S2CellUnion} from \"./S2CellUnion\";\nimport {S2Projections} from \"./S2Projections\";\nimport { S2Point } from \"./S2Point\";\n/**\n * An S2RegionCoverer is a class that allows arbitrary regions to be\n * approximated as unions of cells (S2CellUnion). This is useful for\n * implementing various sorts of search and precomputation operations.\n *\n * Typical usage: {@code S2RegionCoverer coverer; coverer.setMaxCells(5); S2Cap\n * cap = S2Cap.fromAxisAngle(...); S2CellUnion covering;\n * coverer.getCovering(cap, covering); * }\n *\n * This yields a cell union of at most 5 cells that is guaranteed to cover the\n * given cap (a disc-shaped region on the sphere).\n *\n * The approximation algorithm is not optimal but does a pretty good job in\n * practice. The output does not always use the maximum number of cells allowed,\n * both because this would not always yield a better approximation, and because\n * max_cells() is a limit on how much work is done exploring the possible\n * covering as well as a limit on the final output size.\n *\n * One can also generate interior coverings, which are sets of cells which are\n * entirely contained within a region. Interior coverings can be empty, even for\n * non-empty regions, if there are no cells that satisfy the provided\n * constraints and are contained by the region. Note that for performance\n * reasons, it is wise to specify a max_level when computing interior coverings\n * - otherwise for regions with small or zero area, the algorithm may spend a\n * lot of time subdividing cells all the way to leaf level to try to find\n * contained cells.\n *\n * This class is thread-unsafe. Simultaneous calls to any of the getCovering\n * methods will conflict and produce unpredictable results.\n *\n */\nexport class S2RegionCoverer {\n\n /**\n * By default, the covering uses at most 8 cells at any level. This gives a\n * reasonable tradeoff between the number of cells used and the accuracy of\n * the approximation (see table below).\n */\n public static DEFAULT_MAX_CELLS = 8;\n\n private static FACE_CELLS:S2Cell[] = [0, 1, 2, 3, 4, 5].map(face => S2Cell.fromFace(face));\n\n\n private minLevel:number;\n private maxLevel:number;\n private levelMod:number;\n private maxCells:number;\n\n// True if we're computing an interior covering.\n private interiorCovering:boolean;\n\n// Counter of number of candidates created, for performance evaluation.\n private candidatesCreatedCounter:number;\n\n /**\n * We save a temporary copy of the pointer passed to GetCovering() in order to\n * avoid passing this parameter around internally. It is only used (and only\n * valid) for the duration of a single GetCovering() call.\n */\n protected region:S2Region;\n\n /**\n * A temporary variable used by GetCovering() that holds the cell ids that\n * have been added to the covering so far.\n */\n protected result:S2CellId[];\n\n\n /**\n * We keep the candidates in a priority queue. We specify a vector to hold the\n * queue entries since for some reason priority_queue<> uses a deque by\n * default.\n */\n private candidateQueue:PriorityQueue<QueueEntry>;\n\n /**\n * Default constructor, sets all fields to default values.\n */\n public constructor() {\n this.minLevel = 0;\n this.maxLevel = S2CellId.MAX_LEVEL;\n this.levelMod = 1;\n this.maxCells = S2RegionCoverer.DEFAULT_MAX_CELLS;\n this.region = null;\n this.result = [];\n this.candidateQueue = new PriorityQueue<QueueEntry>();\n }\n\n// Set the minimum and maximum cell level to be used. The default is to use\n// all cell levels. Requires: max_level() >= min_level().\n//\n// To find the cell level corresponding to a given physical distance, use\n// the S2Cell metrics defined in s2.h. For example, to find the cell\n// level that corresponds to an average edge length of 10km, use:\n//\n// int level = S2::kAvgEdge.GetClosestLevel(\n// geostore::S2Earth::KmToRadians(length_km));\n//\n// Note: min_level() takes priority over max_cells(), i.e. cells below the\n// given level will never be used even if this causes a large number of\n// cells to be returned.\n\n /**\n * Sets the minimum level to be used.\n */\n public setMinLevel(minLevel:number):S2RegionCoverer {\n // assert (minLevel >= 0 && minLevel <= S2CellId.MAX_LEVEL);\n this.minLevel = Math.max(0, Math.min(S2CellId.MAX_LEVEL, minLevel));\n return this;\n }\n\n /**\n * Sets the maximum level to be used.\n */\n public setMaxLevel(maxLevel:number):S2RegionCoverer {\n // assert (maxLevel >= 0 && maxLevel <= S2CellId.MAX_LEVEL);\n this.maxLevel = Math.max(0, Math.min(S2CellId.MAX_LEVEL, maxLevel));\n return this;\n }\n\n /**\n * If specified, then only cells where (level - min_level) is a multiple of\n * \"level_mod\" will be used (default 1). This effectively allows the branching\n * factor of the S2CellId hierarchy to be increased. Currently the only\n * parameter values allowed are 1, 2, or 3, corresponding to branching factors\n * of 4, 16, and 64 respectively.\n */\n public setLevelMod(levelMod:number):S2RegionCoverer {\n // assert (levelMod >= 1 && levelMod <= 3);\n this.levelMod = Math.max(1, Math.min(3, levelMod));\n return this;\n }\n\n /**\n * Sets the maximum desired number of cells in the approximation (defaults to\n * kDefaultMaxCells). Note the following:\n *\n * <ul>\n * <li>For any setting of max_cells(), up to 6 cells may be returned if that\n * is the minimum number of cells required (e.g. if the region intersects all\n * six face cells). Up to 3 cells may be returned even for very tiny convex\n * regions if they happen to be located at the intersection of three cube\n * faces.\n *\n * <li>For any setting of max_cells(), an arbitrary number of cells may be\n * returned if min_level() is too high for the region being approximated.\n *\n * <li>If max_cells() is less than 4, the area of the covering may be\n * arbitrarily large compared to the area of the original region even if the\n * region is convex (e.g. an S2Cap or S2LatLngRect).\n * </ul>\n *\n * Accuracy is measured by dividing the area of the covering by the area of\n * the original region. The following table shows the median and worst case\n * values for this area ratio on a test case consisting of 100,000 spherical\n * caps of random size (generated using s2regioncoverer_unittest):\n *\n * <pre>\n * max_cells: 3 4 5 6 8 12 20 100 1000\n * median ratio: 5.33 3.32 2.73 2.34 1.98 1.66 1.42 1.11 1.01\n * worst case: 215518 14.41 9.72 5.26 3.91 2.75 1.92 1.20 1.02\n * </pre>\n */\n public setMaxCells(maxCells:number):S2RegionCoverer {\n this.maxCells = maxCells;\n return this;\n }\n\n public getMinLevel(): number {\n return this.minLevel;\n }\n\n public getMaxLevel(): number {\n return this.maxLevel;\n }\n\n public getMaxCells(): number {\n return this.maxCells;\n }\n\n public getLevelMod(): number {\n return this.levelMod;\n }\n\n /**\n * Computes a list of cell ids that covers the given region and satisfies the\n * various restrictions specified above.\n *\n * @param region The region to cover\n * @param covering The list filled in by this method\n */\n public getCoveringCells(region:S2Region):S2CellId[] {\n // Rather than just returning the raw list of cell ids generated by\n // GetCoveringInternal(), we construct a cell union and then denormalize it.\n // This has the effect of replacing four child cells with their parent\n // whenever this does not violate the covering parameters specified\n // (min_level, level_mod, etc). This strategy significantly reduces the\n // number of cells returned in many cases, and it is cheap compared to\n // computing the covering in the first place.\n const tmp = this.getCoveringUnion(region);\n return tmp.denormalize(this.minLevel, this.levelMod);\n }\n\n /**\n * Computes a list of cell ids that is contained within the given region and\n * satisfies the various restrictions specified above.\n *\n * @param region The region to fill\n * @param interior The list filled in by this method\n */\n public getInteriorCoveringCells(region:S2Region):S2CellId[] {\n const tmp = this.getInteriorCoveringUnion(region);\n return tmp.denormalize(this.minLevel, this.levelMod);\n }\n\n /**\n * Return a normalized cell union that covers the given region and satisfies\n * the restrictions *EXCEPT* for min_level() and level_mod(). These criteria\n * cannot be satisfied using a cell union because cell unions are\n * automatically normalized by replacing four child cells with their parent\n * whenever possible. (Note that the list of cell ids passed to the cell union\n * constructor does in fact satisfy all the given restrictions.)\n */\n public getCoveringUnion(region:S2Region, covering:S2CellUnion = new S2CellUnion()):S2CellUnion {\n this.interiorCovering = false;\n this.getCoveringInternal(region);\n covering.initSwap(this.result);\n this.result = [];\n return covering;\n }\n\n /**\n * Return a normalized cell union that is contained within the given region\n * and satisfies the restrictions *EXCEPT* for min_level() and level_mod().\n */\n public getInteriorCoveringUnion(region:S2Region, covering:S2CellUnion=new S2CellUnion()):S2CellUnion {\n this.interiorCovering = true;\n this.getCoveringInternal(region);\n covering.initSwap(this.result);\n this.result = [];\n return covering;\n }\n\n /**\n * Given a connected region and a starting point, return a set of cells at the given level that\n * cover the region.\n */\n public static getSimpleCovering(region: S2Region, start: S2Point, level: number): S2CellId[] {\n return this.floodFill(region, S2CellId.fromPoint(start).parentL(level));\n }\n\n /**\n * If the cell intersects the given region, return a new candidate with no\n * children, otherwise return null. Also marks the candidate as \"terminal\" if\n * it should not be expanded further.\n */\n private newCandidate(cell:S2Cell):Candidate {\n if (!this.region.mayIntersectC(cell)) {\n return null;\n }\n\n let isTerminal = false;\n if (cell.level >= this.minLevel) {\n if (this.interiorCovering) {\n if (this.region.containsC(cell)) {\n isTerminal = true;\n } else if (cell.level + this.levelMod > this.maxLevel) {\n return null;\n }\n } else {\n if (cell.level + this.levelMod > this.maxLevel || this.region.containsC(cell)) {\n isTerminal = true;\n }\n }\n }\n\n const candidate = new Candidate();\n candidate.cell = cell;\n candidate.isTerminal = isTerminal;\n candidate.numChildren = 0;\n if (!isTerminal) {\n candidate.children = [];\n const numOfChildren = 1 << this.maxChildrenShift();\n for (let i = 0; i < numOfChildren; i++) {\n candidate.children.push(new Candidate())\n }\n }\n this.candidatesCreatedCounter++;\n return candidate;\n }\n\n /** Return the log base 2 of the maximum number of children of a candidate. */\n private maxChildrenShift():number {\n return 2 * this.levelMod;\n }\n\n /**\n * Process a candidate by either adding it to the result list or expanding its\n * children and inserting it into the priority queue. Passing an argument of\n * NULL does nothing.\n */\n private addCandidate(candidate:Candidate) {\n if (candidate == null) {\n return;\n }\n\n if (candidate.isTerminal) {\n this.result.push(candidate.cell.id);\n return;\n }\n // assert (candidate.numChildren == 0);\n\n // Expand one level at a time until we hit min_level_ to ensure that\n // we don't skip over it.\n const numLevels = (candidate.cell.level < this.minLevel) ? 1 : this.levelMod;\n\n const numTerminals = this.expandChildren(candidate, candidate.cell, numLevels);\n\n if (candidate.numChildren == 0) {\n // Do nothing\n } else if (!this.interiorCovering && numTerminals == 1 << this.maxChildrenShift()\n && candidate.cell.level >= this.minLevel) {\n // Optimization: add the parent cell rather than all of its children.\n // We can't do this for interior coverings, since the children just\n // intersect the region, but may not be contained by it - we need to\n // subdivide them further.\n candidate.isTerminal = true;\n this.addCandidate(candidate);\n\n } else {\n // We negate the priority so that smaller absolute priorities are returned\n // first. The heuristic is designed to refine the largest cells first,\n // since those are where we have the largest potential gain. Among cells\n // at the same level, we prefer the cells with the smallest number of\n // intersecting children. Finally, we prefer cells that have the smallest\n // number of children that cannot be refined any further.\n const priority = -((((candidate.cell.level << this.maxChildrenShift()) + candidate.numChildren)\n << this.maxChildrenShift()) + numTerminals);\n\n this.candidateQueue.add(new QueueEntry(priority, candidate));\n // logger.info(\"Push: \" + candidate.cell.id() + \" (\" + priority + \") \");\n }\n }\n\n /**\n * Populate the children of \"candidate\" by expanding the given number of\n * levels from the given cell. Returns the number of children that were marked\n * \"terminal\".\n */\n private expandChildren(candidate:Candidate, cell:S2Cell, numLevels:number):number {\n numLevels--;\n\n const childCells = cell.subdivide();\n\n let numTerminals = 0;\n for (let i = 0; i < 4; ++i) {\n if (numLevels > 0) {\n if (this.region.mayIntersectC(childCells[i])) {\n numTerminals += this.expandChildren(candidate, childCells[i], numLevels);\n }\n continue;\n }\n const child = this.newCandidate(childCells[i]);\n\n if (child != null) {\n candidate.children[candidate.numChildren++] = child;\n if (child.isTerminal) {\n ++numTerminals;\n }\n }\n }\n\n\n return numTerminals;\n }\n\n /** Computes a set of initial candidates that cover the given region. */\n private getInitialCandidates() {\n // Optimization: if at least 4 cells are desired (the normal case),\n // start with a 4-cell covering of the region's bounding cap. This\n // lets us skip quite a few levels of refinement when the region to\n // be covered is relatively small.\n if (this.maxCells >= 4) {\n // Find the maximum level such that the bounding cap contains at most one\n // cell vertex at that level.\n const cap = this.region.getCapBound();\n let level =\n Math.min(\n S2Projections.MIN_WIDTH.getMaxLevel(2 * cap.angle().radians),\n Math.min(this.maxLevel, S2CellId.MAX_LEVEL - 1));\n if (this.levelMod > 1 && level > this.minLevel) {\n level -= (level - this.minLevel) % this.levelMod;\n }\n\n // We don't bother trying to optimize the level == 0 case, since more than\n // four face cells may be required.\n if (level > 0) {\n // Find the leaf cell containing the cap axis, and determine which\n // subcell of the parent cell contains it.\n \n const id = S2CellId.fromPoint(cap.axis);\n const base = id.getVertexNeighbors(level);\n for (let i = 0; i < base.length; ++i) {\n this.addCandidate(this.newCandidate(new S2Cell(base[i])));\n }\n return;\n }\n }\n // Default: start with all six cube faces.\n for (let face = 0; face < 6; ++face) {\n this.addCandidate(this.newCandidate(S2RegionCoverer.FACE_CELLS[face]));\n }\n }\n\n /** Generates a covering and stores it in result. */\n private getCoveringInternal(region:S2Region) {\n // Strategy: Start with the 6 faces of the cube. Discard any\n // that do not intersect the shape. Then repeatedly choose the\n // largest cell that intersects the shape and subdivide it.\n //\n // result contains the cells that will be part of the output, while the\n // priority queue contains cells that we may still subdivide further. Cells\n // that are entirely contained within the region are immediately added to\n // the output, while cells that do not intersect the region are immediately\n // discarded.\n // Therefore pq_ only contains cells that partially intersect the region.\n // Candidates are prioritized first according to cell size (larger cells\n // first), then by the number of intersecting children they have (fewest\n // children first), and then by the number of fully contained children\n // (fewest children first).\n\n if (!(this.candidateQueue.size() == 0 && this.result.length == 0)) {\n throw new Error('preconditions are not satisfied')\n }\n // Preconditions.checkState(this.candidateQueue.isEmpty() && this.result.isEmpty());\n\n this.region = region;\n this.candidatesCreatedCounter = 0;\n\n this.getInitialCandidates();\n\n while (this.candidateQueue.size() !== 0 && (!this.interiorCovering || this.result.length < this.maxCells)) {\n const candidate = this.candidateQueue.poll().candidate;\n if (this.interiorCovering || candidate.cell.level < this.minLevel || candidate.numChildren == 1\n || this.result.length + this.candidateQueue.size() + candidate.numChildren <= this.maxCells) {\n // Expand this candidate into its children.\n for (let i = 0; i < candidate.numChildren; ++i) {\n if (!this.interiorCovering || this.result.length < this.maxCells) {\n this.addCandidate(candidate.children[i]);\n }\n }\n } else {\n candidate.isTerminal = true;\n this.addCandidate(candidate);\n }\n }\n\n this.candidateQueue.clear();\n this.region = null;\n }\n\n /**\n * Given a region and a starting cell, return the set of all the edge-connected cells at the same\n * level that intersect \"region\". The output cells are returned in arbitrary order.\n */\n private static floodFill(region: S2Region, start: S2CellId): S2CellId[] {\n const all = new Set<string>();\n const frontier: S2CellId[] = [];\n const output: S2CellId[] = [];\n\n all.add(start.toToken());\n frontier.push(start);\n while (frontier.length !== 0) {\n const id = frontier.pop();\n if (!region.mayIntersectC(new S2Cell(id))) {\n continue;\n }\n output.push(id);\n\n const neighbors: S2CellId[] = id.getEdgeNeighbors();\n for (let edge = 0; edge < 4; ++edge) {\n const nbr = neighbors[edge];\n if (!all.has(nbr.toToken())) {\n frontier.push(nbr);\n all.add(nbr.toToken());\n }\n }\n }\n\n return output;\n }\n}\n\n\nclass Candidate {\n public cell:S2Cell;\n public isTerminal:boolean; // Cell should not be expanded further.\n public numChildren:number; // Number of children that intersect the region.\n public children:Candidate[]; // Actual size may be 0, 4, 16, or 64\n // elements.\n\n public toString() {\n return `isTerminal: ${this.isTerminal} - Cell: ${this.cell.toString()}`;\n }\n}\n\ninterface Comparable<T> {\n compare(other:T):number;\n}\nclass PriorityQueue<T extends Comparable<T>> {\n public items:T[];\n\n constructor() {\n this.clear();\n }\n\n add(item:T) {\n this.items.push(item);\n this.items.sort((a, b) => a.compare(b));\n }\n\n clear() {\n this.items = [];\n }\n\n size() {\n return this.items.length;\n }\n\n poll():T {\n return this.items.splice(0, 1)[0];\n }\n}\n\nclass QueueEntry implements Comparable<QueueEntry> {\n compare(other:QueueEntry):number {\n return this.id < other.id ? 1 : (this.id > other.id ? -1 : 0);\n }\n\n public constructor(public id:number, public candidate:Candidate) {\n\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACOO,IAAM,WAAN,MAAM,UAAS;AAAA,EAGpB,YAAY,IAAW,IAAW;AAChC,SAAK,KAAK;AACV,SAAK,KAAK;AAAA,EACZ;AAAA,EAEA,IAAI,IAAI;AACN,W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