feat: add shapes
This commit is contained in:
68
include/misc/Shapes.h
Normal file
68
include/misc/Shapes.h
Normal file
@@ -0,0 +1,68 @@
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
|
||||
namespace td {
|
||||
namespace utils {
|
||||
namespace shape {
|
||||
|
||||
class Point {
|
||||
private:
|
||||
float m_X, m_Y;
|
||||
public:
|
||||
Point() : m_X(0), m_Y(0) {}
|
||||
Point(float x, float y) : m_X(x), m_Y(y) {}
|
||||
|
||||
float getX() const { return m_X; }
|
||||
float getY() const { return m_Y; }
|
||||
|
||||
void setX(float x) { m_X = x; }
|
||||
void setY(float y) { m_Y = y; }
|
||||
|
||||
float distance(const Point& point) const;
|
||||
float distanceSquared(const Point& point) const;
|
||||
};
|
||||
|
||||
class Circle;
|
||||
|
||||
class Rectangle {
|
||||
private:
|
||||
Point m_Center;
|
||||
float m_Width, m_Height;
|
||||
public:
|
||||
Rectangle() {}
|
||||
|
||||
const Point& getCenter() const { return m_Center; }
|
||||
float getWidth() const { return m_Width; }
|
||||
float getHeight() const { return m_Height; }
|
||||
|
||||
Point getTopLeft() const { return { m_Center.getX() - (m_Width / 2.0f), m_Center.getY() - (m_Height / 2.0f) }; }
|
||||
Point getBottomRight() const { return { m_Center.getX() + (m_Width / 2.0f), m_Center.getY() + (m_Height / 2.0f) }; }
|
||||
|
||||
void setCenter(const Point& center) { m_Center = center; }
|
||||
void setWidth(float width) { m_Width = width; }
|
||||
void setHeight(float height) { m_Height = height; }
|
||||
|
||||
bool collidesWith(const Point& point) const;
|
||||
bool collidesWith(const Rectangle& rect) const;
|
||||
bool collidesWith(const Circle& circle) const;
|
||||
};
|
||||
|
||||
class Circle {
|
||||
private:
|
||||
Point m_Center;
|
||||
float m_Radius;
|
||||
public:
|
||||
Circle() : m_Radius(0) {}
|
||||
|
||||
const Point& getCenter() const { return m_Center; }
|
||||
float getRadius() const { return m_Radius; }
|
||||
|
||||
bool collidesWith(const Point& point) const;
|
||||
bool collidesWith(const Rectangle& rect) const;
|
||||
bool collidesWith(const Circle& circle) const;
|
||||
};
|
||||
|
||||
} // namespace shape
|
||||
} // namespace utils
|
||||
} // namespace td
|
||||
Reference in New Issue
Block a user