{"id":26410508,"url":"https://github.com/alexstevovich/fitdim","last_synced_at":"2026-05-17T13:07:44.313Z","repository":{"id":282505900,"uuid":"948205586","full_name":"alexstevovich/fitdim","owner":"alexstevovich","description":"[Node.js] Scales an N-dimensional array to perfectly fit within a bounding box, maintaining proportions.","archived":false,"fork":false,"pushed_at":"2025-03-13T23:35:32.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-15T03:35:57.923Z","etag":null,"topics":["atomic","bounding-box","dimensions","geometry","n-dimensions","nodejs","pure"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/alexstevovich.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-03-13T23:34:53.000Z","updated_at":"2025-03-13T23:36:34.000Z","dependencies_parsed_at":"2025-03-15T03:36:00.145Z","dependency_job_id":"a7482261-35be-4dcf-9f22-cf0897785c86","html_url":"https://github.com/alexstevovich/fitdim","commit_stats":null,"previous_names":["alexstevovich/fitdim"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstevovich%2Ffitdim","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstevovich%2Ffitdim/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstevovich%2Ffitdim/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alexstevovich%2Ffitdim/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alexstevovich","download_url":"https://codeload.github.com/alexstevovich/fitdim/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244102849,"owners_count":20398386,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["atomic","bounding-box","dimensions","geometry","n-dimensions","nodejs","pure"],"created_at":"2025-03-17T20:18:15.075Z","updated_at":"2026-05-17T13:07:39.291Z","avatar_url":"https://github.com/alexstevovich.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# fitdim\n\n**`fitDim`** scales an **N-dimensional** array to **perfectly fit** within a bounding box, maintaining proportions. It **supports both upscaling and downscaling** to ensure the best possible fit.\n\n## Details\n\n- Works with **any number of dimensions** (2D, 3D, 4D, etc.).\n- **Fits perfectly inside** a given bounding box.\n- **Maintains proportions** without distortion.\n- Supports **both upscaling and downscaling**.\n- **Pure \u0026 atomic function**, ideal for composable utility pipelines.\n\n## Install\n\n`npm install fitdim`\n\n## Usage\n\n```js\nimport { fitDim } from 'fitdim';\n\nconst dims = [1920, 1080];\nconst maxDims = [1280, 800];\n\n// ✅ Scales down to fit perfectly inside [1280, 800]\nconsole.log(fitDim(dims, maxDims));\n// [1280, 720]\n\n// ✅ Scales up to fit inside [600, 800, 1000]\nconsole.log(fitDim([300, 400, 500], [600, 800, 1000]));\n// [600, 800, 1000]\n\n// ✅ Slight upscaling to fit inside [400, 500, 600]\nconsole.log(fitDim([300, 400, 500], [400, 500, 600]));\n// [400, 500, 600]\n\n// ✅ No change (already fits)\nconsole.log(fitDim([300, 400, 500], [300, 400, 500]));\n// [300, 400, 500]\n```\n\n## API\n\n### `fitDim(dims: number[], maxDims: number[]): number[]`\n\n**Scales an N-dimensional array** so that it **fits perfectly within** the given bounding box (`maxDims`), while maintaining proportions.\n\n- **`dims`** – The original array of dimensions (e.g., `[width, height, depth]`).\n- **`maxDims`** – The bounding box (maximum allowed dimensions).\n- **Returns:** A **new array** with adjusted dimensions.\n\n#### ⚠️ Errors\n\n- Throws an error if `dims.length` and `maxDims.length` **do not match**.\n\n## Cheatsheet Patterns\n\nThese patterns help apply common transformations using `fitDim`!\n\n```js\nimport fitDim from 'fitdim';\n\n// 🔢 Round the result (Ceil, Floor, Nearest)\nconst dims = fitDim([1920, 1080], [1280, 800]);\nconst roundedDims = dims.map(Math.round);\n// or use Math.floor / Math.ceil\n\n// 🔍 Check if a resize occurred\nconst original = [1920, 1080];\nconst maxDims = [1280, 800];\nconst fitted = fitDim(original, maxDims);\n\nconst wasResized = !original.every((dim, i) =\u003e dim === fitted[i]);\nconsole.log(wasResized); // true\n```\n\n## Example Use Cases\n\n- **Image Processing** – Prevent excessive pixel count while keeping aspect ratio.\n- **3D Modeling** – Ensure objects stay within a total volume constraint.\n- **Physics Simulations** – Rescale multi-dimensional datasets.\n- **Grid/Matrix Operations** – Adjust data structures without exceeding capacity.\n\n## Related Packages\n\n- [https://github.com/alexstevovich/capdim](https://github.com/alexstevovich/capdim) – Caps total volume while keeping proportions.\n- [https://github.com/alexstevovich/normalizedim](https://github.com/alexstevovich/normalizedim) – Normalizes one axis while keeping proportions.\n- [https://github.com/alexstevovich/percentdim](https://github.com/alexstevovich/percentdim) – Tells you the percent difference between two N-dimensional areas.\n\n\u003csub\u003e_These link might be suffixed with \"-node\" in the future if conflicts arise._\u003c/sub\u003e\n\n## Links\n\n### Development Homepage\n\n[https://github.com/alexstevovich/fitdim](https://github.com/alexstevovich/fitdim)\n\n\u003csub\u003e_This link might be suffixed with \"-node\" in the future if conflicts arise._\u003c/sub\u003e\n\n## License\n\nLicensed under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexstevovich%2Ffitdim","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falexstevovich%2Ffitdim","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falexstevovich%2Ffitdim/lists"}