包详细信息

geom-center-and-normalize

vorg29MIT2.2.0

Center a simplicial complex geometry's positions in place and scale them to fill a defined bounding box.

geom, center, normalize, simplicial

自述文件

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-normalize

Usage

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, ...) or new Array([x, y, z], [x, y, z], ...))

  • options: { center: boolean, normalize: boolean, normalizedSize: number } – enable/disable centering/normalizing and control normalized scaling. center and normalize defaults to true. Scale defaults to 1.

Returns

  • positions: TypedArray | Array | Array<[x, y, z]> – The positions parameter array updated, centered at [0, 0, 0] and normalized to a bounding box of normalizedSize ([-halfScale, -halfScale, -halfScale] x [halfScale, halfScale, halfScale]).

License

MIT. See license file.

更新日志

Changelog

All notable changes to this project will be documented in this file. See commit-and-tag-version for commit guidelines.

2.2.0 (2024-04-16)

Features

  • rename scale to normalizedSize (8007608)

2.1.1 (2024-03-14)

2.1.0 (2024-03-14)

Bug Fixes

  • handle division by 0 for aabb size 0 (26f146c)

Features

  • add support for flat arrays (300c4ad)
  • make center and normalize options (0a051bb)
  • replace normalize option with scaling as boolean/number (fe23ff9)
  • separate normalize and scale parameters (56efcd3)

2.0.0 (2023-02-02)

Features

  • add support for typed array geometries and update positions in place (97ebbf1)

BREAKING CHANGES

  • use ESM