Ion
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ion::text::BinPacker Class Reference

This class implements generic 2D bin-packing using a modified version of the Skyline Bottom-Left algorithm available at: http://clb.demon.fi/files/RectangleBinPack. More...

#include "binpacker.h"

Classes

struct  Rectangle
 Structure representing a rectangle to pack into the bin. More...
 

Public Member Functions

 BinPacker ()
 BinPacker functions. More...
 
 ~BinPacker ()
 
 BinPacker (const BinPacker &from)
 Allow BinPacker to be copied. More...
 
BinPackeroperator= (const BinPacker &from)
 
void AddRectangle (uint64 id, const math::Vector2ui &size)
 Adds a rectangle of the given size to pack into the bin. More...
 
bool Pack (const math::Vector2ui &bin_size)
 Tries to pack all of the rectangles into a bin of the given size. More...
 
const std::vector< Rectangle > & GetRectangles () const
 Returns the vector of rectangles (including positions) resulting from the last call to Pack(). More...
 

Detailed Description

This class implements generic 2D bin-packing using a modified version of the Skyline Bottom-Left algorithm available at: http://clb.demon.fi/files/RectangleBinPack.

Modifications include:

  • Not allowing rotations of rectangles.

Definition at line 36 of file binpacker.h.

Constructor & Destructor Documentation

ion::text::BinPacker::BinPacker ( )

BinPacker functions.

Definition at line 201 of file binpacker.cc.

ion::text::BinPacker::~BinPacker ( )

Definition at line 205 of file binpacker.cc.

ion::text::BinPacker::BinPacker ( const BinPacker from)
explicit

Allow BinPacker to be copied.

Definition at line 203 of file binpacker.cc.

Member Function Documentation

void ion::text::BinPacker::AddRectangle ( uint64  id,
const math::Vector2ui &  size 
)
inline

Adds a rectangle of the given size to pack into the bin.

It is up to the client to manage IDs responsibly; duplicates are not detected here.

Definition at line 60 of file binpacker.h.

const std::vector<Rectangle>& ion::text::BinPacker::GetRectangles ( ) const
inline

Returns the vector of rectangles (including positions) resulting from the last call to Pack().

If Pack() returned false, this vector will not be useful.

Definition at line 72 of file binpacker.h.

BinPacker & ion::text::BinPacker::operator= ( const BinPacker from)

Definition at line 207 of file binpacker.cc.

bool ion::text::BinPacker::Pack ( const math::Vector2ui &  bin_size)

Tries to pack all of the rectangles into a bin of the given size.

Returns true if they were able to fit. This can be called incrementally; only the rectangles added since the last call to Pack() will be processed.

Definition at line 215 of file binpacker.cc.


The documentation for this class was generated from the following files: