CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Offset.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 TOffset2 final {
25 T x = 0;
26
29 T y = 0;
30
32 constexpr TOffset2() noexcept = default;
33 constexpr TOffset2(const TOffset2&) noexcept = default;
34 constexpr TOffset2& operator=(const TOffset2&) noexcept = default;
35
37 inline constexpr TOffset2(T x, T y) noexcept : x{x}, y{y} {}
38
39 template<typename TT> explicit inline constexpr TOffset2(TOffset2<TT> other) noexcept : x(static_cast<T>(other.x)), y(static_cast<T>(other.y)) {}
40 };
41
42 extern template struct CE_SCRIPT_EXPORT(name = "Offset2Float") TOffset2<float>;
43 extern template struct CE_SCRIPT_EXPORT(name = "Offset2") TOffset2<double>;
44 extern template struct TOffset2<Int8>;
45 extern template struct TOffset2<UInt8>;
46 extern template struct TOffset2<Int16>;
47 extern template struct TOffset2<UInt16>;
48 extern template struct TOffset2<Int32>;
49 extern template struct TOffset2<UInt32>;
51 extern template struct TOffset2<UInt64>;
52
55
58
65 T x = 0;
66
69 T y = 0;
70
73 T z = 0;
74
79
81 inline constexpr TOffset3(T x, T y, T z) : x{x}, y{y}, z{z} {}
82
83 template<typename TT>
84 explicit inline constexpr TOffset3(TOffset3<TT> other) noexcept
85 : x(static_cast<T>(other.x)), y(static_cast<T>(other.y)), z(static_cast<T>(other.z)) {}
86
87 template<typename TT>
88 explicit inline constexpr TOffset3(TOffset2<TT> other, T z) noexcept : x(static_cast<T>(other.x)), y(static_cast<T>(other.y)), z(z) {}
89 };
90
91 extern template struct CE_SCRIPT_EXPORT(name = "Offset3Float") TOffset3<float>;
92 extern template struct CE_SCRIPT_EXPORT(name = "Offset3") TOffset3<double>;
93 extern template struct TOffset3<Int8>;
94 extern template struct TOffset3<UInt8>;
95 extern template struct TOffset3<Int16>;
96 extern template struct TOffset3<UInt16>;
97 extern template struct TOffset3<Int32>;
98 extern template struct TOffset3<UInt32>;
100 extern template struct TOffset3<UInt64>;
101
104
107
115 return TOffset2<T>{lhs.x + rhs.x, lhs.y + rhs.y};
116 }
117
124 template<typename T> [[nodiscard]] constexpr TOffset2<T> operator-(const TOffset2<T>& lhs, const TOffset2<T>& rhs) noexcept {
125 return TOffset2<T>{lhs.x - rhs.x, lhs.y - rhs.y};
126 }
127
134 template<typename T> [[nodiscard]] constexpr TOffset3<T> operator+(const TOffset3<T>& lhs, const TOffset3<T>& rhs) noexcept {
135 return TOffset3<T>{lhs.x + rhs.x, lhs.y + rhs.y, lhs.z + rhs.z};
136 }
137
144 template<typename T> [[nodiscard]] constexpr TOffset3<T> operator-(const TOffset3<T>& lhs, const TOffset3<T>& rhs) noexcept {
145 return TOffset3<T>{lhs.x - rhs.x, lhs.y - rhs.y, lhs.z - rhs.z};
146 }
147
150 template<typename T> [[nodiscard]] inline constexpr bool operator==(const TOffset2<T>& lhs, const TOffset2<T>& rhs) noexcept {
151 return (lhs.x == rhs.x && lhs.y == rhs.y);
152 }
153
156 template<typename T> [[nodiscard]] inline constexpr bool operator!=(const TOffset2<T>& lhs, const TOffset2<T>& rhs) noexcept { return !(lhs == rhs); }
157
160 template<typename T> [[nodiscard]] inline constexpr bool operator==(const TOffset3<T>& lhs, const TOffset3<T>& rhs) noexcept {
161 return (lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z);
162 }
163
166 template<typename T> [[nodiscard]] inline constexpr bool operator!=(const TOffset3<T>& lhs, const TOffset3<T>& rhs) noexcept { return !(lhs == rhs); }
167} // namespace CeresEngine::inline Math
168
169template<typename T> struct std::hash<CeresEngine::Math::TOffset2<T>> {
170 using Type = CeresEngine::Math::TOffset2<T>;
171 constexpr size_t operator()(const Type& obj) const { return CeresEngine::hash(obj.x, obj.y); }
172};
173
174template<typename T> struct std::hash<CeresEngine::Math::TOffset3<T>> {
175 using Type = CeresEngine::Math::TOffset3<T>;
176 constexpr size_t operator()(const Type& obj) const { return CeresEngine::hash(obj.x, obj.y, obj.z); }
177};
#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
2-Dimensional offset structure.
Definition Offset.hpp:22
T x
Offset X axis.
Definition Offset.hpp:25
constexpr TOffset2(TOffset2< TT > other) noexcept
Definition Offset.hpp:39
3-Dimensional offset structure.
Definition Offset.hpp:62
T x
Offset X axis.
Definition Offset.hpp:65
constexpr TOffset3(TOffset3< TT > other) noexcept
Definition Offset.hpp:84
constexpr TOffset3(TOffset2< TT > other, T z) noexcept
Definition Offset.hpp:88