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::math::RectPack Class Referencefinal

Rectangle 2D bin packing class. More...

#include <RectPack.hpp>

+ Collaboration diagram for galaxy::math::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< sf::IntRect > pack (const int width, const int height) noexcept
 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< sf::IntRect > & 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< sf::IntRect > m_free_rects
 Free space in master rectangle.
 

Detailed Description

Rectangle 2D bin packing class.

Definition at line 23 of file RectPack.hpp.

Constructor & Destructor Documentation

◆ RectPack()

galaxy::math::RectPack::RectPack ( )
noexcept

Constructor.

Definition at line 14 of file RectPack.cpp.

◆ ~RectPack()

galaxy::math::RectPack::~RectPack ( )
noexcept

Destructor.

Definition at line 20 of file RectPack.cpp.

Member Function Documentation

◆ init()

void galaxy::math::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 25 of file RectPack.cpp.

+ Here is the caller graph for this function:

◆ pack()

std::optional< sf::IntRect > galaxy::math::RectPack::pack ( const int width,
const int height )
nodiscardnoexcept

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 33 of file RectPack.cpp.

+ Here is the caller graph for this function:

◆ clear()

void galaxy::math::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::math::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::math::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< sf::IntRect > & galaxy::math::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::math::RectPack::m_width
private

The starting width of the rectangle.

Definition at line 91 of file RectPack.hpp.

◆ m_height

int galaxy::math::RectPack::m_height
private

The starting width of the rectangle.

Definition at line 96 of file RectPack.hpp.

◆ m_free_rects

std::vector<sf::IntRect> galaxy::math::RectPack::m_free_rects
private

Free space in master rectangle.

Definition at line 101 of file RectPack.hpp.


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