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 e6ab275a1c
All checks were successful
/ Rust CI Check/Build/Test (push) Successful in 13s
/ Create Forgejo Release (push) Successful in 6m45s
build: bump version to 0.2.5
Signed-off-by: Andreas Widen <aw@luflow.net>
2026-08-27 13:32:14 +02:00
.forgejo/workflows ci: updated forgejo/github ci.yaml 2026-08-15 15:44:54 +02:00
.github ci: made bug report issue template clearer 2026-08-21 08:13:01 +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.5 2026-08-27 13:32:14 +02:00
Cargo.toml build: bump version to 0.2.5 2026-08-27 13:32:14 +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: addded additional info to CONTRIBUTING.md 2026-08-27 13:30:32 +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
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.