pts 1.0.0 → 1.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -359,6 +359,47 @@ function _scaled(values: Float64Array, count: number): bigint[] {
359
359
  return out;
360
360
  }
361
361
 
362
+ // `Number(bigint)` is finite below 2^1024; shift in whole limbs until then.
363
+ const FINITE_LIMIT = BigInt(1) << BigInt(1023);
364
+ const SHIFT_STEP = BigInt(64);
365
+
366
+ /**
367
+ * Parameter of a known proper crossing along a→b. Evaluate the determinants
368
+ * exactly before division: shallow crossings can lose most of their digits
369
+ * when two rounded products are subtracted. Used by the polygon overlay.
370
+ */
371
+ export function crossingParameter(
372
+ ax: number,
373
+ ay: number,
374
+ bx: number,
375
+ by: number,
376
+ cx: number,
377
+ cy: number,
378
+ dx: number,
379
+ dy: number,
380
+ ): number {
381
+ _input.set([ax, ay, bx, by, cx, cy, dx, dy]);
382
+ const [a, b, c, d, e, f, g, h] = _scaled(_input, 8);
383
+ const rx = g - e;
384
+ const ry = h - f;
385
+ let numerator = rx * (b - f) - ry * (a - e);
386
+ let denominator = numerator - (rx * (d - f) - ry * (c - e));
387
+ if (denominator < BigInt(0)) {
388
+ numerator = -numerator;
389
+ denominator = -denominator;
390
+ }
391
+ // Keep the conversion finite even when the input doubles span hundreds of
392
+ // binary exponents. The numerator is between zero and the denominator, and
393
+ // a denominator of ordinary size needs no shift at all.
394
+ let shift = BigInt(0);
395
+ let scaled = denominator;
396
+ while (scaled >= FINITE_LIMIT) {
397
+ scaled >>= SHIFT_STEP;
398
+ shift += SHIFT_STEP;
399
+ }
400
+ return Number(numerator >> shift) / Number(scaled);
401
+ }
402
+
362
403
  /** Exact orientation, evaluated in BigInt. Used when the fast filter cannot decide. */
363
404
  export function orient2dExact(
364
405
  ax: number,