Grindstone Game Engine v0.2.0
An open source game engine and toolkit.
Loading...
Searching...
No Matches
Rect.hpp
1#pragma once
2#include "Math.hpp"
3
4namespace Grindstone::Math {
5
6 using Offset2D = Grindstone::Math::Int2;
7 using Offset3D = Grindstone::Math::Int3;
8 using Extent2D = Grindstone::Math::Uint2;
9 using Extent3D = Grindstone::Math::Uint3;
10
11 struct Rect2D {
12 Rect2D() = default;
13 Rect2D(const Rect2D& other) = default;
14 Rect2D(Rect2D&& other) noexcept = default;
15 Rect2D& operator=(const Rect2D& other) = default;
16 Rect2D& operator=(Rect2D&& other) noexcept = default;
17
18 Rect2D(float width, float height) : offset(0.0f, 0.0f), extent(width, height) {}
19 Rect2D(float x, float y, float width, float height) : offset(x, y), extent(width, height) {}
20 Rect2D(Grindstone::Math::Float2 extent) : offset(0, 0), extent(extent) {}
21 Rect2D(Grindstone::Math::Float2 offset, Grindstone::Math::Float2 extent) : offset(offset), extent(extent) {}
22 Rect2D(Grindstone::Math::Float4 v) : offset(v.x, v.y), extent(v.z, v.w) {}
23
24 float GetX() const { return offset.x; }
25 float GetY() const { return offset.y; }
26 float GetWidth() const { return extent.x; }
27 float GetHeight() const { return extent.y; }
28
29 Grindstone::Math::Float2 offset;
30 Grindstone::Math::Float2 extent;
31 };
32
33 struct IntRect2D {
34 IntRect2D() = default;
35 IntRect2D(const IntRect2D& other) = default;
36 IntRect2D(IntRect2D&& other) noexcept = default;
37 IntRect2D& operator=(const IntRect2D& other) = default;
38 IntRect2D& operator=(IntRect2D&& other) noexcept = default;
39
40 IntRect2D(uint32_t width, uint32_t height) : offset(Grindstone::Math::Offset2D(0, 0)), extent(Grindstone::Math::Extent2D(width, height)) {}
41 IntRect2D(int32_t x, int32_t y, uint32_t width, uint32_t height) : offset(Grindstone::Math::Offset2D(x, y)), extent(Grindstone::Math::Extent2D(width, height)) {}
42 IntRect2D(Grindstone::Math::Extent2D extent) : offset(Grindstone::Math::Offset2D(0, 0)), extent(extent) {}
43 IntRect2D(Grindstone::Math::Offset2D offset, Grindstone::Math::Extent2D extent) : offset(offset), extent(extent) {}
44
45 int32_t GetX() const { return offset.x; }
46 int32_t GetY() const { return offset.y; }
47 uint32_t GetWidth() const { return extent.x; }
48 uint32_t GetHeight() const { return extent.y; }
49
50 Grindstone::Math::Offset2D offset;
51 Grindstone::Math::Extent2D extent;
52 };
53
54 struct Box3D {
55 Box3D() = default;
56 Box3D(const Box3D& other) = default;
57 Box3D(Box3D&& other) noexcept = default;
58 Box3D& operator=(const Box3D& other) = default;
59 Box3D& operator=(Box3D&& other) noexcept = default;
60
61 Box3D(float width, float height, float depth) : offset(0.0f, 0.0f, 0.0f), extent(width, height, depth) {}
62 Box3D(Grindstone::Math::Float3 extent) : offset(0.0f, 0.0f, 0.0f), extent(extent) {}
63 Box3D(float x, float y, float z, float width, float height, float depth) : offset(x, y, z), extent(width, height, depth) {}
64 Box3D(Grindstone::Math::Float3 offset, Grindstone::Math::Float3 extent) : offset(offset), extent(extent) {}
65
66 float GetX() const { return offset.x; }
67 float GetY() const { return offset.y; }
68 float GetZ() const { return offset.z; }
69 float GetWidth() const { return extent.x; }
70 float GetHeight() const { return extent.y; }
71 float GetDepth() const { return extent.z; }
72
73 Grindstone::Math::Float3 offset;
74 Grindstone::Math::Float3 extent;
75 };
76
77 struct IntBox3D {
78 IntBox3D() = default;
79 IntBox3D(const IntBox3D& other) = default;
80 IntBox3D(IntBox3D&& other) noexcept = default;
81 IntBox3D& operator=(const IntBox3D& other) = default;
82 IntBox3D& operator=(IntBox3D&& other) noexcept = default;
83
84 IntBox3D(uint32_t width, uint32_t height, uint32_t depth) : offset(Grindstone::Math::Offset3D(0, 0, 0)), extent(Grindstone::Math::Extent3D(width, height, depth)) {}
85 IntBox3D(Grindstone::Math::Extent3D extent) : offset(Grindstone::Math::Offset3D(0, 0, 0)), extent(extent) {}
86 IntBox3D(int32_t x, int32_t y, int32_t z, uint32_t width, uint32_t height, uint32_t depth) : offset(Grindstone::Math::Offset3D(x, y, z)), extent(Grindstone::Math::Extent3D(width, height, depth)) {}
87 IntBox3D(Grindstone::Math::Offset3D offset, Grindstone::Math::Extent3D extent) : offset(offset), extent(extent) {}
88
89 int32_t GetX() const { return offset.x; }
90 int32_t GetY() const { return offset.y; }
91 int32_t GetZ() const { return offset.z; }
92 uint32_t GetWidth() const { return extent.x; }
93 uint32_t GetHeight() const { return extent.y; }
94 uint32_t GetDepth() const { return extent.z; }
95
96 Grindstone::Math::Offset3D offset;
97 Grindstone::Math::Extent3D extent;
98 };
99
100}