-
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(sourcepp): add vector operators, more typedefs
- Loading branch information
1 parent
19fcbde
commit 7cc5cde
Showing
3 changed files
with
97 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,21 @@ | ||
#pragma once | ||
|
||
#include <cstdint> | ||
#include <type_traits> | ||
|
||
// Integer types are intentionally outside the sourcepp namespace | ||
|
||
using std::int8_t; | ||
using std::int16_t; | ||
using std::int32_t; | ||
using std::int64_t; | ||
|
||
using std::uint8_t; | ||
using std::uint16_t; | ||
using std::uint32_t; | ||
using std::uint64_t; | ||
|
||
namespace sourcepp::math { | ||
|
||
template<typename T> | ||
concept Arithmetic = std::is_arithmetic_v<T>; | ||
|
||
} // namespace sourcepp::math |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,34 +1,112 @@ | ||
#pragma once | ||
|
||
#include <concepts> | ||
#include "Integer.h" | ||
|
||
namespace sourcepp::math { | ||
|
||
template<std::floating_point P> | ||
template<Arithmetic P> | ||
struct Vec2 { | ||
P x; | ||
P y; | ||
|
||
[[nodiscard]] Vec2 operator+(const Vec2& other) const { | ||
return {this->x + other.x, this->y + other.y}; | ||
} | ||
|
||
[[nodiscard]] Vec2 operator-(const Vec2& other) const { | ||
return {this->x - other.x, this->y - other.y}; | ||
} | ||
|
||
[[nodiscard]] static constexpr Vec2 zero() { | ||
return {{}, {}}; | ||
} | ||
}; | ||
using Vec2f = Vec2<float>; | ||
using Vec2d = Vec2<double>; | ||
|
||
template<std::floating_point P> | ||
using Vec2i8 = Vec2<int8_t>; | ||
using Vec2i16 = Vec2<int16_t>; | ||
using Vec2i32 = Vec2<int32_t>; | ||
using Vec2i64 = Vec2<int64_t>; | ||
using Vec2i = Vec2i32; | ||
|
||
using Vec2ui8 = Vec2<uint8_t>; | ||
using Vec2ui16 = Vec2<uint16_t>; | ||
using Vec2ui32 = Vec2<uint32_t>; | ||
using Vec2ui64 = Vec2<uint64_t>; | ||
using Vec2ui = Vec2ui32; | ||
|
||
using Vec2f32 = Vec2<float>; | ||
using Vec2f64 = Vec2<double>; | ||
using Vec2f = Vec2f32; | ||
|
||
template<Arithmetic P> | ||
struct Vec3 { | ||
P x; | ||
P y; | ||
P z; | ||
|
||
[[nodiscard]] Vec3 operator+(const Vec3& other) const { | ||
return {this->x + other.x, this->y + other.y, this->z + other.z}; | ||
} | ||
|
||
[[nodiscard]] Vec3 operator-(const Vec3& other) const { | ||
return {this->x - other.x, this->y - other.y, this->z - other.z}; | ||
} | ||
|
||
[[nodiscard]] static constexpr Vec3 zero() { | ||
return {{}, {}, {}}; | ||
} | ||
}; | ||
using Vec3f = Vec3<float>; | ||
using Vec3d = Vec3<double>; | ||
|
||
template<std::floating_point P> | ||
using Vec3i8 = Vec3<int8_t>; | ||
using Vec3i16 = Vec3<int16_t>; | ||
using Vec3i32 = Vec3<int32_t>; | ||
using Vec3i64 = Vec3<int64_t>; | ||
using Vec3i = Vec3i32; | ||
|
||
using Vec3ui8 = Vec3<uint8_t>; | ||
using Vec3ui16 = Vec3<uint16_t>; | ||
using Vec3ui32 = Vec3<uint32_t>; | ||
using Vec3ui64 = Vec3<uint64_t>; | ||
using Vec3ui = Vec3ui32; | ||
|
||
using Vec3f32 = Vec3<float>; | ||
using Vec3f64 = Vec3<double>; | ||
using Vec3f = Vec3f32; | ||
|
||
template<Arithmetic P> | ||
struct Vec4 { | ||
P x; | ||
P y; | ||
P z; | ||
P w; | ||
|
||
[[nodiscard]] Vec4 operator+(const Vec4& other) const { | ||
return {this->x + other.x, this->y + other.y, this->z + other.z, this->w + other.w}; | ||
} | ||
|
||
[[nodiscard]] Vec4 operator-(const Vec4& other) const { | ||
return {this->x - other.x, this->y - other.y, this->z - other.z, this->w - other.w}; | ||
} | ||
|
||
[[nodiscard]] static constexpr Vec4 zero() { | ||
return {{}, {}, {}, {}}; | ||
} | ||
}; | ||
using Vec4f = Vec4<float>; | ||
using Vec4d = Vec4<double>; | ||
|
||
using Vec4i8 = Vec4<int8_t>; | ||
using Vec4i16 = Vec4<int16_t>; | ||
using Vec4i32 = Vec4<int32_t>; | ||
using Vec4i64 = Vec4<int64_t>; | ||
using Vec4i = Vec4i32; | ||
|
||
using Vec4ui8 = Vec4<uint8_t>; | ||
using Vec4ui16 = Vec4<uint16_t>; | ||
using Vec4ui32 = Vec4<uint32_t>; | ||
using Vec4ui64 = Vec4<uint64_t>; | ||
using Vec4ui = Vec4ui32; | ||
|
||
using Vec4f32 = Vec4<float>; | ||
using Vec4f64 = Vec4<double>; | ||
using Vec4f = Vec4f32; | ||
|
||
} // namespace sourcepp::math |