geom-center-and-normalize
v2.3.0
Published
Center a simplicial complex geometry's positions in place and scale them to fill a defined bounding box.
Maintainers
Readme
geom-center-and-normalize
Center a simplicial complex geometry's positions in place and scale them to fill a defined bounding box.
Installation
npm install geom-center-and-normalizeUsage
import centerAndNormalize from "geom-center-and-normalize";
const positions = new Float32Array([
// p1 [x, y, z]
1, 1, 1,
// p2 [x, y, z]
2, 2, 2,
// p3 [x, y, z]
3, 5, 3,
]);
const normalizedPositions = centerAndNormalize(positions);
// => Float32Array(9) [
// -0.25, -0.5, -0.25,
// 0, -0.25, 0,
// 0.25, 0.5, 0.25,
// ]API
centerAndNormalize(positions, [options]): positions
Parameters
positions:
TypedArray | Array | Array<[x, y, z]>– simplicial complex geometry positions (eg.new Float32Array([x, y, z, x, y, z, ...])/new Array(x, y, z, x, y, z, ...)ornew Array([x, y, z], [x, y, z], ...))options:
objectcenter: boolean– move the bounding box center to[0, 0, 0]. Defaults totrue.normalize: boolean– scale positions uniformly so that the bounding box largest side isnormalizedSize. Defaults totrue.normalizedSize: number– size of the bounding box largest side when normalizing. Defaults to1.align: [x, y, z]– per axis position on the bounding box, from-1(min) through0(center) to1(max), placed at the anchor:[0, 0, 0]when centering, the original bounding box center otherwise. Eg.[0, -1, 0]aligns the bounding box min y to the anchor. Defaults to[0, 0, 0].
Returns
- positions:
TypedArray | Array | Array<[x, y, z]>– The positions parameter array updated in place, by default centered at[0, 0, 0]with its bounding box largest side normalized tonormalizedSize.
License
MIT. See license file.
