4 releases
0.1.3 | Nov 10, 2023 |
---|---|
0.1.2 | Nov 9, 2023 |
0.1.1 | Nov 9, 2023 |
0.1.0 | Nov 9, 2023 |
#210 in WebAssembly
30 downloads per month
56KB
1.5K
SLoC
rust-rectangle-dividing
A library of rectangle dividing written in Rust. It can be compiled to WebAssembly. So you can use it in JavaScript.
Motivation
I want to divide a rectangle into smaller rectangles by given conditions (weights, aspect ratio, etc.).
Mainly, I want to use this for generating a map for my react-playground
- https://github.com/kitsuyui/react-playground
- https://react-playground.docs.kitsuyui.com/storybook/?path=/docs/base-treemap-introduction--docs
Usage
import dividing from "rust-rectangle-dividing";
const rect = { x: 0, y: 0, w: 900, h: 800 };
const weights = [4, 4, 1, 1, 1, 1];
const divided = dividing.dividing(rect, weights, true, 1.5, true);
for (const d of divided) {
console.log(d);
}
Result
{ x: 0, y: 0, w: 600, h: 400 }
{ x: 0, y: 400, w: 600, h: 400 }
{ x: 600, y: 600, w: 300, h: 200 }
{ x: 600, y: 400, w: 300, h: 200 }
{ x: 600, y: 200, w: 300, h: 200 }
{ x: 600, y: 0, w: 300, h: 200 }
dividing's arguments are
rect
: The rectangle to be dividedweights
: The weights of each rectangleisVertical
: The direction of the first divisionaspectRatio
: The aspect ratio of each rectangleboustrophedon
: The direction of the next division in the same level
License
MIT
Dependencies
~1.2–2.1MB
~40K SLoC