3 `flow-rbp` is a library for packing rectangles into two-dimensional finite bins
4 using different heuristic methods for placement.
6 The two-dimensional rectangle bin packing is a classical problem in
7 combinatorial optimization. In this problem, one is given a sequence of
8 rectangles `(R1, R2, ... Rn), Ri = (wi, hi)` and the task is to find a packing
9 of these items into a minimum number of bins of size `(W, H)`. No two
10 rectangles may intersect or be contained inside one another. This library uses
11 an algorithm sometimes referred as `The Maximal Rectangles ALgorithm`. This
12 algorithm stores a list of free rectangles that represents the free area of the
17 Add this to your `Cargo.toml`:
21 flow-rbp = { git = "https://luflow.net/git/flow-rbp.git", tag = "v0.1.0" }
27 use flow_rbp::FreeRectHeuristic;
28 use flow_rbp::RectsBinPack;
30 // create a new bin of size 32x32 which allows rotation:
31 let mut rbp = RectsBinPack::new(32, 32, true).unwrap();
33 // make sure occupancy is zero:
34 assert_eq!(rbp.get_occupancy(), 0.0);
36 // add a few rects that should fit:
37 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
38 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
39 assert_eq!(rbp.get_occupancy(), 0.5);
40 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
41 assert_eq!(rbp.insert(16, 16, FreeRectHeuristic::BottomLeft).is_some(), true);
42 assert_eq!(rbp.get_occupancy(), 1.0);
44 // this rect will not fit and therefore returns None:
45 assert_eq!(rbp.insert(1, 1, FreeRectHeuristic::BottomLeft).is_none(), true);
51 See the file 'LICENSE' for license information.