1.0.0 • Published 4 months ago

capdim v1.0.0

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
4 months ago

capdim

capdim caps an N-dimensional array to a maximum total volume (the product of its dimensions) while preserving proportions. It's minimal, atomic, and high performance.

Details

  • Works with any number of dimensions (e.g., 2D, 3D, 4D etc.).
  • Caps total volume without distorting proportions.
  • Pure & atomic function, suitable for composable utility pipelines.

Install

npm install capdim

Usage

import capDim from 'capdim';

console.log(capDim([1920, 1080], 1_000_000));
// [1333.3333333333333, 750]

🔧 API

capDim(dims: number[], maxVolume: number): number[]

Caps the input dimensions so that their total product does not exceed maxVolume.

  • dims – Array of dimensions (e.g., [width, height, depth]).
  • maxVolume – The maximum allowed product of dimensions.
  • Returns: The new scaled-down dimensions (or the original if already within bounds).

Example Use Cases

  • Image Processing – Prevent excessive pixel count while keeping aspect ratio.
  • 3D Modeling – Ensure objects stay within a total volume constraint.
  • Physics Simulations – Rescale multi-dimensional datasets.
  • Grid/Matrix Operations – Adjust data structures without exceeding capacity.

Related Packages

These links might be suffixed with "-node" in the future if conflicts arise.

Links

Development Homepage

https://github.com/alexstevovich/capdim

This link might be suffixed with "-node" in the future if conflicts arise.

License

Licensed under the Apache License 2.0.