Learn R Programming

rectpacker (version 1.0.0)

pack_rects: Pack rectangles into a box using the skyline algorithm

Description

This implementation accepts only integer valued sizes and coordinates.

Usage

pack_rects(box_width, box_height, rect_widths, rect_heights)

Value

data.frame of packing information

idx

Integer index of rectangle in the input

w,h

Integer dimensions of each rectangle

packed

Logical: Was this rectangle packed into the box?

x,y

Integer coordinates of packing position of bottom-left of rectangle

Arguments

box_width, box_height

dimensions of the box into which the rectangles will be packed. Integer values.

rect_widths, rect_heights

widths and heights of the rectangles to pack.

Examples

Run this code
# Pack 10 rectangles into a 25x25 box
# Note: All rectangles in the results have 'packed=TRUE' which
# means they all fit into the box
set.seed(1)
N <- 10
rect_widths  <- sample(N)
rect_heights <- sample(N)
pack_rects(box_width = 25, box_height = 25, rect_widths, rect_heights)

Run the code above in your browser using DataLab