calc_small_box {rectpacker} | R Documentation |
Find the dimensions of a small box to store all the given rectangles
Description
This is a brute force search with a simple heuristic. Is not guaranteed to find the box with the minimum area, but simply a box that snugly fits the rectangles without too much wasted space.
Usage
calc_small_box(
rect_widths,
rect_heights,
aspect_ratios = c(1.61803, 1/1.61803),
verbosity = 0L
)
Arguments
rect_widths , rect_heights |
widths and heights of the rectangles to pack. |
aspect_ratios |
Vector of box aspect ratios to be tested. Aspect ratio
is defined here as |
verbosity |
Level of debugging output. Default: 0 (no output) |
Value
List with 2 elements: width
and height
of a small box
which fits all the rectangles.
Examples
# Find a minimal box to fit 10 random rectangles.
# Search for boxes with aspect ratios in seq(0.5, 2, length.out = 20)
set.seed(2)
N <- 10
rect_widths <- sample(N)
rect_heights <- sample(N)
box <- calc_small_box(rect_widths, rect_heights,
aspect_ratios = seq(0.5, 2, length.out = 20))
box
rects <- pack_rects(box$width, box$height, rect_widths, rect_heights)
all(rects$packed)
[Package rectpacker version 1.0.0 Index]