plugify 1.0.0.0
Loading...
Searching...
No Matches
numerics.hpp
1#pragma once
2
3#include "vector.hpp"
4#include "string.hpp"
5
6namespace plg {
7 PLUGIFY_WARN_PUSH()
8
9#if defined(__clang__)
10 PLUGIFY_WARN_IGNORE("-Wgnu-anonymous-struct")
11 PLUGIFY_WARN_IGNORE("-Wnested-anon-types")
12#elif defined(__GNUC__)
13 PLUGIFY_WARN_IGNORE("-Wpedantic")
14#elif defined(_MSC_VER)
15 PLUGIFY_WARN_IGNORE(4201)
16#endif
17
18 extern "C" {
19 struct vec2 {
20 union {
21 struct {
22 float x;
23 float y;
24 };
25 float data[2];
26 };
27 };
28
29 struct vec3 {
30 union {
31 struct {
32 float x;
33 float y;
34 float z;
35 };
36 float data[3];
37 };
38 };
39
40 struct vec4 {
41 union {
42 struct {
43 float x;
44 float y;
45 float z;
46 float w;
47 };
48 float data[4];
49 };
50 };
51
52 struct mat4x4 {
53 union {
54 struct {
55 float m00, m01, m02, m03;
56 float m10, m11, m12, m13;
57 float m20, m21, m22, m23;
58 float m30, m31, m32, m33;
59 };
60 float m[4][4];
61 float data[16];
62 };
63 };
64 }
65
66 PLUGIFY_WARN_POP()
67
68 constexpr bool operator==(const vec2& lhs, const vec2& rhs) {
69 return lhs.x == rhs.x && lhs.y == rhs.y;
70 }
71
72 constexpr bool operator==(const vec3& lhs, const vec3& rhs) {
73 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z;
74 }
75
76 constexpr bool operator==(const vec4& lhs, const vec4& rhs) {
77 return lhs.x == rhs.x && lhs.y == rhs.y && lhs.z == rhs.z && lhs.w == rhs.w;
78 }
79
80 constexpr bool operator==(const mat4x4& lhs, const mat4x4& rhs) {
81 for (int i = 0; i < 16; ++i) {
82 if (lhs.data[i] != rhs.data[i])
83 return false;
84 }
85 return true;
86 }
87} // namespace plg