@xort/cga 0.1.2 → 0.1.4
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/THIRD_PARTY_NOTICES.md +23 -2
- package/build/@xort_cga.js +1509 -3388
- package/build/cga.d.ts +79 -15
- package/build/cga.esm.js +1509 -3389
- package/dist/THIRD_PARTY_NOTICES.md +23 -2
- package/dist/index.cjs +1509 -3388
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +79 -15
- package/dist/index.d.ts +79 -15
- package/dist/index.js +1509 -3389
- package/dist/index.js.map +1 -1
- package/dist/three.cjs +209 -1962
- package/dist/three.cjs.map +1 -1
- package/dist/three.d.cts +74 -9
- package/dist/three.d.ts +74 -9
- package/dist/three.js +209 -1962
- package/dist/three.js.map +1 -1
- package/package.json +21 -18
- package/readme.md +189 -64
- package/readme.zh-CN.md +241 -0
package/build/cga.esm.js
CHANGED
|
@@ -1,11 +1,5 @@
|
|
|
1
1
|
// \0rolldown/runtime.js
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __commonJSMin = (cb, mod) => () => (mod || (cb((mod = { exports: {} }).exports, mod, mod.exports), cb = null), mod.exports);
|
|
9
3
|
var __exportAll = (all, flags) => {
|
|
10
4
|
let target = Object.setPrototypeOf({}, null);
|
|
11
5
|
for (var name in all) __defProp(target, name, {
|
|
@@ -15,22 +9,6 @@ var __exportAll = (all, flags) => {
|
|
|
15
9
|
if (!(flags & 1)) __defProp(target, Symbol.toStringTag, { value: "Module" });
|
|
16
10
|
return flags & 2 ? target : Object.preventExtensions(target);
|
|
17
11
|
};
|
|
18
|
-
var __copyProps = (to, from, except, desc) => {
|
|
19
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
20
|
-
for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) {
|
|
21
|
-
desc = __getOwnPropDesc(from, key);
|
|
22
|
-
__defProp(to, key, {
|
|
23
|
-
get: desc && desc.get && !desc.configurable ? desc.get : () => from[key],
|
|
24
|
-
enumerable: !desc || desc.enumerable
|
|
25
|
-
});
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
return to;
|
|
29
|
-
};
|
|
30
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
31
|
-
value: mod,
|
|
32
|
-
enumerable: true
|
|
33
|
-
}) : target, mod));
|
|
34
12
|
// src/alg/queries.ts
|
|
35
13
|
/** Squared distances are always measured from the returned witnesses. */
|
|
36
14
|
function distanceResult(a, b, parameters = [0, 0]) {
|
|
@@ -3780,11 +3758,17 @@ function offsetRings(input, delta, join, end, miterLimit) {
|
|
|
3780
3758
|
}
|
|
3781
3759
|
const points = ring.map((p) => ({ ...p }));
|
|
3782
3760
|
if (end === 0 || end === 6) {
|
|
3783
|
-
const a = points[0], b = points[1], z = points.at(-1), y = points.at(-2), l = distance$1(a, b), k = distance$1(z, y)
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3761
|
+
const a = points[0], b = points[1], z = points.at(-1), y = points.at(-2), l = distance$1(a, b), k = distance$1(z, y), startDirection = {
|
|
3762
|
+
X: (b.X - a.X) / l,
|
|
3763
|
+
Y: (b.Y - a.Y) / l
|
|
3764
|
+
}, endDirection = {
|
|
3765
|
+
X: (z.X - y.X) / k,
|
|
3766
|
+
Y: (z.Y - y.Y) / k
|
|
3767
|
+
};
|
|
3768
|
+
a.X -= startDirection.X * delta;
|
|
3769
|
+
a.Y -= startDirection.Y * delta;
|
|
3770
|
+
z.X += endDirection.X * delta;
|
|
3771
|
+
z.Y += endDirection.Y * delta;
|
|
3788
3772
|
}
|
|
3789
3773
|
const right = offsetRing(points, delta, join, miterLimit, false), left = offsetRing([...points].reverse(), delta, join, miterLimit, false), outline = [...right];
|
|
3790
3774
|
const cap = (center, from, to) => {
|
|
@@ -3829,9 +3813,20 @@ function triangulateRings(input) {
|
|
|
3829
3813
|
return values.filter((p, i) => !same(p, values[(i + values.length - 1) % values.length]));
|
|
3830
3814
|
});
|
|
3831
3815
|
if (!rings.length || rings[0].length < 3) return [];
|
|
3832
|
-
|
|
3816
|
+
let extent = 0;
|
|
3817
|
+
for (const ring of rings) for (const p of ring) {
|
|
3818
|
+
if (!Number.isFinite(p.X) || !Number.isFinite(p.Y)) throw new RangeError("Triangulation coordinates must be finite");
|
|
3819
|
+
extent = Math.max(extent, Math.abs(p.X), Math.abs(p.Y));
|
|
3820
|
+
}
|
|
3821
|
+
if (!extent) return [];
|
|
3822
|
+
for (const ring of rings) for (const p of ring) {
|
|
3823
|
+
p.X /= extent;
|
|
3824
|
+
p.Y /= extent;
|
|
3825
|
+
}
|
|
3826
|
+
const epsilon = Number.EPSILON * 16;
|
|
3833
3827
|
const boundaries = rings.filter((r) => r.length >= 3);
|
|
3834
3828
|
if (!boundaries.length) return [];
|
|
3829
|
+
for (const ring of boundaries) if (new Set(ring.map((p) => `${p.X},${p.Y}`)).size !== ring.length) throw new RangeError("Triangulation requires simple rings without repeated vertices");
|
|
3835
3830
|
for (const ring of boundaries) if (ring.some((p) => !Number.isFinite(p.X) || !Number.isFinite(p.Y))) throw new RangeError("Triangulation coordinates must be finite");
|
|
3836
3831
|
for (let r = 0; r < boundaries.length; r++) for (let s = r + 1; s < boundaries.length; s++) {
|
|
3837
3832
|
const a = boundaries[r], b = boundaries[s];
|
|
@@ -6423,7 +6418,7 @@ var Voronoi = class {
|
|
|
6423
6418
|
}
|
|
6424
6419
|
};
|
|
6425
6420
|
// src/alg/delaunay.ts
|
|
6426
|
-
var pow
|
|
6421
|
+
var pow = Math.pow;
|
|
6427
6422
|
function collinear(d) {
|
|
6428
6423
|
const { triangles, coords } = d;
|
|
6429
6424
|
for (let i = 0; i < triangles.length; i += 3) {
|
|
@@ -6534,12 +6529,12 @@ var Delaunay = class Delaunay {
|
|
|
6534
6529
|
const { inedges, hull, _hullIndex, halfedges, triangles, points } = this;
|
|
6535
6530
|
if (inedges[i] === -1 || !points.length) return (i + 1) % (points.length >> 1);
|
|
6536
6531
|
let c = i;
|
|
6537
|
-
let dc = pow
|
|
6532
|
+
let dc = pow(x - points[i * 2], 2) + pow(y - points[i * 2 + 1], 2);
|
|
6538
6533
|
const e0 = inedges[i];
|
|
6539
6534
|
let e = e0;
|
|
6540
6535
|
do {
|
|
6541
6536
|
let t = triangles[e];
|
|
6542
|
-
const dt = pow
|
|
6537
|
+
const dt = pow(x - points[t * 2], 2) + pow(y - points[t * 2 + 1], 2);
|
|
6543
6538
|
if (dt < dc) dc = dt, c = t;
|
|
6544
6539
|
e = e % 3 === 2 ? e - 2 : e + 1;
|
|
6545
6540
|
if (triangles[e] !== i) break;
|
|
@@ -6547,7 +6542,7 @@ var Delaunay = class Delaunay {
|
|
|
6547
6542
|
if (e === -1) {
|
|
6548
6543
|
e = hull[(_hullIndex[i] + 1) % hull.length];
|
|
6549
6544
|
if (e !== t) {
|
|
6550
|
-
if (pow
|
|
6545
|
+
if (pow(x - points[e * 2], 2) + pow(y - points[e * 2 + 1], 2) < dc) return e;
|
|
6551
6546
|
}
|
|
6552
6547
|
break;
|
|
6553
6548
|
}
|
|
@@ -9494,1999 +9489,246 @@ function geometryFromJSON(data) {
|
|
|
9494
9489
|
default: throw new RangeError("Unknown geometry kind");
|
|
9495
9490
|
}
|
|
9496
9491
|
}
|
|
9497
|
-
//
|
|
9498
|
-
|
|
9499
|
-
|
|
9500
|
-
|
|
9501
|
-
|
|
9502
|
-
|
|
9503
|
-
|
|
9504
|
-
|
|
9505
|
-
|
|
9506
|
-
|
|
9507
|
-
|
|
9508
|
-
|
|
9509
|
-
|
|
9510
|
-
|
|
9511
|
-
|
|
9512
|
-
|
|
9513
|
-
|
|
9514
|
-
|
|
9515
|
-
|
|
9516
|
-
|
|
9517
|
-
|
|
9518
|
-
|
|
9519
|
-
|
|
9520
|
-
var inexact;
|
|
9521
|
-
var quadrant;
|
|
9522
|
-
var external = true;
|
|
9523
|
-
var decimalError = "[DecimalError] ";
|
|
9524
|
-
var invalidArgument = decimalError + "Invalid argument: ";
|
|
9525
|
-
var precisionLimitExceeded = decimalError + "Precision limit exceeded";
|
|
9526
|
-
var cryptoUnavailable = decimalError + "crypto unavailable";
|
|
9527
|
-
var tag = "[object Decimal]";
|
|
9528
|
-
var mathfloor = Math.floor;
|
|
9529
|
-
var mathpow = Math.pow;
|
|
9530
|
-
var isBinary = /^0b([01]+(\.[01]*)?|\.[01]+)(p[+-]?\d+)?$/i;
|
|
9531
|
-
var isHex = /^0x([0-9a-f]+(\.[0-9a-f]*)?|\.[0-9a-f]+)(p[+-]?\d+)?$/i;
|
|
9532
|
-
var isOctal = /^0o([0-7]+(\.[0-7]*)?|\.[0-7]+)(p[+-]?\d+)?$/i;
|
|
9533
|
-
var isDecimal = /^(\d+(\.\d*)?|\.\d+)(e[+-]?\d+)?$/i;
|
|
9534
|
-
var BASE = 1e7;
|
|
9535
|
-
var LOG_BASE = 7;
|
|
9536
|
-
var MAX_SAFE_INTEGER = 0x1fffffffffffff;
|
|
9537
|
-
var LN10_PRECISION = LN10.length - 1;
|
|
9538
|
-
var PI_PRECISION = PI$1.length - 1;
|
|
9539
|
-
var P = { toStringTag: tag };
|
|
9540
|
-
P.absoluteValue = P.abs = function() {
|
|
9541
|
-
var x = new this.constructor(this);
|
|
9542
|
-
if (x.s < 0) x.s = 1;
|
|
9543
|
-
return finalise(x);
|
|
9544
|
-
};
|
|
9545
|
-
P.ceil = function() {
|
|
9546
|
-
return finalise(new this.constructor(this), this.e + 1, 2);
|
|
9547
|
-
};
|
|
9548
|
-
P.clampedTo = P.clamp = function(min, max) {
|
|
9549
|
-
var k, x = this, Ctor = x.constructor;
|
|
9550
|
-
min = new Ctor(min);
|
|
9551
|
-
max = new Ctor(max);
|
|
9552
|
-
if (!min.s || !max.s) return new Ctor(NaN);
|
|
9553
|
-
if (min.gt(max)) throw Error(invalidArgument + max);
|
|
9554
|
-
k = x.cmp(min);
|
|
9555
|
-
return k < 0 ? min : x.cmp(max) > 0 ? max : new Ctor(x);
|
|
9556
|
-
};
|
|
9557
|
-
P.comparedTo = P.cmp = function(y) {
|
|
9558
|
-
var i, j, xdL, ydL, x = this, xd = x.d, yd = (y = new x.constructor(y)).d, xs = x.s, ys = y.s;
|
|
9559
|
-
if (!xd || !yd) return !xs || !ys ? NaN : xs !== ys ? xs : xd === yd ? 0 : !xd ^ xs < 0 ? 1 : -1;
|
|
9560
|
-
if (!xd[0] || !yd[0]) return xd[0] ? xs : yd[0] ? -ys : 0;
|
|
9561
|
-
if (xs !== ys) return xs;
|
|
9562
|
-
if (x.e !== y.e) return x.e > y.e ^ xs < 0 ? 1 : -1;
|
|
9563
|
-
xdL = xd.length;
|
|
9564
|
-
ydL = yd.length;
|
|
9565
|
-
for (i = 0, j = xdL < ydL ? xdL : ydL; i < j; ++i) if (xd[i] !== yd[i]) return xd[i] > yd[i] ^ xs < 0 ? 1 : -1;
|
|
9566
|
-
return xdL === ydL ? 0 : xdL > ydL ^ xs < 0 ? 1 : -1;
|
|
9567
|
-
};
|
|
9568
|
-
P.cosine = P.cos = function() {
|
|
9569
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
9570
|
-
if (!x.d) return new Ctor(NaN);
|
|
9571
|
-
if (!x.d[0]) return new Ctor(1);
|
|
9572
|
-
pr = Ctor.precision;
|
|
9573
|
-
rm = Ctor.rounding;
|
|
9574
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
9575
|
-
Ctor.rounding = 1;
|
|
9576
|
-
x = cosine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
9577
|
-
Ctor.precision = pr;
|
|
9578
|
-
Ctor.rounding = rm;
|
|
9579
|
-
return finalise(quadrant == 2 || quadrant == 3 ? x.neg() : x, pr, rm, true);
|
|
9580
|
-
};
|
|
9581
|
-
P.cubeRoot = P.cbrt = function() {
|
|
9582
|
-
var e, m, n, r, rep, s, sd, t, t3, t3plusx, x = this, Ctor = x.constructor;
|
|
9583
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
9584
|
-
external = false;
|
|
9585
|
-
s = x.s * mathpow(x.s * x, 1 / 3);
|
|
9586
|
-
if (!s || Math.abs(s) == 1 / 0) {
|
|
9587
|
-
n = digitsToString(x.d);
|
|
9588
|
-
e = x.e;
|
|
9589
|
-
if (s = (e - n.length + 1) % 3) n += s == 1 || s == -2 ? "0" : "00";
|
|
9590
|
-
s = mathpow(n, 1 / 3);
|
|
9591
|
-
e = mathfloor((e + 1) / 3) - (e % 3 == (e < 0 ? -1 : 2));
|
|
9592
|
-
if (s == 1 / 0) n = "5e" + e;
|
|
9593
|
-
else {
|
|
9594
|
-
n = s.toExponential();
|
|
9595
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
9596
|
-
}
|
|
9597
|
-
r = new Ctor(n);
|
|
9598
|
-
r.s = x.s;
|
|
9599
|
-
} else r = new Ctor(s.toString());
|
|
9600
|
-
sd = (e = Ctor.precision) + 3;
|
|
9492
|
+
// src/math/Decimal.ts
|
|
9493
|
+
var MAX_EXPONENT = 1e6;
|
|
9494
|
+
var MAX_INPUT_DIGITS = 2e4;
|
|
9495
|
+
var abs = (n) => n < 0n ? -n : n;
|
|
9496
|
+
var digits$1 = (n) => abs(n).toString().length;
|
|
9497
|
+
function power(n) {
|
|
9498
|
+
if (!Number.isSafeInteger(n) || n < 0 || n > 202e4) throw new RangeError("Decimal exponent exceeds the supported range");
|
|
9499
|
+
return 10n ** BigInt(n);
|
|
9500
|
+
}
|
|
9501
|
+
function increment(q, remainder, divisor, sign, mode, sticky = false) {
|
|
9502
|
+
if (remainder === 0n && !sticky) return false;
|
|
9503
|
+
if (mode === 0) return true;
|
|
9504
|
+
if (mode === 1) return false;
|
|
9505
|
+
if (mode === 2) return sign > 0n;
|
|
9506
|
+
if (mode === 3) return sign < 0n;
|
|
9507
|
+
const compare = 2n * remainder - divisor;
|
|
9508
|
+
if (compare !== 0n) return compare > 0n;
|
|
9509
|
+
if (sticky) return true;
|
|
9510
|
+
return mode === 4 || mode === 6 && abs(q) % 2n === 1n || mode === 7 && sign > 0n || mode === 8 && sign < 0n;
|
|
9511
|
+
}
|
|
9512
|
+
function integerSqrt(n) {
|
|
9513
|
+
if (n < 2n) return n;
|
|
9514
|
+
let x = 1n << BigInt(Math.ceil(n.toString(2).length / 2));
|
|
9601
9515
|
for (;;) {
|
|
9602
|
-
|
|
9603
|
-
|
|
9604
|
-
|
|
9605
|
-
|
|
9606
|
-
|
|
9607
|
-
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
9516
|
+
const next = (x + n / x) / 2n;
|
|
9517
|
+
if (next >= x) return x;
|
|
9518
|
+
x = next;
|
|
9519
|
+
}
|
|
9520
|
+
}
|
|
9521
|
+
/** Finite decimal subset used by HVec3, Robust and CSG.
|
|
9522
|
+
* Constructors preserve input digits; arithmetic rounds to configured significant digits.
|
|
9523
|
+
* Instances are immutable. Unsupported/non-finite inputs and division by zero throw.
|
|
9524
|
+
*/
|
|
9525
|
+
var Decimal = class Decimal {
|
|
9526
|
+
static precision = 20;
|
|
9527
|
+
static rounding = 4;
|
|
9528
|
+
static ROUND_UP = 0;
|
|
9529
|
+
static ROUND_DOWN = 1;
|
|
9530
|
+
static ROUND_CEIL = 2;
|
|
9531
|
+
static ROUND_FLOOR = 3;
|
|
9532
|
+
static ROUND_HALF_UP = 4;
|
|
9533
|
+
static ROUND_HALF_DOWN = 5;
|
|
9534
|
+
static ROUND_HALF_EVEN = 6;
|
|
9535
|
+
static ROUND_HALF_CEIL = 7;
|
|
9536
|
+
static ROUND_HALF_FLOOR = 8;
|
|
9537
|
+
coefficient;
|
|
9538
|
+
exponent;
|
|
9539
|
+
constructor(value = 0) {
|
|
9540
|
+
if (value instanceof Decimal) {
|
|
9541
|
+
this.coefficient = value.coefficient;
|
|
9542
|
+
this.exponent = value.exponent;
|
|
9543
|
+
return;
|
|
9625
9544
|
}
|
|
9545
|
+
const text = String(value).trim();
|
|
9546
|
+
const match = /^([+-]?)(?:(\d+)(?:\.(\d*))?|\.(\d+))(?:e([+-]?\d+))?$/i.exec(text);
|
|
9547
|
+
if (!match) throw new RangeError("Expected a finite decimal value");
|
|
9548
|
+
const fraction = match[3] ?? match[4] ?? "";
|
|
9549
|
+
const raw = ((match[2] ?? "") + fraction).replace(/^0+/, "") || "0";
|
|
9550
|
+
const exponent = Number(match[5] ?? 0) - fraction.length;
|
|
9551
|
+
if (raw.length > MAX_INPUT_DIGITS || !Number.isSafeInteger(exponent) || Math.abs(exponent) > MAX_EXPONENT) throw new RangeError("Decimal input exceeds the supported range");
|
|
9552
|
+
this.coefficient = BigInt((match[1] === "-" ? "-" : "") + raw);
|
|
9553
|
+
this.exponent = exponent;
|
|
9554
|
+
this.normalize();
|
|
9626
9555
|
}
|
|
9627
|
-
|
|
9628
|
-
|
|
9629
|
-
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
|
|
9633
|
-
|
|
9634
|
-
n = (w - mathfloor(this.e / LOG_BASE)) * LOG_BASE;
|
|
9635
|
-
w = d[w];
|
|
9636
|
-
if (w) for (; w % 10 == 0; w /= 10) n--;
|
|
9637
|
-
if (n < 0) n = 0;
|
|
9638
|
-
}
|
|
9639
|
-
return n;
|
|
9640
|
-
};
|
|
9641
|
-
P.dividedBy = P.div = function(y) {
|
|
9642
|
-
return divide(this, new this.constructor(y));
|
|
9643
|
-
};
|
|
9644
|
-
P.dividedToIntegerBy = P.divToInt = function(y) {
|
|
9645
|
-
var x = this, Ctor = x.constructor;
|
|
9646
|
-
return finalise(divide(x, new Ctor(y), 0, 1, 1), Ctor.precision, Ctor.rounding);
|
|
9647
|
-
};
|
|
9648
|
-
P.equals = P.eq = function(y) {
|
|
9649
|
-
return this.cmp(y) === 0;
|
|
9650
|
-
};
|
|
9651
|
-
P.floor = function() {
|
|
9652
|
-
return finalise(new this.constructor(this), this.e + 1, 3);
|
|
9653
|
-
};
|
|
9654
|
-
P.greaterThan = P.gt = function(y) {
|
|
9655
|
-
return this.cmp(y) > 0;
|
|
9656
|
-
};
|
|
9657
|
-
P.greaterThanOrEqualTo = P.gte = function(y) {
|
|
9658
|
-
var k = this.cmp(y);
|
|
9659
|
-
return k == 1 || k === 0;
|
|
9660
|
-
};
|
|
9661
|
-
P.hyperbolicCosine = P.cosh = function() {
|
|
9662
|
-
var k, n, pr, rm, len, x = this, Ctor = x.constructor, one = new Ctor(1);
|
|
9663
|
-
if (!x.isFinite()) return new Ctor(x.s ? 1 / 0 : NaN);
|
|
9664
|
-
if (x.isZero()) return one;
|
|
9665
|
-
pr = Ctor.precision;
|
|
9666
|
-
rm = Ctor.rounding;
|
|
9667
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
9668
|
-
Ctor.rounding = 1;
|
|
9669
|
-
len = x.d.length;
|
|
9670
|
-
if (len < 32) {
|
|
9671
|
-
k = Math.ceil(len / 3);
|
|
9672
|
-
n = (1 / tinyPow(4, k)).toString();
|
|
9673
|
-
} else {
|
|
9674
|
-
k = 16;
|
|
9675
|
-
n = "2.3283064365386962890625e-10";
|
|
9676
|
-
}
|
|
9677
|
-
x = taylorSeries(Ctor, 1, x.times(n), new Ctor(1), true);
|
|
9678
|
-
var cosh2_x, i = k, d8 = new Ctor(8);
|
|
9679
|
-
for (; i--;) {
|
|
9680
|
-
cosh2_x = x.times(x);
|
|
9681
|
-
x = one.minus(cosh2_x.times(d8.minus(cosh2_x.times(d8))));
|
|
9682
|
-
}
|
|
9683
|
-
return finalise(x, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
9684
|
-
};
|
|
9685
|
-
P.hyperbolicSine = P.sinh = function() {
|
|
9686
|
-
var k, pr, rm, len, x = this, Ctor = x.constructor;
|
|
9687
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
9688
|
-
pr = Ctor.precision;
|
|
9689
|
-
rm = Ctor.rounding;
|
|
9690
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + 4;
|
|
9691
|
-
Ctor.rounding = 1;
|
|
9692
|
-
len = x.d.length;
|
|
9693
|
-
if (len < 3) x = taylorSeries(Ctor, 2, x, x, true);
|
|
9694
|
-
else {
|
|
9695
|
-
k = 1.4 * Math.sqrt(len);
|
|
9696
|
-
k = k > 16 ? 16 : k | 0;
|
|
9697
|
-
x = x.times(1 / tinyPow(5, k));
|
|
9698
|
-
x = taylorSeries(Ctor, 2, x, x, true);
|
|
9699
|
-
var sinh2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
9700
|
-
for (; k--;) {
|
|
9701
|
-
sinh2_x = x.times(x);
|
|
9702
|
-
x = x.times(d5.plus(sinh2_x.times(d16.times(sinh2_x).plus(d20))));
|
|
9703
|
-
}
|
|
9704
|
-
}
|
|
9705
|
-
Ctor.precision = pr;
|
|
9706
|
-
Ctor.rounding = rm;
|
|
9707
|
-
return finalise(x, pr, rm, true);
|
|
9708
|
-
};
|
|
9709
|
-
P.hyperbolicTangent = P.tanh = function() {
|
|
9710
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
9711
|
-
if (!x.isFinite()) return new Ctor(x.s);
|
|
9712
|
-
if (x.isZero()) return new Ctor(x);
|
|
9713
|
-
pr = Ctor.precision;
|
|
9714
|
-
rm = Ctor.rounding;
|
|
9715
|
-
Ctor.precision = pr + 7;
|
|
9716
|
-
Ctor.rounding = 1;
|
|
9717
|
-
return divide(x.sinh(), x.cosh(), Ctor.precision = pr, Ctor.rounding = rm);
|
|
9718
|
-
};
|
|
9719
|
-
P.inverseCosine = P.acos = function() {
|
|
9720
|
-
var x = this, Ctor = x.constructor, k = x.abs().cmp(1), pr = Ctor.precision, rm = Ctor.rounding;
|
|
9721
|
-
if (k !== -1) return k === 0 ? x.isNeg() ? getPi(Ctor, pr, rm) : new Ctor(0) : new Ctor(NaN);
|
|
9722
|
-
if (x.isZero()) return getPi(Ctor, pr + 4, rm).times(.5);
|
|
9723
|
-
Ctor.precision = pr + 6;
|
|
9724
|
-
Ctor.rounding = 1;
|
|
9725
|
-
x = new Ctor(1).minus(x).div(x.plus(1)).sqrt().atan();
|
|
9726
|
-
Ctor.precision = pr;
|
|
9727
|
-
Ctor.rounding = rm;
|
|
9728
|
-
return x.times(2);
|
|
9729
|
-
};
|
|
9730
|
-
P.inverseHyperbolicCosine = P.acosh = function() {
|
|
9731
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
9732
|
-
if (x.lte(1)) return new Ctor(x.eq(1) ? 0 : NaN);
|
|
9733
|
-
if (!x.isFinite()) return new Ctor(x);
|
|
9734
|
-
pr = Ctor.precision;
|
|
9735
|
-
rm = Ctor.rounding;
|
|
9736
|
-
Ctor.precision = pr + Math.max(Math.abs(x.e), x.sd()) + 4;
|
|
9737
|
-
Ctor.rounding = 1;
|
|
9738
|
-
external = false;
|
|
9739
|
-
x = x.times(x).minus(1).sqrt().plus(x);
|
|
9740
|
-
external = true;
|
|
9741
|
-
Ctor.precision = pr;
|
|
9742
|
-
Ctor.rounding = rm;
|
|
9743
|
-
return x.ln();
|
|
9744
|
-
};
|
|
9745
|
-
P.inverseHyperbolicSine = P.asinh = function() {
|
|
9746
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
9747
|
-
if (!x.isFinite() || x.isZero()) return new Ctor(x);
|
|
9748
|
-
pr = Ctor.precision;
|
|
9749
|
-
rm = Ctor.rounding;
|
|
9750
|
-
Ctor.precision = pr + 2 * Math.max(Math.abs(x.e), x.sd()) + 6;
|
|
9751
|
-
Ctor.rounding = 1;
|
|
9752
|
-
external = false;
|
|
9753
|
-
x = x.times(x).plus(1).sqrt().plus(x);
|
|
9754
|
-
external = true;
|
|
9755
|
-
Ctor.precision = pr;
|
|
9756
|
-
Ctor.rounding = rm;
|
|
9757
|
-
return x.ln();
|
|
9758
|
-
};
|
|
9759
|
-
P.inverseHyperbolicTangent = P.atanh = function() {
|
|
9760
|
-
var pr, rm, wpr, xsd, x = this, Ctor = x.constructor;
|
|
9761
|
-
if (!x.isFinite()) return new Ctor(NaN);
|
|
9762
|
-
if (x.e >= 0) return new Ctor(x.abs().eq(1) ? x.s / 0 : x.isZero() ? x : NaN);
|
|
9763
|
-
pr = Ctor.precision;
|
|
9764
|
-
rm = Ctor.rounding;
|
|
9765
|
-
xsd = x.sd();
|
|
9766
|
-
if (Math.max(xsd, pr) < 2 * -x.e - 1) return finalise(new Ctor(x), pr, rm, true);
|
|
9767
|
-
Ctor.precision = wpr = xsd - x.e;
|
|
9768
|
-
x = divide(x.plus(1), new Ctor(1).minus(x), wpr + pr, 1);
|
|
9769
|
-
Ctor.precision = pr + 4;
|
|
9770
|
-
Ctor.rounding = 1;
|
|
9771
|
-
x = x.ln();
|
|
9772
|
-
Ctor.precision = pr;
|
|
9773
|
-
Ctor.rounding = rm;
|
|
9774
|
-
return x.times(.5);
|
|
9775
|
-
};
|
|
9776
|
-
P.inverseSine = P.asin = function() {
|
|
9777
|
-
var halfPi, k, pr, rm, x = this, Ctor = x.constructor;
|
|
9778
|
-
if (x.isZero()) return new Ctor(x);
|
|
9779
|
-
k = x.abs().cmp(1);
|
|
9780
|
-
pr = Ctor.precision;
|
|
9781
|
-
rm = Ctor.rounding;
|
|
9782
|
-
if (k !== -1) {
|
|
9783
|
-
if (k === 0) {
|
|
9784
|
-
halfPi = getPi(Ctor, pr + 4, rm).times(.5);
|
|
9785
|
-
halfPi.s = x.s;
|
|
9786
|
-
return halfPi;
|
|
9787
|
-
}
|
|
9788
|
-
return new Ctor(NaN);
|
|
9789
|
-
}
|
|
9790
|
-
Ctor.precision = pr + 6;
|
|
9791
|
-
Ctor.rounding = 1;
|
|
9792
|
-
x = x.div(new Ctor(1).minus(x.times(x)).sqrt().plus(1)).atan();
|
|
9793
|
-
Ctor.precision = pr;
|
|
9794
|
-
Ctor.rounding = rm;
|
|
9795
|
-
return x.times(2);
|
|
9796
|
-
};
|
|
9797
|
-
P.inverseTangent = P.atan = function() {
|
|
9798
|
-
var i, j, k, n, px, t, r, wpr, x2, x = this, Ctor = x.constructor, pr = Ctor.precision, rm = Ctor.rounding;
|
|
9799
|
-
if (!x.isFinite()) {
|
|
9800
|
-
if (!x.s) return new Ctor(NaN);
|
|
9801
|
-
if (pr + 4 <= PI_PRECISION) {
|
|
9802
|
-
r = getPi(Ctor, pr + 4, rm).times(.5);
|
|
9803
|
-
r.s = x.s;
|
|
9804
|
-
return r;
|
|
9805
|
-
}
|
|
9806
|
-
} else if (x.isZero()) return new Ctor(x);
|
|
9807
|
-
else if (x.abs().eq(1) && pr + 4 <= PI_PRECISION) {
|
|
9808
|
-
r = getPi(Ctor, pr + 4, rm).times(.25);
|
|
9809
|
-
r.s = x.s;
|
|
9810
|
-
return r;
|
|
9556
|
+
static set(config) {
|
|
9557
|
+
const p = config.precision ?? this.precision, r = config.rounding ?? this.rounding;
|
|
9558
|
+
if (!Number.isInteger(p) || p < 1 || p > 1e3) throw new RangeError("Decimal precision must be an integer from 1 to 1000");
|
|
9559
|
+
if (!Number.isInteger(r) || r < 0 || r > 8) throw new RangeError("Decimal rounding must be an integer from 0 to 8");
|
|
9560
|
+
this.precision = p;
|
|
9561
|
+
this.rounding = r;
|
|
9562
|
+
return this;
|
|
9811
9563
|
}
|
|
9812
|
-
|
|
9813
|
-
|
|
9814
|
-
|
|
9815
|
-
|
|
9816
|
-
|
|
9817
|
-
|
|
9818
|
-
|
|
9819
|
-
|
|
9820
|
-
|
|
9821
|
-
|
|
9822
|
-
for (; i !== -1;) {
|
|
9823
|
-
px = px.times(x2);
|
|
9824
|
-
t = r.minus(px.div(n += 2));
|
|
9825
|
-
px = px.times(x2);
|
|
9826
|
-
r = t.plus(px.div(n += 2));
|
|
9827
|
-
if (r.d[j] !== void 0) for (i = j; r.d[i] === t.d[i] && i--;);
|
|
9828
|
-
}
|
|
9829
|
-
if (k) r = r.times(2 << k - 1);
|
|
9830
|
-
external = true;
|
|
9831
|
-
return finalise(r, Ctor.precision = pr, Ctor.rounding = rm, true);
|
|
9832
|
-
};
|
|
9833
|
-
P.isFinite = function() {
|
|
9834
|
-
return !!this.d;
|
|
9835
|
-
};
|
|
9836
|
-
P.isInteger = P.isInt = function() {
|
|
9837
|
-
return !!this.d && mathfloor(this.e / LOG_BASE) > this.d.length - 2;
|
|
9838
|
-
};
|
|
9839
|
-
P.isNaN = function() {
|
|
9840
|
-
return !this.s;
|
|
9841
|
-
};
|
|
9842
|
-
P.isNegative = P.isNeg = function() {
|
|
9843
|
-
return this.s < 0;
|
|
9844
|
-
};
|
|
9845
|
-
P.isPositive = P.isPos = function() {
|
|
9846
|
-
return this.s > 0;
|
|
9847
|
-
};
|
|
9848
|
-
P.isZero = function() {
|
|
9849
|
-
return !!this.d && this.d[0] === 0;
|
|
9850
|
-
};
|
|
9851
|
-
P.lessThan = P.lt = function(y) {
|
|
9852
|
-
return this.cmp(y) < 0;
|
|
9853
|
-
};
|
|
9854
|
-
P.lessThanOrEqualTo = P.lte = function(y) {
|
|
9855
|
-
return this.cmp(y) < 1;
|
|
9856
|
-
};
|
|
9857
|
-
P.logarithm = P.log = function(base) {
|
|
9858
|
-
var isBase10, d, denominator, k, inf, num, sd, r, arg = this, Ctor = arg.constructor, pr = Ctor.precision, rm = Ctor.rounding, guard = 5;
|
|
9859
|
-
if (base == null) {
|
|
9860
|
-
base = new Ctor(10);
|
|
9861
|
-
isBase10 = true;
|
|
9862
|
-
} else {
|
|
9863
|
-
base = new Ctor(base);
|
|
9864
|
-
d = base.d;
|
|
9865
|
-
if (base.s < 0 || !d || !d[0] || base.eq(1)) return new Ctor(NaN);
|
|
9866
|
-
isBase10 = base.eq(10);
|
|
9867
|
-
}
|
|
9868
|
-
d = arg.d;
|
|
9869
|
-
if (arg.s < 0 || !d || !d[0] || arg.eq(1)) return new Ctor(d && !d[0] ? -1 / 0 : arg.s != 1 ? NaN : d ? 0 : 1 / 0);
|
|
9870
|
-
if (isBase10) {
|
|
9871
|
-
if (d.length > 1) inf = true;
|
|
9872
|
-
else {
|
|
9873
|
-
for (k = d[0]; k % 10 === 0;) k /= 10;
|
|
9874
|
-
inf = k !== 1;
|
|
9875
|
-
}
|
|
9876
|
-
}
|
|
9877
|
-
external = false;
|
|
9878
|
-
sd = pr + guard;
|
|
9879
|
-
num = naturalLogarithm(arg, sd);
|
|
9880
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
9881
|
-
r = divide(num, denominator, sd, 1);
|
|
9882
|
-
if (checkRoundingDigits(r.d, k = pr, rm)) do {
|
|
9883
|
-
sd += 10;
|
|
9884
|
-
num = naturalLogarithm(arg, sd);
|
|
9885
|
-
denominator = isBase10 ? getLn10(Ctor, sd + 10) : naturalLogarithm(base, sd);
|
|
9886
|
-
r = divide(num, denominator, sd, 1);
|
|
9887
|
-
if (!inf) {
|
|
9888
|
-
if (+digitsToString(r.d).slice(k + 1, k + 15) + 1 == 1e14) r = finalise(r, pr + 1, 0);
|
|
9889
|
-
break;
|
|
9890
|
-
}
|
|
9891
|
-
} while (checkRoundingDigits(r.d, k += 10, rm));
|
|
9892
|
-
external = true;
|
|
9893
|
-
return finalise(r, pr, rm);
|
|
9894
|
-
};
|
|
9895
|
-
P.minus = P.sub = function(y) {
|
|
9896
|
-
var d, e, i, j, k, len, pr, rm, xd, xe, xLTy, yd, x = this, Ctor = x.constructor;
|
|
9897
|
-
y = new Ctor(y);
|
|
9898
|
-
if (!x.d || !y.d) {
|
|
9899
|
-
if (!x.s || !y.s) y = new Ctor(NaN);
|
|
9900
|
-
else if (x.d) y.s = -y.s;
|
|
9901
|
-
else y = new Ctor(y.d || x.s !== y.s ? x : NaN);
|
|
9902
|
-
return y;
|
|
9903
|
-
}
|
|
9904
|
-
if (x.s != y.s) {
|
|
9905
|
-
y.s = -y.s;
|
|
9906
|
-
return x.plus(y);
|
|
9907
|
-
}
|
|
9908
|
-
xd = x.d;
|
|
9909
|
-
yd = y.d;
|
|
9910
|
-
pr = Ctor.precision;
|
|
9911
|
-
rm = Ctor.rounding;
|
|
9912
|
-
if (!xd[0] || !yd[0]) {
|
|
9913
|
-
if (yd[0]) y.s = -y.s;
|
|
9914
|
-
else if (xd[0]) y = new Ctor(x);
|
|
9915
|
-
else return new Ctor(rm === 3 ? -0 : 0);
|
|
9916
|
-
return external ? finalise(y, pr, rm) : y;
|
|
9917
|
-
}
|
|
9918
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
9919
|
-
xe = mathfloor(x.e / LOG_BASE);
|
|
9920
|
-
xd = xd.slice();
|
|
9921
|
-
k = xe - e;
|
|
9922
|
-
if (k) {
|
|
9923
|
-
xLTy = k < 0;
|
|
9924
|
-
if (xLTy) {
|
|
9925
|
-
d = xd;
|
|
9926
|
-
k = -k;
|
|
9927
|
-
len = yd.length;
|
|
9928
|
-
} else {
|
|
9929
|
-
d = yd;
|
|
9930
|
-
e = xe;
|
|
9931
|
-
len = xd.length;
|
|
9932
|
-
}
|
|
9933
|
-
i = Math.max(Math.ceil(pr / LOG_BASE), len) + 2;
|
|
9934
|
-
if (k > i) {
|
|
9935
|
-
k = i;
|
|
9936
|
-
d.length = 1;
|
|
9937
|
-
}
|
|
9938
|
-
d.reverse();
|
|
9939
|
-
for (i = k; i--;) d.push(0);
|
|
9940
|
-
d.reverse();
|
|
9941
|
-
} else {
|
|
9942
|
-
i = xd.length;
|
|
9943
|
-
len = yd.length;
|
|
9944
|
-
xLTy = i < len;
|
|
9945
|
-
if (xLTy) len = i;
|
|
9946
|
-
for (i = 0; i < len; i++) if (xd[i] != yd[i]) {
|
|
9947
|
-
xLTy = xd[i] < yd[i];
|
|
9948
|
-
break;
|
|
9949
|
-
}
|
|
9950
|
-
k = 0;
|
|
9951
|
-
}
|
|
9952
|
-
if (xLTy) {
|
|
9953
|
-
d = xd;
|
|
9954
|
-
xd = yd;
|
|
9955
|
-
yd = d;
|
|
9956
|
-
y.s = -y.s;
|
|
9957
|
-
}
|
|
9958
|
-
len = xd.length;
|
|
9959
|
-
for (i = yd.length - len; i > 0; --i) xd[len++] = 0;
|
|
9960
|
-
for (i = yd.length; i > k;) {
|
|
9961
|
-
if (xd[--i] < yd[i]) {
|
|
9962
|
-
for (j = i; j && xd[--j] === 0;) xd[j] = BASE - 1;
|
|
9963
|
-
--xd[j];
|
|
9964
|
-
xd[i] += BASE;
|
|
9965
|
-
}
|
|
9966
|
-
xd[i] -= yd[i];
|
|
9967
|
-
}
|
|
9968
|
-
for (; xd[--len] === 0;) xd.pop();
|
|
9969
|
-
for (; xd[0] === 0; xd.shift()) --e;
|
|
9970
|
-
if (!xd[0]) return new Ctor(rm === 3 ? -0 : 0);
|
|
9971
|
-
y.d = xd;
|
|
9972
|
-
y.e = getBase10Exponent(xd, e);
|
|
9973
|
-
return external ? finalise(y, pr, rm) : y;
|
|
9974
|
-
};
|
|
9975
|
-
P.modulo = P.mod = function(y) {
|
|
9976
|
-
var q, x = this, Ctor = x.constructor;
|
|
9977
|
-
y = new Ctor(y);
|
|
9978
|
-
if (!x.d || !y.s || y.d && !y.d[0]) return new Ctor(NaN);
|
|
9979
|
-
if (!y.d || x.d && !x.d[0]) return finalise(new Ctor(x), Ctor.precision, Ctor.rounding);
|
|
9980
|
-
external = false;
|
|
9981
|
-
if (Ctor.modulo == 9) {
|
|
9982
|
-
q = divide(x, y.abs(), 0, 3, 1);
|
|
9983
|
-
q.s *= y.s;
|
|
9984
|
-
} else q = divide(x, y, 0, Ctor.modulo, 1);
|
|
9985
|
-
q = q.times(y);
|
|
9986
|
-
external = true;
|
|
9987
|
-
return x.minus(q);
|
|
9988
|
-
};
|
|
9989
|
-
P.naturalExponential = P.exp = function() {
|
|
9990
|
-
return naturalExponential(this);
|
|
9991
|
-
};
|
|
9992
|
-
P.naturalLogarithm = P.ln = function() {
|
|
9993
|
-
return naturalLogarithm(this);
|
|
9994
|
-
};
|
|
9995
|
-
P.negated = P.neg = function() {
|
|
9996
|
-
var x = new this.constructor(this);
|
|
9997
|
-
x.s = -x.s;
|
|
9998
|
-
return finalise(x);
|
|
9999
|
-
};
|
|
10000
|
-
P.plus = P.add = function(y) {
|
|
10001
|
-
var carry, d, e, i, k, len, pr, rm, xd, yd, x = this, Ctor = x.constructor;
|
|
10002
|
-
y = new Ctor(y);
|
|
10003
|
-
if (!x.d || !y.d) {
|
|
10004
|
-
if (!x.s || !y.s) y = new Ctor(NaN);
|
|
10005
|
-
else if (!x.d) y = new Ctor(y.d || x.s === y.s ? x : NaN);
|
|
10006
|
-
return y;
|
|
10007
|
-
}
|
|
10008
|
-
if (x.s != y.s) {
|
|
10009
|
-
y.s = -y.s;
|
|
10010
|
-
return x.minus(y);
|
|
10011
|
-
}
|
|
10012
|
-
xd = x.d;
|
|
10013
|
-
yd = y.d;
|
|
10014
|
-
pr = Ctor.precision;
|
|
10015
|
-
rm = Ctor.rounding;
|
|
10016
|
-
if (!xd[0] || !yd[0]) {
|
|
10017
|
-
if (!yd[0]) y = new Ctor(x);
|
|
10018
|
-
return external ? finalise(y, pr, rm) : y;
|
|
10019
|
-
}
|
|
10020
|
-
k = mathfloor(x.e / LOG_BASE);
|
|
10021
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
10022
|
-
xd = xd.slice();
|
|
10023
|
-
i = k - e;
|
|
10024
|
-
if (i) {
|
|
10025
|
-
if (i < 0) {
|
|
10026
|
-
d = xd;
|
|
10027
|
-
i = -i;
|
|
10028
|
-
len = yd.length;
|
|
10029
|
-
} else {
|
|
10030
|
-
d = yd;
|
|
10031
|
-
e = k;
|
|
10032
|
-
len = xd.length;
|
|
10033
|
-
}
|
|
10034
|
-
k = Math.ceil(pr / LOG_BASE);
|
|
10035
|
-
len = k > len ? k + 1 : len + 1;
|
|
10036
|
-
if (i > len) {
|
|
10037
|
-
i = len;
|
|
10038
|
-
d.length = 1;
|
|
10039
|
-
}
|
|
10040
|
-
d.reverse();
|
|
10041
|
-
for (; i--;) d.push(0);
|
|
10042
|
-
d.reverse();
|
|
10043
|
-
}
|
|
10044
|
-
len = xd.length;
|
|
10045
|
-
i = yd.length;
|
|
10046
|
-
if (len - i < 0) {
|
|
10047
|
-
i = len;
|
|
10048
|
-
d = yd;
|
|
10049
|
-
yd = xd;
|
|
10050
|
-
xd = d;
|
|
10051
|
-
}
|
|
10052
|
-
for (carry = 0; i;) {
|
|
10053
|
-
carry = (xd[--i] = xd[i] + yd[i] + carry) / BASE | 0;
|
|
10054
|
-
xd[i] %= BASE;
|
|
10055
|
-
}
|
|
10056
|
-
if (carry) {
|
|
10057
|
-
xd.unshift(carry);
|
|
10058
|
-
++e;
|
|
10059
|
-
}
|
|
10060
|
-
for (len = xd.length; xd[--len] == 0;) xd.pop();
|
|
10061
|
-
y.d = xd;
|
|
10062
|
-
y.e = getBase10Exponent(xd, e);
|
|
10063
|
-
return external ? finalise(y, pr, rm) : y;
|
|
10064
|
-
};
|
|
10065
|
-
P.precision = P.sd = function(z) {
|
|
10066
|
-
var k, x = this;
|
|
10067
|
-
if (z !== void 0 && z !== !!z && z !== 1 && z !== 0) throw Error(invalidArgument + z);
|
|
10068
|
-
if (x.d) {
|
|
10069
|
-
k = getPrecision(x.d);
|
|
10070
|
-
if (z && x.e + 1 > k) k = x.e + 1;
|
|
10071
|
-
} else k = NaN;
|
|
10072
|
-
return k;
|
|
10073
|
-
};
|
|
10074
|
-
P.round = function() {
|
|
10075
|
-
var x = this, Ctor = x.constructor;
|
|
10076
|
-
return finalise(new Ctor(x), x.e + 1, Ctor.rounding);
|
|
10077
|
-
};
|
|
10078
|
-
P.sine = P.sin = function() {
|
|
10079
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10080
|
-
if (!x.isFinite()) return new Ctor(NaN);
|
|
10081
|
-
if (x.isZero()) return new Ctor(x);
|
|
10082
|
-
pr = Ctor.precision;
|
|
10083
|
-
rm = Ctor.rounding;
|
|
10084
|
-
Ctor.precision = pr + Math.max(x.e, x.sd()) + LOG_BASE;
|
|
10085
|
-
Ctor.rounding = 1;
|
|
10086
|
-
x = sine(Ctor, toLessThanHalfPi(Ctor, x));
|
|
10087
|
-
Ctor.precision = pr;
|
|
10088
|
-
Ctor.rounding = rm;
|
|
10089
|
-
return finalise(quadrant > 2 ? x.neg() : x, pr, rm, true);
|
|
10090
|
-
};
|
|
10091
|
-
P.squareRoot = P.sqrt = function() {
|
|
10092
|
-
var m, n, sd, r, rep, t, x = this, d = x.d, e = x.e, s = x.s, Ctor = x.constructor;
|
|
10093
|
-
if (s !== 1 || !d || !d[0]) return new Ctor(!s || s < 0 && (!d || d[0]) ? NaN : d ? x : 1 / 0);
|
|
10094
|
-
external = false;
|
|
10095
|
-
s = Math.sqrt(+x);
|
|
10096
|
-
if (s == 0 || s == 1 / 0) {
|
|
10097
|
-
n = digitsToString(d);
|
|
10098
|
-
if ((n.length + e) % 2 == 0) n += "0";
|
|
10099
|
-
s = Math.sqrt(n);
|
|
10100
|
-
e = mathfloor((e + 1) / 2) - (e < 0 || e % 2);
|
|
10101
|
-
if (s == 1 / 0) n = "5e" + e;
|
|
10102
|
-
else {
|
|
10103
|
-
n = s.toExponential();
|
|
10104
|
-
n = n.slice(0, n.indexOf("e") + 1) + e;
|
|
9564
|
+
static config(config) {
|
|
9565
|
+
return this.set(config);
|
|
9566
|
+
}
|
|
9567
|
+
static isDecimal(value) {
|
|
9568
|
+
return value instanceof Decimal;
|
|
9569
|
+
}
|
|
9570
|
+
normalize() {
|
|
9571
|
+
if (this.coefficient === 0n) {
|
|
9572
|
+
this.exponent = 0;
|
|
9573
|
+
return;
|
|
10105
9574
|
}
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
rep = 1;
|
|
10124
|
-
} else {
|
|
10125
|
-
if (!+n || !+n.slice(1) && n.charAt(0) == "5") {
|
|
10126
|
-
finalise(r, e + 1, 1);
|
|
10127
|
-
m = !r.times(r).eq(x);
|
|
10128
|
-
}
|
|
10129
|
-
break;
|
|
9575
|
+
const text = abs(this.coefficient).toString();
|
|
9576
|
+
const trimmed = text.replace(/0+$/, "");
|
|
9577
|
+
this.exponent += text.length - trimmed.length;
|
|
9578
|
+
this.coefficient = BigInt(trimmed) * (this.coefficient < 0n ? -1n : 1n);
|
|
9579
|
+
if (Math.abs(this.exponent) > MAX_EXPONENT) throw new RangeError("Decimal result exceeds the supported exponent range");
|
|
9580
|
+
}
|
|
9581
|
+
static make(coefficient, exponent, round = true, sticky = false) {
|
|
9582
|
+
const result = Object.create(Decimal.prototype);
|
|
9583
|
+
if (round && coefficient !== 0n) {
|
|
9584
|
+
const excess = digits$1(coefficient) - Decimal.precision;
|
|
9585
|
+
if (excess > 0) {
|
|
9586
|
+
const divisor = power(excess), sign = coefficient < 0n ? -1n : 1n;
|
|
9587
|
+
const remainder = abs(coefficient % divisor);
|
|
9588
|
+
let q = coefficient / divisor;
|
|
9589
|
+
if (increment(q, remainder, divisor, sign, Decimal.rounding, sticky)) q += sign;
|
|
9590
|
+
coefficient = q;
|
|
9591
|
+
exponent += excess;
|
|
10130
9592
|
}
|
|
10131
9593
|
}
|
|
9594
|
+
result.coefficient = coefficient;
|
|
9595
|
+
result.exponent = exponent;
|
|
9596
|
+
result.normalize();
|
|
9597
|
+
return result;
|
|
10132
9598
|
}
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
P.tangent = P.tan = function() {
|
|
10137
|
-
var pr, rm, x = this, Ctor = x.constructor;
|
|
10138
|
-
if (!x.isFinite()) return new Ctor(NaN);
|
|
10139
|
-
if (x.isZero()) return new Ctor(x);
|
|
10140
|
-
pr = Ctor.precision;
|
|
10141
|
-
rm = Ctor.rounding;
|
|
10142
|
-
Ctor.precision = pr + 10;
|
|
10143
|
-
Ctor.rounding = 1;
|
|
10144
|
-
x = x.sin();
|
|
10145
|
-
x.s = 1;
|
|
10146
|
-
x = divide(x, new Ctor(1).minus(x.times(x)).sqrt(), pr + 10, 0);
|
|
10147
|
-
Ctor.precision = pr;
|
|
10148
|
-
Ctor.rounding = rm;
|
|
10149
|
-
return finalise(quadrant == 2 || quadrant == 4 ? x.neg() : x, pr, rm, true);
|
|
10150
|
-
};
|
|
10151
|
-
P.times = P.mul = function(y) {
|
|
10152
|
-
var carry, e, i, k, r, rL, t, xdL, ydL, x = this, Ctor = x.constructor, xd = x.d, yd = (y = new Ctor(y)).d;
|
|
10153
|
-
y.s *= x.s;
|
|
10154
|
-
if (!xd || !xd[0] || !yd || !yd[0]) return new Ctor(!y.s || xd && !xd[0] && !yd || yd && !yd[0] && !xd ? NaN : !xd || !yd ? y.s / 0 : y.s * 0);
|
|
10155
|
-
e = mathfloor(x.e / LOG_BASE) + mathfloor(y.e / LOG_BASE);
|
|
10156
|
-
xdL = xd.length;
|
|
10157
|
-
ydL = yd.length;
|
|
10158
|
-
if (xdL < ydL) {
|
|
10159
|
-
r = xd;
|
|
10160
|
-
xd = yd;
|
|
10161
|
-
yd = r;
|
|
10162
|
-
rL = xdL;
|
|
10163
|
-
xdL = ydL;
|
|
10164
|
-
ydL = rL;
|
|
10165
|
-
}
|
|
10166
|
-
r = [];
|
|
10167
|
-
rL = xdL + ydL;
|
|
10168
|
-
for (i = rL; i--;) r.push(0);
|
|
10169
|
-
for (i = ydL; --i >= 0;) {
|
|
10170
|
-
carry = 0;
|
|
10171
|
-
for (k = xdL + i; k > i;) {
|
|
10172
|
-
t = r[k] + yd[i] * xd[k - i - 1] + carry;
|
|
10173
|
-
r[k--] = t % BASE | 0;
|
|
10174
|
-
carry = t / BASE | 0;
|
|
10175
|
-
}
|
|
10176
|
-
r[k] = (r[k] + carry) % BASE | 0;
|
|
10177
|
-
}
|
|
10178
|
-
for (; !r[--rL];) r.pop();
|
|
10179
|
-
if (carry) ++e;
|
|
10180
|
-
else r.shift();
|
|
10181
|
-
y.d = r;
|
|
10182
|
-
y.e = getBase10Exponent(r, e);
|
|
10183
|
-
return external ? finalise(y, Ctor.precision, Ctor.rounding) : y;
|
|
10184
|
-
};
|
|
10185
|
-
P.toBinary = function(sd, rm) {
|
|
10186
|
-
return toStringBinary(this, 2, sd, rm);
|
|
10187
|
-
};
|
|
10188
|
-
P.toDecimalPlaces = P.toDP = function(dp, rm) {
|
|
10189
|
-
var x = this, Ctor = x.constructor;
|
|
10190
|
-
x = new Ctor(x);
|
|
10191
|
-
if (dp === void 0) return x;
|
|
10192
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
10193
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
10194
|
-
else checkInt32(rm, 0, 8);
|
|
10195
|
-
return finalise(x, dp + x.e + 1, rm);
|
|
10196
|
-
};
|
|
10197
|
-
P.toExponential = function(dp, rm) {
|
|
10198
|
-
var str, x = this, Ctor = x.constructor;
|
|
10199
|
-
if (dp === void 0) str = finiteToString(x, true);
|
|
10200
|
-
else {
|
|
10201
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
10202
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
10203
|
-
else checkInt32(rm, 0, 8);
|
|
10204
|
-
x = finalise(new Ctor(x), dp + 1, rm);
|
|
10205
|
-
str = finiteToString(x, true, dp + 1);
|
|
9599
|
+
add(value) {
|
|
9600
|
+
const b = new Decimal(value), e = Math.min(this.exponent, b.exponent);
|
|
9601
|
+
return Decimal.make(this.coefficient * power(this.exponent - e) + b.coefficient * power(b.exponent - e), e);
|
|
10206
9602
|
}
|
|
10207
|
-
|
|
10208
|
-
|
|
10209
|
-
P.toFixed = function(dp, rm) {
|
|
10210
|
-
var str, y, x = this, Ctor = x.constructor;
|
|
10211
|
-
if (dp === void 0) str = finiteToString(x);
|
|
10212
|
-
else {
|
|
10213
|
-
checkInt32(dp, 0, MAX_DIGITS);
|
|
10214
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
10215
|
-
else checkInt32(rm, 0, 8);
|
|
10216
|
-
y = finalise(new Ctor(x), dp + x.e + 1, rm);
|
|
10217
|
-
str = finiteToString(y, false, dp + y.e + 1);
|
|
9603
|
+
plus(value) {
|
|
9604
|
+
return this.add(value);
|
|
10218
9605
|
}
|
|
10219
|
-
|
|
10220
|
-
|
|
10221
|
-
P.toFraction = function(maxD) {
|
|
10222
|
-
var d, d0, d1, d2, e, k, n, n0, n1, pr, q, r, x = this, xd = x.d, Ctor = x.constructor;
|
|
10223
|
-
if (!xd) return new Ctor(x);
|
|
10224
|
-
n1 = d0 = new Ctor(1);
|
|
10225
|
-
d1 = n0 = new Ctor(0);
|
|
10226
|
-
d = new Ctor(d1);
|
|
10227
|
-
e = d.e = getPrecision(xd) - x.e - 1;
|
|
10228
|
-
k = e % LOG_BASE;
|
|
10229
|
-
d.d[0] = mathpow(10, k < 0 ? LOG_BASE + k : k);
|
|
10230
|
-
if (maxD == null) maxD = e > 0 ? d : n1;
|
|
10231
|
-
else {
|
|
10232
|
-
n = new Ctor(maxD);
|
|
10233
|
-
if (!n.isInt() || n.lt(n1)) throw Error(invalidArgument + n);
|
|
10234
|
-
maxD = n.gt(d) ? e > 0 ? d : n1 : n;
|
|
10235
|
-
}
|
|
10236
|
-
external = false;
|
|
10237
|
-
n = new Ctor(digitsToString(xd));
|
|
10238
|
-
pr = Ctor.precision;
|
|
10239
|
-
Ctor.precision = e = xd.length * LOG_BASE * 2;
|
|
10240
|
-
for (;;) {
|
|
10241
|
-
q = divide(n, d, 0, 1, 1);
|
|
10242
|
-
d2 = d0.plus(q.times(d1));
|
|
10243
|
-
if (d2.cmp(maxD) == 1) break;
|
|
10244
|
-
d0 = d1;
|
|
10245
|
-
d1 = d2;
|
|
10246
|
-
d2 = n1;
|
|
10247
|
-
n1 = n0.plus(q.times(d2));
|
|
10248
|
-
n0 = d2;
|
|
10249
|
-
d2 = d;
|
|
10250
|
-
d = n.minus(q.times(d2));
|
|
10251
|
-
n = d2;
|
|
10252
|
-
}
|
|
10253
|
-
d2 = divide(maxD.minus(d0), d1, 0, 1, 1);
|
|
10254
|
-
n0 = n0.plus(d2.times(n1));
|
|
10255
|
-
d0 = d0.plus(d2.times(d1));
|
|
10256
|
-
n0.s = n1.s = x.s;
|
|
10257
|
-
r = divide(n1, d1, e, 1).minus(x).abs().cmp(divide(n0, d0, e, 1).minus(x).abs()) < 1 ? [n1, d1] : [n0, d0];
|
|
10258
|
-
Ctor.precision = pr;
|
|
10259
|
-
external = true;
|
|
10260
|
-
return r;
|
|
10261
|
-
};
|
|
10262
|
-
P.toHexadecimal = P.toHex = function(sd, rm) {
|
|
10263
|
-
return toStringBinary(this, 16, sd, rm);
|
|
10264
|
-
};
|
|
10265
|
-
P.toNearest = function(y, rm) {
|
|
10266
|
-
var x = this, Ctor = x.constructor;
|
|
10267
|
-
x = new Ctor(x);
|
|
10268
|
-
if (y == null) {
|
|
10269
|
-
if (!x.d) return x;
|
|
10270
|
-
y = new Ctor(1);
|
|
10271
|
-
rm = Ctor.rounding;
|
|
10272
|
-
} else {
|
|
10273
|
-
y = new Ctor(y);
|
|
10274
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
10275
|
-
else checkInt32(rm, 0, 8);
|
|
10276
|
-
if (!x.d) return y.s ? x : y;
|
|
10277
|
-
if (!y.d) {
|
|
10278
|
-
if (y.s) y.s = x.s;
|
|
10279
|
-
return y;
|
|
10280
|
-
}
|
|
10281
|
-
}
|
|
10282
|
-
if (y.d[0]) {
|
|
10283
|
-
external = false;
|
|
10284
|
-
x = divide(x, y, 0, rm, 1).times(y);
|
|
10285
|
-
external = true;
|
|
10286
|
-
finalise(x);
|
|
10287
|
-
} else {
|
|
10288
|
-
y.s = x.s;
|
|
10289
|
-
x = y;
|
|
10290
|
-
}
|
|
10291
|
-
return x;
|
|
10292
|
-
};
|
|
10293
|
-
P.toNumber = function() {
|
|
10294
|
-
return +this;
|
|
10295
|
-
};
|
|
10296
|
-
P.toOctal = function(sd, rm) {
|
|
10297
|
-
return toStringBinary(this, 8, sd, rm);
|
|
10298
|
-
};
|
|
10299
|
-
P.toPower = P.pow = function(y) {
|
|
10300
|
-
var e, k, pr, r, rm, s, x = this, Ctor = x.constructor, yn = +(y = new Ctor(y));
|
|
10301
|
-
if (!x.d || !y.d || !x.d[0] || !y.d[0]) return new Ctor(mathpow(+x, yn));
|
|
10302
|
-
x = new Ctor(x);
|
|
10303
|
-
if (x.eq(1)) return x;
|
|
10304
|
-
pr = Ctor.precision;
|
|
10305
|
-
rm = Ctor.rounding;
|
|
10306
|
-
if (y.eq(1)) return finalise(x, pr, rm);
|
|
10307
|
-
e = mathfloor(y.e / LOG_BASE);
|
|
10308
|
-
if (e >= y.d.length - 1 && (k = yn < 0 ? -yn : yn) <= MAX_SAFE_INTEGER) {
|
|
10309
|
-
r = intPow(Ctor, x, k, pr);
|
|
10310
|
-
return y.s < 0 ? new Ctor(1).div(r) : finalise(r, pr, rm);
|
|
10311
|
-
}
|
|
10312
|
-
s = x.s;
|
|
10313
|
-
if (s < 0) {
|
|
10314
|
-
if (e < y.d.length - 1) return new Ctor(NaN);
|
|
10315
|
-
if ((y.d[e] & 1) == 0) s = 1;
|
|
10316
|
-
if (x.e == 0 && x.d[0] == 1 && x.d.length == 1) {
|
|
10317
|
-
x.s = s;
|
|
10318
|
-
return x;
|
|
10319
|
-
}
|
|
10320
|
-
}
|
|
10321
|
-
k = mathpow(+x, yn);
|
|
10322
|
-
e = k == 0 || !isFinite(k) ? mathfloor(yn * (Math.log("0." + digitsToString(x.d)) / Math.LN10 + x.e + 1)) : new Ctor(k + "").e;
|
|
10323
|
-
if (e > Ctor.maxE + 1 || e < Ctor.minE - 1) return new Ctor(e > 0 ? s / 0 : 0);
|
|
10324
|
-
external = false;
|
|
10325
|
-
Ctor.rounding = x.s = 1;
|
|
10326
|
-
k = Math.min(12, (e + "").length);
|
|
10327
|
-
r = naturalExponential(y.times(naturalLogarithm(x, pr + k)), pr);
|
|
10328
|
-
if (r.d) {
|
|
10329
|
-
r = finalise(r, pr + 5, 1);
|
|
10330
|
-
if (checkRoundingDigits(r.d, pr, rm)) {
|
|
10331
|
-
e = pr + 10;
|
|
10332
|
-
r = finalise(naturalExponential(y.times(naturalLogarithm(x, e + k)), e), e + 5, 1);
|
|
10333
|
-
if (+digitsToString(r.d).slice(pr + 1, pr + 15) + 1 == 1e14) r = finalise(r, pr + 1, 0);
|
|
10334
|
-
}
|
|
10335
|
-
}
|
|
10336
|
-
r.s = s;
|
|
10337
|
-
external = true;
|
|
10338
|
-
Ctor.rounding = rm;
|
|
10339
|
-
return finalise(r, pr, rm);
|
|
10340
|
-
};
|
|
10341
|
-
P.toPrecision = function(sd, rm) {
|
|
10342
|
-
var str, x = this, Ctor = x.constructor;
|
|
10343
|
-
if (sd === void 0) str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
10344
|
-
else {
|
|
10345
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
10346
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
10347
|
-
else checkInt32(rm, 0, 8);
|
|
10348
|
-
x = finalise(new Ctor(x), sd, rm);
|
|
10349
|
-
str = finiteToString(x, sd <= x.e || x.e <= Ctor.toExpNeg, sd);
|
|
9606
|
+
sub(value) {
|
|
9607
|
+
return this.add(new Decimal(value).negated());
|
|
10350
9608
|
}
|
|
10351
|
-
|
|
10352
|
-
|
|
10353
|
-
P.toSignificantDigits = P.toSD = function(sd, rm) {
|
|
10354
|
-
var x = this, Ctor = x.constructor;
|
|
10355
|
-
if (sd === void 0) {
|
|
10356
|
-
sd = Ctor.precision;
|
|
10357
|
-
rm = Ctor.rounding;
|
|
10358
|
-
} else {
|
|
10359
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
10360
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
10361
|
-
else checkInt32(rm, 0, 8);
|
|
10362
|
-
}
|
|
10363
|
-
return finalise(new Ctor(x), sd, rm);
|
|
10364
|
-
};
|
|
10365
|
-
P.toString = function() {
|
|
10366
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
10367
|
-
return x.isNeg() && !x.isZero() ? "-" + str : str;
|
|
10368
|
-
};
|
|
10369
|
-
P.truncated = P.trunc = function() {
|
|
10370
|
-
return finalise(new this.constructor(this), this.e + 1, 1);
|
|
10371
|
-
};
|
|
10372
|
-
P.valueOf = P.toJSON = function() {
|
|
10373
|
-
var x = this, Ctor = x.constructor, str = finiteToString(x, x.e <= Ctor.toExpNeg || x.e >= Ctor.toExpPos);
|
|
10374
|
-
return x.isNeg() ? "-" + str : str;
|
|
10375
|
-
};
|
|
10376
|
-
function digitsToString(d) {
|
|
10377
|
-
var i, k, ws, indexOfLastWord = d.length - 1, str = "", w = d[0];
|
|
10378
|
-
if (indexOfLastWord > 0) {
|
|
10379
|
-
str += w;
|
|
10380
|
-
for (i = 1; i < indexOfLastWord; i++) {
|
|
10381
|
-
ws = d[i] + "";
|
|
10382
|
-
k = LOG_BASE - ws.length;
|
|
10383
|
-
if (k) str += getZeroString(k);
|
|
10384
|
-
str += ws;
|
|
10385
|
-
}
|
|
10386
|
-
w = d[i];
|
|
10387
|
-
ws = w + "";
|
|
10388
|
-
k = LOG_BASE - ws.length;
|
|
10389
|
-
if (k) str += getZeroString(k);
|
|
10390
|
-
} else if (w === 0) return "0";
|
|
10391
|
-
for (; w % 10 === 0;) w /= 10;
|
|
10392
|
-
return str + w;
|
|
10393
|
-
}
|
|
10394
|
-
function checkInt32(i, min, max) {
|
|
10395
|
-
if (i !== ~~i || i < min || i > max) throw Error(invalidArgument + i);
|
|
10396
|
-
}
|
|
10397
|
-
function checkRoundingDigits(d, i, rm, repeating) {
|
|
10398
|
-
var di, k = d[0], r, rd;
|
|
10399
|
-
for (; k >= 10; k /= 10) --i;
|
|
10400
|
-
if (--i < 0) {
|
|
10401
|
-
i += LOG_BASE;
|
|
10402
|
-
di = 0;
|
|
10403
|
-
} else {
|
|
10404
|
-
di = Math.ceil((i + 1) / LOG_BASE);
|
|
10405
|
-
i %= LOG_BASE;
|
|
10406
|
-
}
|
|
10407
|
-
k = mathpow(10, LOG_BASE - i);
|
|
10408
|
-
rd = d[di] % k | 0;
|
|
10409
|
-
if (repeating == null) {
|
|
10410
|
-
if (i < 3) {
|
|
10411
|
-
if (i == 0) rd = rd / 100 | 0;
|
|
10412
|
-
else if (i == 1) rd = rd / 10 | 0;
|
|
10413
|
-
r = rm < 4 && rd == 99999 || rm > 3 && rd == 49999 || rd == 5e4 || rd == 0;
|
|
10414
|
-
} else r = (rm < 4 && rd + 1 == k || rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 100 | 0) == mathpow(10, i - 2) - 1 || (rd == k / 2 || rd == 0) && (d[di + 1] / k / 100 | 0) == 0;
|
|
10415
|
-
} else if (i < 4) {
|
|
10416
|
-
if (i == 0) rd = rd / 1e3 | 0;
|
|
10417
|
-
else if (i == 1) rd = rd / 100 | 0;
|
|
10418
|
-
else if (i == 2) rd = rd / 10 | 0;
|
|
10419
|
-
r = (repeating || rm < 4) && rd == 9999 || !repeating && rm > 3 && rd == 4999;
|
|
10420
|
-
} else r = ((repeating || rm < 4) && rd + 1 == k || !repeating && rm > 3 && rd + 1 == k / 2) && (d[di + 1] / k / 1e3 | 0) == mathpow(10, i - 3) - 1;
|
|
10421
|
-
return r;
|
|
10422
|
-
}
|
|
10423
|
-
function convertBase(str, baseIn, baseOut) {
|
|
10424
|
-
var j, arr = [0], arrL, i = 0, strL = str.length;
|
|
10425
|
-
for (; i < strL;) {
|
|
10426
|
-
for (arrL = arr.length; arrL--;) arr[arrL] *= baseIn;
|
|
10427
|
-
arr[0] += NUMERALS.indexOf(str.charAt(i++));
|
|
10428
|
-
for (j = 0; j < arr.length; j++) if (arr[j] > baseOut - 1) {
|
|
10429
|
-
if (arr[j + 1] === void 0) arr[j + 1] = 0;
|
|
10430
|
-
arr[j + 1] += arr[j] / baseOut | 0;
|
|
10431
|
-
arr[j] %= baseOut;
|
|
10432
|
-
}
|
|
10433
|
-
}
|
|
10434
|
-
return arr.reverse();
|
|
10435
|
-
}
|
|
10436
|
-
function cosine(Ctor, x) {
|
|
10437
|
-
var k, len, y;
|
|
10438
|
-
if (x.isZero()) return x;
|
|
10439
|
-
len = x.d.length;
|
|
10440
|
-
if (len < 32) {
|
|
10441
|
-
k = Math.ceil(len / 3);
|
|
10442
|
-
y = (1 / tinyPow(4, k)).toString();
|
|
10443
|
-
} else {
|
|
10444
|
-
k = 16;
|
|
10445
|
-
y = "2.3283064365386962890625e-10";
|
|
10446
|
-
}
|
|
10447
|
-
Ctor.precision += k;
|
|
10448
|
-
x = taylorSeries(Ctor, 1, x.times(y), new Ctor(1));
|
|
10449
|
-
for (var i = k; i--;) {
|
|
10450
|
-
var cos2x = x.times(x);
|
|
10451
|
-
x = cos2x.times(cos2x).minus(cos2x).times(8).plus(1);
|
|
10452
|
-
}
|
|
10453
|
-
Ctor.precision -= k;
|
|
10454
|
-
return x;
|
|
10455
|
-
}
|
|
10456
|
-
var divide = (function() {
|
|
10457
|
-
function multiplyInteger(x, k, base) {
|
|
10458
|
-
var temp, carry = 0, i = x.length;
|
|
10459
|
-
for (x = x.slice(); i--;) {
|
|
10460
|
-
temp = x[i] * k + carry;
|
|
10461
|
-
x[i] = temp % base | 0;
|
|
10462
|
-
carry = temp / base | 0;
|
|
10463
|
-
}
|
|
10464
|
-
if (carry) x.unshift(carry);
|
|
10465
|
-
return x;
|
|
10466
|
-
}
|
|
10467
|
-
function compare(a, b, aL, bL) {
|
|
10468
|
-
var i, r;
|
|
10469
|
-
if (aL != bL) r = aL > bL ? 1 : -1;
|
|
10470
|
-
else for (i = r = 0; i < aL; i++) if (a[i] != b[i]) {
|
|
10471
|
-
r = a[i] > b[i] ? 1 : -1;
|
|
10472
|
-
break;
|
|
10473
|
-
}
|
|
10474
|
-
return r;
|
|
9609
|
+
minus(value) {
|
|
9610
|
+
return this.sub(value);
|
|
10475
9611
|
}
|
|
10476
|
-
|
|
10477
|
-
|
|
10478
|
-
|
|
10479
|
-
a[aL] -= i;
|
|
10480
|
-
i = a[aL] < b[aL] ? 1 : 0;
|
|
10481
|
-
a[aL] = i * base + a[aL] - b[aL];
|
|
10482
|
-
}
|
|
10483
|
-
for (; !a[0] && a.length > 1;) a.shift();
|
|
10484
|
-
}
|
|
10485
|
-
return function(x, y, pr, rm, dp, base) {
|
|
10486
|
-
var cmp, e, i, k, logBase, more, prod, prodL, q, qd, rem, remL, rem0, sd, t, xi, xL, yd0, yL, yz, Ctor = x.constructor, sign = x.s == y.s ? 1 : -1, xd = x.d, yd = y.d;
|
|
10487
|
-
if (!xd || !xd[0] || !yd || !yd[0]) return new Ctor(!x.s || !y.s || (xd ? yd && xd[0] == yd[0] : !yd) ? NaN : xd && xd[0] == 0 || !yd ? sign * 0 : sign / 0);
|
|
10488
|
-
if (base) {
|
|
10489
|
-
logBase = 1;
|
|
10490
|
-
e = x.e - y.e;
|
|
10491
|
-
} else {
|
|
10492
|
-
base = BASE;
|
|
10493
|
-
logBase = LOG_BASE;
|
|
10494
|
-
e = mathfloor(x.e / logBase) - mathfloor(y.e / logBase);
|
|
10495
|
-
}
|
|
10496
|
-
yL = yd.length;
|
|
10497
|
-
xL = xd.length;
|
|
10498
|
-
q = new Ctor(sign);
|
|
10499
|
-
qd = q.d = [];
|
|
10500
|
-
for (i = 0; yd[i] == (xd[i] || 0); i++);
|
|
10501
|
-
if (yd[i] > (xd[i] || 0)) e--;
|
|
10502
|
-
if (pr == null) {
|
|
10503
|
-
sd = pr = Ctor.precision;
|
|
10504
|
-
rm = Ctor.rounding;
|
|
10505
|
-
} else if (dp) sd = pr + (x.e - y.e) + 1;
|
|
10506
|
-
else sd = pr;
|
|
10507
|
-
if (sd < 0) {
|
|
10508
|
-
qd.push(1);
|
|
10509
|
-
more = true;
|
|
10510
|
-
} else {
|
|
10511
|
-
sd = sd / logBase + 2 | 0;
|
|
10512
|
-
i = 0;
|
|
10513
|
-
if (yL == 1) {
|
|
10514
|
-
k = 0;
|
|
10515
|
-
yd = yd[0];
|
|
10516
|
-
sd++;
|
|
10517
|
-
for (; (i < xL || k) && sd--; i++) {
|
|
10518
|
-
t = k * base + (xd[i] || 0);
|
|
10519
|
-
qd[i] = t / yd | 0;
|
|
10520
|
-
k = t % yd | 0;
|
|
10521
|
-
}
|
|
10522
|
-
more = k || i < xL;
|
|
10523
|
-
} else {
|
|
10524
|
-
k = base / (yd[0] + 1) | 0;
|
|
10525
|
-
if (k > 1) {
|
|
10526
|
-
yd = multiplyInteger(yd, k, base);
|
|
10527
|
-
xd = multiplyInteger(xd, k, base);
|
|
10528
|
-
yL = yd.length;
|
|
10529
|
-
xL = xd.length;
|
|
10530
|
-
}
|
|
10531
|
-
xi = yL;
|
|
10532
|
-
rem = xd.slice(0, yL);
|
|
10533
|
-
remL = rem.length;
|
|
10534
|
-
for (; remL < yL;) rem[remL++] = 0;
|
|
10535
|
-
yz = yd.slice();
|
|
10536
|
-
yz.unshift(0);
|
|
10537
|
-
yd0 = yd[0];
|
|
10538
|
-
if (yd[1] >= base / 2) ++yd0;
|
|
10539
|
-
do {
|
|
10540
|
-
k = 0;
|
|
10541
|
-
cmp = compare(yd, rem, yL, remL);
|
|
10542
|
-
if (cmp < 0) {
|
|
10543
|
-
rem0 = rem[0];
|
|
10544
|
-
if (yL != remL) rem0 = rem0 * base + (rem[1] || 0);
|
|
10545
|
-
k = rem0 / yd0 | 0;
|
|
10546
|
-
if (k > 1) {
|
|
10547
|
-
if (k >= base) k = base - 1;
|
|
10548
|
-
prod = multiplyInteger(yd, k, base);
|
|
10549
|
-
prodL = prod.length;
|
|
10550
|
-
remL = rem.length;
|
|
10551
|
-
cmp = compare(prod, rem, prodL, remL);
|
|
10552
|
-
if (cmp == 1) {
|
|
10553
|
-
k--;
|
|
10554
|
-
subtract(prod, yL < prodL ? yz : yd, prodL, base);
|
|
10555
|
-
}
|
|
10556
|
-
} else {
|
|
10557
|
-
if (k == 0) cmp = k = 1;
|
|
10558
|
-
prod = yd.slice();
|
|
10559
|
-
}
|
|
10560
|
-
prodL = prod.length;
|
|
10561
|
-
if (prodL < remL) prod.unshift(0);
|
|
10562
|
-
subtract(rem, prod, remL, base);
|
|
10563
|
-
if (cmp == -1) {
|
|
10564
|
-
remL = rem.length;
|
|
10565
|
-
cmp = compare(yd, rem, yL, remL);
|
|
10566
|
-
if (cmp < 1) {
|
|
10567
|
-
k++;
|
|
10568
|
-
subtract(rem, yL < remL ? yz : yd, remL, base);
|
|
10569
|
-
}
|
|
10570
|
-
}
|
|
10571
|
-
remL = rem.length;
|
|
10572
|
-
} else if (cmp === 0) {
|
|
10573
|
-
k++;
|
|
10574
|
-
rem = [0];
|
|
10575
|
-
}
|
|
10576
|
-
qd[i++] = k;
|
|
10577
|
-
if (cmp && rem[0]) rem[remL++] = xd[xi] || 0;
|
|
10578
|
-
else {
|
|
10579
|
-
rem = [xd[xi]];
|
|
10580
|
-
remL = 1;
|
|
10581
|
-
}
|
|
10582
|
-
} while ((xi++ < xL || rem[0] !== void 0) && sd--);
|
|
10583
|
-
more = rem[0] !== void 0;
|
|
10584
|
-
}
|
|
10585
|
-
if (!qd[0]) qd.shift();
|
|
10586
|
-
}
|
|
10587
|
-
if (logBase == 1) {
|
|
10588
|
-
q.e = e;
|
|
10589
|
-
inexact = more;
|
|
10590
|
-
} else {
|
|
10591
|
-
for (i = 1, k = qd[0]; k >= 10; k /= 10) i++;
|
|
10592
|
-
q.e = i + e * logBase - 1;
|
|
10593
|
-
finalise(q, dp ? pr + q.e + 1 : pr, rm, more);
|
|
10594
|
-
}
|
|
10595
|
-
return q;
|
|
10596
|
-
};
|
|
10597
|
-
})();
|
|
10598
|
-
function finalise(x, sd, rm, isTruncated) {
|
|
10599
|
-
var digits, i, j, k, rd, roundUp, w, xd, xdi, Ctor = x.constructor;
|
|
10600
|
-
out: if (sd != null) {
|
|
10601
|
-
xd = x.d;
|
|
10602
|
-
if (!xd) return x;
|
|
10603
|
-
for (digits = 1, k = xd[0]; k >= 10; k /= 10) digits++;
|
|
10604
|
-
i = sd - digits;
|
|
10605
|
-
if (i < 0) {
|
|
10606
|
-
i += LOG_BASE;
|
|
10607
|
-
j = sd;
|
|
10608
|
-
w = xd[xdi = 0];
|
|
10609
|
-
rd = w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
10610
|
-
} else {
|
|
10611
|
-
xdi = Math.ceil((i + 1) / LOG_BASE);
|
|
10612
|
-
k = xd.length;
|
|
10613
|
-
if (xdi >= k) {
|
|
10614
|
-
if (isTruncated) {
|
|
10615
|
-
for (; k++ <= xdi;) xd.push(0);
|
|
10616
|
-
w = rd = 0;
|
|
10617
|
-
digits = 1;
|
|
10618
|
-
i %= LOG_BASE;
|
|
10619
|
-
j = i - LOG_BASE + 1;
|
|
10620
|
-
} else break out;
|
|
10621
|
-
} else {
|
|
10622
|
-
w = k = xd[xdi];
|
|
10623
|
-
for (digits = 1; k >= 10; k /= 10) digits++;
|
|
10624
|
-
i %= LOG_BASE;
|
|
10625
|
-
j = i - LOG_BASE + digits;
|
|
10626
|
-
rd = j < 0 ? 0 : w / mathpow(10, digits - j - 1) % 10 | 0;
|
|
10627
|
-
}
|
|
10628
|
-
}
|
|
10629
|
-
isTruncated = isTruncated || sd < 0 || xd[xdi + 1] !== void 0 || (j < 0 ? w : w % mathpow(10, digits - j - 1));
|
|
10630
|
-
roundUp = rm < 4 ? (rd || isTruncated) && (rm == 0 || rm == (x.s < 0 ? 3 : 2)) : rd > 5 || rd == 5 && (rm == 4 || isTruncated || rm == 6 && (i > 0 ? j > 0 ? w / mathpow(10, digits - j) : 0 : xd[xdi - 1]) % 10 & 1 || rm == (x.s < 0 ? 8 : 7));
|
|
10631
|
-
if (sd < 1 || !xd[0]) {
|
|
10632
|
-
xd.length = 0;
|
|
10633
|
-
if (roundUp) {
|
|
10634
|
-
sd -= x.e + 1;
|
|
10635
|
-
xd[0] = mathpow(10, (LOG_BASE - sd % LOG_BASE) % LOG_BASE);
|
|
10636
|
-
x.e = -sd || 0;
|
|
10637
|
-
} else xd[0] = x.e = 0;
|
|
10638
|
-
return x;
|
|
10639
|
-
}
|
|
10640
|
-
if (i == 0) {
|
|
10641
|
-
xd.length = xdi;
|
|
10642
|
-
k = 1;
|
|
10643
|
-
xdi--;
|
|
10644
|
-
} else {
|
|
10645
|
-
xd.length = xdi + 1;
|
|
10646
|
-
k = mathpow(10, LOG_BASE - i);
|
|
10647
|
-
xd[xdi] = j > 0 ? (w / mathpow(10, digits - j) % mathpow(10, j) | 0) * k : 0;
|
|
10648
|
-
}
|
|
10649
|
-
if (roundUp) for (;;) if (xdi == 0) {
|
|
10650
|
-
for (i = 1, j = xd[0]; j >= 10; j /= 10) i++;
|
|
10651
|
-
j = xd[0] += k;
|
|
10652
|
-
for (k = 1; j >= 10; j /= 10) k++;
|
|
10653
|
-
if (i != k) {
|
|
10654
|
-
x.e++;
|
|
10655
|
-
if (xd[0] == BASE) xd[0] = 1;
|
|
10656
|
-
}
|
|
10657
|
-
break;
|
|
10658
|
-
} else {
|
|
10659
|
-
xd[xdi] += k;
|
|
10660
|
-
if (xd[xdi] != BASE) break;
|
|
10661
|
-
xd[xdi--] = 0;
|
|
10662
|
-
k = 1;
|
|
10663
|
-
}
|
|
10664
|
-
for (i = xd.length; xd[--i] === 0;) xd.pop();
|
|
10665
|
-
}
|
|
10666
|
-
if (external) {
|
|
10667
|
-
if (x.e > Ctor.maxE) {
|
|
10668
|
-
x.d = null;
|
|
10669
|
-
x.e = NaN;
|
|
10670
|
-
} else if (x.e < Ctor.minE) {
|
|
10671
|
-
x.e = 0;
|
|
10672
|
-
x.d = [0];
|
|
10673
|
-
}
|
|
10674
|
-
}
|
|
10675
|
-
return x;
|
|
10676
|
-
}
|
|
10677
|
-
function finiteToString(x, isExp, sd) {
|
|
10678
|
-
if (!x.isFinite()) return nonFiniteToString(x);
|
|
10679
|
-
var k, e = x.e, str = digitsToString(x.d), len = str.length;
|
|
10680
|
-
if (isExp) {
|
|
10681
|
-
if (sd && (k = sd - len) > 0) str = str.charAt(0) + "." + str.slice(1) + getZeroString(k);
|
|
10682
|
-
else if (len > 1) str = str.charAt(0) + "." + str.slice(1);
|
|
10683
|
-
str = str + (x.e < 0 ? "e" : "e+") + x.e;
|
|
10684
|
-
} else if (e < 0) {
|
|
10685
|
-
str = "0." + getZeroString(-e - 1) + str;
|
|
10686
|
-
if (sd && (k = sd - len) > 0) str += getZeroString(k);
|
|
10687
|
-
} else if (e >= len) {
|
|
10688
|
-
str += getZeroString(e + 1 - len);
|
|
10689
|
-
if (sd && (k = sd - e - 1) > 0) str = str + "." + getZeroString(k);
|
|
10690
|
-
} else {
|
|
10691
|
-
if ((k = e + 1) < len) str = str.slice(0, k) + "." + str.slice(k);
|
|
10692
|
-
if (sd && (k = sd - len) > 0) {
|
|
10693
|
-
if (e + 1 === len) str += ".";
|
|
10694
|
-
str += getZeroString(k);
|
|
10695
|
-
}
|
|
10696
|
-
}
|
|
10697
|
-
return str;
|
|
10698
|
-
}
|
|
10699
|
-
function getBase10Exponent(digits, e) {
|
|
10700
|
-
var w = digits[0];
|
|
10701
|
-
for (e *= LOG_BASE; w >= 10; w /= 10) e++;
|
|
10702
|
-
return e;
|
|
10703
|
-
}
|
|
10704
|
-
function getLn10(Ctor, sd, pr) {
|
|
10705
|
-
if (sd > LN10_PRECISION) {
|
|
10706
|
-
external = true;
|
|
10707
|
-
if (pr) Ctor.precision = pr;
|
|
10708
|
-
throw Error(precisionLimitExceeded);
|
|
10709
|
-
}
|
|
10710
|
-
return finalise(new Ctor(LN10), sd, 1, true);
|
|
10711
|
-
}
|
|
10712
|
-
function getPi(Ctor, sd, rm) {
|
|
10713
|
-
if (sd > PI_PRECISION) throw Error(precisionLimitExceeded);
|
|
10714
|
-
return finalise(new Ctor(PI$1), sd, rm, true);
|
|
10715
|
-
}
|
|
10716
|
-
function getPrecision(digits) {
|
|
10717
|
-
var w = digits.length - 1, len = w * LOG_BASE + 1;
|
|
10718
|
-
w = digits[w];
|
|
10719
|
-
if (w) {
|
|
10720
|
-
for (; w % 10 == 0; w /= 10) len--;
|
|
10721
|
-
for (w = digits[0]; w >= 10; w /= 10) len++;
|
|
10722
|
-
}
|
|
10723
|
-
return len;
|
|
10724
|
-
}
|
|
10725
|
-
function getZeroString(k) {
|
|
10726
|
-
var zs = "";
|
|
10727
|
-
for (; k--;) zs += "0";
|
|
10728
|
-
return zs;
|
|
10729
|
-
}
|
|
10730
|
-
function intPow(Ctor, x, n, pr) {
|
|
10731
|
-
var isTruncated, r = new Ctor(1), k = Math.ceil(pr / LOG_BASE + 4);
|
|
10732
|
-
external = false;
|
|
10733
|
-
for (;;) {
|
|
10734
|
-
if (n % 2) {
|
|
10735
|
-
r = r.times(x);
|
|
10736
|
-
if (truncate(r.d, k)) isTruncated = true;
|
|
10737
|
-
}
|
|
10738
|
-
n = mathfloor(n / 2);
|
|
10739
|
-
if (n === 0) {
|
|
10740
|
-
n = r.d.length - 1;
|
|
10741
|
-
if (isTruncated && r.d[n] === 0) ++r.d[n];
|
|
10742
|
-
break;
|
|
10743
|
-
}
|
|
10744
|
-
x = x.times(x);
|
|
10745
|
-
truncate(x.d, k);
|
|
9612
|
+
mul(value) {
|
|
9613
|
+
const b = new Decimal(value);
|
|
9614
|
+
return Decimal.make(this.coefficient * b.coefficient, this.exponent + b.exponent);
|
|
10746
9615
|
}
|
|
10747
|
-
|
|
10748
|
-
|
|
10749
|
-
}
|
|
10750
|
-
|
|
10751
|
-
|
|
10752
|
-
|
|
10753
|
-
|
|
10754
|
-
|
|
10755
|
-
|
|
10756
|
-
|
|
10757
|
-
|
|
10758
|
-
|
|
10759
|
-
|
|
10760
|
-
|
|
10761
|
-
|
|
10762
|
-
|
|
10763
|
-
|
|
10764
|
-
|
|
10765
|
-
|
|
10766
|
-
|
|
10767
|
-
|
|
10768
|
-
|
|
10769
|
-
if (sd == null) {
|
|
10770
|
-
external = false;
|
|
10771
|
-
wpr = pr;
|
|
10772
|
-
} else wpr = sd;
|
|
10773
|
-
t = new Ctor(.03125);
|
|
10774
|
-
while (x.e > -2) {
|
|
10775
|
-
x = x.times(t);
|
|
10776
|
-
k += 5;
|
|
10777
|
-
}
|
|
10778
|
-
guard = Math.log(mathpow(2, k)) / Math.LN10 * 2 + 5 | 0;
|
|
10779
|
-
wpr += guard;
|
|
10780
|
-
denominator = pow = sum = new Ctor(1);
|
|
10781
|
-
Ctor.precision = wpr;
|
|
10782
|
-
for (;;) {
|
|
10783
|
-
pow = finalise(pow.times(x), wpr, 1);
|
|
10784
|
-
denominator = denominator.times(++i);
|
|
10785
|
-
t = sum.plus(divide(pow, denominator, wpr, 1));
|
|
10786
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
10787
|
-
j = k;
|
|
10788
|
-
while (j--) sum = finalise(sum.times(sum), wpr, 1);
|
|
10789
|
-
if (sd == null) {
|
|
10790
|
-
if (rep < 3 && checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
|
10791
|
-
Ctor.precision = wpr += 10;
|
|
10792
|
-
denominator = pow = t = new Ctor(1);
|
|
10793
|
-
i = 0;
|
|
10794
|
-
rep++;
|
|
10795
|
-
} else return finalise(sum, Ctor.precision = pr, rm, external = true);
|
|
10796
|
-
} else {
|
|
10797
|
-
Ctor.precision = pr;
|
|
10798
|
-
return sum;
|
|
10799
|
-
}
|
|
10800
|
-
}
|
|
10801
|
-
sum = t;
|
|
10802
|
-
}
|
|
10803
|
-
}
|
|
10804
|
-
function naturalLogarithm(y, sd) {
|
|
10805
|
-
var c, c0, denominator, e, numerator, rep, sum, t, wpr, x1, x2, n = 1, guard = 10, x = y, xd = x.d, Ctor = x.constructor, rm = Ctor.rounding, pr = Ctor.precision;
|
|
10806
|
-
if (x.s < 0 || !xd || !xd[0] || !x.e && xd[0] == 1 && xd.length == 1) return new Ctor(xd && !xd[0] ? -1 / 0 : x.s != 1 ? NaN : xd ? 0 : x);
|
|
10807
|
-
if (sd == null) {
|
|
10808
|
-
external = false;
|
|
10809
|
-
wpr = pr;
|
|
10810
|
-
} else wpr = sd;
|
|
10811
|
-
Ctor.precision = wpr += guard;
|
|
10812
|
-
c = digitsToString(xd);
|
|
10813
|
-
c0 = c.charAt(0);
|
|
10814
|
-
if (Math.abs(e = x.e) < 15e14) {
|
|
10815
|
-
while (c0 < 7 && c0 != 1 || c0 == 1 && c.charAt(1) > 3) {
|
|
10816
|
-
x = x.times(y);
|
|
10817
|
-
c = digitsToString(x.d);
|
|
10818
|
-
c0 = c.charAt(0);
|
|
10819
|
-
n++;
|
|
10820
|
-
}
|
|
10821
|
-
e = x.e;
|
|
10822
|
-
if (c0 > 1) {
|
|
10823
|
-
x = new Ctor("0." + c);
|
|
10824
|
-
e++;
|
|
10825
|
-
} else x = new Ctor(c0 + "." + c.slice(1));
|
|
10826
|
-
} else {
|
|
10827
|
-
t = getLn10(Ctor, wpr + 2, pr).times(e + "");
|
|
10828
|
-
x = naturalLogarithm(new Ctor(c0 + "." + c.slice(1)), wpr - guard).plus(t);
|
|
10829
|
-
Ctor.precision = pr;
|
|
10830
|
-
return sd == null ? finalise(x, pr, rm, external = true) : x;
|
|
10831
|
-
}
|
|
10832
|
-
x1 = x;
|
|
10833
|
-
sum = numerator = x = divide(x.minus(1), x.plus(1), wpr, 1);
|
|
10834
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
10835
|
-
denominator = 3;
|
|
10836
|
-
for (;;) {
|
|
10837
|
-
numerator = finalise(numerator.times(x2), wpr, 1);
|
|
10838
|
-
t = sum.plus(divide(numerator, new Ctor(denominator), wpr, 1));
|
|
10839
|
-
if (digitsToString(t.d).slice(0, wpr) === digitsToString(sum.d).slice(0, wpr)) {
|
|
10840
|
-
sum = sum.times(2);
|
|
10841
|
-
if (e !== 0) sum = sum.plus(getLn10(Ctor, wpr + 2, pr).times(e + ""));
|
|
10842
|
-
sum = divide(sum, new Ctor(n), wpr, 1);
|
|
10843
|
-
if (sd == null) {
|
|
10844
|
-
if (checkRoundingDigits(sum.d, wpr - guard, rm, rep)) {
|
|
10845
|
-
Ctor.precision = wpr += guard;
|
|
10846
|
-
t = numerator = x = divide(x1.minus(1), x1.plus(1), wpr, 1);
|
|
10847
|
-
x2 = finalise(x.times(x), wpr, 1);
|
|
10848
|
-
denominator = rep = 1;
|
|
10849
|
-
} else return finalise(sum, Ctor.precision = pr, rm, external = true);
|
|
10850
|
-
} else {
|
|
10851
|
-
Ctor.precision = pr;
|
|
10852
|
-
return sum;
|
|
10853
|
-
}
|
|
10854
|
-
}
|
|
10855
|
-
sum = t;
|
|
10856
|
-
denominator += 2;
|
|
10857
|
-
}
|
|
10858
|
-
}
|
|
10859
|
-
function nonFiniteToString(x) {
|
|
10860
|
-
return String(x.s * x.s / 0);
|
|
10861
|
-
}
|
|
10862
|
-
function parseDecimal(x, str) {
|
|
10863
|
-
var e, i, len;
|
|
10864
|
-
if ((e = str.indexOf(".")) > -1) str = str.replace(".", "");
|
|
10865
|
-
if ((i = str.search(/e/i)) > 0) {
|
|
10866
|
-
if (e < 0) e = i;
|
|
10867
|
-
e += +str.slice(i + 1);
|
|
10868
|
-
str = str.substring(0, i);
|
|
10869
|
-
} else if (e < 0) e = str.length;
|
|
10870
|
-
for (i = 0; str.charCodeAt(i) === 48; i++);
|
|
10871
|
-
for (len = str.length; str.charCodeAt(len - 1) === 48; --len);
|
|
10872
|
-
str = str.slice(i, len);
|
|
10873
|
-
if (str) {
|
|
10874
|
-
len -= i;
|
|
10875
|
-
x.e = e = e - i - 1;
|
|
10876
|
-
x.d = [];
|
|
10877
|
-
i = (e + 1) % LOG_BASE;
|
|
10878
|
-
if (e < 0) i += LOG_BASE;
|
|
10879
|
-
if (i < len) {
|
|
10880
|
-
if (i) x.d.push(+str.slice(0, i));
|
|
10881
|
-
for (len -= LOG_BASE; i < len;) x.d.push(+str.slice(i, i += LOG_BASE));
|
|
10882
|
-
str = str.slice(i);
|
|
10883
|
-
i = LOG_BASE - str.length;
|
|
10884
|
-
} else i -= len;
|
|
10885
|
-
for (; i--;) str += "0";
|
|
10886
|
-
x.d.push(+str);
|
|
10887
|
-
if (external) {
|
|
10888
|
-
if (x.e > x.constructor.maxE) {
|
|
10889
|
-
x.d = null;
|
|
10890
|
-
x.e = NaN;
|
|
10891
|
-
} else if (x.e < x.constructor.minE) {
|
|
10892
|
-
x.e = 0;
|
|
10893
|
-
x.d = [0];
|
|
10894
|
-
}
|
|
10895
|
-
}
|
|
10896
|
-
} else {
|
|
10897
|
-
x.e = 0;
|
|
10898
|
-
x.d = [0];
|
|
10899
|
-
}
|
|
10900
|
-
return x;
|
|
10901
|
-
}
|
|
10902
|
-
function parseOther(x, str) {
|
|
10903
|
-
var base, Ctor, divisor, i, isFloat, len, p, xd, xe;
|
|
10904
|
-
if (str.indexOf("_") > -1) {
|
|
10905
|
-
str = str.replace(/(\d)_(?=\d)/g, "$1");
|
|
10906
|
-
if (isDecimal.test(str)) return parseDecimal(x, str);
|
|
10907
|
-
} else if (str === "Infinity" || str === "NaN") {
|
|
10908
|
-
if (!+str) x.s = NaN;
|
|
10909
|
-
x.e = NaN;
|
|
10910
|
-
x.d = null;
|
|
10911
|
-
return x;
|
|
10912
|
-
}
|
|
10913
|
-
if (isHex.test(str)) {
|
|
10914
|
-
base = 16;
|
|
10915
|
-
str = str.toLowerCase();
|
|
10916
|
-
} else if (isBinary.test(str)) base = 2;
|
|
10917
|
-
else if (isOctal.test(str)) base = 8;
|
|
10918
|
-
else throw Error(invalidArgument + str);
|
|
10919
|
-
i = str.search(/p/i);
|
|
10920
|
-
if (i > 0) {
|
|
10921
|
-
p = +str.slice(i + 1);
|
|
10922
|
-
str = str.substring(2, i);
|
|
10923
|
-
} else str = str.slice(2);
|
|
10924
|
-
i = str.indexOf(".");
|
|
10925
|
-
isFloat = i >= 0;
|
|
10926
|
-
Ctor = x.constructor;
|
|
10927
|
-
if (isFloat) {
|
|
10928
|
-
str = str.replace(".", "");
|
|
10929
|
-
len = str.length;
|
|
10930
|
-
i = len - i;
|
|
10931
|
-
divisor = intPow(Ctor, new Ctor(base), i, i * 2);
|
|
10932
|
-
}
|
|
10933
|
-
xd = convertBase(str, base, BASE);
|
|
10934
|
-
xe = xd.length - 1;
|
|
10935
|
-
for (i = xe; xd[i] === 0; --i) xd.pop();
|
|
10936
|
-
if (i < 0) return new Ctor(x.s * 0);
|
|
10937
|
-
x.e = getBase10Exponent(xd, xe);
|
|
10938
|
-
x.d = xd;
|
|
10939
|
-
external = false;
|
|
10940
|
-
if (isFloat) x = divide(x, divisor, len * 4);
|
|
10941
|
-
if (p) x = x.times(Math.abs(p) < 54 ? mathpow(2, p) : Decimal.pow(2, p));
|
|
10942
|
-
external = true;
|
|
10943
|
-
return x;
|
|
10944
|
-
}
|
|
10945
|
-
function sine(Ctor, x) {
|
|
10946
|
-
var k, len = x.d.length;
|
|
10947
|
-
if (len < 3) return x.isZero() ? x : taylorSeries(Ctor, 2, x, x);
|
|
10948
|
-
k = 1.4 * Math.sqrt(len);
|
|
10949
|
-
k = k > 16 ? 16 : k | 0;
|
|
10950
|
-
x = x.times(1 / tinyPow(5, k));
|
|
10951
|
-
x = taylorSeries(Ctor, 2, x, x);
|
|
10952
|
-
var sin2_x, d5 = new Ctor(5), d16 = new Ctor(16), d20 = new Ctor(20);
|
|
10953
|
-
for (; k--;) {
|
|
10954
|
-
sin2_x = x.times(x);
|
|
10955
|
-
x = x.times(d5.plus(sin2_x.times(d16.times(sin2_x).minus(d20))));
|
|
10956
|
-
}
|
|
10957
|
-
return x;
|
|
10958
|
-
}
|
|
10959
|
-
function taylorSeries(Ctor, n, x, y, isHyperbolic) {
|
|
10960
|
-
var j, t, u, x2, i = 1, pr = Ctor.precision, k = Math.ceil(pr / LOG_BASE);
|
|
10961
|
-
external = false;
|
|
10962
|
-
x2 = x.times(x);
|
|
10963
|
-
u = new Ctor(y);
|
|
10964
|
-
for (;;) {
|
|
10965
|
-
t = divide(u.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
10966
|
-
u = isHyperbolic ? y.plus(t) : y.minus(t);
|
|
10967
|
-
y = divide(t.times(x2), new Ctor(n++ * n++), pr, 1);
|
|
10968
|
-
t = u.plus(y);
|
|
10969
|
-
if (t.d[k] !== void 0) {
|
|
10970
|
-
for (j = k; t.d[j] === u.d[j] && j--;);
|
|
10971
|
-
if (j == -1) break;
|
|
10972
|
-
}
|
|
10973
|
-
j = u;
|
|
10974
|
-
u = y;
|
|
10975
|
-
y = t;
|
|
10976
|
-
t = j;
|
|
10977
|
-
i++;
|
|
10978
|
-
}
|
|
10979
|
-
external = true;
|
|
10980
|
-
t.d.length = k + 1;
|
|
10981
|
-
return t;
|
|
10982
|
-
}
|
|
10983
|
-
function tinyPow(b, e) {
|
|
10984
|
-
var n = b;
|
|
10985
|
-
while (--e) n *= b;
|
|
10986
|
-
return n;
|
|
10987
|
-
}
|
|
10988
|
-
function toLessThanHalfPi(Ctor, x) {
|
|
10989
|
-
var t, isNeg = x.s < 0, pi = getPi(Ctor, Ctor.precision, 1), halfPi = pi.times(.5);
|
|
10990
|
-
x = x.abs();
|
|
10991
|
-
if (x.lte(halfPi)) {
|
|
10992
|
-
quadrant = isNeg ? 4 : 1;
|
|
10993
|
-
return x;
|
|
10994
|
-
}
|
|
10995
|
-
t = x.divToInt(pi);
|
|
10996
|
-
if (t.isZero()) quadrant = isNeg ? 3 : 2;
|
|
10997
|
-
else {
|
|
10998
|
-
x = x.minus(t.times(pi));
|
|
10999
|
-
if (x.lte(halfPi)) {
|
|
11000
|
-
quadrant = isOdd(t) ? isNeg ? 2 : 3 : isNeg ? 4 : 1;
|
|
11001
|
-
return x;
|
|
11002
|
-
}
|
|
11003
|
-
quadrant = isOdd(t) ? isNeg ? 1 : 4 : isNeg ? 3 : 2;
|
|
11004
|
-
}
|
|
11005
|
-
return x.minus(pi).abs();
|
|
11006
|
-
}
|
|
11007
|
-
function toStringBinary(x, baseOut, sd, rm) {
|
|
11008
|
-
var base, e, i, k, len, roundUp, str, xd, y, Ctor = x.constructor, isExp = sd !== void 0;
|
|
11009
|
-
if (isExp) {
|
|
11010
|
-
checkInt32(sd, 1, MAX_DIGITS);
|
|
11011
|
-
if (rm === void 0) rm = Ctor.rounding;
|
|
11012
|
-
else checkInt32(rm, 0, 8);
|
|
11013
|
-
} else {
|
|
11014
|
-
sd = Ctor.precision;
|
|
11015
|
-
rm = Ctor.rounding;
|
|
11016
|
-
}
|
|
11017
|
-
if (!x.isFinite()) str = nonFiniteToString(x);
|
|
11018
|
-
else {
|
|
11019
|
-
str = finiteToString(x);
|
|
11020
|
-
i = str.indexOf(".");
|
|
11021
|
-
if (isExp) {
|
|
11022
|
-
base = 2;
|
|
11023
|
-
if (baseOut == 16) sd = sd * 4 - 3;
|
|
11024
|
-
else if (baseOut == 8) sd = sd * 3 - 2;
|
|
11025
|
-
} else base = baseOut;
|
|
11026
|
-
if (i >= 0) {
|
|
11027
|
-
str = str.replace(".", "");
|
|
11028
|
-
y = new Ctor(1);
|
|
11029
|
-
y.e = str.length - i;
|
|
11030
|
-
y.d = convertBase(finiteToString(y), 10, base);
|
|
11031
|
-
y.e = y.d.length;
|
|
11032
|
-
}
|
|
11033
|
-
xd = convertBase(str, 10, base);
|
|
11034
|
-
e = len = xd.length;
|
|
11035
|
-
for (; xd[--len] == 0;) xd.pop();
|
|
11036
|
-
if (!xd[0]) str = isExp ? "0p+0" : "0";
|
|
11037
|
-
else {
|
|
11038
|
-
if (i < 0) e--;
|
|
11039
|
-
else {
|
|
11040
|
-
x = new Ctor(x);
|
|
11041
|
-
x.d = xd;
|
|
11042
|
-
x.e = e;
|
|
11043
|
-
x = divide(x, y, sd, rm, 0, base);
|
|
11044
|
-
xd = x.d;
|
|
11045
|
-
e = x.e;
|
|
11046
|
-
roundUp = inexact;
|
|
11047
|
-
}
|
|
11048
|
-
i = xd[sd];
|
|
11049
|
-
k = base / 2;
|
|
11050
|
-
roundUp = roundUp || xd[sd + 1] !== void 0;
|
|
11051
|
-
roundUp = rm < 4 ? (i !== void 0 || roundUp) && (rm === 0 || rm === (x.s < 0 ? 3 : 2)) : i > k || i === k && (rm === 4 || roundUp || rm === 6 && xd[sd - 1] & 1 || rm === (x.s < 0 ? 8 : 7));
|
|
11052
|
-
xd.length = sd;
|
|
11053
|
-
if (roundUp) for (; ++xd[--sd] > base - 1;) {
|
|
11054
|
-
xd[sd] = 0;
|
|
11055
|
-
if (!sd) {
|
|
11056
|
-
++e;
|
|
11057
|
-
xd.unshift(1);
|
|
11058
|
-
}
|
|
11059
|
-
}
|
|
11060
|
-
for (len = xd.length; !xd[len - 1]; --len);
|
|
11061
|
-
for (i = 0, str = ""; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
|
11062
|
-
if (isExp) {
|
|
11063
|
-
if (len > 1) {
|
|
11064
|
-
if (baseOut == 16 || baseOut == 8) {
|
|
11065
|
-
i = baseOut == 16 ? 4 : 3;
|
|
11066
|
-
for (--len; len % i; len++) str += "0";
|
|
11067
|
-
xd = convertBase(str, base, baseOut);
|
|
11068
|
-
for (len = xd.length; !xd[len - 1]; --len);
|
|
11069
|
-
for (i = 1, str = "1."; i < len; i++) str += NUMERALS.charAt(xd[i]);
|
|
11070
|
-
} else str = str.charAt(0) + "." + str.slice(1);
|
|
11071
|
-
}
|
|
11072
|
-
str = str + (e < 0 ? "p" : "p+") + e;
|
|
11073
|
-
} else if (e < 0) {
|
|
11074
|
-
for (; ++e;) str = "0" + str;
|
|
11075
|
-
str = "0." + str;
|
|
11076
|
-
} else if (++e > len) for (e -= len; e--;) str += "0";
|
|
11077
|
-
else if (e < len) str = str.slice(0, e) + "." + str.slice(e);
|
|
9616
|
+
times(value) {
|
|
9617
|
+
return this.mul(value);
|
|
9618
|
+
}
|
|
9619
|
+
div(value) {
|
|
9620
|
+
const b = new Decimal(value);
|
|
9621
|
+
if (b.isZero()) throw new RangeError("Division by zero");
|
|
9622
|
+
if (this.isZero()) return new Decimal(0);
|
|
9623
|
+
const scale = Decimal.precision + 2 + digits$1(b.coefficient) - digits$1(this.coefficient);
|
|
9624
|
+
const numerator = this.coefficient * power(Math.max(0, scale));
|
|
9625
|
+
const denominator = b.coefficient * power(Math.max(0, -scale));
|
|
9626
|
+
return Decimal.make(numerator / denominator, this.exponent - b.exponent - scale, true, numerator % denominator !== 0n);
|
|
9627
|
+
}
|
|
9628
|
+
dividedBy(value) {
|
|
9629
|
+
return this.div(value);
|
|
9630
|
+
}
|
|
9631
|
+
sqrt() {
|
|
9632
|
+
if (this.coefficient < 0n) throw new RangeError("Square root requires a nonnegative value");
|
|
9633
|
+
if (this.isZero()) return new Decimal(0);
|
|
9634
|
+
let c = this.coefficient, e = this.exponent;
|
|
9635
|
+
if (e % 2 !== 0) {
|
|
9636
|
+
c *= 10n;
|
|
9637
|
+
e--;
|
|
11078
9638
|
}
|
|
11079
|
-
|
|
9639
|
+
const scale = Math.max(0, Decimal.precision + 2 - Math.ceil(digits$1(c) / 2));
|
|
9640
|
+
const radicand = c * power(2 * scale), root = integerSqrt(radicand);
|
|
9641
|
+
return Decimal.make(root, e / 2 - scale, true, root * root !== radicand);
|
|
11080
9642
|
}
|
|
11081
|
-
|
|
11082
|
-
|
|
11083
|
-
|
|
11084
|
-
|
|
11085
|
-
|
|
9643
|
+
negated() {
|
|
9644
|
+
return Decimal.make(-this.coefficient, this.exponent, false);
|
|
9645
|
+
}
|
|
9646
|
+
neg() {
|
|
9647
|
+
return this.negated();
|
|
9648
|
+
}
|
|
9649
|
+
abs() {
|
|
9650
|
+
return Decimal.make(abs(this.coefficient), this.exponent, false);
|
|
9651
|
+
}
|
|
9652
|
+
comparedTo(value) {
|
|
9653
|
+
const b = new Decimal(value);
|
|
9654
|
+
if (this.coefficient === b.coefficient && this.exponent === b.exponent) return 0;
|
|
9655
|
+
if (this.coefficient < 0n && b.coefficient >= 0n) return -1;
|
|
9656
|
+
if (this.coefficient >= 0n && b.coefficient < 0n) return 1;
|
|
9657
|
+
if (this.isZero()) return b.isNegative() ? 1 : -1;
|
|
9658
|
+
if (b.isZero()) return this.isNegative() ? -1 : 1;
|
|
9659
|
+
const order = digits$1(this.coefficient) + this.exponent;
|
|
9660
|
+
const otherOrder = digits$1(b.coefficient) + b.exponent;
|
|
9661
|
+
if (order !== otherOrder) return (order < otherOrder ? -1 : 1) * (this.isNegative() ? -1 : 1);
|
|
9662
|
+
const e = Math.min(this.exponent, b.exponent);
|
|
9663
|
+
return this.coefficient * power(this.exponent - e) < b.coefficient * power(b.exponent - e) ? -1 : 1;
|
|
9664
|
+
}
|
|
9665
|
+
cmp(value) {
|
|
9666
|
+
return this.comparedTo(value);
|
|
9667
|
+
}
|
|
9668
|
+
eq(value) {
|
|
9669
|
+
return this.comparedTo(value) === 0;
|
|
9670
|
+
}
|
|
9671
|
+
equals(value) {
|
|
9672
|
+
return this.eq(value);
|
|
9673
|
+
}
|
|
9674
|
+
lt(value) {
|
|
9675
|
+
return this.comparedTo(value) < 0;
|
|
9676
|
+
}
|
|
9677
|
+
lte(value) {
|
|
9678
|
+
return this.comparedTo(value) <= 0;
|
|
9679
|
+
}
|
|
9680
|
+
gt(value) {
|
|
9681
|
+
return this.comparedTo(value) > 0;
|
|
9682
|
+
}
|
|
9683
|
+
gte(value) {
|
|
9684
|
+
return this.comparedTo(value) >= 0;
|
|
9685
|
+
}
|
|
9686
|
+
isZero() {
|
|
9687
|
+
return this.coefficient === 0n;
|
|
9688
|
+
}
|
|
9689
|
+
isNegative() {
|
|
9690
|
+
return this.coefficient < 0n;
|
|
9691
|
+
}
|
|
9692
|
+
isPositive() {
|
|
9693
|
+
return this.coefficient > 0n;
|
|
9694
|
+
}
|
|
9695
|
+
isFinite() {
|
|
11086
9696
|
return true;
|
|
11087
9697
|
}
|
|
11088
|
-
|
|
11089
|
-
|
|
11090
|
-
|
|
11091
|
-
|
|
11092
|
-
|
|
11093
|
-
|
|
11094
|
-
|
|
11095
|
-
|
|
11096
|
-
|
|
11097
|
-
|
|
11098
|
-
|
|
11099
|
-
|
|
11100
|
-
|
|
11101
|
-
|
|
11102
|
-
|
|
11103
|
-
|
|
11104
|
-
|
|
11105
|
-
|
|
11106
|
-
|
|
11107
|
-
|
|
11108
|
-
|
|
11109
|
-
|
|
11110
|
-
|
|
11111
|
-
return new this(x).atanh();
|
|
11112
|
-
}
|
|
11113
|
-
function atan2(y, x) {
|
|
11114
|
-
y = new this(y);
|
|
11115
|
-
x = new this(x);
|
|
11116
|
-
var r, pr = this.precision, rm = this.rounding, wpr = pr + 4;
|
|
11117
|
-
if (!y.s || !x.s) r = new this(NaN);
|
|
11118
|
-
else if (!y.d && !x.d) {
|
|
11119
|
-
r = getPi(this, wpr, 1).times(x.s > 0 ? .25 : .75);
|
|
11120
|
-
r.s = y.s;
|
|
11121
|
-
} else if (!x.d || y.isZero()) {
|
|
11122
|
-
r = x.s < 0 ? getPi(this, pr, rm) : new this(0);
|
|
11123
|
-
r.s = y.s;
|
|
11124
|
-
} else if (!y.d || x.isZero()) {
|
|
11125
|
-
r = getPi(this, wpr, 1).times(.5);
|
|
11126
|
-
r.s = y.s;
|
|
11127
|
-
} else if (x.s < 0) {
|
|
11128
|
-
this.precision = wpr;
|
|
11129
|
-
this.rounding = 1;
|
|
11130
|
-
r = this.atan(divide(y, x, wpr, 1));
|
|
11131
|
-
x = getPi(this, wpr, 1);
|
|
11132
|
-
this.precision = pr;
|
|
11133
|
-
this.rounding = rm;
|
|
11134
|
-
r = y.s < 0 ? r.minus(x) : r.plus(x);
|
|
11135
|
-
} else r = this.atan(divide(y, x, wpr, 1));
|
|
11136
|
-
return r;
|
|
11137
|
-
}
|
|
11138
|
-
function cbrt(x) {
|
|
11139
|
-
return new this(x).cbrt();
|
|
11140
|
-
}
|
|
11141
|
-
function ceil(x) {
|
|
11142
|
-
return finalise(x = new this(x), x.e + 1, 2);
|
|
11143
|
-
}
|
|
11144
|
-
function clamp$1(x, min, max) {
|
|
11145
|
-
return new this(x).clamp(min, max);
|
|
11146
|
-
}
|
|
11147
|
-
function config(obj) {
|
|
11148
|
-
if (!obj || typeof obj !== "object") throw Error(decimalError + "Object expected");
|
|
11149
|
-
var i, p, v, useDefaults = obj.defaults === true, ps = [
|
|
11150
|
-
"precision",
|
|
11151
|
-
1,
|
|
11152
|
-
MAX_DIGITS,
|
|
11153
|
-
"rounding",
|
|
11154
|
-
0,
|
|
11155
|
-
8,
|
|
11156
|
-
"toExpNeg",
|
|
11157
|
-
-EXP_LIMIT,
|
|
11158
|
-
0,
|
|
11159
|
-
"toExpPos",
|
|
11160
|
-
0,
|
|
11161
|
-
EXP_LIMIT,
|
|
11162
|
-
"maxE",
|
|
11163
|
-
0,
|
|
11164
|
-
EXP_LIMIT,
|
|
11165
|
-
"minE",
|
|
11166
|
-
-EXP_LIMIT,
|
|
11167
|
-
0,
|
|
11168
|
-
"modulo",
|
|
11169
|
-
0,
|
|
11170
|
-
9
|
|
11171
|
-
];
|
|
11172
|
-
for (i = 0; i < ps.length; i += 3) {
|
|
11173
|
-
if (p = ps[i], useDefaults) this[p] = DEFAULTS[p];
|
|
11174
|
-
if ((v = obj[p]) !== void 0) {
|
|
11175
|
-
if (mathfloor(v) === v && v >= ps[i + 1] && v <= ps[i + 2]) this[p] = v;
|
|
11176
|
-
else throw Error(invalidArgument + p + ": " + v);
|
|
11177
|
-
}
|
|
11178
|
-
}
|
|
11179
|
-
if (p = "crypto", useDefaults) this[p] = DEFAULTS[p];
|
|
11180
|
-
if ((v = obj[p]) !== void 0) {
|
|
11181
|
-
if (v === true || v === false || v === 0 || v === 1) {
|
|
11182
|
-
if (v) {
|
|
11183
|
-
if (typeof crypto != "undefined" && crypto && (crypto.getRandomValues || crypto.randomBytes)) this[p] = true;
|
|
11184
|
-
else throw Error(cryptoUnavailable);
|
|
11185
|
-
} else this[p] = false;
|
|
11186
|
-
} else throw Error(invalidArgument + p + ": " + v);
|
|
11187
|
-
}
|
|
11188
|
-
return this;
|
|
11189
|
-
}
|
|
11190
|
-
function cos(x) {
|
|
11191
|
-
return new this(x).cos();
|
|
11192
|
-
}
|
|
11193
|
-
function cosh(x) {
|
|
11194
|
-
return new this(x).cosh();
|
|
11195
|
-
}
|
|
11196
|
-
function clone$1(obj) {
|
|
11197
|
-
var i, p, ps;
|
|
11198
|
-
function Decimal(v) {
|
|
11199
|
-
var e, i, t, x = this;
|
|
11200
|
-
if (!(x instanceof Decimal)) return new Decimal(v);
|
|
11201
|
-
x.constructor = Decimal;
|
|
11202
|
-
if (isDecimalInstance(v)) {
|
|
11203
|
-
x.s = v.s;
|
|
11204
|
-
if (external) {
|
|
11205
|
-
if (!v.d || v.e > Decimal.maxE) {
|
|
11206
|
-
x.e = NaN;
|
|
11207
|
-
x.d = null;
|
|
11208
|
-
} else if (v.e < Decimal.minE) {
|
|
11209
|
-
x.e = 0;
|
|
11210
|
-
x.d = [0];
|
|
11211
|
-
} else {
|
|
11212
|
-
x.e = v.e;
|
|
11213
|
-
x.d = v.d.slice();
|
|
11214
|
-
}
|
|
11215
|
-
} else {
|
|
11216
|
-
x.e = v.e;
|
|
11217
|
-
x.d = v.d ? v.d.slice() : v.d;
|
|
11218
|
-
}
|
|
11219
|
-
return;
|
|
11220
|
-
}
|
|
11221
|
-
t = typeof v;
|
|
11222
|
-
if (t === "number") {
|
|
11223
|
-
if (v === 0) {
|
|
11224
|
-
x.s = 1 / v < 0 ? -1 : 1;
|
|
11225
|
-
x.e = 0;
|
|
11226
|
-
x.d = [0];
|
|
11227
|
-
return;
|
|
11228
|
-
}
|
|
11229
|
-
if (v < 0) {
|
|
11230
|
-
v = -v;
|
|
11231
|
-
x.s = -1;
|
|
11232
|
-
} else x.s = 1;
|
|
11233
|
-
if (v === ~~v && v < 1e7) {
|
|
11234
|
-
for (e = 0, i = v; i >= 10; i /= 10) e++;
|
|
11235
|
-
if (external) {
|
|
11236
|
-
if (e > Decimal.maxE) {
|
|
11237
|
-
x.e = NaN;
|
|
11238
|
-
x.d = null;
|
|
11239
|
-
} else if (e < Decimal.minE) {
|
|
11240
|
-
x.e = 0;
|
|
11241
|
-
x.d = [0];
|
|
11242
|
-
} else {
|
|
11243
|
-
x.e = e;
|
|
11244
|
-
x.d = [v];
|
|
11245
|
-
}
|
|
11246
|
-
} else {
|
|
11247
|
-
x.e = e;
|
|
11248
|
-
x.d = [v];
|
|
11249
|
-
}
|
|
11250
|
-
return;
|
|
11251
|
-
}
|
|
11252
|
-
if (v * 0 !== 0) {
|
|
11253
|
-
if (!v) x.s = NaN;
|
|
11254
|
-
x.e = NaN;
|
|
11255
|
-
x.d = null;
|
|
11256
|
-
return;
|
|
11257
|
-
}
|
|
11258
|
-
return parseDecimal(x, v.toString());
|
|
11259
|
-
}
|
|
11260
|
-
if (t === "string") {
|
|
11261
|
-
if ((i = v.charCodeAt(0)) === 45) {
|
|
11262
|
-
v = v.slice(1);
|
|
11263
|
-
x.s = -1;
|
|
11264
|
-
} else {
|
|
11265
|
-
if (i === 43) v = v.slice(1);
|
|
11266
|
-
x.s = 1;
|
|
11267
|
-
}
|
|
11268
|
-
return isDecimal.test(v) ? parseDecimal(x, v) : parseOther(x, v);
|
|
11269
|
-
}
|
|
11270
|
-
if (t === "bigint") {
|
|
11271
|
-
if (v < 0) {
|
|
11272
|
-
v = -v;
|
|
11273
|
-
x.s = -1;
|
|
11274
|
-
} else x.s = 1;
|
|
11275
|
-
return parseDecimal(x, v.toString());
|
|
11276
|
-
}
|
|
11277
|
-
throw Error(invalidArgument + v);
|
|
11278
|
-
}
|
|
11279
|
-
Decimal.prototype = P;
|
|
11280
|
-
Decimal.ROUND_UP = 0;
|
|
11281
|
-
Decimal.ROUND_DOWN = 1;
|
|
11282
|
-
Decimal.ROUND_CEIL = 2;
|
|
11283
|
-
Decimal.ROUND_FLOOR = 3;
|
|
11284
|
-
Decimal.ROUND_HALF_UP = 4;
|
|
11285
|
-
Decimal.ROUND_HALF_DOWN = 5;
|
|
11286
|
-
Decimal.ROUND_HALF_EVEN = 6;
|
|
11287
|
-
Decimal.ROUND_HALF_CEIL = 7;
|
|
11288
|
-
Decimal.ROUND_HALF_FLOOR = 8;
|
|
11289
|
-
Decimal.EUCLID = 9;
|
|
11290
|
-
Decimal.config = Decimal.set = config;
|
|
11291
|
-
Decimal.clone = clone$1;
|
|
11292
|
-
Decimal.isDecimal = isDecimalInstance;
|
|
11293
|
-
Decimal.abs = abs;
|
|
11294
|
-
Decimal.acos = acos;
|
|
11295
|
-
Decimal.acosh = acosh;
|
|
11296
|
-
Decimal.add = add;
|
|
11297
|
-
Decimal.asin = asin;
|
|
11298
|
-
Decimal.asinh = asinh;
|
|
11299
|
-
Decimal.atan = atan;
|
|
11300
|
-
Decimal.atanh = atanh;
|
|
11301
|
-
Decimal.atan2 = atan2;
|
|
11302
|
-
Decimal.cbrt = cbrt;
|
|
11303
|
-
Decimal.ceil = ceil;
|
|
11304
|
-
Decimal.clamp = clamp$1;
|
|
11305
|
-
Decimal.cos = cos;
|
|
11306
|
-
Decimal.cosh = cosh;
|
|
11307
|
-
Decimal.div = div;
|
|
11308
|
-
Decimal.exp = exp;
|
|
11309
|
-
Decimal.floor = floor;
|
|
11310
|
-
Decimal.hypot = hypot;
|
|
11311
|
-
Decimal.ln = ln;
|
|
11312
|
-
Decimal.log = log;
|
|
11313
|
-
Decimal.log10 = log10;
|
|
11314
|
-
Decimal.log2 = log2;
|
|
11315
|
-
Decimal.max = max;
|
|
11316
|
-
Decimal.min = min;
|
|
11317
|
-
Decimal.mod = mod;
|
|
11318
|
-
Decimal.mul = mul;
|
|
11319
|
-
Decimal.pow = pow;
|
|
11320
|
-
Decimal.random = random;
|
|
11321
|
-
Decimal.round = round;
|
|
11322
|
-
Decimal.sign = sign$1;
|
|
11323
|
-
Decimal.sin = sin;
|
|
11324
|
-
Decimal.sinh = sinh;
|
|
11325
|
-
Decimal.sqrt = sqrt;
|
|
11326
|
-
Decimal.sub = sub;
|
|
11327
|
-
Decimal.sum = sum;
|
|
11328
|
-
Decimal.tan = tan;
|
|
11329
|
-
Decimal.tanh = tanh;
|
|
11330
|
-
Decimal.trunc = trunc;
|
|
11331
|
-
if (obj === void 0) obj = {};
|
|
11332
|
-
if (obj) {
|
|
11333
|
-
if (obj.defaults !== true) {
|
|
11334
|
-
ps = [
|
|
11335
|
-
"precision",
|
|
11336
|
-
"rounding",
|
|
11337
|
-
"toExpNeg",
|
|
11338
|
-
"toExpPos",
|
|
11339
|
-
"maxE",
|
|
11340
|
-
"minE",
|
|
11341
|
-
"modulo",
|
|
11342
|
-
"crypto"
|
|
11343
|
-
];
|
|
11344
|
-
for (i = 0; i < ps.length;) if (!obj.hasOwnProperty(p = ps[i++])) obj[p] = this[p];
|
|
9698
|
+
isNaN() {
|
|
9699
|
+
return false;
|
|
9700
|
+
}
|
|
9701
|
+
toNumber() {
|
|
9702
|
+
return Number(this.toString());
|
|
9703
|
+
}
|
|
9704
|
+
toString() {
|
|
9705
|
+
const c = abs(this.coefficient).toString(), sign = this.isNegative() ? "-" : "";
|
|
9706
|
+
const order = c.length + this.exponent - 1;
|
|
9707
|
+
if (this.isZero()) return "0";
|
|
9708
|
+
if (order <= -7 || order >= 21) return sign + c[0] + (c.length > 1 ? "." + c.slice(1) : "") + "e" + (order >= 0 ? "+" : "") + order;
|
|
9709
|
+
const point = c.length + this.exponent;
|
|
9710
|
+
return sign + (point <= 0 ? "0." + "0".repeat(-point) + c : point >= c.length ? c + "0".repeat(point - c.length) : c.slice(0, point) + "." + c.slice(point));
|
|
9711
|
+
}
|
|
9712
|
+
toFixed(decimalPlaces = 0, rounding = Decimal.rounding) {
|
|
9713
|
+
if (!Number.isInteger(decimalPlaces) || decimalPlaces < 0 || decimalPlaces > 1e3 || !Number.isInteger(rounding) || rounding < 0 || rounding > 8) throw new RangeError("Invalid decimal places or rounding");
|
|
9714
|
+
const shift = this.exponent + decimalPlaces;
|
|
9715
|
+
let q = this.coefficient;
|
|
9716
|
+
if (shift >= 0) q *= power(shift);
|
|
9717
|
+
else {
|
|
9718
|
+
const divisor = power(-shift), sign = q < 0n ? -1n : 1n, remainder = abs(q % divisor);
|
|
9719
|
+
q /= divisor;
|
|
9720
|
+
if (increment(q, remainder, divisor, sign, rounding)) q += sign;
|
|
11345
9721
|
}
|
|
9722
|
+
const text = abs(q).toString().padStart(decimalPlaces + 1, "0");
|
|
9723
|
+
return (q < 0n ? "-" : "") + (decimalPlaces === 0 ? text : text.slice(0, -decimalPlaces) + "." + text.slice(-decimalPlaces));
|
|
11346
9724
|
}
|
|
11347
|
-
|
|
11348
|
-
|
|
11349
|
-
}
|
|
11350
|
-
function div(x, y) {
|
|
11351
|
-
return new this(x).div(y);
|
|
11352
|
-
}
|
|
11353
|
-
function exp(x) {
|
|
11354
|
-
return new this(x).exp();
|
|
11355
|
-
}
|
|
11356
|
-
function floor(x) {
|
|
11357
|
-
return finalise(x = new this(x), x.e + 1, 3);
|
|
11358
|
-
}
|
|
11359
|
-
function hypot() {
|
|
11360
|
-
var i, n, t = new this(0);
|
|
11361
|
-
external = false;
|
|
11362
|
-
for (i = 0; i < arguments.length;) {
|
|
11363
|
-
n = new this(arguments[i++]);
|
|
11364
|
-
if (!n.d) {
|
|
11365
|
-
if (n.s) {
|
|
11366
|
-
external = true;
|
|
11367
|
-
return new this(1 / 0);
|
|
11368
|
-
}
|
|
11369
|
-
t = n;
|
|
11370
|
-
} else if (t.d) t = t.plus(n.times(n));
|
|
9725
|
+
toJSON() {
|
|
9726
|
+
return this.toString();
|
|
11371
9727
|
}
|
|
11372
|
-
|
|
11373
|
-
|
|
11374
|
-
}
|
|
11375
|
-
|
|
11376
|
-
return obj instanceof Decimal || obj && obj.toStringTag === tag || false;
|
|
11377
|
-
}
|
|
11378
|
-
function ln(x) {
|
|
11379
|
-
return new this(x).ln();
|
|
11380
|
-
}
|
|
11381
|
-
function log(x, y) {
|
|
11382
|
-
return new this(x).log(y);
|
|
11383
|
-
}
|
|
11384
|
-
function log2(x) {
|
|
11385
|
-
return new this(x).log(2);
|
|
11386
|
-
}
|
|
11387
|
-
function log10(x) {
|
|
11388
|
-
return new this(x).log(10);
|
|
11389
|
-
}
|
|
11390
|
-
function max() {
|
|
11391
|
-
return maxOrMin(this, arguments, -1);
|
|
11392
|
-
}
|
|
11393
|
-
function min() {
|
|
11394
|
-
return maxOrMin(this, arguments, 1);
|
|
11395
|
-
}
|
|
11396
|
-
function mod(x, y) {
|
|
11397
|
-
return new this(x).mod(y);
|
|
11398
|
-
}
|
|
11399
|
-
function mul(x, y) {
|
|
11400
|
-
return new this(x).mul(y);
|
|
11401
|
-
}
|
|
11402
|
-
function pow(x, y) {
|
|
11403
|
-
return new this(x).pow(y);
|
|
11404
|
-
}
|
|
11405
|
-
function random(sd) {
|
|
11406
|
-
var d, e, k, n, i = 0, r = new this(1), rd = [];
|
|
11407
|
-
if (sd === void 0) sd = this.precision;
|
|
11408
|
-
else checkInt32(sd, 1, MAX_DIGITS);
|
|
11409
|
-
k = Math.ceil(sd / LOG_BASE);
|
|
11410
|
-
if (!this.crypto) for (; i < k;) rd[i++] = Math.random() * 1e7 | 0;
|
|
11411
|
-
else if (crypto.getRandomValues) {
|
|
11412
|
-
d = crypto.getRandomValues(new Uint32Array(k));
|
|
11413
|
-
for (; i < k;) {
|
|
11414
|
-
n = d[i];
|
|
11415
|
-
if (n >= 429e7) d[i] = crypto.getRandomValues(/* @__PURE__ */ new Uint32Array(1))[0];
|
|
11416
|
-
else rd[i++] = n % 1e7;
|
|
11417
|
-
}
|
|
11418
|
-
} else if (crypto.randomBytes) {
|
|
11419
|
-
d = crypto.randomBytes(k *= 4);
|
|
11420
|
-
for (; i < k;) {
|
|
11421
|
-
n = d[i] + (d[i + 1] << 8) + (d[i + 2] << 16) + ((d[i + 3] & 127) << 24);
|
|
11422
|
-
if (n >= 214e7) crypto.randomBytes(4).copy(d, i);
|
|
11423
|
-
else {
|
|
11424
|
-
rd.push(n % 1e7);
|
|
11425
|
-
i += 4;
|
|
11426
|
-
}
|
|
11427
|
-
}
|
|
11428
|
-
i = k / 4;
|
|
11429
|
-
} else throw Error(cryptoUnavailable);
|
|
11430
|
-
k = rd[--i];
|
|
11431
|
-
sd %= LOG_BASE;
|
|
11432
|
-
if (k && sd) {
|
|
11433
|
-
n = mathpow(10, LOG_BASE - sd);
|
|
11434
|
-
rd[i] = (k / n | 0) * n;
|
|
11435
|
-
}
|
|
11436
|
-
for (; rd[i] === 0; i--) rd.pop();
|
|
11437
|
-
if (i < 0) {
|
|
11438
|
-
e = 0;
|
|
11439
|
-
rd = [0];
|
|
11440
|
-
} else {
|
|
11441
|
-
e = -1;
|
|
11442
|
-
for (; rd[0] === 0; e -= LOG_BASE) rd.shift();
|
|
11443
|
-
for (k = 1, n = rd[0]; n >= 10; n /= 10) k++;
|
|
11444
|
-
if (k < LOG_BASE) e -= LOG_BASE - k;
|
|
11445
|
-
}
|
|
11446
|
-
r.e = e;
|
|
11447
|
-
r.d = rd;
|
|
11448
|
-
return r;
|
|
11449
|
-
}
|
|
11450
|
-
function round(x) {
|
|
11451
|
-
return finalise(x = new this(x), x.e + 1, this.rounding);
|
|
11452
|
-
}
|
|
11453
|
-
function sign$1(x) {
|
|
11454
|
-
x = new this(x);
|
|
11455
|
-
return x.d ? x.d[0] ? x.s : 0 * x.s : x.s || NaN;
|
|
11456
|
-
}
|
|
11457
|
-
function sin(x) {
|
|
11458
|
-
return new this(x).sin();
|
|
11459
|
-
}
|
|
11460
|
-
function sinh(x) {
|
|
11461
|
-
return new this(x).sinh();
|
|
11462
|
-
}
|
|
11463
|
-
function sqrt(x) {
|
|
11464
|
-
return new this(x).sqrt();
|
|
11465
|
-
}
|
|
11466
|
-
function sub(x, y) {
|
|
11467
|
-
return new this(x).sub(y);
|
|
11468
|
-
}
|
|
11469
|
-
function sum() {
|
|
11470
|
-
var i = 0, args = arguments, x = new this(args[i]);
|
|
11471
|
-
external = false;
|
|
11472
|
-
for (; x.s && ++i < args.length;) x = x.plus(args[i]);
|
|
11473
|
-
external = true;
|
|
11474
|
-
return finalise(x, this.precision, this.rounding);
|
|
11475
|
-
}
|
|
11476
|
-
function tan(x) {
|
|
11477
|
-
return new this(x).tan();
|
|
11478
|
-
}
|
|
11479
|
-
function tanh(x) {
|
|
11480
|
-
return new this(x).tanh();
|
|
11481
|
-
}
|
|
11482
|
-
function trunc(x) {
|
|
11483
|
-
return finalise(x = new this(x), x.e + 1, 1);
|
|
11484
|
-
}
|
|
11485
|
-
P[Symbol.for("nodejs.util.inspect.custom")] = P.toString;
|
|
11486
|
-
P[Symbol.toStringTag] = "Decimal";
|
|
11487
|
-
var Decimal = P.constructor = clone$1(DEFAULTS);
|
|
11488
|
-
LN10 = new Decimal(LN10);
|
|
11489
|
-
PI$1 = new Decimal(PI$1);
|
|
9728
|
+
valueOf() {
|
|
9729
|
+
return this.toString();
|
|
9730
|
+
}
|
|
9731
|
+
};
|
|
11490
9732
|
// src/math/HVec3.ts
|
|
11491
9733
|
/** Mutable decimal vector. Pass strings to preserve more precision than a JS number. */
|
|
11492
9734
|
var HVec3 = class HVec3 {
|
|
@@ -12377,1401 +10619,1274 @@ var Rectangle$1 = class Rectangle$1 {
|
|
|
12377
10619
|
return result;
|
|
12378
10620
|
}
|
|
12379
10621
|
};
|
|
12380
|
-
|
|
12381
|
-
var
|
|
12382
|
-
|
|
12383
|
-
|
|
12384
|
-
|
|
12385
|
-
|
|
12386
|
-
|
|
12387
|
-
|
|
12388
|
-
|
|
12389
|
-
|
|
12390
|
-
|
|
12391
|
-
|
|
12392
|
-
|
|
12393
|
-
|
|
12394
|
-
|
|
12395
|
-
|
|
12396
|
-
|
|
12397
|
-
|
|
12398
|
-
|
|
12399
|
-
|
|
12400
|
-
|
|
12401
|
-
|
|
12402
|
-
|
|
12403
|
-
|
|
12404
|
-
|
|
12405
|
-
|
|
12406
|
-
|
|
12407
|
-
|
|
12408
|
-
|
|
12409
|
-
|
|
12410
|
-
|
|
12411
|
-
|
|
12412
|
-
|
|
12413
|
-
|
|
12414
|
-
|
|
12415
|
-
|
|
12416
|
-
|
|
12417
|
-
|
|
12418
|
-
|
|
12419
|
-
|
|
12420
|
-
|
|
12421
|
-
|
|
12422
|
-
|
|
12423
|
-
|
|
12424
|
-
|
|
12425
|
-
|
|
12426
|
-
|
|
12427
|
-
|
|
12428
|
-
|
|
12429
|
-
|
|
12430
|
-
|
|
12431
|
-
|
|
12432
|
-
|
|
12433
|
-
|
|
12434
|
-
|
|
12435
|
-
|
|
12436
|
-
|
|
12437
|
-
|
|
12438
|
-
|
|
12439
|
-
|
|
12440
|
-
|
|
12441
|
-
|
|
12442
|
-
|
|
12443
|
-
|
|
12444
|
-
|
|
12445
|
-
|
|
12446
|
-
|
|
12447
|
-
|
|
12448
|
-
|
|
12449
|
-
|
|
12450
|
-
|
|
12451
|
-
|
|
12452
|
-
|
|
12453
|
-
|
|
12454
|
-
|
|
12455
|
-
|
|
12456
|
-
|
|
12457
|
-
|
|
12458
|
-
|
|
12459
|
-
|
|
12460
|
-
|
|
12461
|
-
|
|
12462
|
-
|
|
12463
|
-
|
|
12464
|
-
|
|
12465
|
-
|
|
12466
|
-
|
|
12467
|
-
|
|
12468
|
-
|
|
12469
|
-
|
|
12470
|
-
|
|
12471
|
-
|
|
12472
|
-
|
|
12473
|
-
|
|
12474
|
-
|
|
12475
|
-
|
|
12476
|
-
|
|
12477
|
-
|
|
12478
|
-
|
|
12479
|
-
|
|
12480
|
-
|
|
12481
|
-
|
|
12482
|
-
|
|
12483
|
-
|
|
12484
|
-
|
|
12485
|
-
|
|
12486
|
-
|
|
12487
|
-
|
|
12488
|
-
|
|
12489
|
-
|
|
12490
|
-
|
|
12491
|
-
|
|
12492
|
-
|
|
12493
|
-
|
|
12494
|
-
|
|
12495
|
-
|
|
12496
|
-
|
|
12497
|
-
|
|
12498
|
-
|
|
12499
|
-
|
|
12500
|
-
|
|
12501
|
-
|
|
12502
|
-
|
|
12503
|
-
|
|
12504
|
-
|
|
12505
|
-
|
|
12506
|
-
|
|
12507
|
-
|
|
12508
|
-
|
|
12509
|
-
|
|
12510
|
-
|
|
12511
|
-
|
|
12512
|
-
|
|
12513
|
-
|
|
12514
|
-
|
|
12515
|
-
|
|
12516
|
-
|
|
12517
|
-
|
|
12518
|
-
|
|
12519
|
-
|
|
12520
|
-
|
|
12521
|
-
|
|
12522
|
-
|
|
12523
|
-
|
|
12524
|
-
|
|
12525
|
-
|
|
12526
|
-
|
|
12527
|
-
|
|
12528
|
-
|
|
12529
|
-
|
|
12530
|
-
|
|
12531
|
-
|
|
12532
|
-
|
|
12533
|
-
|
|
12534
|
-
|
|
12535
|
-
|
|
12536
|
-
|
|
12537
|
-
|
|
12538
|
-
|
|
12539
|
-
|
|
12540
|
-
|
|
12541
|
-
|
|
12542
|
-
|
|
12543
|
-
|
|
12544
|
-
|
|
12545
|
-
|
|
12546
|
-
|
|
12547
|
-
|
|
12548
|
-
|
|
12549
|
-
|
|
12550
|
-
|
|
12551
|
-
|
|
12552
|
-
|
|
12553
|
-
|
|
12554
|
-
|
|
12555
|
-
|
|
12556
|
-
|
|
12557
|
-
|
|
12558
|
-
|
|
12559
|
-
|
|
12560
|
-
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
12565
|
-
|
|
12566
|
-
|
|
12567
|
-
|
|
12568
|
-
|
|
12569
|
-
|
|
12570
|
-
|
|
12571
|
-
|
|
12572
|
-
|
|
12573
|
-
|
|
12574
|
-
|
|
12575
|
-
|
|
12576
|
-
|
|
12577
|
-
|
|
12578
|
-
|
|
12579
|
-
|
|
12580
|
-
|
|
12581
|
-
|
|
12582
|
-
|
|
12583
|
-
|
|
12584
|
-
|
|
12585
|
-
|
|
12586
|
-
|
|
12587
|
-
|
|
12588
|
-
|
|
12589
|
-
|
|
12590
|
-
|
|
12591
|
-
|
|
12592
|
-
|
|
12593
|
-
|
|
12594
|
-
|
|
12595
|
-
|
|
12596
|
-
|
|
12597
|
-
|
|
12598
|
-
|
|
12599
|
-
|
|
12600
|
-
|
|
12601
|
-
|
|
12602
|
-
|
|
12603
|
-
|
|
12604
|
-
|
|
12605
|
-
|
|
12606
|
-
|
|
12607
|
-
|
|
12608
|
-
|
|
12609
|
-
|
|
12610
|
-
|
|
12611
|
-
|
|
12612
|
-
|
|
12613
|
-
|
|
12614
|
-
|
|
12615
|
-
|
|
12616
|
-
|
|
12617
|
-
|
|
12618
|
-
|
|
12619
|
-
|
|
12620
|
-
|
|
12621
|
-
|
|
12622
|
-
|
|
12623
|
-
|
|
12624
|
-
|
|
12625
|
-
|
|
12626
|
-
|
|
12627
|
-
|
|
12628
|
-
|
|
12629
|
-
|
|
12630
|
-
|
|
12631
|
-
|
|
12632
|
-
|
|
12633
|
-
|
|
12634
|
-
|
|
12635
|
-
|
|
12636
|
-
|
|
12637
|
-
|
|
12638
|
-
|
|
12639
|
-
|
|
12640
|
-
|
|
12641
|
-
|
|
12642
|
-
|
|
12643
|
-
|
|
12644
|
-
|
|
12645
|
-
|
|
12646
|
-
|
|
12647
|
-
|
|
12648
|
-
|
|
12649
|
-
|
|
12650
|
-
|
|
12651
|
-
|
|
12652
|
-
|
|
12653
|
-
|
|
12654
|
-
|
|
12655
|
-
|
|
12656
|
-
|
|
12657
|
-
|
|
12658
|
-
|
|
12659
|
-
|
|
12660
|
-
|
|
12661
|
-
|
|
12662
|
-
|
|
12663
|
-
|
|
12664
|
-
|
|
12665
|
-
|
|
12666
|
-
|
|
12667
|
-
|
|
12668
|
-
|
|
12669
|
-
|
|
12670
|
-
|
|
12671
|
-
|
|
12672
|
-
|
|
12673
|
-
|
|
12674
|
-
|
|
12675
|
-
|
|
12676
|
-
|
|
12677
|
-
|
|
12678
|
-
|
|
12679
|
-
|
|
12680
|
-
|
|
12681
|
-
|
|
12682
|
-
|
|
12683
|
-
|
|
12684
|
-
|
|
12685
|
-
|
|
12686
|
-
|
|
12687
|
-
|
|
12688
|
-
|
|
12689
|
-
|
|
12690
|
-
|
|
12691
|
-
|
|
12692
|
-
|
|
12693
|
-
|
|
12694
|
-
|
|
12695
|
-
|
|
12696
|
-
|
|
12697
|
-
|
|
12698
|
-
|
|
12699
|
-
|
|
12700
|
-
|
|
12701
|
-
|
|
12702
|
-
|
|
12703
|
-
|
|
12704
|
-
|
|
12705
|
-
|
|
12706
|
-
|
|
12707
|
-
|
|
12708
|
-
|
|
12709
|
-
|
|
12710
|
-
|
|
12711
|
-
|
|
12712
|
-
|
|
12713
|
-
|
|
12714
|
-
|
|
12715
|
-
|
|
12716
|
-
|
|
12717
|
-
|
|
12718
|
-
|
|
12719
|
-
|
|
12720
|
-
|
|
12721
|
-
|
|
12722
|
-
|
|
12723
|
-
|
|
12724
|
-
|
|
12725
|
-
|
|
12726
|
-
|
|
12727
|
-
|
|
12728
|
-
|
|
12729
|
-
|
|
12730
|
-
|
|
12731
|
-
|
|
12732
|
-
|
|
12733
|
-
|
|
12734
|
-
|
|
12735
|
-
|
|
12736
|
-
|
|
12737
|
-
|
|
12738
|
-
|
|
12739
|
-
|
|
12740
|
-
|
|
12741
|
-
|
|
12742
|
-
|
|
12743
|
-
|
|
12744
|
-
|
|
12745
|
-
|
|
12746
|
-
|
|
12747
|
-
|
|
12748
|
-
|
|
12749
|
-
|
|
12750
|
-
|
|
12751
|
-
|
|
12752
|
-
|
|
12753
|
-
|
|
12754
|
-
|
|
12755
|
-
|
|
12756
|
-
|
|
12757
|
-
|
|
12758
|
-
|
|
12759
|
-
|
|
12760
|
-
|
|
12761
|
-
|
|
12762
|
-
|
|
12763
|
-
|
|
12764
|
-
|
|
12765
|
-
|
|
12766
|
-
|
|
12767
|
-
|
|
12768
|
-
|
|
12769
|
-
|
|
12770
|
-
|
|
12771
|
-
|
|
12772
|
-
|
|
12773
|
-
|
|
12774
|
-
|
|
12775
|
-
|
|
12776
|
-
|
|
12777
|
-
|
|
12778
|
-
|
|
12779
|
-
|
|
12780
|
-
|
|
12781
|
-
|
|
12782
|
-
|
|
12783
|
-
|
|
12784
|
-
|
|
12785
|
-
|
|
12786
|
-
|
|
12787
|
-
|
|
12788
|
-
|
|
12789
|
-
|
|
12790
|
-
|
|
12791
|
-
|
|
12792
|
-
|
|
12793
|
-
|
|
12794
|
-
|
|
12795
|
-
|
|
12796
|
-
|
|
12797
|
-
|
|
12798
|
-
|
|
12799
|
-
|
|
12800
|
-
|
|
12801
|
-
|
|
12802
|
-
|
|
12803
|
-
|
|
12804
|
-
|
|
12805
|
-
|
|
12806
|
-
|
|
12807
|
-
|
|
12808
|
-
|
|
12809
|
-
|
|
12810
|
-
|
|
12811
|
-
|
|
12812
|
-
|
|
12813
|
-
|
|
12814
|
-
|
|
12815
|
-
|
|
12816
|
-
|
|
12817
|
-
|
|
12818
|
-
|
|
12819
|
-
|
|
12820
|
-
|
|
12821
|
-
|
|
12822
|
-
|
|
12823
|
-
|
|
12824
|
-
|
|
12825
|
-
|
|
12826
|
-
|
|
12827
|
-
|
|
12828
|
-
|
|
12829
|
-
|
|
12830
|
-
|
|
12831
|
-
|
|
12832
|
-
|
|
12833
|
-
|
|
12834
|
-
|
|
12835
|
-
|
|
12836
|
-
|
|
12837
|
-
|
|
12838
|
-
|
|
12839
|
-
|
|
12840
|
-
|
|
12841
|
-
|
|
12842
|
-
|
|
12843
|
-
|
|
12844
|
-
|
|
12845
|
-
|
|
12846
|
-
|
|
12847
|
-
|
|
12848
|
-
|
|
12849
|
-
|
|
12850
|
-
|
|
12851
|
-
|
|
12852
|
-
|
|
12853
|
-
|
|
12854
|
-
|
|
12855
|
-
|
|
12856
|
-
|
|
12857
|
-
|
|
12858
|
-
|
|
12859
|
-
|
|
12860
|
-
|
|
12861
|
-
|
|
12862
|
-
|
|
12863
|
-
|
|
12864
|
-
|
|
12865
|
-
|
|
12866
|
-
|
|
12867
|
-
|
|
12868
|
-
|
|
12869
|
-
|
|
12870
|
-
|
|
12871
|
-
|
|
12872
|
-
|
|
12873
|
-
|
|
12874
|
-
|
|
12875
|
-
|
|
12876
|
-
|
|
12877
|
-
|
|
12878
|
-
|
|
12879
|
-
|
|
12880
|
-
|
|
12881
|
-
|
|
12882
|
-
|
|
12883
|
-
|
|
12884
|
-
|
|
12885
|
-
|
|
12886
|
-
|
|
12887
|
-
|
|
12888
|
-
|
|
12889
|
-
|
|
12890
|
-
|
|
12891
|
-
|
|
12892
|
-
|
|
12893
|
-
|
|
12894
|
-
|
|
12895
|
-
|
|
12896
|
-
|
|
12897
|
-
|
|
12898
|
-
|
|
12899
|
-
|
|
12900
|
-
|
|
12901
|
-
|
|
12902
|
-
|
|
12903
|
-
|
|
12904
|
-
|
|
12905
|
-
|
|
12906
|
-
|
|
12907
|
-
|
|
12908
|
-
|
|
12909
|
-
|
|
12910
|
-
|
|
12911
|
-
|
|
12912
|
-
|
|
12913
|
-
|
|
12914
|
-
|
|
12915
|
-
|
|
12916
|
-
|
|
12917
|
-
|
|
12918
|
-
|
|
12919
|
-
|
|
12920
|
-
|
|
12921
|
-
|
|
12922
|
-
|
|
12923
|
-
|
|
12924
|
-
|
|
12925
|
-
|
|
12926
|
-
|
|
12927
|
-
|
|
12928
|
-
|
|
12929
|
-
|
|
12930
|
-
|
|
12931
|
-
|
|
12932
|
-
|
|
12933
|
-
|
|
12934
|
-
|
|
12935
|
-
|
|
12936
|
-
|
|
12937
|
-
|
|
12938
|
-
|
|
12939
|
-
|
|
12940
|
-
|
|
12941
|
-
|
|
12942
|
-
|
|
12943
|
-
|
|
12944
|
-
|
|
12945
|
-
|
|
12946
|
-
|
|
12947
|
-
|
|
12948
|
-
|
|
12949
|
-
|
|
12950
|
-
|
|
12951
|
-
|
|
12952
|
-
|
|
12953
|
-
|
|
12954
|
-
|
|
12955
|
-
|
|
12956
|
-
-
|
|
12957
|
-
|
|
12958
|
-
|
|
12959
|
-
|
|
12960
|
-
|
|
12961
|
-
|
|
12962
|
-
|
|
12963
|
-
|
|
12964
|
-
|
|
12965
|
-
|
|
12966
|
-
|
|
12967
|
-
|
|
12968
|
-
|
|
12969
|
-
|
|
12970
|
-
|
|
12971
|
-
|
|
12972
|
-
|
|
12973
|
-
|
|
12974
|
-
|
|
12975
|
-
|
|
12976
|
-
|
|
12977
|
-
|
|
12978
|
-
|
|
12979
|
-
|
|
12980
|
-
|
|
12981
|
-
|
|
12982
|
-
|
|
12983
|
-
|
|
12984
|
-
|
|
12985
|
-
|
|
12986
|
-
|
|
12987
|
-
|
|
12988
|
-
|
|
12989
|
-
|
|
12990
|
-
|
|
12991
|
-
|
|
12992
|
-
|
|
12993
|
-
|
|
12994
|
-
|
|
12995
|
-
|
|
12996
|
-
|
|
12997
|
-
|
|
12998
|
-
|
|
12999
|
-
|
|
13000
|
-
|
|
13001
|
-
|
|
13002
|
-
|
|
13003
|
-
|
|
13004
|
-
|
|
13005
|
-
|
|
13006
|
-
|
|
13007
|
-
|
|
13008
|
-
|
|
13009
|
-
|
|
13010
|
-
|
|
13011
|
-
|
|
13012
|
-
|
|
13013
|
-
|
|
13014
|
-
|
|
13015
|
-
|
|
13016
|
-
|
|
13017
|
-
|
|
13018
|
-
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
|
|
13027
|
-
|
|
13028
|
-
|
|
13029
|
-
|
|
13030
|
-
|
|
13031
|
-
|
|
13032
|
-
|
|
13033
|
-
sbet12a = sbet2 * cbet1;
|
|
13034
|
-
sbet12a += cbet2 * sbet1;
|
|
13035
|
-
shortline = cbet12 >= 0 && sbet12 < .5 && cbet2 * lam12 < .5;
|
|
13036
|
-
if (shortline) {
|
|
13037
|
-
sbetm2 = m.sq(sbet1 + sbet2);
|
|
13038
|
-
sbetm2 /= sbetm2 + m.sq(cbet1 + cbet2);
|
|
13039
|
-
vals.dnm = Math.sqrt(1 + this._ep2 * sbetm2);
|
|
13040
|
-
omg12 = lam12 / (this._f1 * vals.dnm);
|
|
13041
|
-
somg12 = Math.sin(omg12);
|
|
13042
|
-
comg12 = Math.cos(omg12);
|
|
10622
|
+
var epsilon = Math.pow(.5, 52);
|
|
10623
|
+
var degree = Math.PI / 180;
|
|
10624
|
+
function sq(x) {
|
|
10625
|
+
return x * x;
|
|
10626
|
+
}
|
|
10627
|
+
function hypot(x, y) {
|
|
10628
|
+
return Math.sqrt(x * x + y * y);
|
|
10629
|
+
}
|
|
10630
|
+
var cbrt = Math.cbrt;
|
|
10631
|
+
var atanh = Math.atanh;
|
|
10632
|
+
function copysign(x, y) {
|
|
10633
|
+
return Math.abs(x) * (y < 0 || y === 0 && 1 / y < 0 ? -1 : 1);
|
|
10634
|
+
}
|
|
10635
|
+
function sum(u, v) {
|
|
10636
|
+
var s = u + v, up = s - v, vpp = s - up, t;
|
|
10637
|
+
up -= u;
|
|
10638
|
+
vpp -= v;
|
|
10639
|
+
t = s ? 0 - (up + vpp) : s;
|
|
10640
|
+
return {
|
|
10641
|
+
s,
|
|
10642
|
+
t
|
|
10643
|
+
};
|
|
10644
|
+
}
|
|
10645
|
+
function polyval(N, p, s, x) {
|
|
10646
|
+
var y = N < 0 ? 0 : p[s++];
|
|
10647
|
+
while (--N >= 0) y = y * x + p[s++];
|
|
10648
|
+
return y;
|
|
10649
|
+
}
|
|
10650
|
+
function AngRound(x) {
|
|
10651
|
+
var z = 1 / 16, y = Math.abs(x);
|
|
10652
|
+
y = y < z ? z - (z - y) : y;
|
|
10653
|
+
return copysign(y, x);
|
|
10654
|
+
}
|
|
10655
|
+
function remainder(x, y) {
|
|
10656
|
+
x %= y;
|
|
10657
|
+
return x < -y / 2 ? x + y : x < y / 2 ? x : x - y;
|
|
10658
|
+
}
|
|
10659
|
+
function AngNormalize(x) {
|
|
10660
|
+
var y = remainder(x, 360);
|
|
10661
|
+
return Math.abs(y) === 180 ? copysign(180, x) : y;
|
|
10662
|
+
}
|
|
10663
|
+
function LatFix(x) {
|
|
10664
|
+
return Math.abs(x) > 90 ? NaN : x;
|
|
10665
|
+
}
|
|
10666
|
+
function AngDiff(x, y) {
|
|
10667
|
+
var r = sum(remainder(-x, 360), remainder(y, 360)), d, e;
|
|
10668
|
+
r = sum(remainder(r.s, 360), r.t);
|
|
10669
|
+
d = r.s;
|
|
10670
|
+
e = r.t;
|
|
10671
|
+
if (d === 0 || Math.abs(d) === 180) d = copysign(d, e === 0 ? y - x : -e);
|
|
10672
|
+
return {
|
|
10673
|
+
d,
|
|
10674
|
+
e
|
|
10675
|
+
};
|
|
10676
|
+
}
|
|
10677
|
+
function sincosd(x) {
|
|
10678
|
+
var d = x % 360, r, q = Math.round(d / 90), s, c, sinx, cosx;
|
|
10679
|
+
d -= 90 * q;
|
|
10680
|
+
r = d * degree;
|
|
10681
|
+
s = Math.sin(r);
|
|
10682
|
+
c = Math.cos(r);
|
|
10683
|
+
if (Math.abs(d) === 45) {
|
|
10684
|
+
c = Math.sqrt(.5);
|
|
10685
|
+
s = copysign(c, r);
|
|
10686
|
+
} else if (Math.abs(d) === 30) {
|
|
10687
|
+
c = Math.sqrt(.75);
|
|
10688
|
+
s = copysign(.5, r);
|
|
10689
|
+
}
|
|
10690
|
+
switch (q & 3) {
|
|
10691
|
+
case 0:
|
|
10692
|
+
sinx = s;
|
|
10693
|
+
cosx = c;
|
|
10694
|
+
break;
|
|
10695
|
+
case 1:
|
|
10696
|
+
sinx = c;
|
|
10697
|
+
cosx = -s;
|
|
10698
|
+
break;
|
|
10699
|
+
case 2:
|
|
10700
|
+
sinx = -s;
|
|
10701
|
+
cosx = -c;
|
|
10702
|
+
break;
|
|
10703
|
+
default:
|
|
10704
|
+
sinx = -c;
|
|
10705
|
+
cosx = s;
|
|
10706
|
+
}
|
|
10707
|
+
cosx += 0;
|
|
10708
|
+
if (sinx === 0) sinx = copysign(sinx, x);
|
|
10709
|
+
return {
|
|
10710
|
+
s: sinx,
|
|
10711
|
+
c: cosx
|
|
10712
|
+
};
|
|
10713
|
+
}
|
|
10714
|
+
function sincosde(x, t) {
|
|
10715
|
+
var d = x % 360, r, q = Math.round(d / 90), s, c, sinx, cosx;
|
|
10716
|
+
d = AngRound(d - 90 * q + t);
|
|
10717
|
+
r = d * degree;
|
|
10718
|
+
s = Math.sin(r);
|
|
10719
|
+
c = Math.cos(r);
|
|
10720
|
+
if (Math.abs(d) === 45) {
|
|
10721
|
+
c = Math.sqrt(.5);
|
|
10722
|
+
s = copysign(c, r);
|
|
10723
|
+
} else if (Math.abs(d) === 30) {
|
|
10724
|
+
c = Math.sqrt(.75);
|
|
10725
|
+
s = copysign(.5, r);
|
|
10726
|
+
}
|
|
10727
|
+
switch (q & 3) {
|
|
10728
|
+
case 0:
|
|
10729
|
+
sinx = s;
|
|
10730
|
+
cosx = c;
|
|
10731
|
+
break;
|
|
10732
|
+
case 1:
|
|
10733
|
+
sinx = c;
|
|
10734
|
+
cosx = -s;
|
|
10735
|
+
break;
|
|
10736
|
+
case 2:
|
|
10737
|
+
sinx = -s;
|
|
10738
|
+
cosx = -c;
|
|
10739
|
+
break;
|
|
10740
|
+
default:
|
|
10741
|
+
sinx = -c;
|
|
10742
|
+
cosx = s;
|
|
10743
|
+
}
|
|
10744
|
+
cosx += 0;
|
|
10745
|
+
if (sinx === 0) sinx = copysign(sinx, x + t);
|
|
10746
|
+
return {
|
|
10747
|
+
s: sinx,
|
|
10748
|
+
c: cosx
|
|
10749
|
+
};
|
|
10750
|
+
}
|
|
10751
|
+
function atan2d(y, x) {
|
|
10752
|
+
var q = 0, ang;
|
|
10753
|
+
if (Math.abs(y) > Math.abs(x)) {
|
|
10754
|
+
[y, x] = [x, y];
|
|
10755
|
+
q = 2;
|
|
10756
|
+
}
|
|
10757
|
+
if (copysign(1, x) < 0) {
|
|
10758
|
+
x = -x;
|
|
10759
|
+
++q;
|
|
10760
|
+
}
|
|
10761
|
+
ang = Math.atan2(y, x) / degree;
|
|
10762
|
+
switch (q) {
|
|
10763
|
+
case 1:
|
|
10764
|
+
ang = copysign(180, y) - ang;
|
|
10765
|
+
break;
|
|
10766
|
+
case 2:
|
|
10767
|
+
ang = 90 - ang;
|
|
10768
|
+
break;
|
|
10769
|
+
case 3: ang = -90 + ang;
|
|
10770
|
+
}
|
|
10771
|
+
return ang;
|
|
10772
|
+
}
|
|
10773
|
+
// src-gis/math/geodesic/kernel.ts
|
|
10774
|
+
/**
|
|
10775
|
+
* Internal TypeScript port of Karney's order-6 geodesic solver.
|
|
10776
|
+
* Derived from GeographicLib geodesic 2.2.0 (2011–2022, Charles Karney), MIT.
|
|
10777
|
+
* Algorithm: https://doi.org/10.1007/s00190-012-0578-z
|
|
10778
|
+
* See THIRD_PARTY_NOTICES.md. No runtime package or global namespace is used.
|
|
10779
|
+
*/
|
|
10780
|
+
var GEOGRAPHICLIB_GEODESIC_ORDER = 6;
|
|
10781
|
+
var nA1_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
10782
|
+
var nA2_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
10783
|
+
var nA3_ = GEOGRAPHICLIB_GEODESIC_ORDER;
|
|
10784
|
+
var nA3x_ = nA3_;
|
|
10785
|
+
var nC3x_;
|
|
10786
|
+
var nC4x_;
|
|
10787
|
+
var maxit1_ = 20;
|
|
10788
|
+
var maxit2_ = maxit1_ + 53 + 10;
|
|
10789
|
+
var tol0_ = epsilon;
|
|
10790
|
+
var tol1_ = 200 * tol0_;
|
|
10791
|
+
var tol2_ = Math.sqrt(tol0_);
|
|
10792
|
+
var tolb_ = tol0_;
|
|
10793
|
+
var xthresh_ = 1e3 * tol2_;
|
|
10794
|
+
var A1m1f_coeff;
|
|
10795
|
+
var C1f_coeff;
|
|
10796
|
+
var C1pf_coeff;
|
|
10797
|
+
var A2m1f_coeff;
|
|
10798
|
+
var C2f_coeff;
|
|
10799
|
+
var A3_coeff;
|
|
10800
|
+
var C3_coeff;
|
|
10801
|
+
var C4_coeff;
|
|
10802
|
+
var tiny_ = Math.sqrt(Number.MIN_VALUE / Number.EPSILON);
|
|
10803
|
+
nC3x_ = 15;
|
|
10804
|
+
nC4x_ = 21;
|
|
10805
|
+
var DISTANCE = 1025;
|
|
10806
|
+
var STANDARD = 1929;
|
|
10807
|
+
var DISTANCE_IN = 2051;
|
|
10808
|
+
var REDUCEDLENGTH = 4101;
|
|
10809
|
+
var OUT_MASK = 65408;
|
|
10810
|
+
function SinCosSeries(sinp, sinx, cosx, c) {
|
|
10811
|
+
let k = c.length, n = k - (sinp ? 1 : 0), ar = 2 * (cosx - sinx) * (cosx + sinx), y0 = n & 1 ? c[--k] : 0, y1 = 0;
|
|
10812
|
+
n = Math.floor(n / 2);
|
|
10813
|
+
while (n--) {
|
|
10814
|
+
y1 = ar * y0 - y1 + c[--k];
|
|
10815
|
+
y0 = ar * y1 - y0 + c[--k];
|
|
10816
|
+
}
|
|
10817
|
+
return sinp ? 2 * sinx * cosx * y0 : cosx * (y0 - y1);
|
|
10818
|
+
}
|
|
10819
|
+
function astroid(x, y) {
|
|
10820
|
+
let k, p = sq(x), q = sq(y), r = (p + q - 1) / 6, S, r2, r3, disc, u, T3, T, ang, v, uv, w;
|
|
10821
|
+
if (!(q === 0 && r <= 0)) {
|
|
10822
|
+
S = p * q / 4;
|
|
10823
|
+
r2 = sq(r);
|
|
10824
|
+
r3 = r * r2;
|
|
10825
|
+
disc = S * (S + 2 * r3);
|
|
10826
|
+
u = r;
|
|
10827
|
+
if (disc >= 0) {
|
|
10828
|
+
T3 = S + r3;
|
|
10829
|
+
T3 += T3 < 0 ? -Math.sqrt(disc) : Math.sqrt(disc);
|
|
10830
|
+
T = cbrt(T3);
|
|
10831
|
+
u += T + (T !== 0 ? r2 / T : 0);
|
|
10832
|
+
} else {
|
|
10833
|
+
ang = Math.atan2(Math.sqrt(-disc), -(S + r3));
|
|
10834
|
+
u += 2 * r * Math.cos(ang / 3);
|
|
10835
|
+
}
|
|
10836
|
+
v = Math.sqrt(sq(u) + q);
|
|
10837
|
+
uv = u < 0 ? q / (v - u) : u + v;
|
|
10838
|
+
w = (uv - q) / (2 * v);
|
|
10839
|
+
k = uv / (Math.sqrt(uv + sq(w)) + w);
|
|
10840
|
+
} else k = 0;
|
|
10841
|
+
return k;
|
|
10842
|
+
}
|
|
10843
|
+
A1m1f_coeff = [
|
|
10844
|
+
1,
|
|
10845
|
+
4,
|
|
10846
|
+
64,
|
|
10847
|
+
0,
|
|
10848
|
+
256
|
|
10849
|
+
];
|
|
10850
|
+
function A1m1f(eps) {
|
|
10851
|
+
return (polyval(Math.floor(nA1_ / 2), A1m1f_coeff, 0, sq(eps)) / A1m1f_coeff[4] + eps) / (1 - eps);
|
|
10852
|
+
}
|
|
10853
|
+
C1f_coeff = [
|
|
10854
|
+
-1,
|
|
10855
|
+
6,
|
|
10856
|
+
-16,
|
|
10857
|
+
32,
|
|
10858
|
+
-9,
|
|
10859
|
+
64,
|
|
10860
|
+
-128,
|
|
10861
|
+
2048,
|
|
10862
|
+
9,
|
|
10863
|
+
-16,
|
|
10864
|
+
768,
|
|
10865
|
+
3,
|
|
10866
|
+
-5,
|
|
10867
|
+
512,
|
|
10868
|
+
-7,
|
|
10869
|
+
1280,
|
|
10870
|
+
-7,
|
|
10871
|
+
2048
|
|
10872
|
+
];
|
|
10873
|
+
function C1f(eps, c) {
|
|
10874
|
+
let eps2 = sq(eps), d = eps, o = 0, l, p;
|
|
10875
|
+
for (l = 1; l <= 6; ++l) {
|
|
10876
|
+
p = Math.floor((6 - l) / 2);
|
|
10877
|
+
c[l] = d * polyval(p, C1f_coeff, o, eps2) / C1f_coeff[o + p + 1];
|
|
10878
|
+
o += p + 2;
|
|
10879
|
+
d *= eps;
|
|
10880
|
+
}
|
|
10881
|
+
}
|
|
10882
|
+
C1pf_coeff = [
|
|
10883
|
+
205,
|
|
10884
|
+
-432,
|
|
10885
|
+
768,
|
|
10886
|
+
1536,
|
|
10887
|
+
4005,
|
|
10888
|
+
-4736,
|
|
10889
|
+
3840,
|
|
10890
|
+
12288,
|
|
10891
|
+
-225,
|
|
10892
|
+
116,
|
|
10893
|
+
384,
|
|
10894
|
+
-7173,
|
|
10895
|
+
2695,
|
|
10896
|
+
7680,
|
|
10897
|
+
3467,
|
|
10898
|
+
7680,
|
|
10899
|
+
38081,
|
|
10900
|
+
61440
|
|
10901
|
+
];
|
|
10902
|
+
function C1pf(eps, c) {
|
|
10903
|
+
let eps2 = sq(eps), d = eps, o = 0, l, p;
|
|
10904
|
+
for (l = 1; l <= 6; ++l) {
|
|
10905
|
+
p = Math.floor((6 - l) / 2);
|
|
10906
|
+
c[l] = d * polyval(p, C1pf_coeff, o, eps2) / C1pf_coeff[o + p + 1];
|
|
10907
|
+
o += p + 2;
|
|
10908
|
+
d *= eps;
|
|
10909
|
+
}
|
|
10910
|
+
}
|
|
10911
|
+
A2m1f_coeff = [
|
|
10912
|
+
-11,
|
|
10913
|
+
-28,
|
|
10914
|
+
-192,
|
|
10915
|
+
0,
|
|
10916
|
+
256
|
|
10917
|
+
];
|
|
10918
|
+
function A2m1f(eps) {
|
|
10919
|
+
return (polyval(Math.floor(nA2_ / 2), A2m1f_coeff, 0, sq(eps)) / A2m1f_coeff[4] - eps) / (1 + eps);
|
|
10920
|
+
}
|
|
10921
|
+
C2f_coeff = [
|
|
10922
|
+
1,
|
|
10923
|
+
2,
|
|
10924
|
+
16,
|
|
10925
|
+
32,
|
|
10926
|
+
35,
|
|
10927
|
+
64,
|
|
10928
|
+
384,
|
|
10929
|
+
2048,
|
|
10930
|
+
15,
|
|
10931
|
+
80,
|
|
10932
|
+
768,
|
|
10933
|
+
7,
|
|
10934
|
+
35,
|
|
10935
|
+
512,
|
|
10936
|
+
63,
|
|
10937
|
+
1280,
|
|
10938
|
+
77,
|
|
10939
|
+
2048
|
|
10940
|
+
];
|
|
10941
|
+
function C2f(eps, c) {
|
|
10942
|
+
let eps2 = sq(eps), d = eps, o = 0, l, p;
|
|
10943
|
+
for (l = 1; l <= 6; ++l) {
|
|
10944
|
+
p = Math.floor((6 - l) / 2);
|
|
10945
|
+
c[l] = d * polyval(p, C2f_coeff, o, eps2) / C2f_coeff[o + p + 1];
|
|
10946
|
+
o += p + 2;
|
|
10947
|
+
d *= eps;
|
|
10948
|
+
}
|
|
10949
|
+
}
|
|
10950
|
+
A3_coeff = [
|
|
10951
|
+
-3,
|
|
10952
|
+
128,
|
|
10953
|
+
-2,
|
|
10954
|
+
-3,
|
|
10955
|
+
64,
|
|
10956
|
+
-1,
|
|
10957
|
+
-3,
|
|
10958
|
+
-1,
|
|
10959
|
+
16,
|
|
10960
|
+
3,
|
|
10961
|
+
-1,
|
|
10962
|
+
-2,
|
|
10963
|
+
8,
|
|
10964
|
+
1,
|
|
10965
|
+
-1,
|
|
10966
|
+
2,
|
|
10967
|
+
1,
|
|
10968
|
+
1
|
|
10969
|
+
];
|
|
10970
|
+
C3_coeff = [
|
|
10971
|
+
3,
|
|
10972
|
+
128,
|
|
10973
|
+
2,
|
|
10974
|
+
5,
|
|
10975
|
+
128,
|
|
10976
|
+
-1,
|
|
10977
|
+
3,
|
|
10978
|
+
3,
|
|
10979
|
+
64,
|
|
10980
|
+
-1,
|
|
10981
|
+
0,
|
|
10982
|
+
1,
|
|
10983
|
+
8,
|
|
10984
|
+
-1,
|
|
10985
|
+
1,
|
|
10986
|
+
4,
|
|
10987
|
+
5,
|
|
10988
|
+
256,
|
|
10989
|
+
1,
|
|
10990
|
+
3,
|
|
10991
|
+
128,
|
|
10992
|
+
-3,
|
|
10993
|
+
-2,
|
|
10994
|
+
3,
|
|
10995
|
+
64,
|
|
10996
|
+
1,
|
|
10997
|
+
-3,
|
|
10998
|
+
2,
|
|
10999
|
+
32,
|
|
11000
|
+
7,
|
|
11001
|
+
512,
|
|
11002
|
+
-10,
|
|
11003
|
+
9,
|
|
11004
|
+
384,
|
|
11005
|
+
5,
|
|
11006
|
+
-9,
|
|
11007
|
+
5,
|
|
11008
|
+
192,
|
|
11009
|
+
7,
|
|
11010
|
+
512,
|
|
11011
|
+
-14,
|
|
11012
|
+
7,
|
|
11013
|
+
512,
|
|
11014
|
+
21,
|
|
11015
|
+
2560
|
|
11016
|
+
];
|
|
11017
|
+
C4_coeff = [
|
|
11018
|
+
97,
|
|
11019
|
+
15015,
|
|
11020
|
+
1088,
|
|
11021
|
+
156,
|
|
11022
|
+
45045,
|
|
11023
|
+
-224,
|
|
11024
|
+
-4784,
|
|
11025
|
+
1573,
|
|
11026
|
+
45045,
|
|
11027
|
+
-10656,
|
|
11028
|
+
14144,
|
|
11029
|
+
-4576,
|
|
11030
|
+
-858,
|
|
11031
|
+
45045,
|
|
11032
|
+
64,
|
|
11033
|
+
624,
|
|
11034
|
+
-4576,
|
|
11035
|
+
6864,
|
|
11036
|
+
-3003,
|
|
11037
|
+
15015,
|
|
11038
|
+
100,
|
|
11039
|
+
208,
|
|
11040
|
+
572,
|
|
11041
|
+
3432,
|
|
11042
|
+
-12012,
|
|
11043
|
+
30030,
|
|
11044
|
+
45045,
|
|
11045
|
+
1,
|
|
11046
|
+
9009,
|
|
11047
|
+
-2944,
|
|
11048
|
+
468,
|
|
11049
|
+
135135,
|
|
11050
|
+
5792,
|
|
11051
|
+
1040,
|
|
11052
|
+
-1287,
|
|
11053
|
+
135135,
|
|
11054
|
+
5952,
|
|
11055
|
+
-11648,
|
|
11056
|
+
9152,
|
|
11057
|
+
-2574,
|
|
11058
|
+
135135,
|
|
11059
|
+
-64,
|
|
11060
|
+
-624,
|
|
11061
|
+
4576,
|
|
11062
|
+
-6864,
|
|
11063
|
+
3003,
|
|
11064
|
+
135135,
|
|
11065
|
+
8,
|
|
11066
|
+
10725,
|
|
11067
|
+
1856,
|
|
11068
|
+
-936,
|
|
11069
|
+
225225,
|
|
11070
|
+
-8448,
|
|
11071
|
+
4992,
|
|
11072
|
+
-1144,
|
|
11073
|
+
225225,
|
|
11074
|
+
-1440,
|
|
11075
|
+
4160,
|
|
11076
|
+
-4576,
|
|
11077
|
+
1716,
|
|
11078
|
+
225225,
|
|
11079
|
+
-136,
|
|
11080
|
+
63063,
|
|
11081
|
+
1024,
|
|
11082
|
+
-208,
|
|
11083
|
+
105105,
|
|
11084
|
+
3584,
|
|
11085
|
+
-3328,
|
|
11086
|
+
1144,
|
|
11087
|
+
315315,
|
|
11088
|
+
-128,
|
|
11089
|
+
135135,
|
|
11090
|
+
-2560,
|
|
11091
|
+
832,
|
|
11092
|
+
405405,
|
|
11093
|
+
128,
|
|
11094
|
+
99099
|
|
11095
|
+
];
|
|
11096
|
+
var Geodesic = class {
|
|
11097
|
+
a = NaN;
|
|
11098
|
+
f = NaN;
|
|
11099
|
+
_f1 = NaN;
|
|
11100
|
+
_e2 = NaN;
|
|
11101
|
+
_ep2 = NaN;
|
|
11102
|
+
_n = NaN;
|
|
11103
|
+
_b = NaN;
|
|
11104
|
+
_c2 = NaN;
|
|
11105
|
+
_etol2 = NaN;
|
|
11106
|
+
_A3x = [];
|
|
11107
|
+
_C3x = [];
|
|
11108
|
+
_C4x = [];
|
|
11109
|
+
constructor(a, f) {
|
|
11110
|
+
this.a = a;
|
|
11111
|
+
this.f = f;
|
|
11112
|
+
this._f1 = 1 - this.f;
|
|
11113
|
+
this._e2 = this.f * (2 - this.f);
|
|
11114
|
+
this._ep2 = this._e2 / sq(this._f1);
|
|
11115
|
+
this._n = this.f / (2 - this.f);
|
|
11116
|
+
this._b = this.a * this._f1;
|
|
11117
|
+
this._c2 = (sq(this.a) + sq(this._b) * (this._e2 === 0 ? 1 : (this._e2 > 0 ? atanh(Math.sqrt(this._e2)) : Math.atan(Math.sqrt(-this._e2))) / Math.sqrt(Math.abs(this._e2)))) / 2;
|
|
11118
|
+
this._etol2 = .1 * tol2_ / Math.sqrt(Math.max(.001, Math.abs(this.f)) * Math.min(1, 1 - this.f / 2) / 2);
|
|
11119
|
+
if (!(isFinite(this.a) && this.a > 0)) throw new RangeError("Equatorial radius is not positive");
|
|
11120
|
+
if (!(isFinite(this._b) && this._b > 0)) throw new RangeError("Polar semi-axis is not positive");
|
|
11121
|
+
this._A3x = new Array(nA3x_);
|
|
11122
|
+
this._C3x = new Array(nC3x_);
|
|
11123
|
+
this._C4x = new Array(nC4x_);
|
|
11124
|
+
this.A3coeff();
|
|
11125
|
+
this.C3coeff();
|
|
11126
|
+
this.C4coeff();
|
|
11127
|
+
}
|
|
11128
|
+
A3coeff() {
|
|
11129
|
+
let o = 0, k = 0, j, p;
|
|
11130
|
+
for (j = 5; j >= 0; --j) {
|
|
11131
|
+
p = Math.min(nA3_ - j - 1, j);
|
|
11132
|
+
this._A3x[k++] = polyval(p, A3_coeff, o, this._n) / A3_coeff[o + p + 1];
|
|
11133
|
+
o += p + 2;
|
|
11134
|
+
}
|
|
11135
|
+
}
|
|
11136
|
+
C3coeff() {
|
|
11137
|
+
let o = 0, k = 0, l, j, p;
|
|
11138
|
+
for (l = 1; l < 6; ++l) for (j = 5; j >= l; --j) {
|
|
11139
|
+
p = Math.min(6 - j - 1, j);
|
|
11140
|
+
this._C3x[k++] = polyval(p, C3_coeff, o, this._n) / C3_coeff[o + p + 1];
|
|
11141
|
+
o += p + 2;
|
|
11142
|
+
}
|
|
11143
|
+
}
|
|
11144
|
+
C4coeff() {
|
|
11145
|
+
let o = 0, k = 0, l, j, p;
|
|
11146
|
+
for (l = 0; l < 6; ++l) for (j = 5; j >= l; --j) {
|
|
11147
|
+
p = 6 - j - 1;
|
|
11148
|
+
this._C4x[k++] = polyval(p, C4_coeff, o, this._n) / C4_coeff[o + p + 1];
|
|
11149
|
+
o += p + 2;
|
|
11150
|
+
}
|
|
11151
|
+
}
|
|
11152
|
+
A3f(eps) {
|
|
11153
|
+
return polyval(5, this._A3x, 0, eps);
|
|
11154
|
+
}
|
|
11155
|
+
C3f(eps, c) {
|
|
11156
|
+
let mult = 1, o = 0, l, p;
|
|
11157
|
+
for (l = 1; l < 6; ++l) {
|
|
11158
|
+
p = 6 - l - 1;
|
|
11159
|
+
mult *= eps;
|
|
11160
|
+
c[l] = mult * polyval(p, this._C3x, o, eps);
|
|
11161
|
+
o += p + 1;
|
|
11162
|
+
}
|
|
11163
|
+
}
|
|
11164
|
+
C4f(eps, c) {
|
|
11165
|
+
let mult = 1, o = 0, l, p;
|
|
11166
|
+
for (l = 0; l < 6; ++l) {
|
|
11167
|
+
p = 6 - l - 1;
|
|
11168
|
+
c[l] = mult * polyval(p, this._C4x, o, eps);
|
|
11169
|
+
o += p + 1;
|
|
11170
|
+
mult *= eps;
|
|
11171
|
+
}
|
|
11172
|
+
}
|
|
11173
|
+
Lengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask = 0, C1a, C2a) {
|
|
11174
|
+
outmask &= OUT_MASK;
|
|
11175
|
+
let vals = {
|
|
11176
|
+
s12b: NaN,
|
|
11177
|
+
m0: NaN,
|
|
11178
|
+
m12b: NaN,
|
|
11179
|
+
M12: NaN,
|
|
11180
|
+
M21: NaN
|
|
11181
|
+
}, m0x = 0, J12 = 0, A1 = 0, A2 = 0, B1, B2, l, csig12, t;
|
|
11182
|
+
if (outmask & 13317) {
|
|
11183
|
+
A1 = A1m1f(eps);
|
|
11184
|
+
C1f(eps, C1a);
|
|
11185
|
+
if (outmask & 12293) {
|
|
11186
|
+
A2 = A2m1f(eps);
|
|
11187
|
+
C2f(eps, C2a);
|
|
11188
|
+
m0x = A1 - A2;
|
|
11189
|
+
A2 = 1 + A2;
|
|
11190
|
+
}
|
|
11191
|
+
A1 = 1 + A1;
|
|
11192
|
+
}
|
|
11193
|
+
if (outmask & 1025) {
|
|
11194
|
+
B1 = SinCosSeries(true, ssig2, csig2, C1a) - SinCosSeries(true, ssig1, csig1, C1a);
|
|
11195
|
+
vals.s12b = A1 * (sig12 + B1);
|
|
11196
|
+
if (outmask & 12293) {
|
|
11197
|
+
B2 = SinCosSeries(true, ssig2, csig2, C2a) - SinCosSeries(true, ssig1, csig1, C2a);
|
|
11198
|
+
J12 = m0x * sig12 + (A1 * B1 - A2 * B2);
|
|
11199
|
+
}
|
|
11200
|
+
} else if (outmask & 12293) {
|
|
11201
|
+
for (l = 1; l <= 6; ++l) C2a[l] = A1 * C1a[l] - A2 * C2a[l];
|
|
11202
|
+
J12 = m0x * sig12 + (SinCosSeries(true, ssig2, csig2, C2a) - SinCosSeries(true, ssig1, csig1, C2a));
|
|
11203
|
+
}
|
|
11204
|
+
if (outmask & 4101) {
|
|
11205
|
+
vals.m0 = m0x;
|
|
11206
|
+
vals.m12b = dn2 * (csig1 * ssig2) - dn1 * (ssig1 * csig2) - csig1 * csig2 * J12;
|
|
11207
|
+
} else vals.m12b = NaN;
|
|
11208
|
+
if (outmask & 8197) {
|
|
11209
|
+
csig12 = csig1 * csig2 + ssig1 * ssig2;
|
|
11210
|
+
t = this._ep2 * (cbet1 - cbet2) * (cbet1 + cbet2) / (dn1 + dn2);
|
|
11211
|
+
vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * ssig1 / dn1;
|
|
11212
|
+
vals.M21 = csig12 - (t * ssig1 - csig1 * J12) * ssig2 / dn2;
|
|
11213
|
+
}
|
|
11214
|
+
return vals;
|
|
11215
|
+
}
|
|
11216
|
+
InverseStart(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a) {
|
|
11217
|
+
let vals = {
|
|
11218
|
+
sig12: NaN,
|
|
11219
|
+
dnm: NaN,
|
|
11220
|
+
salp1: NaN,
|
|
11221
|
+
calp1: NaN,
|
|
11222
|
+
salp2: NaN,
|
|
11223
|
+
calp2: NaN
|
|
11224
|
+
}, sbet12 = sbet2 * cbet1 - cbet2 * sbet1, cbet12 = cbet2 * cbet1 + sbet2 * sbet1, sbet12a, shortline, omg12, sbetm2, somg12, comg12, t, ssig12, csig12, x, y, lamscale, betscale, k2, eps, cbet12a, bet12a, m12b, m0, nvals, k, omg12a, lam12x;
|
|
11225
|
+
vals.sig12 = -1;
|
|
11226
|
+
sbet12a = sbet2 * cbet1;
|
|
11227
|
+
sbet12a += cbet2 * sbet1;
|
|
11228
|
+
shortline = cbet12 >= 0 && sbet12 < .5 && cbet2 * lam12 < .5;
|
|
11229
|
+
if (shortline) {
|
|
11230
|
+
sbetm2 = sq(sbet1 + sbet2);
|
|
11231
|
+
sbetm2 /= sbetm2 + sq(cbet1 + cbet2);
|
|
11232
|
+
vals.dnm = Math.sqrt(1 + this._ep2 * sbetm2);
|
|
11233
|
+
omg12 = lam12 / (this._f1 * vals.dnm);
|
|
11234
|
+
somg12 = Math.sin(omg12);
|
|
11235
|
+
comg12 = Math.cos(omg12);
|
|
11236
|
+
} else {
|
|
11237
|
+
somg12 = slam12;
|
|
11238
|
+
comg12 = clam12;
|
|
11239
|
+
}
|
|
11240
|
+
vals.salp1 = cbet2 * somg12;
|
|
11241
|
+
vals.calp1 = comg12 >= 0 ? sbet12 + cbet2 * sbet1 * sq(somg12) / (1 + comg12) : sbet12a - cbet2 * sbet1 * sq(somg12) / (1 - comg12);
|
|
11242
|
+
ssig12 = hypot(vals.salp1, vals.calp1);
|
|
11243
|
+
csig12 = sbet1 * sbet2 + cbet1 * cbet2 * comg12;
|
|
11244
|
+
if (shortline && ssig12 < this._etol2) {
|
|
11245
|
+
vals.salp2 = cbet1 * somg12;
|
|
11246
|
+
vals.calp2 = sbet12 - cbet1 * sbet2 * (comg12 >= 0 ? sq(somg12) / (1 + comg12) : 1 - comg12);
|
|
11247
|
+
t = hypot(vals.salp2, vals.calp2);
|
|
11248
|
+
vals.salp2 /= t;
|
|
11249
|
+
vals.calp2 /= t;
|
|
11250
|
+
vals.sig12 = Math.atan2(ssig12, csig12);
|
|
11251
|
+
} else if (Math.abs(this._n) > .1 || csig12 >= 0 || ssig12 >= 6 * Math.abs(this._n) * Math.PI * sq(cbet1)) {} else {
|
|
11252
|
+
lam12x = Math.atan2(-slam12, -clam12);
|
|
11253
|
+
if (this.f >= 0) {
|
|
11254
|
+
k2 = sq(sbet1) * this._ep2;
|
|
11255
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
11256
|
+
lamscale = this.f * cbet1 * this.A3f(eps) * Math.PI;
|
|
11257
|
+
betscale = lamscale * cbet1;
|
|
11258
|
+
x = lam12x / lamscale;
|
|
11259
|
+
y = sbet12a / betscale;
|
|
11260
|
+
} else {
|
|
11261
|
+
cbet12a = cbet2 * cbet1 - sbet2 * sbet1;
|
|
11262
|
+
bet12a = Math.atan2(sbet12a, cbet12a);
|
|
11263
|
+
nvals = this.Lengths(this._n, Math.PI + bet12a, sbet1, -cbet1, dn1, sbet2, cbet2, dn2, cbet1, cbet2, REDUCEDLENGTH, C1a, C2a);
|
|
11264
|
+
m12b = nvals.m12b;
|
|
11265
|
+
m0 = nvals.m0;
|
|
11266
|
+
x = -1 + m12b / (cbet1 * cbet2 * m0 * Math.PI);
|
|
11267
|
+
betscale = x < -.01 ? sbet12a / x : -this.f * sq(cbet1) * Math.PI;
|
|
11268
|
+
lamscale = betscale / cbet1;
|
|
11269
|
+
y = lam12 / lamscale;
|
|
11270
|
+
}
|
|
11271
|
+
if (y > -tol1_ && x > -1 - xthresh_) {
|
|
11272
|
+
if (this.f >= 0) {
|
|
11273
|
+
vals.salp1 = Math.min(1, -x);
|
|
11274
|
+
vals.calp1 = -Math.sqrt(1 - sq(vals.salp1));
|
|
13043
11275
|
} else {
|
|
13044
|
-
|
|
13045
|
-
|
|
11276
|
+
vals.calp1 = Math.max(x > -tol1_ ? 0 : -1, x);
|
|
11277
|
+
vals.salp1 = Math.sqrt(1 - sq(vals.calp1));
|
|
13046
11278
|
}
|
|
11279
|
+
} else {
|
|
11280
|
+
k = astroid(x, y);
|
|
11281
|
+
omg12a = lamscale * (this.f >= 0 ? -x * k / (1 + k) : -y * (1 + k) / k);
|
|
11282
|
+
somg12 = Math.sin(omg12a);
|
|
11283
|
+
comg12 = -Math.cos(omg12a);
|
|
13047
11284
|
vals.salp1 = cbet2 * somg12;
|
|
13048
|
-
vals.calp1 =
|
|
13049
|
-
|
|
13050
|
-
|
|
13051
|
-
|
|
13052
|
-
|
|
13053
|
-
|
|
13054
|
-
|
|
13055
|
-
|
|
13056
|
-
|
|
13057
|
-
|
|
13058
|
-
|
|
13059
|
-
|
|
13060
|
-
|
|
13061
|
-
|
|
13062
|
-
|
|
13063
|
-
|
|
13064
|
-
|
|
13065
|
-
|
|
13066
|
-
|
|
13067
|
-
|
|
13068
|
-
|
|
13069
|
-
|
|
13070
|
-
|
|
13071
|
-
|
|
13072
|
-
|
|
13073
|
-
|
|
13074
|
-
|
|
13075
|
-
|
|
13076
|
-
|
|
13077
|
-
|
|
13078
|
-
|
|
13079
|
-
|
|
13080
|
-
|
|
13081
|
-
|
|
13082
|
-
|
|
13083
|
-
|
|
13084
|
-
|
|
13085
|
-
|
|
13086
|
-
|
|
13087
|
-
|
|
13088
|
-
|
|
13089
|
-
|
|
13090
|
-
|
|
13091
|
-
|
|
13092
|
-
|
|
13093
|
-
|
|
13094
|
-
|
|
13095
|
-
|
|
13096
|
-
|
|
13097
|
-
|
|
13098
|
-
|
|
13099
|
-
|
|
13100
|
-
|
|
13101
|
-
|
|
13102
|
-
|
|
13103
|
-
|
|
13104
|
-
|
|
13105
|
-
|
|
13106
|
-
|
|
13107
|
-
|
|
13108
|
-
|
|
13109
|
-
|
|
13110
|
-
|
|
13111
|
-
|
|
13112
|
-
|
|
13113
|
-
|
|
13114
|
-
|
|
13115
|
-
|
|
13116
|
-
|
|
13117
|
-
|
|
13118
|
-
|
|
13119
|
-
|
|
13120
|
-
|
|
13121
|
-
|
|
13122
|
-
|
|
13123
|
-
|
|
13124
|
-
|
|
13125
|
-
|
|
13126
|
-
|
|
13127
|
-
|
|
13128
|
-
|
|
13129
|
-
|
|
13130
|
-
|
|
13131
|
-
|
|
13132
|
-
|
|
13133
|
-
|
|
13134
|
-
|
|
13135
|
-
|
|
13136
|
-
|
|
13137
|
-
|
|
13138
|
-
|
|
13139
|
-
|
|
13140
|
-
|
|
13141
|
-
|
|
13142
|
-
|
|
13143
|
-
|
|
13144
|
-
|
|
13145
|
-
|
|
13146
|
-
|
|
13147
|
-
|
|
13148
|
-
|
|
13149
|
-
|
|
13150
|
-
|
|
13151
|
-
|
|
13152
|
-
|
|
13153
|
-
|
|
13154
|
-
|
|
13155
|
-
|
|
13156
|
-
|
|
13157
|
-
|
|
13158
|
-
|
|
13159
|
-
|
|
13160
|
-
|
|
13161
|
-
|
|
13162
|
-
|
|
13163
|
-
|
|
13164
|
-
|
|
13165
|
-
|
|
13166
|
-
|
|
13167
|
-
|
|
13168
|
-
|
|
13169
|
-
|
|
13170
|
-
|
|
13171
|
-
|
|
13172
|
-
|
|
13173
|
-
|
|
13174
|
-
|
|
13175
|
-
|
|
13176
|
-
|
|
13177
|
-
|
|
13178
|
-
|
|
13179
|
-
|
|
13180
|
-
|
|
13181
|
-
|
|
13182
|
-
|
|
13183
|
-
|
|
13184
|
-
|
|
13185
|
-
|
|
13186
|
-
|
|
13187
|
-
|
|
13188
|
-
|
|
13189
|
-
|
|
13190
|
-
|
|
13191
|
-
|
|
13192
|
-
|
|
13193
|
-
|
|
13194
|
-
|
|
13195
|
-
|
|
13196
|
-
|
|
13197
|
-
|
|
13198
|
-
|
|
13199
|
-
|
|
13200
|
-
|
|
13201
|
-
|
|
13202
|
-
|
|
13203
|
-
|
|
13204
|
-
|
|
13205
|
-
|
|
13206
|
-
|
|
13207
|
-
|
|
13208
|
-
|
|
13209
|
-
|
|
13210
|
-
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
|
|
13216
|
-
|
|
13217
|
-
|
|
13218
|
-
|
|
13219
|
-
|
|
13220
|
-
|
|
13221
|
-
|
|
13222
|
-
|
|
13223
|
-
|
|
13224
|
-
|
|
13225
|
-
|
|
13226
|
-
|
|
13227
|
-
|
|
13228
|
-
|
|
13229
|
-
|
|
13230
|
-
|
|
13231
|
-
|
|
13232
|
-
|
|
13233
|
-
|
|
13234
|
-
|
|
13235
|
-
|
|
13236
|
-
|
|
13237
|
-
if (
|
|
13238
|
-
|
|
13239
|
-
|
|
13240
|
-
|
|
13241
|
-
|
|
13242
|
-
|
|
13243
|
-
|
|
13244
|
-
|
|
13245
|
-
|
|
13246
|
-
|
|
11285
|
+
vals.calp1 = sbet12a - cbet2 * sbet1 * sq(somg12) / (1 - comg12);
|
|
11286
|
+
}
|
|
11287
|
+
}
|
|
11288
|
+
if (!(vals.salp1 <= 0)) {
|
|
11289
|
+
t = hypot(vals.salp1, vals.calp1);
|
|
11290
|
+
vals.salp1 /= t;
|
|
11291
|
+
vals.calp1 /= t;
|
|
11292
|
+
} else {
|
|
11293
|
+
vals.salp1 = 1;
|
|
11294
|
+
vals.calp1 = 0;
|
|
11295
|
+
}
|
|
11296
|
+
return vals;
|
|
11297
|
+
}
|
|
11298
|
+
Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam120, clam120, diffp, C1a, C2a, C3a) {
|
|
11299
|
+
let vals = {
|
|
11300
|
+
ssig1: NaN,
|
|
11301
|
+
csig1: NaN,
|
|
11302
|
+
salp2: NaN,
|
|
11303
|
+
calp2: NaN,
|
|
11304
|
+
ssig2: NaN,
|
|
11305
|
+
csig2: NaN,
|
|
11306
|
+
sig12: NaN,
|
|
11307
|
+
eps: NaN,
|
|
11308
|
+
domg12: NaN,
|
|
11309
|
+
lam12: NaN,
|
|
11310
|
+
dlam12: NaN
|
|
11311
|
+
}, t, salp0, calp0, somg1, comg1, somg2, comg2, somg12, comg12, B312, eta, k2, nvals;
|
|
11312
|
+
if (sbet1 === 0 && calp1 === 0) calp1 = -tiny_;
|
|
11313
|
+
salp0 = salp1 * cbet1;
|
|
11314
|
+
calp0 = hypot(calp1, salp1 * sbet1);
|
|
11315
|
+
vals.ssig1 = sbet1;
|
|
11316
|
+
somg1 = salp0 * sbet1;
|
|
11317
|
+
vals.csig1 = comg1 = calp1 * cbet1;
|
|
11318
|
+
t = hypot(vals.ssig1, vals.csig1);
|
|
11319
|
+
vals.ssig1 /= t;
|
|
11320
|
+
vals.csig1 /= t;
|
|
11321
|
+
vals.salp2 = cbet2 !== cbet1 ? salp0 / cbet2 : salp1;
|
|
11322
|
+
vals.calp2 = cbet2 !== cbet1 || Math.abs(sbet2) !== -sbet1 ? Math.sqrt(sq(calp1 * cbet1) + (cbet1 < -sbet1 ? (cbet2 - cbet1) * (cbet1 + cbet2) : (sbet1 - sbet2) * (sbet1 + sbet2))) / cbet2 : Math.abs(calp1);
|
|
11323
|
+
vals.ssig2 = sbet2;
|
|
11324
|
+
somg2 = salp0 * sbet2;
|
|
11325
|
+
vals.csig2 = comg2 = vals.calp2 * cbet2;
|
|
11326
|
+
t = hypot(vals.ssig2, vals.csig2);
|
|
11327
|
+
vals.ssig2 /= t;
|
|
11328
|
+
vals.csig2 /= t;
|
|
11329
|
+
vals.sig12 = Math.atan2(Math.max(0, vals.csig1 * vals.ssig2 - vals.ssig1 * vals.csig2), vals.csig1 * vals.csig2 + vals.ssig1 * vals.ssig2);
|
|
11330
|
+
somg12 = Math.max(0, comg1 * somg2 - somg1 * comg2);
|
|
11331
|
+
comg12 = comg1 * comg2 + somg1 * somg2;
|
|
11332
|
+
eta = Math.atan2(somg12 * clam120 - comg12 * slam120, comg12 * clam120 + somg12 * slam120);
|
|
11333
|
+
k2 = sq(calp0) * this._ep2;
|
|
11334
|
+
vals.eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
11335
|
+
this.C3f(vals.eps, C3a);
|
|
11336
|
+
B312 = SinCosSeries(true, vals.ssig2, vals.csig2, C3a) - SinCosSeries(true, vals.ssig1, vals.csig1, C3a);
|
|
11337
|
+
vals.domg12 = -this.f * this.A3f(vals.eps) * salp0 * (vals.sig12 + B312);
|
|
11338
|
+
vals.lam12 = eta + vals.domg12;
|
|
11339
|
+
if (diffp) {
|
|
11340
|
+
if (vals.calp2 === 0) vals.dlam12 = -2 * this._f1 * dn1 / sbet1;
|
|
11341
|
+
else {
|
|
11342
|
+
nvals = this.Lengths(vals.eps, vals.sig12, vals.ssig1, vals.csig1, dn1, vals.ssig2, vals.csig2, dn2, cbet1, cbet2, REDUCEDLENGTH, C1a, C2a);
|
|
11343
|
+
vals.dlam12 = nvals.m12b;
|
|
11344
|
+
vals.dlam12 *= this._f1 / (vals.calp2 * cbet2);
|
|
11345
|
+
}
|
|
11346
|
+
}
|
|
11347
|
+
return vals;
|
|
11348
|
+
}
|
|
11349
|
+
Inverse(lat1, lon1, lat2, lon2, outmask = 0) {
|
|
11350
|
+
let r, vals;
|
|
11351
|
+
if (!outmask) outmask = STANDARD;
|
|
11352
|
+
if (outmask === 32768) outmask |= STANDARD;
|
|
11353
|
+
outmask &= OUT_MASK;
|
|
11354
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, outmask);
|
|
11355
|
+
vals = r.vals;
|
|
11356
|
+
if (outmask & 512) {
|
|
11357
|
+
vals.azi1 = atan2d(r.salp1, r.calp1);
|
|
11358
|
+
vals.azi2 = atan2d(r.salp2, r.calp2);
|
|
11359
|
+
}
|
|
11360
|
+
return vals;
|
|
11361
|
+
}
|
|
11362
|
+
InverseInt(lat1, lon1, lat2, lon2, outmask = 0) {
|
|
11363
|
+
let vals = {
|
|
11364
|
+
azi1: NaN,
|
|
11365
|
+
azi2: NaN,
|
|
11366
|
+
lat1: NaN,
|
|
11367
|
+
lat2: NaN,
|
|
11368
|
+
lon1: NaN,
|
|
11369
|
+
lon2: NaN,
|
|
11370
|
+
M12: NaN,
|
|
11371
|
+
M21: NaN,
|
|
11372
|
+
a12: NaN,
|
|
11373
|
+
s12: NaN,
|
|
11374
|
+
m12: NaN,
|
|
11375
|
+
S12: NaN
|
|
11376
|
+
}, lon12, lon12s, lonsign, t, swapp, latsign, sbet1, cbet1, sbet2, cbet2, s12x = NaN, m12x = NaN, dn1, dn2, lam12, slam12, clam12, sig12, calp1 = NaN, salp1 = NaN, calp2 = NaN, salp2 = NaN, C1a, C2a, C3a, meridian, nvals, ssig1 = NaN, csig1 = NaN, ssig2 = NaN, csig2 = NaN, eps, omg12 = NaN, dnm, numit, salp1a, calp1a, salp1b, calp1b, tripn, tripb, v, dv, dalp1, sdalp1, cdalp1, nsalp1, lengthmask, salp0, calp0, alp12, k2, A4, C4a, B41, B42, somg12, comg12 = NaN, domg12, dbet1, dbet2, salp12, calp12, sdomg12, cdomg12;
|
|
11377
|
+
vals.lat1 = lat1 = LatFix(lat1);
|
|
11378
|
+
vals.lat2 = lat2 = LatFix(lat2);
|
|
11379
|
+
lat1 = AngRound(lat1);
|
|
11380
|
+
lat2 = AngRound(lat2);
|
|
11381
|
+
lon12 = AngDiff(lon1, lon2);
|
|
11382
|
+
lon12s = lon12.e;
|
|
11383
|
+
lon12 = lon12.d;
|
|
11384
|
+
if (outmask & 32768) {
|
|
11385
|
+
vals.lon1 = lon1;
|
|
11386
|
+
vals.lon2 = lon1 + lon12 + lon12s;
|
|
11387
|
+
} else {
|
|
11388
|
+
vals.lon1 = AngNormalize(lon1);
|
|
11389
|
+
vals.lon2 = AngNormalize(lon2);
|
|
11390
|
+
}
|
|
11391
|
+
lonsign = copysign(1, lon12);
|
|
11392
|
+
lon12 *= lonsign;
|
|
11393
|
+
lon12s *= lonsign;
|
|
11394
|
+
lam12 = lon12 * degree;
|
|
11395
|
+
t = sincosde(lon12, lon12s);
|
|
11396
|
+
slam12 = t.s;
|
|
11397
|
+
clam12 = t.c;
|
|
11398
|
+
lon12s = 180 - lon12 - lon12s;
|
|
11399
|
+
swapp = Math.abs(lat1) < Math.abs(lat2) || isNaN(lat2) ? -1 : 1;
|
|
11400
|
+
if (swapp < 0) {
|
|
11401
|
+
lonsign *= -1;
|
|
11402
|
+
[lat2, lat1] = [lat1, lat2];
|
|
11403
|
+
}
|
|
11404
|
+
latsign = copysign(1, -lat1);
|
|
11405
|
+
lat1 *= latsign;
|
|
11406
|
+
lat2 *= latsign;
|
|
11407
|
+
t = sincosd(lat1);
|
|
11408
|
+
sbet1 = this._f1 * t.s;
|
|
11409
|
+
cbet1 = t.c;
|
|
11410
|
+
t = hypot(sbet1, cbet1);
|
|
11411
|
+
sbet1 /= t;
|
|
11412
|
+
cbet1 /= t;
|
|
11413
|
+
cbet1 = Math.max(tiny_, cbet1);
|
|
11414
|
+
t = sincosd(lat2);
|
|
11415
|
+
sbet2 = this._f1 * t.s;
|
|
11416
|
+
cbet2 = t.c;
|
|
11417
|
+
t = hypot(sbet2, cbet2);
|
|
11418
|
+
sbet2 /= t;
|
|
11419
|
+
cbet2 /= t;
|
|
11420
|
+
cbet2 = Math.max(tiny_, cbet2);
|
|
11421
|
+
if (cbet1 < -sbet1) {
|
|
11422
|
+
if (cbet2 === cbet1) sbet2 = copysign(sbet1, sbet2);
|
|
11423
|
+
} else if (Math.abs(sbet2) === -sbet1) cbet2 = cbet1;
|
|
11424
|
+
dn1 = Math.sqrt(1 + this._ep2 * sq(sbet1));
|
|
11425
|
+
dn2 = Math.sqrt(1 + this._ep2 * sq(sbet2));
|
|
11426
|
+
C1a = new Array(7);
|
|
11427
|
+
C2a = new Array(7);
|
|
11428
|
+
C3a = new Array(6);
|
|
11429
|
+
meridian = lat1 === -90 || slam12 === 0;
|
|
11430
|
+
if (meridian) {
|
|
11431
|
+
calp1 = clam12;
|
|
11432
|
+
salp1 = slam12;
|
|
11433
|
+
calp2 = 1;
|
|
11434
|
+
salp2 = 0;
|
|
11435
|
+
ssig1 = sbet1;
|
|
11436
|
+
csig1 = calp1 * cbet1;
|
|
11437
|
+
ssig2 = sbet2;
|
|
11438
|
+
csig2 = calp2 * cbet2;
|
|
11439
|
+
sig12 = Math.atan2(Math.max(0, csig1 * ssig2 - ssig1 * csig2), csig1 * csig2 + ssig1 * ssig2);
|
|
11440
|
+
nvals = this.Lengths(this._n, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, outmask | 5125, C1a, C2a);
|
|
11441
|
+
s12x = nvals.s12b;
|
|
11442
|
+
m12x = nvals.m12b;
|
|
11443
|
+
if (outmask & 8197) {
|
|
11444
|
+
vals.M12 = nvals.M12;
|
|
11445
|
+
vals.M21 = nvals.M21;
|
|
11446
|
+
}
|
|
11447
|
+
if (sig12 < tol2_ || m12x >= 0) {
|
|
11448
|
+
if (sig12 < 3 * tiny_ || sig12 < tol0_ && (s12x < 0 || m12x < 0)) sig12 = m12x = s12x = 0;
|
|
11449
|
+
m12x *= this._b;
|
|
11450
|
+
s12x *= this._b;
|
|
11451
|
+
vals.a12 = sig12 / degree;
|
|
11452
|
+
} else meridian = false;
|
|
11453
|
+
}
|
|
11454
|
+
somg12 = 2;
|
|
11455
|
+
if (!meridian && sbet1 === 0 && (this.f <= 0 || lon12s >= this.f * 180)) {
|
|
11456
|
+
calp1 = calp2 = 0;
|
|
11457
|
+
salp1 = salp2 = 1;
|
|
11458
|
+
s12x = this.a * lam12;
|
|
11459
|
+
sig12 = omg12 = lam12 / this._f1;
|
|
11460
|
+
m12x = this._b * Math.sin(sig12);
|
|
11461
|
+
if (outmask & 8197) vals.M12 = vals.M21 = Math.cos(sig12);
|
|
11462
|
+
vals.a12 = lon12 / this._f1;
|
|
11463
|
+
} else if (!meridian) {
|
|
11464
|
+
nvals = this.InverseStart(sbet1, cbet1, dn1, sbet2, cbet2, dn2, lam12, slam12, clam12, C1a, C2a);
|
|
11465
|
+
sig12 = nvals.sig12;
|
|
11466
|
+
salp1 = nvals.salp1;
|
|
11467
|
+
calp1 = nvals.calp1;
|
|
11468
|
+
if (sig12 >= 0) {
|
|
11469
|
+
salp2 = nvals.salp2;
|
|
11470
|
+
calp2 = nvals.calp2;
|
|
11471
|
+
dnm = nvals.dnm;
|
|
11472
|
+
s12x = sig12 * this._b * dnm;
|
|
11473
|
+
m12x = sq(dnm) * this._b * Math.sin(sig12 / dnm);
|
|
11474
|
+
if (outmask & 8197) vals.M12 = vals.M21 = Math.cos(sig12 / dnm);
|
|
11475
|
+
vals.a12 = sig12 / degree;
|
|
11476
|
+
omg12 = lam12 / (this._f1 * dnm);
|
|
11477
|
+
} else {
|
|
11478
|
+
numit = 0;
|
|
11479
|
+
salp1a = tiny_;
|
|
11480
|
+
calp1a = 1;
|
|
11481
|
+
salp1b = tiny_;
|
|
11482
|
+
calp1b = -1;
|
|
11483
|
+
for (tripn = false, tripb = false;; ++numit) {
|
|
11484
|
+
nvals = this.Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam12, clam12, numit < maxit1_, C1a, C2a, C3a);
|
|
11485
|
+
v = nvals.lam12;
|
|
11486
|
+
salp2 = nvals.salp2;
|
|
11487
|
+
calp2 = nvals.calp2;
|
|
13247
11488
|
sig12 = nvals.sig12;
|
|
13248
|
-
|
|
13249
|
-
|
|
13250
|
-
|
|
13251
|
-
|
|
13252
|
-
|
|
13253
|
-
|
|
13254
|
-
|
|
13255
|
-
|
|
13256
|
-
|
|
13257
|
-
|
|
13258
|
-
|
|
13259
|
-
} else {
|
|
13260
|
-
|
|
13261
|
-
|
|
13262
|
-
calp1a = 1;
|
|
13263
|
-
salp1b = g.tiny_;
|
|
13264
|
-
calp1b = -1;
|
|
13265
|
-
for (tripn = false, tripb = false;; ++numit) {
|
|
13266
|
-
nvals = this.Lambda12(sbet1, cbet1, dn1, sbet2, cbet2, dn2, salp1, calp1, slam12, clam12, numit < maxit1_, C1a, C2a, C3a);
|
|
13267
|
-
v = nvals.lam12;
|
|
13268
|
-
salp2 = nvals.salp2;
|
|
13269
|
-
calp2 = nvals.calp2;
|
|
13270
|
-
sig12 = nvals.sig12;
|
|
13271
|
-
ssig1 = nvals.ssig1;
|
|
13272
|
-
csig1 = nvals.csig1;
|
|
13273
|
-
ssig2 = nvals.ssig2;
|
|
13274
|
-
csig2 = nvals.csig2;
|
|
13275
|
-
eps = nvals.eps;
|
|
13276
|
-
domg12 = nvals.domg12;
|
|
13277
|
-
dv = nvals.dlam12;
|
|
13278
|
-
if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * tol0_) || numit == maxit2_) break;
|
|
13279
|
-
if (v > 0 && (numit < maxit1_ || calp1 / salp1 > calp1b / salp1b)) {
|
|
13280
|
-
salp1b = salp1;
|
|
13281
|
-
calp1b = calp1;
|
|
13282
|
-
} else if (v < 0 && (numit < maxit1_ || calp1 / salp1 < calp1a / salp1a)) {
|
|
13283
|
-
salp1a = salp1;
|
|
13284
|
-
calp1a = calp1;
|
|
13285
|
-
}
|
|
13286
|
-
if (numit < maxit1_ && dv > 0) {
|
|
13287
|
-
dalp1 = -v / dv;
|
|
13288
|
-
if (Math.abs(dalp1) < Math.PI) {
|
|
13289
|
-
sdalp1 = Math.sin(dalp1);
|
|
13290
|
-
cdalp1 = Math.cos(dalp1);
|
|
13291
|
-
nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
|
|
13292
|
-
if (nsalp1 > 0) {
|
|
13293
|
-
calp1 = calp1 * cdalp1 - salp1 * sdalp1;
|
|
13294
|
-
salp1 = nsalp1;
|
|
13295
|
-
t = m.hypot(salp1, calp1);
|
|
13296
|
-
salp1 /= t;
|
|
13297
|
-
calp1 /= t;
|
|
13298
|
-
tripn = Math.abs(v) <= 16 * tol0_;
|
|
13299
|
-
continue;
|
|
13300
|
-
}
|
|
13301
|
-
}
|
|
13302
|
-
}
|
|
13303
|
-
salp1 = (salp1a + salp1b) / 2;
|
|
13304
|
-
calp1 = (calp1a + calp1b) / 2;
|
|
13305
|
-
t = m.hypot(salp1, calp1);
|
|
13306
|
-
salp1 /= t;
|
|
13307
|
-
calp1 /= t;
|
|
13308
|
-
tripn = false;
|
|
13309
|
-
tripb = Math.abs(salp1a - salp1) + (calp1a - calp1) < tolb_ || Math.abs(salp1 - salp1b) + (calp1 - calp1b) < tolb_;
|
|
13310
|
-
}
|
|
13311
|
-
lengthmask = outmask | (outmask & (g.REDUCEDLENGTH | g.GEODESICSCALE) ? g.DISTANCE : g.NONE);
|
|
13312
|
-
nvals = this.Lengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, lengthmask, C1a, C2a);
|
|
13313
|
-
s12x = nvals.s12b;
|
|
13314
|
-
m12x = nvals.m12b;
|
|
13315
|
-
if (outmask & g.GEODESICSCALE) {
|
|
13316
|
-
vals.M12 = nvals.M12;
|
|
13317
|
-
vals.M21 = nvals.M21;
|
|
13318
|
-
}
|
|
13319
|
-
m12x *= this._b;
|
|
13320
|
-
s12x *= this._b;
|
|
13321
|
-
vals.a12 = sig12 / m.degree;
|
|
13322
|
-
if (outmask & g.AREA) {
|
|
13323
|
-
sdomg12 = Math.sin(domg12);
|
|
13324
|
-
cdomg12 = Math.cos(domg12);
|
|
13325
|
-
somg12 = slam12 * cdomg12 - clam12 * sdomg12;
|
|
13326
|
-
comg12 = clam12 * cdomg12 + slam12 * sdomg12;
|
|
13327
|
-
}
|
|
13328
|
-
}
|
|
13329
|
-
}
|
|
13330
|
-
if (outmask & g.DISTANCE) vals.s12 = 0 + s12x;
|
|
13331
|
-
if (outmask & g.REDUCEDLENGTH) vals.m12 = 0 + m12x;
|
|
13332
|
-
if (outmask & g.AREA) {
|
|
13333
|
-
salp0 = salp1 * cbet1;
|
|
13334
|
-
calp0 = m.hypot(calp1, salp1 * sbet1);
|
|
13335
|
-
if (calp0 !== 0 && salp0 !== 0) {
|
|
13336
|
-
ssig1 = sbet1;
|
|
13337
|
-
csig1 = calp1 * cbet1;
|
|
13338
|
-
ssig2 = sbet2;
|
|
13339
|
-
csig2 = calp2 * cbet2;
|
|
13340
|
-
k2 = m.sq(calp0) * this._ep2;
|
|
13341
|
-
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
13342
|
-
A4 = m.sq(this.a) * calp0 * salp0 * this._e2;
|
|
13343
|
-
t = m.hypot(ssig1, csig1);
|
|
13344
|
-
ssig1 /= t;
|
|
13345
|
-
csig1 /= t;
|
|
13346
|
-
t = m.hypot(ssig2, csig2);
|
|
13347
|
-
ssig2 /= t;
|
|
13348
|
-
csig2 /= t;
|
|
13349
|
-
C4a = new Array(g.nC4_);
|
|
13350
|
-
this.C4f(eps, C4a);
|
|
13351
|
-
B41 = g.SinCosSeries(false, ssig1, csig1, C4a);
|
|
13352
|
-
B42 = g.SinCosSeries(false, ssig2, csig2, C4a);
|
|
13353
|
-
vals.S12 = A4 * (B42 - B41);
|
|
13354
|
-
} else vals.S12 = 0;
|
|
13355
|
-
if (!meridian && somg12 == 2) {
|
|
13356
|
-
somg12 = Math.sin(omg12);
|
|
13357
|
-
comg12 = Math.cos(omg12);
|
|
11489
|
+
ssig1 = nvals.ssig1;
|
|
11490
|
+
csig1 = nvals.csig1;
|
|
11491
|
+
ssig2 = nvals.ssig2;
|
|
11492
|
+
csig2 = nvals.csig2;
|
|
11493
|
+
eps = nvals.eps;
|
|
11494
|
+
domg12 = nvals.domg12;
|
|
11495
|
+
dv = nvals.dlam12;
|
|
11496
|
+
if (tripb || !(Math.abs(v) >= (tripn ? 8 : 1) * tol0_) || numit == maxit2_) break;
|
|
11497
|
+
if (v > 0 && (numit < maxit1_ || calp1 / salp1 > calp1b / salp1b)) {
|
|
11498
|
+
salp1b = salp1;
|
|
11499
|
+
calp1b = calp1;
|
|
11500
|
+
} else if (v < 0 && (numit < maxit1_ || calp1 / salp1 < calp1a / salp1a)) {
|
|
11501
|
+
salp1a = salp1;
|
|
11502
|
+
calp1a = calp1;
|
|
13358
11503
|
}
|
|
13359
|
-
if (
|
|
13360
|
-
|
|
13361
|
-
|
|
13362
|
-
|
|
13363
|
-
|
|
13364
|
-
|
|
13365
|
-
|
|
13366
|
-
|
|
13367
|
-
|
|
13368
|
-
|
|
13369
|
-
|
|
11504
|
+
if (numit < maxit1_ && dv > 0) {
|
|
11505
|
+
dalp1 = -v / dv;
|
|
11506
|
+
if (Math.abs(dalp1) < Math.PI) {
|
|
11507
|
+
sdalp1 = Math.sin(dalp1);
|
|
11508
|
+
cdalp1 = Math.cos(dalp1);
|
|
11509
|
+
nsalp1 = salp1 * cdalp1 + calp1 * sdalp1;
|
|
11510
|
+
if (nsalp1 > 0) {
|
|
11511
|
+
calp1 = calp1 * cdalp1 - salp1 * sdalp1;
|
|
11512
|
+
salp1 = nsalp1;
|
|
11513
|
+
t = hypot(salp1, calp1);
|
|
11514
|
+
salp1 /= t;
|
|
11515
|
+
calp1 /= t;
|
|
11516
|
+
tripn = Math.abs(v) <= 16 * tol0_;
|
|
11517
|
+
continue;
|
|
11518
|
+
}
|
|
13370
11519
|
}
|
|
13371
|
-
alp12 = Math.atan2(salp12, calp12);
|
|
13372
11520
|
}
|
|
13373
|
-
|
|
13374
|
-
|
|
13375
|
-
|
|
13376
|
-
|
|
13377
|
-
|
|
13378
|
-
|
|
13379
|
-
|
|
13380
|
-
if (outmask & g.GEODESICSCALE) [vals.M21, vals.M12] = [vals.M12, vals.M21];
|
|
13381
|
-
}
|
|
13382
|
-
salp1 *= swapp * lonsign;
|
|
13383
|
-
calp1 *= swapp * latsign;
|
|
13384
|
-
salp2 *= swapp * lonsign;
|
|
13385
|
-
calp2 *= swapp * latsign;
|
|
13386
|
-
return {
|
|
13387
|
-
vals,
|
|
13388
|
-
salp1,
|
|
13389
|
-
calp1,
|
|
13390
|
-
salp2,
|
|
13391
|
-
calp2
|
|
13392
|
-
};
|
|
13393
|
-
};
|
|
13394
|
-
g.Geodesic.prototype.GenDirect = function(lat1, lon1, azi1, arcmode, s12_a12, outmask) {
|
|
13395
|
-
var line;
|
|
13396
|
-
if (!outmask) outmask = g.STANDARD;
|
|
13397
|
-
else if (outmask === g.LONG_UNROLL) outmask |= g.STANDARD;
|
|
13398
|
-
if (!arcmode) outmask |= g.DISTANCE_IN;
|
|
13399
|
-
line = new l.GeodesicLine(this, lat1, lon1, azi1, outmask);
|
|
13400
|
-
return line.GenPosition(arcmode, s12_a12, outmask);
|
|
13401
|
-
};
|
|
13402
|
-
g.Geodesic.prototype.Direct = function(lat1, lon1, azi1, s12, outmask) {
|
|
13403
|
-
return this.GenDirect(lat1, lon1, azi1, false, s12, outmask);
|
|
13404
|
-
};
|
|
13405
|
-
g.Geodesic.prototype.ArcDirect = function(lat1, lon1, azi1, a12, outmask) {
|
|
13406
|
-
return this.GenDirect(lat1, lon1, azi1, true, a12, outmask);
|
|
13407
|
-
};
|
|
13408
|
-
g.Geodesic.prototype.Line = function(lat1, lon1, azi1, caps) {
|
|
13409
|
-
return new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
13410
|
-
};
|
|
13411
|
-
g.Geodesic.prototype.DirectLine = function(lat1, lon1, azi1, s12, caps) {
|
|
13412
|
-
return this.GenDirectLine(lat1, lon1, azi1, false, s12, caps);
|
|
13413
|
-
};
|
|
13414
|
-
g.Geodesic.prototype.ArcDirectLine = function(lat1, lon1, azi1, a12, caps) {
|
|
13415
|
-
return this.GenDirectLine(lat1, lon1, azi1, true, a12, caps);
|
|
13416
|
-
};
|
|
13417
|
-
g.Geodesic.prototype.GenDirectLine = function(lat1, lon1, azi1, arcmode, s12_a12, caps) {
|
|
13418
|
-
var t;
|
|
13419
|
-
if (!caps) caps = g.STANDARD | g.DISTANCE_IN;
|
|
13420
|
-
if (!arcmode) caps |= g.DISTANCE_IN;
|
|
13421
|
-
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
13422
|
-
t.GenSetDistance(arcmode, s12_a12);
|
|
13423
|
-
return t;
|
|
13424
|
-
};
|
|
13425
|
-
g.Geodesic.prototype.InverseLine = function(lat1, lon1, lat2, lon2, caps) {
|
|
13426
|
-
var r, t, azi1;
|
|
13427
|
-
if (!caps) caps = g.STANDARD | g.DISTANCE_IN;
|
|
13428
|
-
r = this.InverseInt(lat1, lon1, lat2, lon2, g.ARC);
|
|
13429
|
-
azi1 = m.atan2d(r.salp1, r.calp1);
|
|
13430
|
-
if (caps & (g.OUT_MASK & g.DISTANCE_IN)) caps |= g.DISTANCE;
|
|
13431
|
-
t = new l.GeodesicLine(this, lat1, lon1, azi1, caps, r.salp1, r.calp1);
|
|
13432
|
-
t.SetArc(r.vals.a12);
|
|
13433
|
-
return t;
|
|
13434
|
-
};
|
|
13435
|
-
g.Geodesic.prototype.Polygon = function(polyline) {
|
|
13436
|
-
return new p.PolygonArea(this, polyline);
|
|
13437
|
-
};
|
|
13438
|
-
g.WGS84 = new g.Geodesic(c.WGS84.a, c.WGS84.f);
|
|
13439
|
-
})(geodesic.Geodesic, geodesic.GeodesicLine, geodesic.PolygonArea, geodesic.Math, geodesic.Constants);
|
|
13440
|
-
(function(g, l, m) {
|
|
13441
|
-
"use strict";
|
|
13442
|
-
l.GeodesicLine = function(geod, lat1, lon1, azi1, caps, salp1, calp1) {
|
|
13443
|
-
var t, cbet1, sbet1, eps, s, c;
|
|
13444
|
-
if (!caps) caps = g.STANDARD | g.DISTANCE_IN;
|
|
13445
|
-
this.a = geod.a;
|
|
13446
|
-
this.f = geod.f;
|
|
13447
|
-
this._b = geod._b;
|
|
13448
|
-
this._c2 = geod._c2;
|
|
13449
|
-
this._f1 = geod._f1;
|
|
13450
|
-
this.caps = caps | g.LATITUDE | g.AZIMUTH | g.LONG_UNROLL;
|
|
13451
|
-
this.lat1 = m.LatFix(lat1);
|
|
13452
|
-
this.lon1 = lon1;
|
|
13453
|
-
if (typeof salp1 === "undefined" || typeof calp1 === "undefined") {
|
|
13454
|
-
this.azi1 = m.AngNormalize(azi1);
|
|
13455
|
-
t = m.sincosd(m.AngRound(this.azi1));
|
|
13456
|
-
this.salp1 = t.s;
|
|
13457
|
-
this.calp1 = t.c;
|
|
13458
|
-
} else {
|
|
13459
|
-
this.azi1 = azi1;
|
|
13460
|
-
this.salp1 = salp1;
|
|
13461
|
-
this.calp1 = calp1;
|
|
13462
|
-
}
|
|
13463
|
-
t = m.sincosd(m.AngRound(this.lat1));
|
|
13464
|
-
sbet1 = this._f1 * t.s;
|
|
13465
|
-
cbet1 = t.c;
|
|
13466
|
-
t = m.hypot(sbet1, cbet1);
|
|
13467
|
-
sbet1 /= t;
|
|
13468
|
-
cbet1 /= t;
|
|
13469
|
-
cbet1 = Math.max(g.tiny_, cbet1);
|
|
13470
|
-
this._dn1 = Math.sqrt(1 + geod._ep2 * m.sq(sbet1));
|
|
13471
|
-
this._salp0 = this.salp1 * cbet1;
|
|
13472
|
-
this._calp0 = m.hypot(this.calp1, this.salp1 * sbet1);
|
|
13473
|
-
this._ssig1 = sbet1;
|
|
13474
|
-
this._somg1 = this._salp0 * sbet1;
|
|
13475
|
-
this._csig1 = this._comg1 = sbet1 !== 0 || this.calp1 !== 0 ? cbet1 * this.calp1 : 1;
|
|
13476
|
-
t = m.hypot(this._ssig1, this._csig1);
|
|
13477
|
-
this._ssig1 /= t;
|
|
13478
|
-
this._csig1 /= t;
|
|
13479
|
-
this._k2 = m.sq(this._calp0) * geod._ep2;
|
|
13480
|
-
eps = this._k2 / (2 * (1 + Math.sqrt(1 + this._k2)) + this._k2);
|
|
13481
|
-
if (this.caps & g.CAP_C1) {
|
|
13482
|
-
this._A1m1 = g.A1m1f(eps);
|
|
13483
|
-
this._C1a = new Array(g.nC1_ + 1);
|
|
13484
|
-
g.C1f(eps, this._C1a);
|
|
13485
|
-
this._B11 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C1a);
|
|
13486
|
-
s = Math.sin(this._B11);
|
|
13487
|
-
c = Math.cos(this._B11);
|
|
13488
|
-
this._stau1 = this._ssig1 * c + this._csig1 * s;
|
|
13489
|
-
this._ctau1 = this._csig1 * c - this._ssig1 * s;
|
|
13490
|
-
}
|
|
13491
|
-
if (this.caps & g.CAP_C1p) {
|
|
13492
|
-
this._C1pa = new Array(g.nC1p_ + 1);
|
|
13493
|
-
g.C1pf(eps, this._C1pa);
|
|
13494
|
-
}
|
|
13495
|
-
if (this.caps & g.CAP_C2) {
|
|
13496
|
-
this._A2m1 = g.A2m1f(eps);
|
|
13497
|
-
this._C2a = new Array(g.nC2_ + 1);
|
|
13498
|
-
g.C2f(eps, this._C2a);
|
|
13499
|
-
this._B21 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C2a);
|
|
13500
|
-
}
|
|
13501
|
-
if (this.caps & g.CAP_C3) {
|
|
13502
|
-
this._C3a = new Array(g.nC3_);
|
|
13503
|
-
geod.C3f(eps, this._C3a);
|
|
13504
|
-
this._A3c = -this.f * this._salp0 * geod.A3f(eps);
|
|
13505
|
-
this._B31 = g.SinCosSeries(true, this._ssig1, this._csig1, this._C3a);
|
|
11521
|
+
salp1 = (salp1a + salp1b) / 2;
|
|
11522
|
+
calp1 = (calp1a + calp1b) / 2;
|
|
11523
|
+
t = hypot(salp1, calp1);
|
|
11524
|
+
salp1 /= t;
|
|
11525
|
+
calp1 /= t;
|
|
11526
|
+
tripn = false;
|
|
11527
|
+
tripb = Math.abs(salp1a - salp1) + (calp1a - calp1) < tolb_ || Math.abs(salp1 - salp1b) + (calp1 - calp1b) < tolb_;
|
|
13506
11528
|
}
|
|
13507
|
-
|
|
13508
|
-
|
|
13509
|
-
|
|
13510
|
-
|
|
13511
|
-
|
|
11529
|
+
lengthmask = outmask | (outmask & 12293 ? DISTANCE : 0);
|
|
11530
|
+
nvals = this.Lengths(eps, sig12, ssig1, csig1, dn1, ssig2, csig2, dn2, cbet1, cbet2, lengthmask, C1a, C2a);
|
|
11531
|
+
s12x = nvals.s12b;
|
|
11532
|
+
m12x = nvals.m12b;
|
|
11533
|
+
if (outmask & 8197) {
|
|
11534
|
+
vals.M12 = nvals.M12;
|
|
11535
|
+
vals.M21 = nvals.M21;
|
|
13512
11536
|
}
|
|
13513
|
-
|
|
13514
|
-
|
|
13515
|
-
|
|
13516
|
-
|
|
13517
|
-
|
|
13518
|
-
|
|
13519
|
-
|
|
13520
|
-
|
|
13521
|
-
vals.azi1 = this.azi1;
|
|
13522
|
-
vals.lon1 = outmask & g.LONG_UNROLL ? this.lon1 : m.AngNormalize(this.lon1);
|
|
13523
|
-
if (arcmode) vals.a12 = s12_a12;
|
|
13524
|
-
else vals.s12 = s12_a12;
|
|
13525
|
-
if (!(arcmode || this.caps & g.DISTANCE_IN & g.OUT_MASK)) {
|
|
13526
|
-
vals.a12 = NaN;
|
|
13527
|
-
return vals;
|
|
11537
|
+
m12x *= this._b;
|
|
11538
|
+
s12x *= this._b;
|
|
11539
|
+
vals.a12 = sig12 / degree;
|
|
11540
|
+
if (outmask & 16400) {
|
|
11541
|
+
sdomg12 = Math.sin(domg12);
|
|
11542
|
+
cdomg12 = Math.cos(domg12);
|
|
11543
|
+
somg12 = slam12 * cdomg12 - clam12 * sdomg12;
|
|
11544
|
+
comg12 = clam12 * cdomg12 + slam12 * sdomg12;
|
|
13528
11545
|
}
|
|
13529
|
-
|
|
13530
|
-
|
|
13531
|
-
|
|
13532
|
-
|
|
13533
|
-
|
|
13534
|
-
|
|
13535
|
-
|
|
13536
|
-
|
|
13537
|
-
|
|
13538
|
-
|
|
13539
|
-
|
|
13540
|
-
|
|
13541
|
-
|
|
13542
|
-
|
|
13543
|
-
|
|
13544
|
-
|
|
13545
|
-
|
|
13546
|
-
|
|
13547
|
-
|
|
13548
|
-
|
|
13549
|
-
|
|
13550
|
-
|
|
13551
|
-
|
|
13552
|
-
|
|
11546
|
+
}
|
|
11547
|
+
}
|
|
11548
|
+
if (outmask & 1025) vals.s12 = 0 + s12x;
|
|
11549
|
+
if (outmask & 4101) vals.m12 = 0 + m12x;
|
|
11550
|
+
if (outmask & 16400) {
|
|
11551
|
+
salp0 = salp1 * cbet1;
|
|
11552
|
+
calp0 = hypot(calp1, salp1 * sbet1);
|
|
11553
|
+
if (calp0 !== 0 && salp0 !== 0) {
|
|
11554
|
+
ssig1 = sbet1;
|
|
11555
|
+
csig1 = calp1 * cbet1;
|
|
11556
|
+
ssig2 = sbet2;
|
|
11557
|
+
csig2 = calp2 * cbet2;
|
|
11558
|
+
k2 = sq(calp0) * this._ep2;
|
|
11559
|
+
eps = k2 / (2 * (1 + Math.sqrt(1 + k2)) + k2);
|
|
11560
|
+
A4 = sq(this.a) * calp0 * salp0 * this._e2;
|
|
11561
|
+
t = hypot(ssig1, csig1);
|
|
11562
|
+
ssig1 /= t;
|
|
11563
|
+
csig1 /= t;
|
|
11564
|
+
t = hypot(ssig2, csig2);
|
|
11565
|
+
ssig2 /= t;
|
|
11566
|
+
csig2 /= t;
|
|
11567
|
+
C4a = new Array(6);
|
|
11568
|
+
this.C4f(eps, C4a);
|
|
11569
|
+
B41 = SinCosSeries(false, ssig1, csig1, C4a);
|
|
11570
|
+
B42 = SinCosSeries(false, ssig2, csig2, C4a);
|
|
11571
|
+
vals.S12 = A4 * (B42 - B41);
|
|
11572
|
+
} else vals.S12 = 0;
|
|
11573
|
+
if (!meridian && somg12 == 2) {
|
|
11574
|
+
somg12 = Math.sin(omg12);
|
|
11575
|
+
comg12 = Math.cos(omg12);
|
|
11576
|
+
}
|
|
11577
|
+
if (!meridian && comg12 > -.7071 && sbet2 - sbet1 < 1.75) {
|
|
11578
|
+
domg12 = 1 + comg12;
|
|
11579
|
+
dbet1 = 1 + cbet1;
|
|
11580
|
+
dbet2 = 1 + cbet2;
|
|
11581
|
+
alp12 = 2 * Math.atan2(somg12 * (sbet1 * dbet2 + sbet2 * dbet1), domg12 * (sbet1 * sbet2 + dbet1 * dbet2));
|
|
11582
|
+
} else {
|
|
11583
|
+
salp12 = salp2 * calp1 - calp2 * salp1;
|
|
11584
|
+
calp12 = calp2 * calp1 + salp2 * salp1;
|
|
11585
|
+
if (salp12 === 0 && calp12 < 0) {
|
|
11586
|
+
salp12 = tiny_ * calp1;
|
|
11587
|
+
calp12 = -1;
|
|
13553
11588
|
}
|
|
11589
|
+
alp12 = Math.atan2(salp12, calp12);
|
|
11590
|
+
}
|
|
11591
|
+
vals.S12 += this._c2 * alp12;
|
|
11592
|
+
vals.S12 *= swapp * lonsign * latsign;
|
|
11593
|
+
vals.S12 += 0;
|
|
11594
|
+
}
|
|
11595
|
+
if (swapp < 0) {
|
|
11596
|
+
[salp2, salp1] = [salp1, salp2];
|
|
11597
|
+
[calp2, calp1] = [calp1, calp2];
|
|
11598
|
+
if (outmask & 8197) [vals.M21, vals.M12] = [vals.M12, vals.M21];
|
|
11599
|
+
}
|
|
11600
|
+
salp1 *= swapp * lonsign;
|
|
11601
|
+
calp1 *= swapp * latsign;
|
|
11602
|
+
salp2 *= swapp * lonsign;
|
|
11603
|
+
calp2 *= swapp * latsign;
|
|
11604
|
+
return {
|
|
11605
|
+
vals,
|
|
11606
|
+
salp1,
|
|
11607
|
+
calp1,
|
|
11608
|
+
salp2,
|
|
11609
|
+
calp2
|
|
11610
|
+
};
|
|
11611
|
+
}
|
|
11612
|
+
GenDirect(lat1, lon1, azi1, arcmode, s12_a12, outmask = 0) {
|
|
11613
|
+
let line;
|
|
11614
|
+
if (!outmask) outmask = STANDARD;
|
|
11615
|
+
else if (outmask === 32768) outmask |= STANDARD;
|
|
11616
|
+
if (!arcmode) outmask |= DISTANCE_IN;
|
|
11617
|
+
line = new GeodesicLine(this, lat1, lon1, azi1, outmask);
|
|
11618
|
+
return line.GenPosition(arcmode, s12_a12, outmask);
|
|
11619
|
+
}
|
|
11620
|
+
Direct(lat1, lon1, azi1, s12, outmask = 0) {
|
|
11621
|
+
return this.GenDirect(lat1, lon1, azi1, false, s12, outmask);
|
|
11622
|
+
}
|
|
11623
|
+
ArcDirect(lat1, lon1, azi1, a12, outmask = 0) {
|
|
11624
|
+
return this.GenDirect(lat1, lon1, azi1, true, a12, outmask);
|
|
11625
|
+
}
|
|
11626
|
+
Line(lat1, lon1, azi1, caps = 0) {
|
|
11627
|
+
return new GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
11628
|
+
}
|
|
11629
|
+
DirectLine(lat1, lon1, azi1, s12, caps = 0) {
|
|
11630
|
+
return this.GenDirectLine(lat1, lon1, azi1, false, s12, caps);
|
|
11631
|
+
}
|
|
11632
|
+
ArcDirectLine(lat1, lon1, azi1, a12, caps = 0) {
|
|
11633
|
+
return this.GenDirectLine(lat1, lon1, azi1, true, a12, caps);
|
|
11634
|
+
}
|
|
11635
|
+
GenDirectLine(lat1, lon1, azi1, arcmode, s12_a12, caps = 0) {
|
|
11636
|
+
let t;
|
|
11637
|
+
if (!caps) caps = 3979;
|
|
11638
|
+
if (!arcmode) caps |= DISTANCE_IN;
|
|
11639
|
+
t = new GeodesicLine(this, lat1, lon1, azi1, caps);
|
|
11640
|
+
t.GenSetDistance(arcmode, s12_a12);
|
|
11641
|
+
return t;
|
|
11642
|
+
}
|
|
11643
|
+
InverseLine(lat1, lon1, lat2, lon2, caps = 0) {
|
|
11644
|
+
let r, t, azi1;
|
|
11645
|
+
if (!caps) caps = 3979;
|
|
11646
|
+
r = this.InverseInt(lat1, lon1, lat2, lon2, 64);
|
|
11647
|
+
azi1 = atan2d(r.salp1, r.calp1);
|
|
11648
|
+
if (caps & 2048) caps |= DISTANCE;
|
|
11649
|
+
t = new GeodesicLine(this, lat1, lon1, azi1, caps, r.salp1, r.calp1);
|
|
11650
|
+
t.SetArc(r.vals.a12);
|
|
11651
|
+
return t;
|
|
11652
|
+
}
|
|
11653
|
+
};
|
|
11654
|
+
var GeodesicLine = class {
|
|
11655
|
+
a = NaN;
|
|
11656
|
+
f = NaN;
|
|
11657
|
+
_b = NaN;
|
|
11658
|
+
_c2 = NaN;
|
|
11659
|
+
_f1 = NaN;
|
|
11660
|
+
caps = NaN;
|
|
11661
|
+
lat1 = NaN;
|
|
11662
|
+
lon1 = NaN;
|
|
11663
|
+
azi1 = NaN;
|
|
11664
|
+
salp1 = NaN;
|
|
11665
|
+
calp1 = NaN;
|
|
11666
|
+
_dn1 = NaN;
|
|
11667
|
+
_salp0 = NaN;
|
|
11668
|
+
_calp0 = NaN;
|
|
11669
|
+
_ssig1 = NaN;
|
|
11670
|
+
_somg1 = NaN;
|
|
11671
|
+
_csig1 = NaN;
|
|
11672
|
+
_comg1 = NaN;
|
|
11673
|
+
_k2 = NaN;
|
|
11674
|
+
_A1m1 = NaN;
|
|
11675
|
+
_C1a = [];
|
|
11676
|
+
_B11 = NaN;
|
|
11677
|
+
_stau1 = NaN;
|
|
11678
|
+
_ctau1 = NaN;
|
|
11679
|
+
_C1pa = [];
|
|
11680
|
+
_A2m1 = NaN;
|
|
11681
|
+
_C2a = [];
|
|
11682
|
+
_B21 = NaN;
|
|
11683
|
+
_C3a = [];
|
|
11684
|
+
_A3c = NaN;
|
|
11685
|
+
_B31 = NaN;
|
|
11686
|
+
_C4a = [];
|
|
11687
|
+
_A4 = NaN;
|
|
11688
|
+
_B41 = NaN;
|
|
11689
|
+
a13 = NaN;
|
|
11690
|
+
s13 = NaN;
|
|
11691
|
+
constructor(geod, lat1, lon1, azi1, caps = 0, salp1, calp1) {
|
|
11692
|
+
let t, cbet1, sbet1, eps, s, c;
|
|
11693
|
+
if (!caps) caps = 3979;
|
|
11694
|
+
this.a = geod.a;
|
|
11695
|
+
this.f = geod.f;
|
|
11696
|
+
this._b = geod._b;
|
|
11697
|
+
this._c2 = geod._c2;
|
|
11698
|
+
this._f1 = geod._f1;
|
|
11699
|
+
this.caps = caps | 33408;
|
|
11700
|
+
this.lat1 = LatFix(lat1);
|
|
11701
|
+
this.lon1 = lon1;
|
|
11702
|
+
if (typeof salp1 === "undefined" || typeof calp1 === "undefined") {
|
|
11703
|
+
this.azi1 = AngNormalize(azi1);
|
|
11704
|
+
t = sincosd(AngRound(this.azi1));
|
|
11705
|
+
this.salp1 = t.s;
|
|
11706
|
+
this.calp1 = t.c;
|
|
11707
|
+
} else {
|
|
11708
|
+
this.azi1 = azi1;
|
|
11709
|
+
this.salp1 = salp1;
|
|
11710
|
+
this.calp1 = calp1;
|
|
11711
|
+
}
|
|
11712
|
+
t = sincosd(AngRound(this.lat1));
|
|
11713
|
+
sbet1 = this._f1 * t.s;
|
|
11714
|
+
cbet1 = t.c;
|
|
11715
|
+
t = hypot(sbet1, cbet1);
|
|
11716
|
+
sbet1 /= t;
|
|
11717
|
+
cbet1 /= t;
|
|
11718
|
+
cbet1 = Math.max(tiny_, cbet1);
|
|
11719
|
+
this._dn1 = Math.sqrt(1 + geod._ep2 * sq(sbet1));
|
|
11720
|
+
this._salp0 = this.salp1 * cbet1;
|
|
11721
|
+
this._calp0 = hypot(this.calp1, this.salp1 * sbet1);
|
|
11722
|
+
this._ssig1 = sbet1;
|
|
11723
|
+
this._somg1 = this._salp0 * sbet1;
|
|
11724
|
+
this._csig1 = this._comg1 = sbet1 !== 0 || this.calp1 !== 0 ? cbet1 * this.calp1 : 1;
|
|
11725
|
+
t = hypot(this._ssig1, this._csig1);
|
|
11726
|
+
this._ssig1 /= t;
|
|
11727
|
+
this._csig1 /= t;
|
|
11728
|
+
this._k2 = sq(this._calp0) * geod._ep2;
|
|
11729
|
+
eps = this._k2 / (2 * (1 + Math.sqrt(1 + this._k2)) + this._k2);
|
|
11730
|
+
if (this.caps & 1) {
|
|
11731
|
+
this._A1m1 = A1m1f(eps);
|
|
11732
|
+
this._C1a = new Array(7);
|
|
11733
|
+
C1f(eps, this._C1a);
|
|
11734
|
+
this._B11 = SinCosSeries(true, this._ssig1, this._csig1, this._C1a);
|
|
11735
|
+
s = Math.sin(this._B11);
|
|
11736
|
+
c = Math.cos(this._B11);
|
|
11737
|
+
this._stau1 = this._ssig1 * c + this._csig1 * s;
|
|
11738
|
+
this._ctau1 = this._csig1 * c - this._ssig1 * s;
|
|
11739
|
+
}
|
|
11740
|
+
if (this.caps & 2) {
|
|
11741
|
+
this._C1pa = new Array(7);
|
|
11742
|
+
C1pf(eps, this._C1pa);
|
|
11743
|
+
}
|
|
11744
|
+
if (this.caps & 4) {
|
|
11745
|
+
this._A2m1 = A2m1f(eps);
|
|
11746
|
+
this._C2a = new Array(7);
|
|
11747
|
+
C2f(eps, this._C2a);
|
|
11748
|
+
this._B21 = SinCosSeries(true, this._ssig1, this._csig1, this._C2a);
|
|
11749
|
+
}
|
|
11750
|
+
if (this.caps & 8) {
|
|
11751
|
+
this._C3a = new Array(6);
|
|
11752
|
+
geod.C3f(eps, this._C3a);
|
|
11753
|
+
this._A3c = -this.f * this._salp0 * geod.A3f(eps);
|
|
11754
|
+
this._B31 = SinCosSeries(true, this._ssig1, this._csig1, this._C3a);
|
|
11755
|
+
}
|
|
11756
|
+
if (this.caps & 16) {
|
|
11757
|
+
this._C4a = new Array(6);
|
|
11758
|
+
geod.C4f(eps, this._C4a);
|
|
11759
|
+
this._A4 = sq(this.a) * this._calp0 * this._salp0 * geod._e2;
|
|
11760
|
+
this._B41 = SinCosSeries(false, this._ssig1, this._csig1, this._C4a);
|
|
11761
|
+
}
|
|
11762
|
+
this.a13 = this.s13 = NaN;
|
|
11763
|
+
}
|
|
11764
|
+
GenPosition(arcmode, s12_a12, outmask = 0) {
|
|
11765
|
+
let vals = {
|
|
11766
|
+
lat1: NaN,
|
|
11767
|
+
azi1: NaN,
|
|
11768
|
+
lon1: NaN,
|
|
11769
|
+
a12: NaN,
|
|
11770
|
+
s12: NaN,
|
|
11771
|
+
lon2: NaN,
|
|
11772
|
+
lat2: NaN,
|
|
11773
|
+
azi2: NaN,
|
|
11774
|
+
m12: NaN,
|
|
11775
|
+
M12: NaN,
|
|
11776
|
+
M21: NaN,
|
|
11777
|
+
S12: NaN
|
|
11778
|
+
}, sig12, ssig12, csig12, B12, AB1, ssig2, csig2, tau12, s, c, serr, omg12, lam12, lon12, E, sbet2, cbet2, somg2, comg2, salp2, calp2, dn2, B22, AB2, J12, t, B42, salp12, calp12;
|
|
11779
|
+
if (!outmask) outmask = STANDARD;
|
|
11780
|
+
else if (outmask === 32768) outmask |= STANDARD;
|
|
11781
|
+
outmask &= this.caps & OUT_MASK;
|
|
11782
|
+
vals.lat1 = this.lat1;
|
|
11783
|
+
vals.azi1 = this.azi1;
|
|
11784
|
+
vals.lon1 = outmask & 32768 ? this.lon1 : AngNormalize(this.lon1);
|
|
11785
|
+
if (arcmode) vals.a12 = s12_a12;
|
|
11786
|
+
else vals.s12 = s12_a12;
|
|
11787
|
+
if (!(arcmode || this.caps & 2048)) {
|
|
11788
|
+
vals.a12 = NaN;
|
|
11789
|
+
return vals;
|
|
11790
|
+
}
|
|
11791
|
+
B12 = 0;
|
|
11792
|
+
AB1 = 0;
|
|
11793
|
+
if (arcmode) {
|
|
11794
|
+
sig12 = s12_a12 * degree;
|
|
11795
|
+
t = sincosd(s12_a12);
|
|
11796
|
+
ssig12 = t.s;
|
|
11797
|
+
csig12 = t.c;
|
|
11798
|
+
} else {
|
|
11799
|
+
tau12 = s12_a12 / (this._b * (1 + this._A1m1));
|
|
11800
|
+
s = Math.sin(tau12);
|
|
11801
|
+
c = Math.cos(tau12);
|
|
11802
|
+
B12 = -SinCosSeries(true, this._stau1 * c + this._ctau1 * s, this._ctau1 * c - this._stau1 * s, this._C1pa);
|
|
11803
|
+
sig12 = tau12 - (B12 - this._B11);
|
|
11804
|
+
ssig12 = Math.sin(sig12);
|
|
11805
|
+
csig12 = Math.cos(sig12);
|
|
11806
|
+
if (Math.abs(this.f) > .01) {
|
|
13554
11807
|
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
|
13555
11808
|
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
|
13556
|
-
|
|
13557
|
-
|
|
13558
|
-
|
|
13559
|
-
|
|
13560
|
-
|
|
13561
|
-
|
|
13562
|
-
|
|
13563
|
-
|
|
13564
|
-
|
|
13565
|
-
|
|
13566
|
-
|
|
13567
|
-
|
|
13568
|
-
|
|
13569
|
-
|
|
13570
|
-
|
|
13571
|
-
|
|
13572
|
-
|
|
13573
|
-
|
|
13574
|
-
|
|
13575
|
-
|
|
13576
|
-
|
|
13577
|
-
|
|
13578
|
-
|
|
13579
|
-
|
|
13580
|
-
|
|
13581
|
-
|
|
13582
|
-
|
|
13583
|
-
|
|
13584
|
-
|
|
13585
|
-
|
|
13586
|
-
|
|
13587
|
-
|
|
13588
|
-
|
|
13589
|
-
|
|
13590
|
-
|
|
13591
|
-
|
|
13592
|
-
|
|
13593
|
-
|
|
13594
|
-
|
|
13595
|
-
|
|
13596
|
-
|
|
13597
|
-
|
|
13598
|
-
|
|
13599
|
-
|
|
13600
|
-
|
|
13601
|
-
|
|
13602
|
-
|
|
13603
|
-
|
|
13604
|
-
|
|
13605
|
-
|
|
13606
|
-
|
|
13607
|
-
|
|
13608
|
-
|
|
13609
|
-
|
|
13610
|
-
|
|
13611
|
-
|
|
13612
|
-
|
|
13613
|
-
|
|
13614
|
-
|
|
13615
|
-
|
|
13616
|
-
|
|
13617
|
-
|
|
13618
|
-
|
|
13619
|
-
|
|
13620
|
-
|
|
13621
|
-
|
|
13622
|
-
|
|
13623
|
-
|
|
13624
|
-
|
|
13625
|
-
|
|
13626
|
-
|
|
13627
|
-
|
|
13628
|
-
|
|
13629
|
-
|
|
13630
|
-
|
|
13631
|
-
|
|
13632
|
-
|
|
13633
|
-
|
|
13634
|
-
|
|
13635
|
-
|
|
13636
|
-
|
|
13637
|
-
}, AreaReduceA = function(area, area0, crossings, reverse, sign) {
|
|
13638
|
-
area.Remainder(area0);
|
|
13639
|
-
if (crossings & 1) area.Add((area.Sum() < 0 ? 1 : -1) * area0 / 2);
|
|
13640
|
-
if (!reverse) area.Negate();
|
|
13641
|
-
if (sign) {
|
|
13642
|
-
if (area.Sum() > area0 / 2) area.Add(-area0);
|
|
13643
|
-
else if (area.Sum() <= -area0 / 2) area.Add(+area0);
|
|
13644
|
-
} else if (area.Sum() >= area0) area.Add(-area0);
|
|
13645
|
-
else if (area.Sum() < 0) area.Add(+area0);
|
|
13646
|
-
return 0 + area.Sum();
|
|
13647
|
-
}, AreaReduceB = function(area, area0, crossings, reverse, sign) {
|
|
13648
|
-
area = m.remainder(area, area0);
|
|
13649
|
-
if (crossings & 1) area += (area < 0 ? 1 : -1) * area0 / 2;
|
|
13650
|
-
if (!reverse) area *= -1;
|
|
13651
|
-
if (sign) {
|
|
13652
|
-
if (area > area0 / 2) area -= area0;
|
|
13653
|
-
else if (area <= -area0 / 2) area += area0;
|
|
13654
|
-
} else if (area >= area0) area -= area0;
|
|
13655
|
-
else if (area < 0) area += area0;
|
|
13656
|
-
return 0 + area;
|
|
13657
|
-
};
|
|
13658
|
-
p.PolygonArea = function(geod, polyline) {
|
|
13659
|
-
this._geod = geod;
|
|
13660
|
-
this.a = this._geod.a;
|
|
13661
|
-
this.f = this._geod.f;
|
|
13662
|
-
this._area0 = 4 * Math.PI * geod._c2;
|
|
13663
|
-
this.polyline = !polyline ? false : polyline;
|
|
13664
|
-
this._mask = g.LATITUDE | g.LONGITUDE | g.DISTANCE | (this.polyline ? g.NONE : g.AREA | g.LONG_UNROLL);
|
|
13665
|
-
if (!this.polyline) this._areasum = new a.Accumulator(0);
|
|
13666
|
-
this._perimetersum = new a.Accumulator(0);
|
|
13667
|
-
this.Clear();
|
|
13668
|
-
};
|
|
13669
|
-
p.PolygonArea.prototype.Clear = function() {
|
|
13670
|
-
this.num = 0;
|
|
13671
|
-
this._crossings = 0;
|
|
13672
|
-
if (!this.polyline) this._areasum.Set(0);
|
|
13673
|
-
this._perimetersum.Set(0);
|
|
13674
|
-
this._lat0 = this._lon0 = this.lat = this.lon = NaN;
|
|
13675
|
-
};
|
|
13676
|
-
p.PolygonArea.prototype.AddPoint = function(lat, lon) {
|
|
13677
|
-
var t;
|
|
13678
|
-
if (this.num === 0) {
|
|
13679
|
-
this._lat0 = this.lat = lat;
|
|
13680
|
-
this._lon0 = this.lon = lon;
|
|
13681
|
-
} else {
|
|
13682
|
-
t = this._geod.Inverse(this.lat, this.lon, lat, lon, this._mask);
|
|
13683
|
-
this._perimetersum.Add(t.s12);
|
|
13684
|
-
if (!this.polyline) {
|
|
13685
|
-
this._areasum.Add(t.S12);
|
|
13686
|
-
this._crossings += transit(this.lon, lon);
|
|
13687
|
-
}
|
|
13688
|
-
this.lat = lat;
|
|
13689
|
-
this.lon = lon;
|
|
13690
|
-
}
|
|
13691
|
-
++this.num;
|
|
13692
|
-
};
|
|
13693
|
-
p.PolygonArea.prototype.AddEdge = function(azi, s) {
|
|
13694
|
-
var t;
|
|
13695
|
-
if (this.num) {
|
|
13696
|
-
t = this._geod.Direct(this.lat, this.lon, azi, s, this._mask);
|
|
13697
|
-
this._perimetersum.Add(s);
|
|
13698
|
-
if (!this.polyline) {
|
|
13699
|
-
this._areasum.Add(t.S12);
|
|
13700
|
-
this._crossings += transitdirect(this.lon, t.lon2);
|
|
13701
|
-
}
|
|
13702
|
-
this.lat = t.lat2;
|
|
13703
|
-
this.lon = t.lon2;
|
|
13704
|
-
}
|
|
13705
|
-
++this.num;
|
|
13706
|
-
};
|
|
13707
|
-
p.PolygonArea.prototype.Compute = function(reverse, sign) {
|
|
13708
|
-
var vals = { number: this.num }, t, tempsum;
|
|
13709
|
-
if (this.num < 2) {
|
|
13710
|
-
vals.perimeter = 0;
|
|
13711
|
-
if (!this.polyline) vals.area = 0;
|
|
13712
|
-
return vals;
|
|
13713
|
-
}
|
|
13714
|
-
if (this.polyline) {
|
|
13715
|
-
vals.perimeter = this._perimetersum.Sum();
|
|
13716
|
-
return vals;
|
|
13717
|
-
}
|
|
13718
|
-
t = this._geod.Inverse(this.lat, this.lon, this._lat0, this._lon0, this._mask);
|
|
13719
|
-
vals.perimeter = this._perimetersum.Sum(t.s12);
|
|
13720
|
-
tempsum = new a.Accumulator(this._areasum);
|
|
13721
|
-
tempsum.Add(t.S12);
|
|
13722
|
-
vals.area = AreaReduceA(tempsum, this._area0, this._crossings + transit(this.lon, this._lon0), reverse, sign);
|
|
13723
|
-
return vals;
|
|
13724
|
-
};
|
|
13725
|
-
p.PolygonArea.prototype.TestPoint = function(lat, lon, reverse, sign) {
|
|
13726
|
-
var vals = { number: this.num + 1 }, t, tempsum, crossings, i;
|
|
13727
|
-
if (this.num === 0) {
|
|
13728
|
-
vals.perimeter = 0;
|
|
13729
|
-
if (!this.polyline) vals.area = 0;
|
|
13730
|
-
return vals;
|
|
13731
|
-
}
|
|
13732
|
-
vals.perimeter = this._perimetersum.Sum();
|
|
13733
|
-
tempsum = this.polyline ? 0 : this._areasum.Sum();
|
|
13734
|
-
crossings = this._crossings;
|
|
13735
|
-
for (i = 0; i < (this.polyline ? 1 : 2); ++i) {
|
|
13736
|
-
t = this._geod.Inverse(i === 0 ? this.lat : lat, i === 0 ? this.lon : lon, i !== 0 ? this._lat0 : lat, i !== 0 ? this._lon0 : lon, this._mask);
|
|
13737
|
-
vals.perimeter += t.s12;
|
|
13738
|
-
if (!this.polyline) {
|
|
13739
|
-
tempsum += t.S12;
|
|
13740
|
-
crossings += transit(i === 0 ? this.lon : lon, i !== 0 ? this._lon0 : lon);
|
|
13741
|
-
}
|
|
13742
|
-
}
|
|
13743
|
-
if (this.polyline) return vals;
|
|
13744
|
-
vals.area = AreaReduceB(tempsum, this._area0, crossings, reverse, sign);
|
|
13745
|
-
return vals;
|
|
13746
|
-
};
|
|
13747
|
-
p.PolygonArea.prototype.TestEdge = function(azi, s, reverse, sign) {
|
|
13748
|
-
var vals = { number: this.num ? this.num + 1 : 0 }, t, tempsum, crossings;
|
|
13749
|
-
if (this.num === 0) return vals;
|
|
13750
|
-
vals.perimeter = this._perimetersum.Sum() + s;
|
|
13751
|
-
if (this.polyline) return vals;
|
|
13752
|
-
tempsum = this._areasum.Sum();
|
|
13753
|
-
crossings = this._crossings;
|
|
13754
|
-
t = this._geod.Direct(this.lat, this.lon, azi, s, this._mask);
|
|
13755
|
-
tempsum += t.S12;
|
|
13756
|
-
crossings += transitdirect(this.lon, t.lon2);
|
|
13757
|
-
crossings += transit(t.lon2, this._lon0);
|
|
13758
|
-
t = this._geod.Inverse(t.lat2, t.lon2, this._lat0, this._lon0, this._mask);
|
|
13759
|
-
vals.perimeter += t.s12;
|
|
13760
|
-
tempsum += t.S12;
|
|
13761
|
-
vals.area = AreaReduceB(tempsum, this._area0, crossings, reverse, sign);
|
|
13762
|
-
return vals;
|
|
13763
|
-
};
|
|
13764
|
-
})(geodesic.PolygonArea, geodesic.Geodesic, geodesic.Math, geodesic.Accumulator);
|
|
13765
|
-
cb(geodesic);
|
|
13766
|
-
})(function(geo) {
|
|
13767
|
-
if (typeof module === "object" && module.exports) module.exports = geo;
|
|
13768
|
-
else if (typeof define === "function" && define.amd) define("geographiclib-geodesic", [], function() {
|
|
13769
|
-
return geo;
|
|
13770
|
-
});
|
|
13771
|
-
else window.geodesic = geo;
|
|
13772
|
-
});
|
|
13773
|
-
})))(), 1);
|
|
13774
|
-
/** Karney geodesics via GeographicLib; antipodal inputs are supported. */
|
|
11809
|
+
B12 = SinCosSeries(true, ssig2, csig2, this._C1a);
|
|
11810
|
+
serr = (1 + this._A1m1) * (sig12 + (B12 - this._B11)) - s12_a12 / this._b;
|
|
11811
|
+
sig12 = sig12 - serr / Math.sqrt(1 + this._k2 * sq(ssig2));
|
|
11812
|
+
ssig12 = Math.sin(sig12);
|
|
11813
|
+
csig12 = Math.cos(sig12);
|
|
11814
|
+
}
|
|
11815
|
+
}
|
|
11816
|
+
ssig2 = this._ssig1 * csig12 + this._csig1 * ssig12;
|
|
11817
|
+
csig2 = this._csig1 * csig12 - this._ssig1 * ssig12;
|
|
11818
|
+
dn2 = Math.sqrt(1 + this._k2 * sq(ssig2));
|
|
11819
|
+
if (outmask & 13317) {
|
|
11820
|
+
if (arcmode || Math.abs(this.f) > .01) B12 = SinCosSeries(true, ssig2, csig2, this._C1a);
|
|
11821
|
+
AB1 = (1 + this._A1m1) * (B12 - this._B11);
|
|
11822
|
+
}
|
|
11823
|
+
sbet2 = this._calp0 * ssig2;
|
|
11824
|
+
cbet2 = hypot(this._salp0, this._calp0 * csig2);
|
|
11825
|
+
if (cbet2 === 0) cbet2 = csig2 = tiny_;
|
|
11826
|
+
salp2 = this._salp0;
|
|
11827
|
+
calp2 = this._calp0 * csig2;
|
|
11828
|
+
if (arcmode && outmask & 1025) vals.s12 = this._b * ((1 + this._A1m1) * sig12 + AB1);
|
|
11829
|
+
if (outmask & 264) {
|
|
11830
|
+
somg2 = this._salp0 * ssig2;
|
|
11831
|
+
comg2 = csig2;
|
|
11832
|
+
E = copysign(1, this._salp0);
|
|
11833
|
+
omg12 = outmask & 32768 ? E * (sig12 - (Math.atan2(ssig2, csig2) - Math.atan2(this._ssig1, this._csig1)) + (Math.atan2(E * somg2, comg2) - Math.atan2(E * this._somg1, this._comg1))) : Math.atan2(somg2 * this._comg1 - comg2 * this._somg1, comg2 * this._comg1 + somg2 * this._somg1);
|
|
11834
|
+
lam12 = omg12 + this._A3c * (sig12 + (SinCosSeries(true, ssig2, csig2, this._C3a) - this._B31));
|
|
11835
|
+
lon12 = lam12 / degree;
|
|
11836
|
+
vals.lon2 = outmask & 32768 ? this.lon1 + lon12 : AngNormalize(AngNormalize(this.lon1) + AngNormalize(lon12));
|
|
11837
|
+
}
|
|
11838
|
+
if (outmask & 128) vals.lat2 = atan2d(sbet2, this._f1 * cbet2);
|
|
11839
|
+
if (outmask & 512) vals.azi2 = atan2d(salp2, calp2);
|
|
11840
|
+
if (outmask & 12293) {
|
|
11841
|
+
B22 = SinCosSeries(true, ssig2, csig2, this._C2a);
|
|
11842
|
+
AB2 = (1 + this._A2m1) * (B22 - this._B21);
|
|
11843
|
+
J12 = (this._A1m1 - this._A2m1) * sig12 + (AB1 - AB2);
|
|
11844
|
+
if (outmask & 4101) vals.m12 = this._b * (dn2 * (this._csig1 * ssig2) - this._dn1 * (this._ssig1 * csig2) - this._csig1 * csig2 * J12);
|
|
11845
|
+
if (outmask & 8197) {
|
|
11846
|
+
t = this._k2 * (ssig2 - this._ssig1) * (ssig2 + this._ssig1) / (this._dn1 + dn2);
|
|
11847
|
+
vals.M12 = csig12 + (t * ssig2 - csig2 * J12) * this._ssig1 / this._dn1;
|
|
11848
|
+
vals.M21 = csig12 - (t * this._ssig1 - this._csig1 * J12) * ssig2 / dn2;
|
|
11849
|
+
}
|
|
11850
|
+
}
|
|
11851
|
+
if (outmask & 16400) {
|
|
11852
|
+
B42 = SinCosSeries(false, ssig2, csig2, this._C4a);
|
|
11853
|
+
if (this._calp0 === 0 || this._salp0 === 0) {
|
|
11854
|
+
salp12 = salp2 * this.calp1 - calp2 * this.salp1;
|
|
11855
|
+
calp12 = calp2 * this.calp1 + salp2 * this.salp1;
|
|
11856
|
+
} else {
|
|
11857
|
+
salp12 = this._calp0 * this._salp0 * (csig12 <= 0 ? this._csig1 * (1 - csig12) + ssig12 * this._ssig1 : ssig12 * (this._csig1 * ssig12 / (1 + csig12) + this._ssig1));
|
|
11858
|
+
calp12 = sq(this._salp0) + sq(this._calp0) * this._csig1 * csig2;
|
|
11859
|
+
}
|
|
11860
|
+
vals.S12 = this._c2 * Math.atan2(salp12, calp12) + this._A4 * (B42 - this._B41);
|
|
11861
|
+
}
|
|
11862
|
+
if (!arcmode) vals.a12 = sig12 / degree;
|
|
11863
|
+
return vals;
|
|
11864
|
+
}
|
|
11865
|
+
Position(s12, outmask = 0) {
|
|
11866
|
+
return this.GenPosition(false, s12, outmask);
|
|
11867
|
+
}
|
|
11868
|
+
ArcPosition(a12, outmask = 0) {
|
|
11869
|
+
return this.GenPosition(true, a12, outmask);
|
|
11870
|
+
}
|
|
11871
|
+
GenSetDistance(arcmode, s13_a13) {
|
|
11872
|
+
if (arcmode) this.SetArc(s13_a13);
|
|
11873
|
+
else this.SetDistance(s13_a13);
|
|
11874
|
+
}
|
|
11875
|
+
SetDistance(s13) {
|
|
11876
|
+
let r;
|
|
11877
|
+
this.s13 = s13;
|
|
11878
|
+
r = this.GenPosition(false, this.s13, 64);
|
|
11879
|
+
this.a13 = 0 + r.a12;
|
|
11880
|
+
}
|
|
11881
|
+
SetArc(a13) {
|
|
11882
|
+
let r;
|
|
11883
|
+
this.a13 = a13;
|
|
11884
|
+
r = this.GenPosition(true, this.a13, DISTANCE);
|
|
11885
|
+
this.s13 = 0 + r.s12;
|
|
11886
|
+
}
|
|
11887
|
+
};
|
|
11888
|
+
// src-gis/core/EllipsoidGeodesic.ts
|
|
11889
|
+
/** Internal TypeScript Karney geodesics; antipodal inputs are supported. */
|
|
13775
11890
|
var EllipsoidGeodesic = class {
|
|
13776
11891
|
ellipsoid;
|
|
13777
11892
|
start = new Cartographic();
|
|
@@ -13787,7 +11902,7 @@ var EllipsoidGeodesic = class {
|
|
|
13787
11902
|
}
|
|
13788
11903
|
createGeodesic(e) {
|
|
13789
11904
|
if (e.x !== e.y) throw new RangeError("Geodesics require an ellipsoid of revolution about Z");
|
|
13790
|
-
return new
|
|
11905
|
+
return new Geodesic(e.x, (e.x - e.z) / e.x);
|
|
13791
11906
|
}
|
|
13792
11907
|
setEndPoints(start, end) {
|
|
13793
11908
|
this.start = start.clone().validate();
|
|
@@ -13801,6 +11916,11 @@ var EllipsoidGeodesic = class {
|
|
|
13801
11916
|
this.surfaceDistance = r.s12;
|
|
13802
11917
|
this.startHeading = r.azi1 * Math.PI / 180;
|
|
13803
11918
|
this.endHeading = r.azi2 * Math.PI / 180;
|
|
11919
|
+
if (![
|
|
11920
|
+
this.surfaceDistance,
|
|
11921
|
+
this.startHeading,
|
|
11922
|
+
this.endHeading
|
|
11923
|
+
].every(Number.isFinite)) throw new RangeError("Geodesic solver could not produce finite properties");
|
|
13804
11924
|
return this;
|
|
13805
11925
|
}
|
|
13806
11926
|
interpolateUsingSurfaceDistance(distance, result) {
|
|
@@ -15010,4 +13130,4 @@ var DelaunaySlow = class {
|
|
|
15010
13130
|
return [u, v];
|
|
15011
13131
|
}
|
|
15012
13132
|
};
|
|
15013
|
-
export { ArrayObject, BSP, BTree, Box, BufferAttribute, BufferGeometry, csg_exports as CSG, Capsule, Circle, ClipType, Color, ConvexHull, Curve, DEGREES_PER_RADIAN, Delaunator, Delaunay, DelaunaySlow, Disk, Distance, EndType, Euler, EventHandler, Extrude, Float32BufferAttribute, Float64BufferAttribute, Frustum, src_gis_exports as GIS, HVec3, IKanimation_exports as IK, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntersectType, JoinType, KdTree, Line, Mat3, Mat4, MeshTool, ONE_OVER_PI, ONE_OVER_TWO_PI, Orientation, PI, PI_OVER_FOUR, PI_OVER_SIX, PI_OVER_THREE, PI_OVER_TWO, PI_TWO, Path, Plane, Point, PolyTree, Polygon, Polyline, QuadTree, QuadTree as QuatTree, Quat, RADIANS_PER_ARCSECOND, RADIANS_PER_DEGREE, Ray, Rectangle, robust_exports as Robust, Segment, Shape, Sphere, THREE_PI_OVER_TWO, ToDegrees, Tree, Triangle, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Vec2, Vec3, Vec4, Voronoi, angle, applyMatrix4, applyQuat, approximateEqual, boundingBox, calcCircleFromThreePoint, calculateVolume, ceilPowerOfTwo, circle, circleDistance, clamp, classify, cleanPolygon, clipPolygons, clone, closestPair, compose, convexHull, convexHull3D, delta4, delta5, delta6, delta7, delta8, delta9, disk, diskDistance, distance, euler, extrude, extrudeNext, extrudeToGeometryBuffer, extrude_obsolete, flat, floorPowerOfTwo, forall, geometryFromJSON, intersects, isInOnePlane, isPowerOfTwo, lerp, line, linkSide, linkSides, linkToGeometry, linksToGeometry, m3, m4, offsetPaths, pointsCollinear, projectOnPlane, quat, randFloat, randInt, recognitionPlane, reverseOnPlane, rotate, rotateByUnitVectors, scale, segment, sign, simplifyPointList, simplifyPolygon, smootherstep, smoothstep, splitPlaneGeometry, toFixed, toFixedAry, toGeometryBuffer, toRadians, translate, triangulation, unique, v2, v3, v4, vecs, vectorCompare };
|
|
13133
|
+
export { ArrayObject, BSP, BTree, Box, BufferAttribute, BufferGeometry, csg_exports as CSG, Capsule, Circle, ClipType, Color, ConvexHull, Curve, DEGREES_PER_RADIAN, Decimal, Delaunator, Delaunay, DelaunaySlow, Disk, Distance, EndType, Euler, EventHandler, Extrude, Float32BufferAttribute, Float64BufferAttribute, Frustum, src_gis_exports as GIS, HVec3, IKanimation_exports as IK, Int16BufferAttribute, Int32BufferAttribute, Int8BufferAttribute, IntersectType, JoinType, KdTree, Line, Mat3, Mat4, MeshTool, ONE_OVER_PI, ONE_OVER_TWO_PI, Orientation, PI, PI_OVER_FOUR, PI_OVER_SIX, PI_OVER_THREE, PI_OVER_TWO, PI_TWO, Path, Plane, Point, PolyTree, Polygon, Polyline, QuadTree, QuadTree as QuatTree, Quat, RADIANS_PER_ARCSECOND, RADIANS_PER_DEGREE, Ray, Rectangle, robust_exports as Robust, Segment, Shape, Sphere, THREE_PI_OVER_TWO, ToDegrees, Tree, Triangle, Uint16BufferAttribute, Uint32BufferAttribute, Uint8BufferAttribute, Uint8ClampedBufferAttribute, Vec2, Vec3, Vec4, Voronoi, angle, applyMatrix4, applyQuat, approximateEqual, boundingBox, calcCircleFromThreePoint, calculateVolume, ceilPowerOfTwo, circle, circleDistance, clamp, classify, cleanPolygon, clipPolygons, clone, closestPair, compose, convexHull, convexHull3D, delta4, delta5, delta6, delta7, delta8, delta9, disk, diskDistance, distance, euler, extrude, extrudeNext, extrudeToGeometryBuffer, extrude_obsolete, flat, floorPowerOfTwo, forall, geometryFromJSON, intersects, isInOnePlane, isPowerOfTwo, lerp, line, linkSide, linkSides, linkToGeometry, linksToGeometry, m3, m4, offsetPaths, pointsCollinear, projectOnPlane, quat, randFloat, randInt, recognitionPlane, reverseOnPlane, rotate, rotateByUnitVectors, scale, segment, sign, simplifyPointList, simplifyPolygon, smootherstep, smoothstep, splitPlaneGeometry, toFixed, toFixedAry, toGeometryBuffer, toRadians, translate, triangulation, unique, v2, v3, v4, vecs, vectorCompare };
|