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
RectPack.hpp
Go to the documentation of this file.
1
7
8#ifndef GALAXY_MATH_RECTPACK_HPP_
9#define GALAXY_MATH_RECTPACK_HPP_
10
11#include <optional>
12#include <vector>
13
14#include <SFML/Graphics/Rect.hpp>
15
16namespace galaxy
17{
18 namespace math
19 {
23 class RectPack final
24 {
25 public:
29 RectPack() noexcept;
30
34 ~RectPack() noexcept;
35
44 void init(const int width, const int height) noexcept;
45
55 [[nodiscard]]
56 std::optional<sf::IntRect> pack(const int width, const int height) noexcept;
57
61 void clear() noexcept;
62
68 [[nodiscard]]
69 int get_width() const noexcept;
70
76 [[nodiscard]]
77 int get_height() const noexcept;
78
84 [[nodiscard]]
85 const std::vector<sf::IntRect>& get_free_space() const noexcept;
86
87 private:
92
97
101 std::vector<sf::IntRect> m_free_rects;
102 };
103 } // namespace math
104} // namespace galaxy
105
106#endif
Rectangle 2D bin packing class.
Definition RectPack.hpp:24
void init(const int width, const int height) noexcept
Set starting width and height of rectangle.
Definition RectPack.cpp:25
std::optional< sf::IntRect > pack(const int width, const int height) noexcept
Pack a rectangle into the master rectangle.
Definition RectPack.cpp:33
int get_width() const noexcept
Get total width.
Definition RectPack.cpp:96
int m_width
The starting width of the rectangle.
Definition RectPack.hpp:91
~RectPack() noexcept
Destructor.
Definition RectPack.cpp:20
void clear() noexcept
Clear all data.
Definition RectPack.cpp:90
std::vector< sf::IntRect > m_free_rects
Free space in master rectangle.
Definition RectPack.hpp:101
int m_height
The starting width of the rectangle.
Definition RectPack.hpp:96
RectPack() noexcept
Constructor.
Definition RectPack.cpp:14
const std::vector< sf::IntRect > & get_free_space() const noexcept
Get free rectangles.
Definition RectPack.cpp:106
int get_height() const noexcept
Get total height.
Definition RectPack.cpp:101
Timer.hpp galaxy.
Definition Async.hpp:17