Skip to main content

@math.gl/core/types

From v3.6

@math.gl/core provides shared numeric array, bounds, and spheroid types, plus runtime array checks and Float16 support detection.

Usageโ€‹

Use import type for declarations that add no runtime code:

import type {NumericArray, NumberArray3, Bounds3D} from '@math.gl/core/types';

NumberArray covers JavaScript number arrays; NumericArray also includes numeric typed arrays. Sized variants describe fixed component counts. See array types and bounds for the contracts and runtime helpers.

Featuresโ€‹

FeatureSupportNotes
Number and typed-array declarationsโœ…NumericArray, TypedArray and constructor types, with BigInt typed arrays represented separately.
Fixed-component array typesโœ…Sized NumberArray/NumericArray variants cover commonly used vector, matrix, and bounds lengths.
Runtime representation guardsโœ…Array and typed-array guards include intrinsic, cross-realm Uint16 and Float16 checks.
Half-float storage capability detectionโœ…Native Float16Array detection and constructor selection; the Uint16 fallback stores encoded bits rather than decoded numeric values.
Bounds and spheroid contractsโœ…Bounds2D/3D and SpheroidParameters describe geometry independently of renderers and CRS engines.
Runtime enforcement of sized declarationsโŒType declarations do not validate buffer length, coordinate units, or physical meaning at runtime.
Bundled Float16 arithmetic polyfillโŒThe helpers select/detect storage. They do not supply numeric half-float array semantics when the runtime lacks them.

Installationโ€‹

npm install @math.gl/core

SpheroidParametersโ€‹

A type-only geometry contract with semiMajorAxis and semiMinorAxis in metres. Both axes must be finite and positive, with semiMinorAxis <= semiMajorAxis. Equal axes describe a sphere. It contains no datum, axis order, coordinate units or epoch metadata. The type is also exported by core, geospatial and projection.

Use Ellipsoid.fromSpheroid and toSpheroid to exchange this geometry with the geospatial class. The type adds no runtime code.