galaxy 1.0.0
Real-Time C++23 Game Programming Framework. Built on data-driven design principles and agile software engineering.
Loading...
Searching...
No Matches
galaxy::RectPack Class Referencefinal

Rectangle 2D bin packing class. More...

#include <RectPack.hpp>

+ Collaboration diagram for galaxy::RectPack:

Public Member Functions

 RectPack () noexcept
 Constructor.
 
 ~RectPack () noexcept
 Destructor.
 
void init (const int width, const int height) noexcept
 Set starting width and height of rectangle.
 
std::optional< iRectpack (const int width, const int height)
 Pack a rectangle into the master rectangle.
 
void clear () noexcept
 Clear all data.
 
int get_width () const noexcept
 Get total width.
 
int get_height () const noexcept
 Get total height.
 
const std::vector< iRect > & get_free_space () const noexcept
 Get free rectangles.
 

Private Attributes

int m_width
 The starting width of the rectangle.
 
int m_height
 The starting width of the rectangle.
 
std::vector< iRectm_free_rects
 Free space in master rectangle.
 

Detailed Description

Rectangle 2D bin packing class.

Definition at line 21 of file RectPack.hpp.

Constructor & Destructor Documentation

◆ RectPack()

galaxy::RectPack::RectPack ( )
noexcept

Constructor.

Definition at line 12 of file RectPack.cpp.

◆ ~RectPack()

galaxy::RectPack::~RectPack ( )
noexcept

Destructor.

Definition at line 18 of file RectPack.cpp.

Member Function Documentation

◆ init()

void galaxy::RectPack::init ( const int width,
const int height )
noexcept

Set starting width and height of rectangle.

Generally should be a power of 2.

Parameters
widthWidth of the master rectangle.
heightHeight of the master rectangle.

Definition at line 23 of file RectPack.cpp.

+ Here is the caller graph for this function:

◆ pack()

std::optional< iRect > galaxy::RectPack::pack ( const int width,
const int height )
nodiscard

Pack a rectangle into the master rectangle.

Parameters
widthWidth of the rectangle to pack.
heightHeight of the rectangle to pack.
Returns
Returns the location of the packed rectangle on the master rectangle. Otherwise, returns a std::nullopt.

Definition at line 31 of file RectPack.cpp.

+ Here is the caller graph for this function:

◆ clear()

void galaxy::RectPack::clear ( )
noexcept

Clear all data.

Definition at line 90 of file RectPack.cpp.

+ Here is the caller graph for this function:

◆ get_width()

int galaxy::RectPack::get_width ( ) const
nodiscardnoexcept

Get total width.

Returns
Integer.

Definition at line 96 of file RectPack.cpp.

+ Here is the caller graph for this function:

◆ get_height()

int galaxy::RectPack::get_height ( ) const
nodiscardnoexcept

Get total height.

Returns
Integer.

Definition at line 101 of file RectPack.cpp.

+ Here is the caller graph for this function:

◆ get_free_space()

const std::vector< iRect > & galaxy::RectPack::get_free_space ( ) const
nodiscardnoexcept

Get free rectangles.

Returns
Const meta::vector.

Definition at line 106 of file RectPack.cpp.

+ Here is the caller graph for this function:

Member Data Documentation

◆ m_width

int galaxy::RectPack::m_width
private

The starting width of the rectangle.

Definition at line 89 of file RectPack.hpp.

◆ m_height

int galaxy::RectPack::m_height
private

The starting width of the rectangle.

Definition at line 94 of file RectPack.hpp.

◆ m_free_rects

std::vector<iRect> galaxy::RectPack::m_free_rects
private

Free space in master rectangle.

Definition at line 99 of file RectPack.hpp.


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