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