ProtoTracer  1.0
Real-time 3D rendering and animation engine
Loading...
Searching...
No Matches
Shape.h
Go to the documentation of this file.
1/**
2 * @file Shape.h
3 * @brief Defines the Shape base class for representing geometric shapes in 2D space.
4 *
5 * The Shape class provides a common interface for 2D shapes with properties such as center,
6 * size, and rotation. Derived classes must implement the `IsInShape` method to define
7 * specific shape boundaries.
8 *
9 * @date 22/12/2024
10 * @version 1.0
11 * @author Coela Can't
12 */
13
14#pragma once
15
16#include "../../../Utils/Math/Vector2D.h"
17
18/**
19 * @class Shape
20 * @brief Abstract base class for 2D geometric shapes.
21 */
22class Shape {
23protected:
24 Vector2D center; ///< The center point of the shape.
25 Vector2D size; ///< The size of the shape, large enough to fit within a bounding rectangle.
26 float rotation; ///< The rotation of the shape in degrees.
27
28public:
29 /**
30 * @brief Constructs a Shape object with specified center, size, and rotation.
31 * @param center Center point of the shape.
32 * @param size Dimensions of the shape.
33 * @param rotation Rotation angle in degrees.
34 */
36
37 /**
38 * @brief Sets the center of the shape.
39 * @param center New center point.
40 */
42
43 /**
44 * @brief Translates the shape by a given offset.
45 * @param offset Offset vector to translate the shape.
46 */
47 void Translate(Vector2D offset);
48
49 /**
50 * @brief Gets the center point of the shape.
51 * @return The center point of the shape.
52 */
54
55 /**
56 * @brief Sets the size of the shape.
57 * @param size New dimensions of the shape.
58 */
59 void SetSize(Vector2D size);
60
61 /**
62 * @brief Scales the shape by a given factor.
63 * @param scale Scale factor for the shape dimensions.
64 */
65 void Scale(Vector2D scale);
66
67 /**
68 * @brief Gets the size of the shape.
69 * @return The size of the shape.
70 */
72
73 /**
74 * @brief Sets the rotation angle of the shape.
75 * @param rotation New rotation angle in degrees.
76 */
77 void SetRotation(float rotation);
78
79 /**
80 * @brief Rotates the shape by a given offset angle.
81 * @param offset Offset angle in degrees.
82 */
83 void Rotate(float offset);
84
85 /**
86 * @brief Gets the current rotation angle of the shape.
87 * @return The rotation angle in degrees.
88 */
89 float GetRotation();
90
91 /**
92 * @brief Checks if a given point lies within the shape's boundaries.
93 * @param point The point to check.
94 * @return True if the point is within the shape, otherwise false.
95 */
96 virtual bool IsInShape(Vector2D point) = 0;
97};
Abstract base class for 2D geometric shapes.
Definition Shape.h:22
float GetRotation()
Gets the current rotation angle of the shape.
Definition Shape.cpp:39
Vector2D GetCenter()
Gets the center point of the shape.
Definition Shape.cpp:15
void Translate(Vector2D offset)
Translates the shape by a given offset.
Definition Shape.cpp:11
float rotation
The rotation of the shape in degrees.
Definition Shape.h:26
virtual bool IsInShape(Vector2D point)=0
Checks if a given point lies within the shape's boundaries.
void Scale(Vector2D scale)
Scales the shape by a given factor.
Definition Shape.cpp:23
void SetRotation(float rotation)
Sets the rotation angle of the shape.
Definition Shape.cpp:31
Vector2D GetSize()
Gets the size of the shape.
Definition Shape.cpp:27
void Rotate(float offset)
Rotates the shape by a given offset angle.
Definition Shape.cpp:35
void SetSize(Vector2D size)
Sets the size of the shape.
Definition Shape.cpp:19
void SetCenter(Vector2D center)
Sets the center of the shape.
Definition Shape.cpp:7
Vector2D center
The center point of the shape.
Definition Shape.h:24
Vector2D size
The size of the shape, large enough to fit within a bounding rectangle.
Definition Shape.h:25
Represents a 2D vector (X, Y) and provides methods for vector arithmetic.
Definition Vector2D.h:27