Skip to content

Internal algorithms ​

The core has zero runtime dependencies. Geometry, polygon kernels, decimal arithmetic, CSG, IK and geodesics are maintained in TypeScript. Three.js is an optional display adapter; GPU chunks use GLSL. Ported algorithms retain their licenses.

Decimal ​

js
import { Decimal } from '@xort/cga';
const previous = { precision: Decimal.precision, rounding: Decimal.rounding };
try {
    Decimal.set({ precision: 50, rounding: Decimal.ROUND_HALF_EVEN });
    console.log(new Decimal(2).sqrt().toString());
} finally { Decimal.set(previous); }
  • Signed BigInt coefficient × decimal exponent; immutable values, string inputs preserve digits.
  • Arithmetic, square root, comparison and formatting; 1–1000 significant digits and nine rounding modes. Default: 20 digits, half-up. Configuration is shared; restore temporary changes.
  • Maximum input coefficient: 20,000 digits. Normalized exponent magnitude: 1,000,000. toFixed supports 0–1000 decimal places.
  • Division by zero, negative square roots, non-finite values, hexadecimal inputs and invalid configurations throw. Negative zero becomes 0.
  • This is the finite subset used by HVec3, Robust and CSG, not the complete decimal.js API. Use DecimalValue and internal Decimal.isDecimal; convert foreign values explicitly to strings.

Geodesics ​

The internal Karney port supports inverse/direct solutions, poles, date-line crossings, antipodal points and extended or negative distances. Surface distance ignores height. It requires a Z-axis ellipsoid of revolution.

The order-six series targets low-flattening ellipsoids; double-precision accuracy for |f| < 0.02 follows the algorithm addenda. High-eccentricity ellipsoids do not have the same accuracy guarantee; an exact elliptic-integral solver remains future work.

Polygon kernels ​

Hole triangulation uses visible bridges and ear clipping. Planar booleans enumerate intersections, classify edges and assemble rings; offsets build and resolve stroke contours. Inputs must satisfy the API restrictions.

Validation records and dependency gates are maintained separately from usage guides.

MIT licensed · Internal TypeScript algorithms