CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Extent.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
12
14
15#include <cstdint>
16
17namespace CeresEngine::inline Math {
18
22 template<typename T> struct TExtent2 final {
25 T width = 0;
26
29 T height = 0;
30
32 TExtent2() noexcept = default;
33
34 // CE_SCRIPT_EXPORT()
35 TExtent2(const TExtent2&) noexcept = default;
36 constexpr TExtent2& operator=(const TExtent2&) noexcept = default;
37
39 inline TExtent2(T width, T height) noexcept : width(width), height(height) {}
40
41 template<typename TT>
42 explicit inline TExtent2(TExtent2<TT> other) noexcept : width(static_cast<T>(other.width)), height(static_cast<T>(other.height)) {}
43 };
44
45 extern template struct CE_SCRIPT_EXPORT(name = "Extent2Float") TExtent2<float>;
46 extern template struct CE_SCRIPT_EXPORT(name = "Extent2") TExtent2<double>;
47 extern template struct TExtent2<Int8>;
48 extern template struct TExtent2<UInt8>;
49 extern template struct TExtent2<Int16>;
50 extern template struct TExtent2<UInt16>;
51 extern template struct TExtent2<Int32>;
52 extern template struct TExtent2<UInt32>;
54 extern template struct TExtent2<UInt64>;
55
58
61
64
71 T width = 0;
72
75 T height = 0;
76
79 T depth = 0;
80
83
84 // CE_SCRIPT_EXPORT()
87
89 inline TExtent3(T width, T height, T depth) noexcept : width(width), height(height), depth(depth) {}
90
92 inline TExtent3(const TExtent2<T>& other, T depth = T(1)) noexcept : width(other.width), height(other.height), depth(depth) {}
93
94 template<typename TT>
95 explicit inline TExtent3(TExtent3<TT> other) noexcept
96 : width(static_cast<T>(other.width)), height(static_cast<T>(other.height)), depth(static_cast<T>(other.depth)) {}
97
98 template<typename TT>
99 explicit inline TExtent3(TExtent2<TT> other, T depth) noexcept requires(!std::is_same_v<T, TT>)
100 : width(static_cast<T>(other.width)), height(static_cast<T>(other.height)), depth(depth) {}
101 };
102
103 extern template struct CE_SCRIPT_EXPORT(name = "Extent3Float") TExtent3<float>;
104 extern template struct CE_SCRIPT_EXPORT(name = "Extent3") TExtent3<double>;
105 extern template struct TExtent3<Int8>;
106 extern template struct TExtent3<UInt8>;
107 extern template struct TExtent3<Int16>;
108 extern template struct TExtent3<UInt16>;
109 extern template struct TExtent3<Int32>;
110 extern template struct TExtent3<UInt32>;
112 extern template struct TExtent3<UInt64>;
113
116
119
126 return TExtent2<T>{lhs.width + rhs.width, lhs.height + rhs.height};
127 }
128
133 template<typename T> [[nodiscard]] constexpr TExtent2<T> operator-(const TExtent2<T>& lhs, const TExtent2<T>& rhs) noexcept {
134 return TExtent2<T>{lhs.width - rhs.width, lhs.height - rhs.height};
135 }
136
139 template<typename T> [[nodiscard]] constexpr TExtent2<T> operator*(const TExtent2<T>& lhs, T& rhs) noexcept {
140 return TExtent2<T>{lhs.width * rhs, lhs.height * rhs};
141 }
142
145 template<typename T> [[nodiscard]] constexpr TExtent2<T> operator/(const TExtent2<T>& lhs, T& rhs) noexcept {
146 return TExtent2<T>{lhs.width / rhs, lhs.height / rhs};
147 }
148
151 template<typename T> constexpr TExtent2<T>& operator*=(TExtent2<T>& lhs, T rhs) noexcept {
152 lhs = lhs * rhs;
153 return lhs;
154 }
155
158 template<typename T> constexpr TExtent2<T>& operator/=(TExtent2<T>& lhs, T rhs) noexcept {
159 lhs = lhs / rhs;
160 return lhs;
161 }
162
168 template<typename T> [[nodiscard]] constexpr TExtent3<T> operator+(const TExtent3<T>& lhs, const TExtent3<T>& rhs) noexcept {
169 return TExtent3<T>{lhs.width + rhs.width, lhs.height + rhs.height, lhs.depth + rhs.depth};
170 }
171
176 template<typename T> [[nodiscard]] constexpr TExtent3<T> operator-(const TExtent3<T>& lhs, const TExtent3<T>& rhs) noexcept {
177 return TExtent3<T>{lhs.width - rhs.width, lhs.height - rhs.height, lhs.depth - rhs.depth};
178 }
179
182 template<typename T> [[nodiscard]] inline constexpr bool operator==(const TExtent2<T>& lhs, const TExtent2<T>& rhs) noexcept {
183 return (lhs.width == rhs.width && lhs.height == rhs.height);
184 }
185
188 template<typename T> [[nodiscard]] inline constexpr bool operator!=(const TExtent2<T>& lhs, const TExtent2<T>& rhs) noexcept { return !(lhs == rhs); }
189
192 template<typename T> [[nodiscard]] inline constexpr bool operator==(const TExtent3<T>& lhs, const TExtent3<T>& rhs) noexcept {
193 return (lhs.width == rhs.width && lhs.height == rhs.height && lhs.depth == rhs.depth);
194 }
195
198 template<typename T> [[nodiscard]] inline constexpr bool operator!=(const TExtent3<T>& lhs, const TExtent3<T>& rhs) noexcept { return !(lhs == rhs); }
199
200} // namespace CeresEngine::inline Math
201
202template<typename T> struct std::hash<CeresEngine::Math::TExtent2<T>> {
203 using Type = CeresEngine::Math::TExtent2<T>;
204 constexpr size_t operator()(const Type& obj) const { return CeresEngine::hash(obj.width, obj.height); }
205};
206
207template<typename T> struct std::hash<CeresEngine::Math::TExtent3<T>> {
208 using Type = CeresEngine::Math::TExtent3<T>;
209 constexpr size_t operator()(const Type& obj) const { return CeresEngine::hash(obj.width, obj.height, obj.depth); }
210};
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Definition Application.hpp:19
std::uint64_t UInt64
Definition DataTypes.hpp:26
bool operator!=(const ShortAllocator< T, N, A1 > &x, const ShortAllocator< U, M, A2 > &y) noexcept
Definition Allocator.hpp:416
std::int32_t Int32
Definition DataTypes.hpp:21
std::uint16_t UInt16
Definition DataTypes.hpp:20
ButtonSet operator-(const ButtonSet &set, const Button button)
Removes a button from a set.
Definition Input.hpp:270
std::uint8_t UInt8
Definition DataTypes.hpp:17
bool operator==(const ShortAllocator< T, N, A1 > &x, const ShortAllocator< U, M, A2 > &y) noexcept
Definition Allocator.hpp:411
std::int64_t Int64
Definition DataTypes.hpp:24
std::uint32_t UInt32
Definition DataTypes.hpp:23
BasicString< T, CharTraits, RawAllocator > operator+(const BasicString< T, CharTraits, RawAllocator > &lhs, const T *rhs)
Definition String.hpp:119
std::int8_t Int8
Definition DataTypes.hpp:15
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
std::int16_t Int16
Definition DataTypes.hpp:18
Definition Angle.hpp:20
constexpr TExtent2< T > & operator/=(TExtent2< T > &lhs, T rhs) noexcept
Returns the division of left hand side extent 'lhs' and the right hand side extent 'rhs'.
Definition Extent.hpp:158
constexpr TExtent2< T > & operator*=(TExtent2< T > &lhs, T rhs) noexcept
Returns the multiplication of left hand side extent 'lhs' and the right hand side extent 'rhs'.
Definition Extent.hpp:151
2-Dimensional extent structure.
Definition Extent.hpp:22
T width
Extent X axis, i.e. width.
Definition Extent.hpp:25
TExtent2(TExtent2< TT > other) noexcept
Definition Extent.hpp:42
3-Dimensional extent structure.
Definition Extent.hpp:68
TExtent3(TExtent2< TT > other, T depth) noexcept
Definition Extent.hpp:99
TExtent3(TExtent3< TT > other) noexcept
Definition Extent.hpp:95
T width
Extent X axis, i.e. width.
Definition Extent.hpp:71