GIGA REFACTOR
This commit is contained in:
@@ -7,76 +7,77 @@ namespace td {
|
||||
namespace utils {
|
||||
namespace shape {
|
||||
|
||||
float Point::distance(const Point& point) const {
|
||||
return std::sqrt(distanceSquared(point));
|
||||
float Point::Distance(const Point& point) const {
|
||||
return std::sqrt(DistanceSquared(point));
|
||||
}
|
||||
|
||||
float Point::distanceSquared(const Point& point) const {
|
||||
return (m_X - point.getX()) * (m_X - point.getX()) + (m_Y - point.getY()) * (m_Y - point.getY());
|
||||
float Point::DistanceSquared(const Point& point) const {
|
||||
return (m_X - point.GetX()) * (m_X - point.GetX()) + (m_Y - point.GetY()) * (m_Y - point.GetY());
|
||||
}
|
||||
|
||||
|
||||
bool Rectangle::collidesWith(const Point& point) const {
|
||||
return point.getX() > getTopLeft().getX() && point.getX() < getBottomRight().getX() &&
|
||||
point.getY() > getTopLeft().getY() && point.getY() < getBottomRight().getY();
|
||||
bool Rectangle::CollidesWith(const Point& point) const {
|
||||
return point.GetX() > GetTopLeft().GetX() && point.GetX() < GetBottomRight().GetX() &&
|
||||
point.GetY() > GetTopLeft().GetY() && point.GetY() < GetBottomRight().GetY();
|
||||
}
|
||||
|
||||
bool Rectangle::collidesWith(const Rectangle& rect) const {
|
||||
Point point1{ rect.getTopLeft().getX(), rect.getTopLeft().getY() };
|
||||
Point point2{ rect.getTopLeft().getX(), rect.getBottomRight().getY() };
|
||||
Point point3{ rect.getBottomRight().getX(), rect.getTopLeft().getY() };
|
||||
Point point4{ rect.getBottomRight().getX(), rect.getBottomRight().getY() };
|
||||
bool Rectangle::CollidesWith(const Rectangle& rect) const {
|
||||
|
||||
if (collidesWith(point1)) return true;
|
||||
if (collidesWith(point2)) return true;
|
||||
if (collidesWith(point3)) return true;
|
||||
if (collidesWith(point4)) return true;
|
||||
Point point1{ rect.GetTopLeft().GetX(), rect.GetTopLeft().GetY() };
|
||||
Point point2{ rect.GetTopLeft().GetX(), rect.GetBottomRight().GetY() };
|
||||
Point point3{ rect.GetBottomRight().GetX(), rect.GetTopLeft().GetY() };
|
||||
Point point4{ rect.GetBottomRight().GetX(), rect.GetBottomRight().GetY() };
|
||||
|
||||
if (CollidesWith(point1)) return true;
|
||||
if (CollidesWith(point2)) return true;
|
||||
if (CollidesWith(point3)) return true;
|
||||
if (CollidesWith(point4)) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool Rectangle::collidesWith(const Circle& circle) const {
|
||||
return circle.collidesWith(*this);
|
||||
bool Rectangle::CollidesWith(const Circle& circle) const {
|
||||
return circle.CollidesWith(*this);
|
||||
}
|
||||
|
||||
float Rectangle::distance(const Circle& circle) const {
|
||||
return circle.distance(*this);
|
||||
float Rectangle::Distance(const Circle& circle) const {
|
||||
return circle.Distance(*this);
|
||||
}
|
||||
|
||||
float Rectangle::distanceSquared(const Circle& circle) const {
|
||||
return circle.distanceSquared(*this);
|
||||
float Rectangle::DistanceSquared(const Circle& circle) const {
|
||||
return circle.DistanceSquared(*this);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
bool Circle::collidesWith(const Point& point) const {
|
||||
return m_Radius * m_Radius > m_Center.distanceSquared(point);
|
||||
bool Circle::CollidesWith(const Point& point) const {
|
||||
return m_Radius * m_Radius > m_Center.DistanceSquared(point);
|
||||
}
|
||||
|
||||
bool Circle::collidesWith(const Rectangle& rect) const {
|
||||
float distanceSquared_ = distanceSquared(rect);
|
||||
bool Circle::CollidesWith(const Rectangle& rect) const {
|
||||
float DistanceSquared_ = DistanceSquared(rect);
|
||||
|
||||
return distanceSquared_ < m_Radius* m_Radius;
|
||||
return DistanceSquared_ < m_Radius* m_Radius;
|
||||
}
|
||||
|
||||
bool Circle::collidesWith(const Circle& circle) const {
|
||||
return m_Radius + circle.getRadius() > m_Center.distanceSquared(circle.getCenter());
|
||||
bool Circle::CollidesWith(const Circle& circle) const {
|
||||
return m_Radius + circle.GetRadius() > m_Center.DistanceSquared(circle.GetCenter());
|
||||
}
|
||||
|
||||
float Circle::distance(const Rectangle& rect) const {
|
||||
return std::sqrt(distanceSquared(rect));
|
||||
float Circle::Distance(const Rectangle& rect) const {
|
||||
return std::sqrt(DistanceSquared(rect));
|
||||
}
|
||||
|
||||
float Circle::distanceSquared(const Rectangle& rect) const {
|
||||
float closestX = std::clamp(m_Center.getX(), rect.getTopLeft().getX(), rect.getBottomRight().getX());
|
||||
float closestY = std::clamp(m_Center.getY(), rect.getTopLeft().getY(), rect.getBottomRight().getY());
|
||||
float Circle::DistanceSquared(const Rectangle& rect) const {
|
||||
float closestX = std::clamp(m_Center.GetX(), rect.GetTopLeft().GetX(), rect.GetBottomRight().GetX());
|
||||
float closestY = std::clamp(m_Center.GetY(), rect.GetTopLeft().GetY(), rect.GetBottomRight().GetY());
|
||||
|
||||
float distanceX = m_Center.getX() - closestX;
|
||||
float distanceY = m_Center.getY() - closestY;
|
||||
float DistanceX = m_Center.GetX() - closestX;
|
||||
float DistanceY = m_Center.GetY() - closestY;
|
||||
|
||||
return (distanceX * distanceX) + (distanceY * distanceY);
|
||||
return (DistanceX * DistanceX) + (DistanceY * DistanceY);
|
||||
}
|
||||
|
||||
} // namespace shape
|
||||
|
||||
Reference in New Issue
Block a user