Initial commit.

Signed-off-by: Andreas Widen <aw@luflow.net>
This commit is contained in:
Andreas Widen 2026-07-27 17:38:52 +02:00
commit d13d74df42
Signed by: hfsoulz
GPG key ID: 5B85F9B5F576A667
10 changed files with 1278 additions and 0 deletions

51
README.md Normal file
View file

@ -0,0 +1,51 @@
# flow-rbp
`flow-rbp` is a library for packing rectangles into two-dimensional finite bins
using different heuristic methods for placement.
The two-dimensional rectangle bin packing is a classical problem in
combinatorial optimization. In this problem, one is given a sequence of
rectangles `(R1, R2, ... Rn), Ri = (wi, hi)` and the task is to find a packing
of these items into a minimum number of bins of size `(W, H)`. No two
rectangles may intersect or be contained inside one another. This library uses
an algorithm sometimes referred as `The Maximal Rectangles ALgorithm`. This
algorithm stores a list of free rectangles that represents the free area of the
bin.
## Usage
Add this to your `Cargo.toml`:
```
[dependencies]
flow-rbp = { git = "https://luflow.net/git/hfsoulz/flow-rbp.git", tag = "v0.1.0" }
```
Then:
```rust
use flow_rbp::FreeRectHeuristic;
use flow_rbp::RectsBinPack;
// create a new bin of size 32x32 which allows rotation:
let mut rbp = RectsBinPack::new(32, 32, true).unwrap();
// make sure occupancy is zero:
assert_eq!(rbp.get_occupancy(), 0.0);
// add a few rects that should fit:
assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
assert_eq!(rbp.get_occupancy(), 0.5);
assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
assert_eq!(rbp.get_occupancy(), 1.0);
// this rect will not fit and therefore returns None:
assert_eq!(rbp.insert(1, 1, FreeRectHeuristic::BottomLeft).is_none(), true);
```
## LICENSE
See the file 'LICENSE' for license information.