@xort/cga 0.1.2 → 0.1.3

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