@math.gl/geometry 5.0.0-beta.5 → 5.0.0-beta.6
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/README.md +3 -0
- package/dist/index.cjs +111 -0
- package/dist/index.cjs.map +3 -3
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/utils/project-bounds.d.ts +44 -0
- package/dist/utils/project-bounds.d.ts.map +1 -0
- package/dist/utils/project-bounds.js +93 -0
- package/dist/utils/project-bounds.js.map +1 -0
- package/dist/utils/project-texture-coordinates.d.ts +19 -0
- package/dist/utils/project-texture-coordinates.d.ts.map +1 -0
- package/dist/utils/project-texture-coordinates.js +49 -0
- package/dist/utils/project-texture-coordinates.js.map +1 -0
- package/package.json +3 -3
- package/src/index.ts +9 -0
- package/src/utils/project-bounds.ts +154 -0
- package/src/utils/project-texture-coordinates.ts +67 -0
package/README.md
CHANGED
|
@@ -26,6 +26,9 @@ The experimental `HingeTree` evaluates rigid panels connected by hinges. See the
|
|
|
26
26
|
|
|
27
27
|
Optional `@math.gl/geometry/lighting` and `@math.gl/geometry/color` subpaths provide renderer-independent photometric and color LUT calculations. See the [lighting and color guide](https://math.gl/docs/modules/geometry/lighting). These CPU graphics utilities return numbers and typed arrays; file parsing remains in loaders.gl.
|
|
28
28
|
|
|
29
|
+
`projectBounds` samples a prepared nonlinear transform over a finite box. Its result distinguishes approximate fitting from an enclosure conditional on caller-qualified Lipschitz bounds. See the [API reference](https://math.gl/docs/modules/geometry/utils/api-reference/project-bounds).
|
|
30
|
+
Generate detached float64 UVs for CPU positions with `projectTextureCoordinates`, an explicit image rectangle and a prepared synchronous transform. It does not infer projection seams, clip domains or allocate GPU resources. See the [API reference](https://math.gl/docs/modules/geometry/utils/api-reference/project-texture-coordinates).
|
|
31
|
+
|
|
29
32
|
## Sources and credits
|
|
30
33
|
|
|
31
34
|
See [the packaged source and license index](./THIRD-PARTY-NOTICES.md) and
|
package/dist/index.cjs
CHANGED
|
@@ -136,6 +136,8 @@ __export(index_exports, {
|
|
|
136
136
|
octPack: () => octPack,
|
|
137
137
|
octPackFloat: () => octPackFloat,
|
|
138
138
|
octUnpack: () => octUnpack,
|
|
139
|
+
projectBounds: () => projectBounds,
|
|
140
|
+
projectTextureCoordinates: () => projectTextureCoordinates,
|
|
139
141
|
qualifySurfaceTransition: () => qualifySurfaceTransition,
|
|
140
142
|
sampleCurveAdaptive: () => sampleCurveAdaptive,
|
|
141
143
|
spheresIntersect: () => spheresIntersect,
|
|
@@ -7213,4 +7215,113 @@ function quadraticMinimum(value) {
|
|
|
7213
7215
|
throw new RangeError("Nonfinite surface orientation");
|
|
7214
7216
|
return result;
|
|
7215
7217
|
}
|
|
7218
|
+
|
|
7219
|
+
// dist/utils/project-bounds.js
|
|
7220
|
+
function projectBounds(sourceBounds, options) {
|
|
7221
|
+
const [minimum, maximum] = sourceBounds;
|
|
7222
|
+
const size = minimum.length;
|
|
7223
|
+
const { transform, targetSize = size, subdivisions = 8, maxSamples = 262144, lipschitz } = options;
|
|
7224
|
+
if (size !== 2 && size !== 3 || maximum.length !== size || targetSize !== 2 && targetSize !== 3) {
|
|
7225
|
+
throw new RangeError("Bounds and target dimension must be 2 or 3");
|
|
7226
|
+
}
|
|
7227
|
+
if (!Number.isSafeInteger(subdivisions) || subdivisions < 1 || !Number.isSafeInteger(maxSamples) || maxSamples < 1) {
|
|
7228
|
+
throw new RangeError("Subdivision and sample budgets must be positive safe integers");
|
|
7229
|
+
}
|
|
7230
|
+
if (lipschitz && (lipschitz.length !== targetSize || !Array.from(lipschitz).every((value) => Number.isFinite(value) && value >= 0))) {
|
|
7231
|
+
throw new RangeError("Lipschitz constants must be finite, nonnegative and match target size");
|
|
7232
|
+
}
|
|
7233
|
+
const widths = [];
|
|
7234
|
+
const counts = [];
|
|
7235
|
+
let count = 1;
|
|
7236
|
+
for (let axis = 0; axis < size; axis++) {
|
|
7237
|
+
const width = maximum[axis] - minimum[axis];
|
|
7238
|
+
if (!Number.isFinite(minimum[axis]) || !Number.isFinite(maximum[axis]) || !Number.isFinite(width) || width < 0) {
|
|
7239
|
+
throw new RangeError("Source bounds must have finite ordered coordinates and extents");
|
|
7240
|
+
}
|
|
7241
|
+
widths.push(width);
|
|
7242
|
+
counts.push(width === 0 ? 1 : subdivisions + 1);
|
|
7243
|
+
count *= counts[axis];
|
|
7244
|
+
if (!Number.isSafeInteger(count) || count > maxSamples) {
|
|
7245
|
+
throw new RangeError("Projected bounds exceed the sample budget");
|
|
7246
|
+
}
|
|
7247
|
+
}
|
|
7248
|
+
const lower = new Array(targetSize).fill(Infinity);
|
|
7249
|
+
const upper = new Array(targetSize).fill(-Infinity);
|
|
7250
|
+
for (let index = 0; index < count; index++) {
|
|
7251
|
+
let remaining = index;
|
|
7252
|
+
const source = [];
|
|
7253
|
+
for (let axis = 0; axis < size; axis++) {
|
|
7254
|
+
const step = remaining % counts[axis];
|
|
7255
|
+
remaining = Math.floor(remaining / counts[axis]);
|
|
7256
|
+
source.push(step === 0 ? minimum[axis] : step === subdivisions ? maximum[axis] : minimum[axis] + widths[axis] * (step / subdivisions));
|
|
7257
|
+
}
|
|
7258
|
+
const projected = transform(source);
|
|
7259
|
+
if (!projected || projected.length < targetSize) {
|
|
7260
|
+
return { status: "invalid", bounds: null, sampleCount: index + 1 };
|
|
7261
|
+
}
|
|
7262
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
7263
|
+
if (!Number.isFinite(projected[axis]))
|
|
7264
|
+
return { status: "invalid", bounds: null, sampleCount: index + 1 };
|
|
7265
|
+
lower[axis] = Math.min(lower[axis], projected[axis]);
|
|
7266
|
+
upper[axis] = Math.max(upper[axis], projected[axis]);
|
|
7267
|
+
}
|
|
7268
|
+
}
|
|
7269
|
+
if (lipschitz) {
|
|
7270
|
+
const radius2 = Math.hypot(...widths.map((width, axis) => width / subdivisions / 2 + 4 * Number.EPSILON * Math.max(Math.abs(minimum[axis]), Math.abs(maximum[axis]))));
|
|
7271
|
+
for (let axis = 0; axis < targetSize; axis++) {
|
|
7272
|
+
const displacement = lipschitz[axis] * radius2;
|
|
7273
|
+
const roundoff = 8 * Number.EPSILON * Math.max(1, Math.abs(lower[axis]), Math.abs(upper[axis]), displacement);
|
|
7274
|
+
lower[axis] -= displacement + roundoff;
|
|
7275
|
+
upper[axis] += displacement + roundoff;
|
|
7276
|
+
if (!Number.isFinite(lower[axis]) || !Number.isFinite(upper[axis])) {
|
|
7277
|
+
return { status: "invalid", bounds: null, sampleCount: count };
|
|
7278
|
+
}
|
|
7279
|
+
}
|
|
7280
|
+
}
|
|
7281
|
+
return {
|
|
7282
|
+
status: lipschitz ? "conservative" : "sampled",
|
|
7283
|
+
bounds: [lower, upper],
|
|
7284
|
+
sampleCount: count
|
|
7285
|
+
};
|
|
7286
|
+
}
|
|
7287
|
+
|
|
7288
|
+
// dist/utils/project-texture-coordinates.js
|
|
7289
|
+
function projectTextureCoordinates(positions, options) {
|
|
7290
|
+
const { transform, bounds, size = 3, origin = "top-left" } = options;
|
|
7291
|
+
if (size !== 2 && size !== 3)
|
|
7292
|
+
throw new RangeError("Source size must be 2 or 3");
|
|
7293
|
+
if (!Number.isSafeInteger(positions.length) || positions.length < 0 || positions.length % size) {
|
|
7294
|
+
throw new RangeError("Positions must contain complete packed vertices");
|
|
7295
|
+
}
|
|
7296
|
+
if (origin !== "top-left" && origin !== "bottom-left") {
|
|
7297
|
+
throw new RangeError("Invalid texture origin");
|
|
7298
|
+
}
|
|
7299
|
+
if (bounds.length !== 4 || !bounds.every(Number.isFinite)) {
|
|
7300
|
+
throw new RangeError("Image bounds must contain four finite values");
|
|
7301
|
+
}
|
|
7302
|
+
const [left, bottom, right, top] = bounds;
|
|
7303
|
+
const width = right - left;
|
|
7304
|
+
const height = top - bottom;
|
|
7305
|
+
if (!(width > 0) || !(height > 0) || !Number.isFinite(width) || !Number.isFinite(height)) {
|
|
7306
|
+
throw new RangeError("Image bounds must have finite positive extents");
|
|
7307
|
+
}
|
|
7308
|
+
const count = positions.length / size;
|
|
7309
|
+
const result = new Float64Array(count * 2);
|
|
7310
|
+
for (let index = 0; index < count; index++) {
|
|
7311
|
+
const source = Array.from({ length: size }, (_, axis) => positions[index * size + axis]);
|
|
7312
|
+
if (!source.every(Number.isFinite))
|
|
7313
|
+
throw new RangeError(`Invalid source vertex ${index}`);
|
|
7314
|
+
const projected = transform(source);
|
|
7315
|
+
if (!projected || projected.length < 2 || !Number.isFinite(projected[0]) || !Number.isFinite(projected[1])) {
|
|
7316
|
+
throw new RangeError(`Invalid projected vertex ${index}`);
|
|
7317
|
+
}
|
|
7318
|
+
const u = (projected[0] - left) / width;
|
|
7319
|
+
const v = origin === "top-left" ? (top - projected[1]) / height : (projected[1] - bottom) / height;
|
|
7320
|
+
if (!Number.isFinite(u) || !Number.isFinite(v))
|
|
7321
|
+
throw new RangeError(`Invalid UV at vertex ${index}`);
|
|
7322
|
+
result[index * 2] = u;
|
|
7323
|
+
result[index * 2 + 1] = v;
|
|
7324
|
+
}
|
|
7325
|
+
return result;
|
|
7326
|
+
}
|
|
7216
7327
|
//# sourceMappingURL=index.cjs.map
|