SA_Maths
Sapphire Suite's C++ Maths Library
Loading...
Searching...
No Matches
AABB2D.hpp
Go to the documentation of this file.
1// Copyright (c) 2023 Sapphire's Suite. All Rights Reserved.
2
3#pragma once
4
5#ifndef SAPPHIRE_MATHS_AABB2D_GUARD
6#define SAPPHIRE_MATHS_AABB2D_GUARD
7
9
20namespace SA
21{
22 template <typename T>
23 struct AABB3D;
24
30 template <typename T>
31 struct AABB2D
32 {
35
38
39
40//{ Constructors
41
43 AABB2D() = default;
44
51 AABB2D(const Vec2<T>& _min, const Vec2<T>& _max);
52
59 AABB2D(const AABB2D& _first, const AABB2D& _second);
60
66 AABB2D(const AABB3D<T>& _aabb3D) noexcept;
67
68//}
69
70
71//{ Equals
72
78 bool IsValid() const noexcept;
79
80
89 constexpr bool Equals(const AABB2D& _other, T _epsilon = std::numeric_limits<T>::epsilon()) const noexcept;
90
91
99 constexpr bool operator==(const AABB2D& _rhs) const noexcept;
100
108 constexpr bool operator!=(const AABB2D& _rhs) const noexcept;
109
110//}
111
112
113//{ Collisions
114
122 bool IsCollidingX(const AABB2D& _other) const;
123
131 bool IsCollidingY(const AABB2D& _other) const;
132
140 bool IsColliding(const AABB2D& _other) const;
141
142//}
143
144
145//{ Geometry
146
152 float Width() const;
153
159 float Height() const;
160
166 Vec2<T> Center() const;
167
173 float Area() const;
174
175//}
176
185 static AABB2D Merge(const AABB2D& _first, const AABB2D& _second);
186
187 };
188
189
190#if SA_LOGGER_IMPL
191
203 template <typename T>
204 std::string ToString(const AABB2D<T>& _aabb);
205
206#endif
207
208
209//{ Aliases
210
213
216
217//}
218
219}
220
221
224#include <SA/Maths/Geometry/AABB2D.inl>
225
226#endif // GUARD
Vector 2 type implementation.
AABB 2D Sapphire's class.
Definition AABB2D.hpp:32
AABB2D(const AABB3D< T > &_aabb3D) noexcept
Constructor from AABB3D.
bool IsColliding(const AABB2D &_other) const
Perform collision test on every axis.
Vec2< T > max
Max box component.
Definition AABB2D.hpp:37
bool IsCollidingY(const AABB2D &_other) const
Perform collision test on Y axis only.
float Area() const
Compute area from min and max.
Vec2< T > min
Min box component.
Definition AABB2D.hpp:34
bool IsValid() const noexcept
Wether this AABB has valid values (ie min < max);.
AABB2D(const AABB2D &_first, const AABB2D &_second)
Merge 2 AABB box.
bool IsCollidingX(const AABB2D &_other) const
Perform collision test on X axis only.
AABB2D(const Vec2< T > &_min, const Vec2< T > &_max)
Value constructor from min and max.
float Height() const
Compute height (Y axis) from min and max.
constexpr bool Equals(const AABB2D &_other, T _epsilon=std::numeric_limits< T >::epsilon()) const noexcept
Compare 2 AABB2D.
Vec2< T > Center() const
Compute center from min and max.
static AABB2D Merge(const AABB2D &_first, const AABB2D &_second)
Merge 2 AABB2D box to create a big AABB2D which wrap both boxes.
AABB2D()=default
Default constructor.
float Width() const
Compute width (X axis) from min and max.
AABB 3D Sapphire's class.
Definition AABB3D.hpp:31
Vector 2 Sapphire's class.
Definition Vector2.hpp:41