Migrate AABB2D implementation to it's cpp file
This commit is contained in:
@@ -64,7 +64,8 @@ add_library(J3ML SHARED ${J3ML_SRC}
|
||||
include/J3ML/Algorithm/DifferentialSolvers.h
|
||||
include/J3ML/Units.h
|
||||
src/J3ML/J3ML.cpp
|
||||
include/J3ML/LinearAlgebra/Matrix.h)
|
||||
include/J3ML/LinearAlgebra/Matrix.h
|
||||
src/J3ML/Geometry/AABB2D.cpp)
|
||||
set_target_properties(J3ML PROPERTIES LINKER_LANGUAGE CXX)
|
||||
|
||||
install(TARGETS ${PROJECT_NAME} DESTINATION lib/${PROJECT_NAME})
|
||||
|
@@ -17,90 +17,37 @@ namespace J3ML::Geometry
|
||||
minPoint(min), maxPoint(max)
|
||||
{}
|
||||
|
||||
float Width() const { return maxPoint.x - minPoint.x; }
|
||||
float Height() const { return maxPoint.y - minPoint.y; }
|
||||
float Width() const;
|
||||
float Height() const;
|
||||
|
||||
float DistanceSq(const Vector2& pt) const
|
||||
{
|
||||
Vector2 cp = pt.Clamp(minPoint, maxPoint);
|
||||
return cp.DistanceSq(pt);
|
||||
}
|
||||
float DistanceSq(const Vector2& pt) const;
|
||||
|
||||
void SetNegativeInfinity();
|
||||
|
||||
void Enclose(const Vector2& point)
|
||||
{
|
||||
minPoint = Vector2::Min(minPoint, point);
|
||||
maxPoint = Vector2::Max(maxPoint, point);
|
||||
}
|
||||
void Enclose(const Vector2& point);
|
||||
|
||||
bool Intersects(const AABB2D& rhs) const
|
||||
{
|
||||
return maxPoint.x >= rhs.minPoint.x &&
|
||||
maxPoint.y >= rhs.minPoint.y &&
|
||||
rhs.maxPoint.x >= minPoint.x &&
|
||||
rhs.maxPoint.y >= minPoint.y;
|
||||
}
|
||||
bool Intersects(const AABB2D& rhs) const;
|
||||
|
||||
bool Contains(const AABB2D& rhs) const
|
||||
{
|
||||
return rhs.minPoint.x >= minPoint.x && rhs.minPoint.y >= minPoint.y
|
||||
&& rhs.maxPoint.x <= maxPoint.x && rhs.maxPoint.y <= maxPoint.y;
|
||||
}
|
||||
bool Contains(const AABB2D& rhs) const;
|
||||
|
||||
bool Contains(const Vector2& pt) const
|
||||
{
|
||||
return pt.x >= minPoint.x && pt.y >= minPoint.y
|
||||
&& pt.x <= maxPoint.x && pt.y <= maxPoint.y;
|
||||
}
|
||||
bool Contains(const Vector2& pt) const;
|
||||
|
||||
bool Contains(int x, int y) const
|
||||
{
|
||||
return x >= minPoint.x && y >= minPoint.y
|
||||
&& x <= maxPoint.x && y <= maxPoint.y;
|
||||
}
|
||||
bool Contains(int x, int y) const;
|
||||
|
||||
bool IsDegenerate() const
|
||||
{
|
||||
return minPoint.x >= maxPoint.x || minPoint.y >= maxPoint.y;
|
||||
}
|
||||
bool IsDegenerate() const;
|
||||
|
||||
bool HasNegativeVolume() const
|
||||
{
|
||||
return maxPoint.x < minPoint.x || maxPoint.y < minPoint.y;
|
||||
}
|
||||
bool HasNegativeVolume() const;
|
||||
|
||||
bool IsFinite() const
|
||||
{
|
||||
return minPoint.IsFinite() && maxPoint.IsFinite() && minPoint.MinElement() > -1e5f && maxPoint.MaxElement() < 1e5f;
|
||||
}
|
||||
bool IsFinite() const;
|
||||
|
||||
Vector2 PosInside(const Vector2 &normalizedPos) const
|
||||
{
|
||||
return minPoint + normalizedPos.Mul(maxPoint - minPoint);
|
||||
}
|
||||
Vector2 PosInside(const Vector2 &normalizedPos) const;
|
||||
|
||||
Vector2 ToNormalizedLocalSpace(const Vector2 &pt) const
|
||||
{
|
||||
return (pt - minPoint).Div(maxPoint - minPoint);
|
||||
}
|
||||
Vector2 ToNormalizedLocalSpace(const Vector2 &pt) const;
|
||||
|
||||
|
||||
AABB2D operator+(const Vector2& pt) const
|
||||
{
|
||||
AABB2D a;
|
||||
a.minPoint = minPoint + pt;
|
||||
a.maxPoint = maxPoint + pt;
|
||||
return a;
|
||||
}
|
||||
AABB2D operator+(const Vector2& pt) const;
|
||||
|
||||
AABB2D operator-(const Vector2& pt) const
|
||||
{
|
||||
AABB2D a;
|
||||
a.minPoint = minPoint - pt;
|
||||
a.maxPoint = maxPoint - pt;
|
||||
return a;
|
||||
}
|
||||
AABB2D operator-(const Vector2& pt) const;
|
||||
|
||||
};
|
||||
}
|
@@ -30,6 +30,7 @@ namespace J3ML::LinearAlgebra {
|
||||
static const Vector2 Down;
|
||||
static const Vector2 Right;
|
||||
static const Vector2 NaN;
|
||||
static const Vector2 Infinity;
|
||||
|
||||
float GetX() const;
|
||||
float GetY() const;
|
||||
|
80
src/J3ML/Geometry/AABB2D.cpp
Normal file
80
src/J3ML/Geometry/AABB2D.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
#include <J3ML/Geometry/AABB2D.h>
|
||||
|
||||
namespace J3ML::Geometry
|
||||
{
|
||||
|
||||
float AABB2D::Width() const { return maxPoint.x - minPoint.x; }
|
||||
|
||||
float AABB2D::Height() const { return maxPoint.y - minPoint.y; }
|
||||
|
||||
float AABB2D::DistanceSq(const Vector2 &pt) const {
|
||||
Vector2 cp = pt.Clamp(minPoint, maxPoint);
|
||||
return cp.DistanceSq(pt);
|
||||
}
|
||||
|
||||
void AABB2D::SetNegativeInfinity() {
|
||||
minPoint = Vector2::Infinity;
|
||||
maxPoint = -Vector2::Infinity;
|
||||
}
|
||||
|
||||
void AABB2D::Enclose(const Vector2 &point) {
|
||||
minPoint = Vector2::Min(minPoint, point);
|
||||
maxPoint = Vector2::Max(maxPoint, point);
|
||||
}
|
||||
|
||||
bool AABB2D::Intersects(const AABB2D &rhs) const {
|
||||
return maxPoint.x >= rhs.minPoint.x &&
|
||||
maxPoint.y >= rhs.minPoint.y &&
|
||||
rhs.maxPoint.x >= minPoint.x &&
|
||||
rhs.maxPoint.y >= minPoint.y;
|
||||
}
|
||||
|
||||
bool AABB2D::Contains(const AABB2D &rhs) const {
|
||||
return rhs.minPoint.x >= minPoint.x && rhs.minPoint.y >= minPoint.y
|
||||
&& rhs.maxPoint.x <= maxPoint.x && rhs.maxPoint.y <= maxPoint.y;
|
||||
}
|
||||
|
||||
bool AABB2D::Contains(const Vector2 &pt) const {
|
||||
return pt.x >= minPoint.x && pt.y >= minPoint.y
|
||||
&& pt.x <= maxPoint.x && pt.y <= maxPoint.y;
|
||||
}
|
||||
|
||||
bool AABB2D::Contains(int x, int y) const {
|
||||
return x >= minPoint.x && y >= minPoint.y
|
||||
&& x <= maxPoint.x && y <= maxPoint.y;
|
||||
}
|
||||
|
||||
bool AABB2D::IsDegenerate() const {
|
||||
return minPoint.x >= maxPoint.x || minPoint.y >= maxPoint.y;
|
||||
}
|
||||
|
||||
bool AABB2D::HasNegativeVolume() const {
|
||||
return maxPoint.x < minPoint.x || maxPoint.y < minPoint.y;
|
||||
}
|
||||
|
||||
bool AABB2D::IsFinite() const {
|
||||
return minPoint.IsFinite() && maxPoint.IsFinite() && minPoint.MinElement() > -1e5f && maxPoint.MaxElement() < 1e5f;
|
||||
}
|
||||
|
||||
Vector2 AABB2D::PosInside(const Vector2 &normalizedPos) const {
|
||||
return minPoint + normalizedPos.Mul(maxPoint - minPoint);
|
||||
}
|
||||
|
||||
Vector2 AABB2D::ToNormalizedLocalSpace(const Vector2 &pt) const {
|
||||
return (pt - minPoint).Div(maxPoint - minPoint);
|
||||
}
|
||||
|
||||
AABB2D AABB2D::operator+(const Vector2 &pt) const {
|
||||
AABB2D a;
|
||||
a.minPoint = minPoint + pt;
|
||||
a.maxPoint = maxPoint + pt;
|
||||
return a;
|
||||
}
|
||||
|
||||
AABB2D AABB2D::operator-(const Vector2 &pt) const {
|
||||
AABB2D a;
|
||||
a.minPoint = minPoint - pt;
|
||||
a.maxPoint = maxPoint - pt;
|
||||
return a;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user