A library for packing rectangles into two-dimensional finite bins written in Rust. https://luflow.net/
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
Andreas Widen 3f38753922
All checks were successful
/ Rust CI Check/Build/Test (push) Successful in 10s
/ Create Forgejo Release (push) Successful in 5m53s
build: added exclude folder
Signed-off-by: Andreas Widen <aw@luflow.net>
2026-09-05 20:04:24 +02:00
.forgejo/workflows ci: updated github issue/pull request templates 2026-09-05 19:31:56 +02:00
.github ci: updated github issue/pull request templates 2026-09-05 19:31:56 +02:00
src docs: updated docs 2026-08-13 15:00:52 +02:00
tests ci: added clippy to ci and use hash for actions 2026-08-13 14:05:25 +02:00
.gitignore Initial commit. 2026-08-11 20:04:21 +02:00
AUTHORS Initial commit. 2026-08-11 20:04:21 +02:00
Cargo.lock build: bump version to 0.2.8 2026-09-05 20:01:31 +02:00
Cargo.toml build: added exclude folder 2026-09-05 20:04:24 +02:00
cliff.toml Initial commit. 2026-08-11 20:04:21 +02:00
CODE_OF_CONDUCT.md chore: added CODE_OF_CONDUCT.md 2026-08-18 14:17:13 +02:00
CONTRIBUTING.md chore: updated CONTRIBUTING.md 2026-09-05 19:58:09 +02:00
LICENSE chore: remove project desc in LICENSE 2026-08-12 14:08:44 +02:00
README.md chore: updated README.md 2026-08-18 15:46:55 +02:00
rustfmt.toml chore: added rustfmt.toml 2026-08-29 13:21:53 +02:00
SECURITY.md chore: added SECURITY.md 2026-08-18 14:20:15 +02:00

flow-rectpack

flow-rectpack 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 flow-rectpack to your Cargo.toml:

cargo add flow-rectpack

Then:

use flow_rectpack::FreeRectHeuristic;
use flow_rectpack::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!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some());
assert!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some());
assert!(rbp.get_occupancy(), 0.5);
assert!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some());
assert!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some());
assert!(rbp.get_occupancy(), 1.0);

// this rect will not fit and therefore returns None:
assert!(rbp.insert(1, 1, FreeRectHeuristic::BottomLeft).is_none());

LICENSE

See the file 'LICENSE' for license information.