Skip to content

Domain modules ​

Modules use Robust, CSG, IK and GIS namespaces to avoid conflicting with core geometry names.

Decimal and CSG ​

js
import { HVec3, Robust } from '@xort/cga';
const point = new HVec3('0.1', '0.2', '0.3').add(new HVec3('0.2', 0, 0));
const plane = new Robust.Plane(new Robust.Vec(0, 0, 2), new Robust.Vec(0, 0, 4));
console.log(point.toJSON()); // ['0.3', '0.2', '0.3']
console.log(plane.signedDistanceTo(new Robust.Vec(0, 0, 5)).toString()); // 3

Pass long decimals as strings. HVec3 is mutable; its Decimal components are immutable. Robust.Vec supports arbitrary dimensions, with cross products limited to 3D. Decimal limits and configuration.

CSG.Polygon accepts planar, convex, consistently wound faces. new CSG.BSP(faces) creates a closed solid; union / intersect / sub return new solids without changing operands. Default face tolerance is 1e-15 model units. BSP cost depends strongly on input topology. The optional ThreeBSP adapter bakes Mesh world transforms; UVs and material groups are not retained.

Inverse kinematics ​

js
import { IK, v3 } from '@xort/cga';
const chain = IK.Skeleton.fromPoints([v3(), v3(1, 0, 0), v3(2, 0, 0)]);
chain.chain[0].constraints.push(new IK.HingeConstraint(v3(0, 0, 1), 0, Math.PI / 2));
console.log(new IK.CCDSolver().solve(chain, v3(1, 1, 0), { iterations: 100, tolerance: 1e-5 }));

A skeleton is one connected chain; model branches separately. Joints use world positions. Hinge limits are accumulated radians relative to the initial state; slider limits use model units and may change bone length. Use one hinge or slider per joint and separate stateful constraint instances. Unreachable targets report converged: false.

GIS ​

js
import { GIS } from '@xort/cga';
const position = GIS.Cartographic.fromDegrees(116.4, 39.9, 50);
const ecef = GIS.Ellipsoid.WGS84.cartographicToCartesian(position);
const line = new GIS.EllipsoidGeodesic(undefined,
    GIS.Cartographic.fromDegrees(0, 0), GIS.Cartographic.fromDegrees(180, 0));
console.log(ecef, line.surfaceDistance); // approximately 20,003,931.459 meters

Cartographic values use radians and WGS84 heights in meters. ECEF axes are X=0°E, Y=90°E, Z=north. At the ellipsoid center, cartographic conversion returns undefined. Geodesics require a Z-axis ellipsoid of revolution; surface distances ignore height and support antipodal points.

  • GeographicTilingScheme: 2×1 root tiles, north-to-south Y; wrapped rectangles use west > east.
  • DcTerrainProvider: JSON tiles { width, height, buffer, heightScale?, heightOffset? }, at least 2×2, samples from north to south. Heights use bilinear interpolation.
  • UrlTemplateImageryProvider: URL templates, injectable fetch/decoders and AbortSignal. KTX/CRN needs a host decoder.
  • TaskProcessor: asynchronous functions or Workers. At capacity it returns undefined; destruction rejects pending tasks.
  • Globe: supplies tile meshes and imagery for a host renderer. pick intersects the reference ellipsoid; getHeight reads loaded terrain.

Try the domain examples. Network examples inject local data; replace sample service URLs before using a real provider.

MIT licensed · Internal TypeScript algorithms