Guillaume 1.0.0
Guillaume.
Loading...
Searching...
No Matches
rectangle.hpp
1/*
2 Copyright (c) 2025 ETIB Corporation
3
4 Permission is hereby granted, free of charge, to any person obtaining a copy of
5 this software and associated documentation files (the "Software"), to deal in
6 the Software without restriction, including without limitation the rights to
7 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8 of the Software, and to permit persons to whom the Software is furnished to do
9 so, subject to the following conditions:
10
11 The above copyright notice and this permission notice shall be included in all
12 copies or substantial portions of the Software.
13
14 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 SOFTWARE.
21 */
22
23#pragma once
24
25#include "point.hpp"
26#include "primitives/polygon.hpp"
27#include <cmath>
28
37class Rectangle : public Polygon {
38private:
39 float _width;
40 float _height;
41
42public:
48 : Polygon({
49 Vertex(Point(-0.5f, -0.5f, 0.0f),
50 Color(1.0f, 0.0f, 0.0f, 1.0f)), // Top-left
51 Vertex(Point(0.5f, -0.5f, 0.0f),
52 Color(1.0f, 0.0f, 0.0f, 1.0f)), // Top-right
53 Vertex(Point(0.5f, 0.5f, 0.0f),
54 Color(1.0f, 0.0f, 0.0f, 1.0f)), // Bottom-right
55 Vertex(Point(-0.5f, 0.5f, 0.0f),
56 Color(1.0f, 0.0f, 0.0f, 1.0f)), // Bottom-left
57 }),
58 _width(1), _height(1) {}
59
63 ~Rectangle(void) override = default;
64
68 float getWidth() const { return _width; }
69
73 float getHeight() const { return _height; }
74
85 Rectangle &setDimensions(float width, float height) {
86 _width = width;
87 _height = height;
88
89 return *this;
90 }
91
101 Rectangle &setHeight(float height) {
102 _height = height;
103 return *this;
104 }
105
115 Rectangle &setWidth(float width) {
116 _width = width;
117 return *this;
118 }
119};
Represents an RGBA color with floating-point channels in [0, 1].
Definition color.hpp:42
Represents a point in 3D space.
Definition point.hpp:35
Represents a polygon primitive for 3D rendering.
Definition polygon.hpp:39
Represents a rectangle primitive. The Rectangle class is a derived class of Polygon that represents a...
Definition rectangle.hpp:37
~Rectangle(void) override=default
Destructor.
float getWidth() const
Accessors.
Definition rectangle.hpp:68
Rectangle & setDimensions(float width, float height)
Sets the dimensions of the rectangle.
Definition rectangle.hpp:85
Rectangle & setHeight(float height)
Sets the height of the rectangle.
Definition rectangle.hpp:101
Rectangle & setWidth(float width)
Sets the width of the rectangle.
Definition rectangle.hpp:115
Rectangle(void)
Default constructor - initializes an square centered at origin with width and height of 1 unit.
Definition rectangle.hpp:47
float getHeight() const
Accessors.
Definition rectangle.hpp:73
Definition vertex.hpp:28