2 published: 2026-06-10 11:31:00
3 updated: 2026-06-10 11:31:00
4 topics: flow-rbp, Rect bin packing, Rust
5 title: flow-rbp: A library for packing rectangles into two-dimensional finite bins
6 snippet: flow-rbp is a library for packing rectangles into two-dimensional finite bins using different heuristic methods for placement.
10 [flow-rbp](https://luflow.net/git-repos/flow-rbp.git) is a library for packing
11 rectangles into two-dimensional finite bins using different heuristic methods
14 The two-dimensional rectangle bin packing is a classical problem in
15 combinatorial optimization. In this problem, one is given a sequence of
16 rectangles `(R1, R2, ... Rn), Ri = (wi, hi)` and the task is to find a packing
17 of these items into a minimum number of bins of size `(W, H)`. No two
18 rectangles may intersect or be contained inside one another. This library uses
19 an algorithm sometimes referred as `The Maximal Rectangles ALgorithm`. This
20 algorithm stores a list of free rectangles that represents the free area of the
23 [flow-texpack](https://luflow.net/git-repos/flow-texpack.git) is a program that
24 uses [flow-rbp](https://luflow.net/git-repos/flow-rbp.git) to generate texture
29 Install `Rust` from your package manager or by downloading from here:
30 [https://rust-lang.org/](https://rust-lang.org/).
34 Install `git` from your package manager or by downloading from here:
35 [https://git-scm.com/install](https://git-scm.com/install). The [git
36 repository](https://luflow.net/git-repos/flow-rbp.git) can also be browsed
39 Clone the `git` repository:
42 git clone https://luflow.net/git/flow-rbp.git
47 Add this to your `Cargo.toml`:
51 flow-rbp = { git = "https://luflow.net/git/flow-rbp.git", tag = "v0.1.0" }
57 use flow_rbp::FreeRectHeuristic;
58 use flow_rbp::RectsBinPack;
60 // create a new bin of size 32x32 which allows rotation:
61 let mut rbp = RectsBinPack::new(32, 32, true).unwrap();
63 // make sure occupancy is zero:
64 assert_eq!(rbp.get_occupancy(), 0.0);
66 // add a few rects that should fit:
67 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
68 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
69 assert_eq!(rbp.get_occupancy(), 0.5);
70 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
71 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
72 assert_eq!(rbp.get_occupancy(), 1.0);
74 // this rect will not fit and therefore returns None:
75 assert_eq!(rbp.insert(1, 1, FreeRectHeuristic::BottomLeft).is_none(), true);
81 [flow-rbp](https://luflow.net/git-repos/flow-rbp.git) is licensed under the
82 zlib license. This license allows you to use `flow-rbp` freely in any software.