From bdb3521263e1e6697ee82693a1def139db17dcc8 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Mon, 29 Apr 2024 15:07:32 +0200 Subject: [PATCH 01/10] add vector3 record --- cmake/sac-core-ext.txt | 1 + src/structures/Vec3d.sac | 225 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 226 insertions(+) create mode 100644 src/structures/Vec3d.sac diff --git a/cmake/sac-core-ext.txt b/cmake/sac-core-ext.txt index ed94ae74..51ad43ef 100644 --- a/cmake/sac-core-ext.txt +++ b/cmake/sac-core-ext.txt @@ -47,6 +47,7 @@ structures/ComplexScalarArith.sac Ext structures/ComplexBasics.sac Ext structures/Complex.sac Ext structures/Quaternion.sac Ext +structures/Vec3d.sac Ext structures/Char.sac Core structures/Bits.sac Core structures/String.sac Core diff --git a/src/structures/Vec3d.sac b/src/structures/Vec3d.sac new file mode 100644 index 00000000..5fea8191 --- /dev/null +++ b/src/structures/Vec3d.sac @@ -0,0 +1,225 @@ +module Vec3d; + +export all; + +struct Vec3d { + double x; + double y; + double z; +}; + +inline double +l2norm (struct Vec3d v) +{ + x = _mul_SxS_ (v.x, v.x); + y = _mul_SxS_ (v.y, v.y); + z = _mul_SxS_ (v.z, v.z); + return Math::sqrt (_add_SxS_ (_add_SxS_ (x, y), z)); +} + +/****************************************************************************** + * + * Binary operations + * + ******************************************************************************/ + +#define VEC3D_BIN_AxA(name, op) \ +inline struct Vec3d[d:shp] \ +name (struct Vec3d[d:shp] a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + Vec3d{ op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ + op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ + op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z) }; \ + } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ +} + +#define VEC3D_BIN_AxS(name, op) \ +inline struct Vec3d[d:shp] \ +name (struct Vec3d[d:shp] a, struct Vec3d b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + Vec3d{ op (_sel_VxA_ (iv, a).x, b.x), \ + op (_sel_VxA_ (iv, a).y, b.y), \ + op (_sel_VxA_ (iv, a).z, b.z) }; \ + } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ +} + +#define VEC3D_BIN_SxA(name, op) \ +inline struct Vec3d[d:shp] \ +name (struct Vec3d a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + Vec3d{ op (a.x, _sel_VxA_ (iv, b).x), \ + op (a.y, _sel_VxA_ (iv, b).y), \ + op (a.z, _sel_VxA_ (iv, b).z) }; \ + } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ +} + +#define VEC3D_BIN_AxD(name, op) \ +inline struct Vec3d[d:shp] \ +name (struct Vec3d[d:shp] a, double b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + Vec3d{ op (_sel_VxA_ (iv, a).x, b), \ + op (_sel_VxA_ (iv, a).y, b), \ + op (_sel_VxA_ (iv, a).z, b) }; \ + } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ +} + +#define VEC3D_BIN_DxA(name, op) \ +inline struct Vec3d[d:shp] \ +name (double a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + Vec3d{ op (a, _sel_VxA_ (iv, b).x), \ + op (a, _sel_VxA_ (iv, b).y), \ + op (a, _sel_VxA_ (iv, b).z) }; \ + } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ +} + +#define VEC3D_BIN_SxS(name, op) \ +inline struct Vec3d \ +name (struct Vec3d a, struct Vec3d b) \ +{ \ + return Vec3d{ op (a.x, b.x), op (a.y, b.y), op (a.z, b.z) }; \ +} + +#define VEC3D_BIN(name, op) \ +VEC3D_BIN_AxA(name, op) \ +VEC3D_BIN_AxS(name, op) \ +VEC3D_BIN_SxA(name, op) \ +VEC3D_BIN_AxD(name, op) \ +VEC3D_BIN_DxA(name, op) \ +VEC3D_BIN_SxS(name, op) + +VEC3D_BIN(+, _add_SxS_) +VEC3D_BIN(-, _sub_SxS_) +VEC3D_BIN(*, _mul_SxS_) +VEC3D_BIN(/, _div_SxS_) + +/****************************************************************************** + * + * Unary operations + * + ******************************************************************************/ + +#define VEC3D_UNARY_A(name, op) \ +inline struct Vec3d[d:shp] \ +name (struct Vec3d[d:shp] a) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + Vec3d{ op (_sel_VxA_ (iv, a).x), \ + op (_sel_VxA_ (iv, a).y), \ + op (_sel_VxA_ (iv, a).z) }; \ + } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ +} + +#define VEC3D_UNARY_S(name, op) \ +inline struct Vec3d \ +name (struct Vec3d a) \ +{ \ + return Vec3d{ op (a.x), op (a.y), op (a.z) }; \ +} + +#define VEC3D_UNARY(name, op) \ +VEC3D_UNARY_A(name, op) \ +VEC3D_UNARY_S(name, op) + +VEC3D_UNARY(-, _neg_S_) + +/****************************************************************************** + * + * Equality operations + * + ******************************************************************************/ + +#define VEC3D_EQ_AxA(name, op) \ +inline bool[d:shp] \ +name (struct Vec3d[d:shp] a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + _and_SxS_ (op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ + _and_SxS_ (op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ + op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_AxS(name, op) \ +inline bool[d:shp] \ +name (struct Vec3d[d:shp] a, struct Vec3d b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + _and_SxS_ (op (_sel_VxA_ (iv, a).x, b.x), \ + _and_SxS_ (op (_sel_VxA_ (iv, a).y, b.y), \ + op (_sel_VxA_ (iv, a).z, b.z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_SxA(name, op) \ +inline bool[d:shp] \ +name (struct Vec3d a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + _and_SxS_ (op (a.x, _sel_VxA_ (iv, b).x), \ + _and_SxS_ (op (a.y, _sel_VxA_ (iv, b).y), \ + op (a.z, _sel_VxA_ (iv, b).z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_AxD(name, op) \ +inline bool[d:shp] \ +name (struct Vec3d[d:shp] a, double b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + _and_SxS_ (op (_sel_VxA_ (iv, a).x, b), \ + _and_SxS_ (op (_sel_VxA_ (iv, a).y, b), \ + op (_sel_VxA_ (iv, a).z, b))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_DxA(name, op) \ +inline bool[d:shp] \ +name (double a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + _and_SxS_ (op (a, _sel_VxA_ (iv, b).x), \ + _and_SxS_ (op (a, _sel_VxA_ (iv, b).y), \ + op (a, _sel_VxA_ (iv, b).z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_SxS(name, op) \ +inline bool \ +name (struct Vec3d a, struct Vec3d b) \ +{ \ + return _and_SxS_ (op (a.x, b.x), \ + _and_SxS_ (op (a.y, b.y), \ + op (a.z, b.z))); \ +} + +#define VEC3D_EQ(name, op) \ +VEC3D_EQ_AxA(name, op) \ +VEC3D_EQ_AxS(name, op) \ +VEC3D_EQ_SxA(name, op) \ +VEC3D_EQ_AxD(name, op) \ +VEC3D_EQ_DxA(name, op) \ +VEC3D_EQ_SxS(name, op) + +VEC3D_EQ(==, _eq_SxS_) +VEC3D_EQ(!=, _neq_SxS_) +VEC3D_EQ(>, _gt_SxS_) +VEC3D_EQ(>=, _ge_SxS_) +VEC3D_EQ(<, _lt_SxS_) +VEC3D_EQ(<=, _le_SxS_) From 75c0b7911dbe4912cbd06a39304defcc602cf01c Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Tue, 30 Apr 2024 10:21:42 +0200 Subject: [PATCH 02/10] vec3d remove ambiguous equality operations --- src/structures/Vec3d.sac | 90 ---------------------------------------- 1 file changed, 90 deletions(-) diff --git a/src/structures/Vec3d.sac b/src/structures/Vec3d.sac index 5fea8191..11229d65 100644 --- a/src/structures/Vec3d.sac +++ b/src/structures/Vec3d.sac @@ -133,93 +133,3 @@ VEC3D_UNARY_A(name, op) \ VEC3D_UNARY_S(name, op) VEC3D_UNARY(-, _neg_S_) - -/****************************************************************************** - * - * Equality operations - * - ******************************************************************************/ - -#define VEC3D_EQ_AxA(name, op) \ -inline bool[d:shp] \ -name (struct Vec3d[d:shp] a, struct Vec3d[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - _and_SxS_ (op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ - _and_SxS_ (op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ - op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_AxS(name, op) \ -inline bool[d:shp] \ -name (struct Vec3d[d:shp] a, struct Vec3d b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - _and_SxS_ (op (_sel_VxA_ (iv, a).x, b.x), \ - _and_SxS_ (op (_sel_VxA_ (iv, a).y, b.y), \ - op (_sel_VxA_ (iv, a).z, b.z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_SxA(name, op) \ -inline bool[d:shp] \ -name (struct Vec3d a, struct Vec3d[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - _and_SxS_ (op (a.x, _sel_VxA_ (iv, b).x), \ - _and_SxS_ (op (a.y, _sel_VxA_ (iv, b).y), \ - op (a.z, _sel_VxA_ (iv, b).z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_AxD(name, op) \ -inline bool[d:shp] \ -name (struct Vec3d[d:shp] a, double b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - _and_SxS_ (op (_sel_VxA_ (iv, a).x, b), \ - _and_SxS_ (op (_sel_VxA_ (iv, a).y, b), \ - op (_sel_VxA_ (iv, a).z, b))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_DxA(name, op) \ -inline bool[d:shp] \ -name (double a, struct Vec3d[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - _and_SxS_ (op (a, _sel_VxA_ (iv, b).x), \ - _and_SxS_ (op (a, _sel_VxA_ (iv, b).y), \ - op (a, _sel_VxA_ (iv, b).z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_SxS(name, op) \ -inline bool \ -name (struct Vec3d a, struct Vec3d b) \ -{ \ - return _and_SxS_ (op (a.x, b.x), \ - _and_SxS_ (op (a.y, b.y), \ - op (a.z, b.z))); \ -} - -#define VEC3D_EQ(name, op) \ -VEC3D_EQ_AxA(name, op) \ -VEC3D_EQ_AxS(name, op) \ -VEC3D_EQ_SxA(name, op) \ -VEC3D_EQ_AxD(name, op) \ -VEC3D_EQ_DxA(name, op) \ -VEC3D_EQ_SxS(name, op) - -VEC3D_EQ(==, _eq_SxS_) -VEC3D_EQ(!=, _neq_SxS_) -VEC3D_EQ(>, _gt_SxS_) -VEC3D_EQ(>=, _ge_SxS_) -VEC3D_EQ(<, _lt_SxS_) -VEC3D_EQ(<=, _le_SxS_) From 86803637812fe9f8f497140cb02517895e9ecf42 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Tue, 30 Apr 2024 12:04:10 +0200 Subject: [PATCH 03/10] rename vec3d to vector3 --- cmake/sac-core-ext.txt | 2 +- src/structures/{Vec3d.sac => Vector3.sac} | 90 +++++++++++------------ 2 files changed, 46 insertions(+), 46 deletions(-) rename src/structures/{Vec3d.sac => Vector3.sac} (60%) diff --git a/cmake/sac-core-ext.txt b/cmake/sac-core-ext.txt index 51ad43ef..8054eacf 100644 --- a/cmake/sac-core-ext.txt +++ b/cmake/sac-core-ext.txt @@ -47,7 +47,7 @@ structures/ComplexScalarArith.sac Ext structures/ComplexBasics.sac Ext structures/Complex.sac Ext structures/Quaternion.sac Ext -structures/Vec3d.sac Ext +structures/Vector3.sac Ext structures/Char.sac Core structures/Bits.sac Core structures/String.sac Core diff --git a/src/structures/Vec3d.sac b/src/structures/Vector3.sac similarity index 60% rename from src/structures/Vec3d.sac rename to src/structures/Vector3.sac index 11229d65..0718958e 100644 --- a/src/structures/Vec3d.sac +++ b/src/structures/Vector3.sac @@ -1,15 +1,15 @@ -module Vec3d; +module Vector3; export all; -struct Vec3d { +struct Vector3 { double x; double y; double z; }; inline double -l2norm (struct Vec3d v) +l2norm (struct Vector3 v) { x = _mul_SxS_ (v.x, v.x); y = _mul_SxS_ (v.y, v.y); @@ -24,70 +24,70 @@ l2norm (struct Vec3d v) ******************************************************************************/ #define VEC3D_BIN_AxA(name, op) \ -inline struct Vec3d[d:shp] \ -name (struct Vec3d[d:shp] a, struct Vec3d[d:shp] b) \ +inline struct Vector3[d:shp] \ +name (struct Vector3[d:shp] a, struct Vector3[d:shp] b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vec3d{ op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ - op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ - op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z) }; \ - } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ + Vector3{ op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ + op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ + op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z) }; \ + } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ } #define VEC3D_BIN_AxS(name, op) \ -inline struct Vec3d[d:shp] \ -name (struct Vec3d[d:shp] a, struct Vec3d b) \ +inline struct Vector3[d:shp] \ +name (struct Vector3[d:shp] a, struct Vector3 b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vec3d{ op (_sel_VxA_ (iv, a).x, b.x), \ - op (_sel_VxA_ (iv, a).y, b.y), \ - op (_sel_VxA_ (iv, a).z, b.z) }; \ - } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ + Vector3{ op (_sel_VxA_ (iv, a).x, b.x), \ + op (_sel_VxA_ (iv, a).y, b.y), \ + op (_sel_VxA_ (iv, a).z, b.z) }; \ + } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ } #define VEC3D_BIN_SxA(name, op) \ -inline struct Vec3d[d:shp] \ -name (struct Vec3d a, struct Vec3d[d:shp] b) \ +inline struct Vector3[d:shp] \ +name (struct Vector3 a, struct Vector3[d:shp] b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vec3d{ op (a.x, _sel_VxA_ (iv, b).x), \ - op (a.y, _sel_VxA_ (iv, b).y), \ - op (a.z, _sel_VxA_ (iv, b).z) }; \ - } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ + Vector3{ op (a.x, _sel_VxA_ (iv, b).x), \ + op (a.y, _sel_VxA_ (iv, b).y), \ + op (a.z, _sel_VxA_ (iv, b).z) }; \ + } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ } #define VEC3D_BIN_AxD(name, op) \ -inline struct Vec3d[d:shp] \ -name (struct Vec3d[d:shp] a, double b) \ +inline struct Vector3[d:shp] \ +name (struct Vector3[d:shp] a, double b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vec3d{ op (_sel_VxA_ (iv, a).x, b), \ - op (_sel_VxA_ (iv, a).y, b), \ - op (_sel_VxA_ (iv, a).z, b) }; \ - } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ + Vector3{ op (_sel_VxA_ (iv, a).x, b), \ + op (_sel_VxA_ (iv, a).y, b), \ + op (_sel_VxA_ (iv, a).z, b) }; \ + } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ } #define VEC3D_BIN_DxA(name, op) \ -inline struct Vec3d[d:shp] \ -name (double a, struct Vec3d[d:shp] b) \ +inline struct Vector3[d:shp] \ +name (double a, struct Vector3[d:shp] b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vec3d{ op (a, _sel_VxA_ (iv, b).x), \ - op (a, _sel_VxA_ (iv, b).y), \ - op (a, _sel_VxA_ (iv, b).z) }; \ - } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ + Vector3{ op (a, _sel_VxA_ (iv, b).x), \ + op (a, _sel_VxA_ (iv, b).y), \ + op (a, _sel_VxA_ (iv, b).z) }; \ + } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ } #define VEC3D_BIN_SxS(name, op) \ -inline struct Vec3d \ -name (struct Vec3d a, struct Vec3d b) \ +inline struct Vector3 \ +name (struct Vector3 a, struct Vector3 b) \ { \ - return Vec3d{ op (a.x, b.x), op (a.y, b.y), op (a.z, b.z) }; \ + return Vector3{ op (a.x, b.x), op (a.y, b.y), op (a.z, b.z) }; \ } #define VEC3D_BIN(name, op) \ @@ -110,22 +110,22 @@ VEC3D_BIN(/, _div_SxS_) ******************************************************************************/ #define VEC3D_UNARY_A(name, op) \ -inline struct Vec3d[d:shp] \ -name (struct Vec3d[d:shp] a) \ +inline struct Vector3[d:shp] \ +name (struct Vector3[d:shp] a) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vec3d{ op (_sel_VxA_ (iv, a).x), \ - op (_sel_VxA_ (iv, a).y), \ - op (_sel_VxA_ (iv, a).z) }; \ - } : genarray (shp, Vec3d{ 0d, 0d, 0d }); \ + Vector3{ op (_sel_VxA_ (iv, a).x), \ + op (_sel_VxA_ (iv, a).y), \ + op (_sel_VxA_ (iv, a).z) }; \ + } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ } #define VEC3D_UNARY_S(name, op) \ -inline struct Vec3d \ -name (struct Vec3d a) \ +inline struct Vector3 \ +name (struct Vector3 a) \ { \ - return Vec3d{ op (a.x), op (a.y), op (a.z) }; \ + return Vector3{ op (a.x), op (a.y), op (a.z) }; \ } #define VEC3D_UNARY(name, op) \ From f7d44a46e8b51488edc6aef40c235613e3323458 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 1 May 2024 16:23:17 +0200 Subject: [PATCH 04/10] vec3d equality operations --- src/structures/Vector3.sac | 90 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/src/structures/Vector3.sac b/src/structures/Vector3.sac index 0718958e..6b0d4474 100644 --- a/src/structures/Vector3.sac +++ b/src/structures/Vector3.sac @@ -133,3 +133,93 @@ VEC3D_UNARY_A(name, op) \ VEC3D_UNARY_S(name, op) VEC3D_UNARY(-, _neg_S_) + +/****************************************************************************** + * + * Equality operations + * + ******************************************************************************/ + +#define VEC3D_EQ_AxA(name, op, and_or) \ +inline bool[d:shp] \ +name (struct Vec3d[d:shp] a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + and_or (op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ + and_or (op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ + op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_AxS(name, op) \ +inline bool[d:shp] \ +name (struct Vec3d[d:shp] a, struct Vec3d b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + and_or (op (_sel_VxA_ (iv, a).x, b.x), \ + and_or (op (_sel_VxA_ (iv, a).y, b.y), \ + op (_sel_VxA_ (iv, a).z, b.z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_SxA(name, op) \ +inline bool[d:shp] \ +name (struct Vec3d a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + and_or (op (a.x, _sel_VxA_ (iv, b).x), \ + and_or (op (a.y, _sel_VxA_ (iv, b).y), \ + op (a.z, _sel_VxA_ (iv, b).z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_AxD(name, op) \ +inline bool[d:shp] \ +name (struct Vec3d[d:shp] a, double b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + and_or (op (_sel_VxA_ (iv, a).x, b), \ + and_or (op (_sel_VxA_ (iv, a).y, b), \ + op (_sel_VxA_ (iv, a).z, b))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_DxA(name, op) \ +inline bool[d:shp] \ +name (double a, struct Vec3d[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_ (0, shp) <= iv < shp) : \ + and_or (op (a, _sel_VxA_ (iv, b).x), \ + and_or (op (a, _sel_VxA_ (iv, b).y), \ + op (a, _sel_VxA_ (iv, b).z))); \ + } : genarray (shp, true); \ +} + +#define VEC3D_EQ_SxS(name, op) \ +inline bool \ +name (struct Vec3d a, struct Vec3d b) \ +{ \ + return and_or (op (a.x, b.x), \ + and_or (op (a.y, b.y), \ + op (a.z, b.z))); \ +} + +#define VEC3D_EQ(name, op, and_or) \ +VEC3D_EQ_AxA(name, op, and_or) \ +VEC3D_EQ_AxS(name, op, and_or) \ +VEC3D_EQ_SxA(name, op, and_or) \ +VEC3D_EQ_AxD(name, op, and_or) \ +VEC3D_EQ_DxA(name, op, and_or) \ +VEC3D_EQ_SxS(name, op, and_or) + +VEC3D_EQ(==, _eq_SxS_, _and_SxS_) +VEC3D_EQ(!=, _neq_SxS_, _or_SxS_ ) +VEC3D_EQ(>, _gt_SxS_, _and_SxS_) +VEC3D_EQ(>=, _ge_SxS_, _and_SxS_) +VEC3D_EQ(<, _lt_SxS_, _and_SxS_) +VEC3D_EQ(<=, _le_SxS_, _and_SxS_) From ba95d3496fe643912d792b22de56c3fbace4e680 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 1 May 2024 16:30:29 +0200 Subject: [PATCH 05/10] add missing macro arguments --- src/structures/Vector3.sac | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/structures/Vector3.sac b/src/structures/Vector3.sac index 6b0d4474..2ccbc733 100644 --- a/src/structures/Vector3.sac +++ b/src/structures/Vector3.sac @@ -142,7 +142,7 @@ VEC3D_UNARY(-, _neg_S_) #define VEC3D_EQ_AxA(name, op, and_or) \ inline bool[d:shp] \ -name (struct Vec3d[d:shp] a, struct Vec3d[d:shp] b) \ +name (struct Vector3[d:shp] a, struct Vector3[d:shp] b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ @@ -152,9 +152,9 @@ name (struct Vec3d[d:shp] a, struct Vec3d[d:shp] b) \ } : genarray (shp, true); \ } -#define VEC3D_EQ_AxS(name, op) \ +#define VEC3D_EQ_AxS(name, op, and_or) \ inline bool[d:shp] \ -name (struct Vec3d[d:shp] a, struct Vec3d b) \ +name (struct Vector3[d:shp] a, struct Vector3 b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ @@ -164,9 +164,9 @@ name (struct Vec3d[d:shp] a, struct Vec3d b) \ } : genarray (shp, true); \ } -#define VEC3D_EQ_SxA(name, op) \ +#define VEC3D_EQ_SxA(name, op, and_or) \ inline bool[d:shp] \ -name (struct Vec3d a, struct Vec3d[d:shp] b) \ +name (struct Vector3 a, struct Vector3[d:shp] b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ @@ -176,9 +176,9 @@ name (struct Vec3d a, struct Vec3d[d:shp] b) \ } : genarray (shp, true); \ } -#define VEC3D_EQ_AxD(name, op) \ +#define VEC3D_EQ_AxD(name, op, and_or) \ inline bool[d:shp] \ -name (struct Vec3d[d:shp] a, double b) \ +name (struct Vector3[d:shp] a, double b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ @@ -188,9 +188,9 @@ name (struct Vec3d[d:shp] a, double b) \ } : genarray (shp, true); \ } -#define VEC3D_EQ_DxA(name, op) \ +#define VEC3D_EQ_DxA(name, op, and_or) \ inline bool[d:shp] \ -name (double a, struct Vec3d[d:shp] b) \ +name (double a, struct Vector3[d:shp] b) \ { \ return with { \ (_mul_SxV_ (0, shp) <= iv < shp) : \ @@ -200,9 +200,9 @@ name (double a, struct Vec3d[d:shp] b) \ } : genarray (shp, true); \ } -#define VEC3D_EQ_SxS(name, op) \ +#define VEC3D_EQ_SxS(name, op, and_or) \ inline bool \ -name (struct Vec3d a, struct Vec3d b) \ +name (struct Vector3 a, struct Vector3 b) \ { \ return and_or (op (a.x, b.x), \ and_or (op (a.y, b.y), \ @@ -219,7 +219,3 @@ VEC3D_EQ_SxS(name, op, and_or) VEC3D_EQ(==, _eq_SxS_, _and_SxS_) VEC3D_EQ(!=, _neq_SxS_, _or_SxS_ ) -VEC3D_EQ(>, _gt_SxS_, _and_SxS_) -VEC3D_EQ(>=, _ge_SxS_, _and_SxS_) -VEC3D_EQ(<, _lt_SxS_, _and_SxS_) -VEC3D_EQ(<=, _le_SxS_, _and_SxS_) From 97d360e451e397c8230fbf45f352c885e4932c6c Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Thu, 2 May 2024 12:13:40 +0200 Subject: [PATCH 06/10] add Vector3 to Structures.sac --- src/structures/Structures.sac | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/structures/Structures.sac b/src/structures/Structures.sac index de5169b3..e8c56edf 100644 --- a/src/structures/Structures.sac +++ b/src/structures/Structures.sac @@ -5,8 +5,9 @@ import Bits: all; import Char: all; import String: all; #ifdef EXT_STDLIB -import Complex: all; -import Quaternion: all; +import Complex : all; +import Quaternion : all; +import Vector3 : all; #ifndef SAC_BACKEND_MUTC import Color8: all; import List: all; From 9c5561ad031127ac156471d92981ed8e8c27f1b2 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Wed, 13 Nov 2024 09:19:37 +0100 Subject: [PATCH 07/10] Add DxS and SxD variants for Vector3 --- src/structures/Vector3.sac | 42 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/src/structures/Vector3.sac b/src/structures/Vector3.sac index 2ccbc733..091090b2 100644 --- a/src/structures/Vector3.sac +++ b/src/structures/Vector3.sac @@ -90,13 +90,31 @@ name (struct Vector3 a, struct Vector3 b) \ return Vector3{ op (a.x, b.x), op (a.y, b.y), op (a.z, b.z) }; \ } +#define VEC3D_BIN_SxD(name, op) \ +inline struct Vector3 \ +name (struct Vector3 a, double b) \ +{ \ + return Vector3{ op (a.x, b), op (a.y, b), op (a.z, b) }; \ +} + + +#define VEC3D_BIN_DxS(name, op) \ +inline struct Vector3 \ +name (double a, struct Vector3 b) \ +{ \ + return Vector3{ op (a, b.x), op (a, b.y), op (a, b.z) }; \ +} + + #define VEC3D_BIN(name, op) \ VEC3D_BIN_AxA(name, op) \ VEC3D_BIN_AxS(name, op) \ VEC3D_BIN_SxA(name, op) \ VEC3D_BIN_AxD(name, op) \ VEC3D_BIN_DxA(name, op) \ -VEC3D_BIN_SxS(name, op) +VEC3D_BIN_SxS(name, op) \ +VEC3D_BIN_SxD(name, op) \ +VEC3D_BIN_DxS(name, op) VEC3D_BIN(+, _add_SxS_) VEC3D_BIN(-, _sub_SxS_) @@ -209,13 +227,33 @@ name (struct Vector3 a, struct Vector3 b) \ op (a.z, b.z))); \ } +#define VEC3D_EQ_SxD(name, op, and_or) \ +inline bool \ +name (struct Vector3 a, double b) \ +{ \ + return and_or (op (a.x, b), \ + and_or (op (a.y, b), \ + op (a.z, b))); \ +} + +#define VEC3D_EQ_DxS(name, op, and_or) \ +inline bool \ +name (double a, struct Vector3 b) \ +{ \ + return and_or (op (a, b.x), \ + and_or (op (a, b.y), \ + op (a, b.z))); \ +} + #define VEC3D_EQ(name, op, and_or) \ VEC3D_EQ_AxA(name, op, and_or) \ VEC3D_EQ_AxS(name, op, and_or) \ VEC3D_EQ_SxA(name, op, and_or) \ VEC3D_EQ_AxD(name, op, and_or) \ VEC3D_EQ_DxA(name, op, and_or) \ -VEC3D_EQ_SxS(name, op, and_or) +VEC3D_EQ_SxS(name, op, and_or) \ +VEC3D_EQ_SxD(name, op, and_or) \ +VEC3D_EQ_DxS(name, op, and_or) VEC3D_EQ(==, _eq_SxS_, _and_SxS_) VEC3D_EQ(!=, _neq_SxS_, _or_SxS_ ) From 7ca603843c8d44bc2b66f8f33c6514472f1f84e1 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Tue, 7 Jan 2025 11:38:09 +0100 Subject: [PATCH 08/10] add float variant of vector3 --- cmake/sac-core-ext.txt | 1 + src/structures/Structures.sac | 1 + src/structures/Vector3.mac | 241 +++++++++++++++++++++++++++++++ src/structures/Vector3.sac | 262 +--------------------------------- src/structures/Vector3f.sac | 5 + 5 files changed, 252 insertions(+), 258 deletions(-) create mode 100644 src/structures/Vector3.mac create mode 100644 src/structures/Vector3f.sac diff --git a/cmake/sac-core-ext.txt b/cmake/sac-core-ext.txt index 8054eacf..acfde798 100644 --- a/cmake/sac-core-ext.txt +++ b/cmake/sac-core-ext.txt @@ -48,6 +48,7 @@ structures/ComplexBasics.sac Ext structures/Complex.sac Ext structures/Quaternion.sac Ext structures/Vector3.sac Ext +structures/Vector3f.sac Ext structures/Char.sac Core structures/Bits.sac Core structures/String.sac Core diff --git a/src/structures/Structures.sac b/src/structures/Structures.sac index e8c56edf..a7bfdc71 100644 --- a/src/structures/Structures.sac +++ b/src/structures/Structures.sac @@ -8,6 +8,7 @@ import String: all; import Complex : all; import Quaternion : all; import Vector3 : all; +import Vector3f : all; #ifndef SAC_BACKEND_MUTC import Color8: all; import List: all; diff --git a/src/structures/Vector3.mac b/src/structures/Vector3.mac new file mode 100644 index 00000000..44b0cb85 --- /dev/null +++ b/src/structures/Vector3.mac @@ -0,0 +1,241 @@ +module VECTOR3; + +export all; + +struct VECTOR3 { + REAL x; + REAL y; + REAL z; +}; + +inline REAL +l2norm(struct VECTOR3 v) +{ + x = _mul_SxS_(v.x, v.x); + y = _mul_SxS_(v.y, v.y); + z = _mul_SxS_(v.z, v.z); + return Math::sqrt(_add_SxS_(_add_SxS_(x, y), z)); +} + +/****************************************************************************** + * + * Binary operations + * + ******************************************************************************/ + +#define VEC3D_BIN_AxA(name, op) \ +inline struct VECTOR3[d:shp] \ +name(struct VECTOR3[d:shp] a, struct VECTOR3[d:shp] b) \ +{ \ + return { iv -> VECTOR3 { op(_sel_VxA_(iv, a).x, _sel_VxA_(iv, b).x), \ + op(_sel_VxA_(iv, a).y, _sel_VxA_(iv, b).y), \ + op(_sel_VxA_(iv, a).z, _sel_VxA_(iv, b).z) } }; \ +} + +#define VEC3D_BIN_AxS(name, op) \ +inline struct VECTOR3[d:shp] \ +name(struct VECTOR3[d:shp] a, struct VECTOR3 b) \ +{ \ + return { iv -> VECTOR3 { op(_sel_VxA_(iv, a).x, b.x), \ + op(_sel_VxA_(iv, a).y, b.y), \ + op(_sel_VxA_(iv, a).z, b.z) } }; \ +} + +#define VEC3D_BIN_SxA(name, op) \ +inline struct VECTOR3[d:shp] \ +name(struct VECTOR3 a, struct VECTOR3[d:shp] b) \ +{ \ + return { iv -> VECTOR3 { op(a.x, _sel_VxA_(iv, b).x), \ + op(a.y, _sel_VxA_(iv, b).y), \ + op(a.z, _sel_VxA_(iv, b).z) } }; \ +} + +#define VEC3D_BIN_AxD(name, op) \ +inline struct VECTOR3[d:shp] \ +name(struct VECTOR3[d:shp] a, REAL b) \ +{ \ + return { iv -> VECTOR3 { op(_sel_VxA_(iv, a).x, b), \ + op(_sel_VxA_(iv, a).y, b), \ + op(_sel_VxA_(iv, a).z, b) } }; \ +} + +#define VEC3D_BIN_DxA(name, op) \ +inline struct VECTOR3[d:shp] \ +name(REAL a, struct VECTOR3[d:shp] b) \ +{ \ + return { iv -> VECTOR3 { op(a, _sel_VxA_(iv, b).x), \ + op(a, _sel_VxA_(iv, b).y), \ + op(a, _sel_VxA_(iv, b).z) } }; \ +} + +#define VEC3D_BIN_SxS(name, op) \ +inline struct VECTOR3 \ +name(struct VECTOR3 a, struct VECTOR3 b) \ +{ \ + return VECTOR3 { op(a.x, b.x), op(a.y, b.y), op(a.z, b.z) }; \ +} + +#define VEC3D_BIN_SxD(name, op) \ +inline struct VECTOR3 \ +name(struct VECTOR3 a, REAL b) \ +{ \ + return VECTOR3 { op(a.x, b), op(a.y, b), op(a.z, b) }; \ +} + + +#define VEC3D_BIN_DxS(name, op) \ +inline struct VECTOR3 \ +name(REAL a, struct VECTOR3 b) \ +{ \ + return VECTOR3 { op(a, b.x), op(a, b.y), op(a, b.z) }; \ +} + + +#define VEC3D_BIN(name, op) \ +VEC3D_BIN_AxA(name, op) \ +VEC3D_BIN_AxS(name, op) \ +VEC3D_BIN_SxA(name, op) \ +VEC3D_BIN_AxD(name, op) \ +VEC3D_BIN_DxA(name, op) \ +VEC3D_BIN_SxS(name, op) \ +VEC3D_BIN_SxD(name, op) \ +VEC3D_BIN_DxS(name, op) + +VEC3D_BIN(+, _add_SxS_) +VEC3D_BIN(-, _sub_SxS_) +VEC3D_BIN(*, _mul_SxS_) +VEC3D_BIN(/, _div_SxS_) + +/****************************************************************************** + * + * Unary operations + * + ******************************************************************************/ + +#define VEC3D_UNARY_A(name, op) \ +inline struct VECTOR3[d:shp] \ +name(struct VECTOR3[d:shp] a) \ +{ \ + return { iv -> VECTOR3 { op(_sel_VxA_(iv, a).x), \ + op(_sel_VxA_(iv, a).y), \ + op(_sel_VxA_(iv, a).z) } }; \ +} + +#define VEC3D_UNARY_S(name, op) \ +inline struct VECTOR3 \ +name(struct VECTOR3 a) \ +{ \ + return VECTOR3{ op(a.x), op(a.y), op(a.z) }; \ +} + +#define VEC3D_UNARY(name, op) \ +VEC3D_UNARY_A(name, op) \ +VEC3D_UNARY_S(name, op) + +VEC3D_UNARY(-, _neg_S_) + +/****************************************************************************** + * + * Equality operations + * + ******************************************************************************/ + +#define VEC3D_EQ_AxA(name, op, and_or) \ +inline bool[d:shp] \ +name(struct VECTOR3[d:shp] a, struct VECTOR3[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_(0, shp) <= iv < shp) : \ + and_or(op(_sel_VxA_(iv, a).x, _sel_VxA_(iv, b).x), \ + and_or(op(_sel_VxA_(iv, a).y, _sel_VxA_(iv, b).y), \ + op(_sel_VxA_(iv, a).z, _sel_VxA_(iv, b).z))); \ + }: genarray(shp, true); \ +} + +#define VEC3D_EQ_AxS(name, op, and_or) \ +inline bool[d:shp] \ +name(struct VECTOR3[d:shp] a, struct VECTOR3 b) \ +{ \ + return with { \ + (_mul_SxV_(0, shp) <= iv < shp) : \ + and_or(op(_sel_VxA_(iv, a).x, b.x), \ + and_or(op(_sel_VxA_(iv, a).y, b.y), \ + op(_sel_VxA_(iv, a).z, b.z))); \ + }: genarray(shp, true); \ +} + +#define VEC3D_EQ_SxA(name, op, and_or) \ +inline bool[d:shp] \ +name(struct VECTOR3 a, struct VECTOR3[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_(0, shp) <= iv < shp) : \ + and_or(op(a.x, _sel_VxA_(iv, b).x), \ + and_or(op(a.y, _sel_VxA_(iv, b).y), \ + op(a.z, _sel_VxA_(iv, b).z))); \ + }: genarray(shp, true); \ +} + +#define VEC3D_EQ_AxD(name, op, and_or) \ +inline bool[d:shp] \ +name(struct VECTOR3[d:shp] a, REAL b) \ +{ \ + return with { \ + (_mul_SxV_(0, shp) <= iv < shp) : \ + and_or(op(_sel_VxA_(iv, a).x, b), \ + and_or(op(_sel_VxA_(iv, a).y, b), \ + op(_sel_VxA_(iv, a).z, b))); \ + }: genarray(shp, true); \ +} + +#define VEC3D_EQ_DxA(name, op, and_or) \ +inline bool[d:shp] \ +name(REAL a, struct VECTOR3[d:shp] b) \ +{ \ + return with { \ + (_mul_SxV_(0, shp) <= iv < shp) : \ + and_or(op(a, _sel_VxA_(iv, b).x), \ + and_or(op(a, _sel_VxA_(iv, b).y), \ + op(a, _sel_VxA_(iv, b).z))); \ + }: genarray(shp, true); \ +} + +#define VEC3D_EQ_SxS(name, op, and_or) \ +inline bool \ +name(struct VECTOR3 a, struct VECTOR3 b) \ +{ \ + return and_or(op(a.x, b.x), \ + and_or(op(a.y, b.y), \ + op(a.z, b.z))); \ +} + +#define VEC3D_EQ_SxD(name, op, and_or) \ +inline bool \ +name(struct VECTOR3 a, REAL b) \ +{ \ + return and_or(op(a.x, b), \ + and_or(op(a.y, b), \ + op(a.z, b))); \ +} + +#define VEC3D_EQ_DxS(name, op, and_or) \ +inline bool \ +name(REAL a, struct VECTOR3 b) \ +{ \ + return and_or(op(a, b.x), \ + and_or(op(a, b.y), \ + op(a, b.z))); \ +} + +#define VEC3D_EQ(name, op, and_or) \ +VEC3D_EQ_AxA(name, op, and_or) \ +VEC3D_EQ_AxS(name, op, and_or) \ +VEC3D_EQ_SxA(name, op, and_or) \ +VEC3D_EQ_AxD(name, op, and_or) \ +VEC3D_EQ_DxA(name, op, and_or) \ +VEC3D_EQ_SxS(name, op, and_or) \ +VEC3D_EQ_SxD(name, op, and_or) \ +VEC3D_EQ_DxS(name, op, and_or) + +VEC3D_EQ(==, _eq_SxS_, _and_SxS_) +VEC3D_EQ(!=, _neq_SxS_, _or_SxS_) diff --git a/src/structures/Vector3.sac b/src/structures/Vector3.sac index 091090b2..f40c14e2 100644 --- a/src/structures/Vector3.sac +++ b/src/structures/Vector3.sac @@ -1,259 +1,5 @@ -module Vector3; +#define VECTOR3 Vector3 +#define REAL double +#define ZERO 0d -export all; - -struct Vector3 { - double x; - double y; - double z; -}; - -inline double -l2norm (struct Vector3 v) -{ - x = _mul_SxS_ (v.x, v.x); - y = _mul_SxS_ (v.y, v.y); - z = _mul_SxS_ (v.z, v.z); - return Math::sqrt (_add_SxS_ (_add_SxS_ (x, y), z)); -} - -/****************************************************************************** - * - * Binary operations - * - ******************************************************************************/ - -#define VEC3D_BIN_AxA(name, op) \ -inline struct Vector3[d:shp] \ -name (struct Vector3[d:shp] a, struct Vector3[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vector3{ op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ - op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ - op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z) }; \ - } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ -} - -#define VEC3D_BIN_AxS(name, op) \ -inline struct Vector3[d:shp] \ -name (struct Vector3[d:shp] a, struct Vector3 b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vector3{ op (_sel_VxA_ (iv, a).x, b.x), \ - op (_sel_VxA_ (iv, a).y, b.y), \ - op (_sel_VxA_ (iv, a).z, b.z) }; \ - } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ -} - -#define VEC3D_BIN_SxA(name, op) \ -inline struct Vector3[d:shp] \ -name (struct Vector3 a, struct Vector3[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vector3{ op (a.x, _sel_VxA_ (iv, b).x), \ - op (a.y, _sel_VxA_ (iv, b).y), \ - op (a.z, _sel_VxA_ (iv, b).z) }; \ - } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ -} - -#define VEC3D_BIN_AxD(name, op) \ -inline struct Vector3[d:shp] \ -name (struct Vector3[d:shp] a, double b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vector3{ op (_sel_VxA_ (iv, a).x, b), \ - op (_sel_VxA_ (iv, a).y, b), \ - op (_sel_VxA_ (iv, a).z, b) }; \ - } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ -} - -#define VEC3D_BIN_DxA(name, op) \ -inline struct Vector3[d:shp] \ -name (double a, struct Vector3[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vector3{ op (a, _sel_VxA_ (iv, b).x), \ - op (a, _sel_VxA_ (iv, b).y), \ - op (a, _sel_VxA_ (iv, b).z) }; \ - } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ -} - -#define VEC3D_BIN_SxS(name, op) \ -inline struct Vector3 \ -name (struct Vector3 a, struct Vector3 b) \ -{ \ - return Vector3{ op (a.x, b.x), op (a.y, b.y), op (a.z, b.z) }; \ -} - -#define VEC3D_BIN_SxD(name, op) \ -inline struct Vector3 \ -name (struct Vector3 a, double b) \ -{ \ - return Vector3{ op (a.x, b), op (a.y, b), op (a.z, b) }; \ -} - - -#define VEC3D_BIN_DxS(name, op) \ -inline struct Vector3 \ -name (double a, struct Vector3 b) \ -{ \ - return Vector3{ op (a, b.x), op (a, b.y), op (a, b.z) }; \ -} - - -#define VEC3D_BIN(name, op) \ -VEC3D_BIN_AxA(name, op) \ -VEC3D_BIN_AxS(name, op) \ -VEC3D_BIN_SxA(name, op) \ -VEC3D_BIN_AxD(name, op) \ -VEC3D_BIN_DxA(name, op) \ -VEC3D_BIN_SxS(name, op) \ -VEC3D_BIN_SxD(name, op) \ -VEC3D_BIN_DxS(name, op) - -VEC3D_BIN(+, _add_SxS_) -VEC3D_BIN(-, _sub_SxS_) -VEC3D_BIN(*, _mul_SxS_) -VEC3D_BIN(/, _div_SxS_) - -/****************************************************************************** - * - * Unary operations - * - ******************************************************************************/ - -#define VEC3D_UNARY_A(name, op) \ -inline struct Vector3[d:shp] \ -name (struct Vector3[d:shp] a) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - Vector3{ op (_sel_VxA_ (iv, a).x), \ - op (_sel_VxA_ (iv, a).y), \ - op (_sel_VxA_ (iv, a).z) }; \ - } : genarray (shp, Vector3{ 0d, 0d, 0d }); \ -} - -#define VEC3D_UNARY_S(name, op) \ -inline struct Vector3 \ -name (struct Vector3 a) \ -{ \ - return Vector3{ op (a.x), op (a.y), op (a.z) }; \ -} - -#define VEC3D_UNARY(name, op) \ -VEC3D_UNARY_A(name, op) \ -VEC3D_UNARY_S(name, op) - -VEC3D_UNARY(-, _neg_S_) - -/****************************************************************************** - * - * Equality operations - * - ******************************************************************************/ - -#define VEC3D_EQ_AxA(name, op, and_or) \ -inline bool[d:shp] \ -name (struct Vector3[d:shp] a, struct Vector3[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - and_or (op (_sel_VxA_ (iv, a).x, _sel_VxA_ (iv, b).x), \ - and_or (op (_sel_VxA_ (iv, a).y, _sel_VxA_ (iv, b).y), \ - op (_sel_VxA_ (iv, a).z, _sel_VxA_ (iv, b).z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_AxS(name, op, and_or) \ -inline bool[d:shp] \ -name (struct Vector3[d:shp] a, struct Vector3 b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - and_or (op (_sel_VxA_ (iv, a).x, b.x), \ - and_or (op (_sel_VxA_ (iv, a).y, b.y), \ - op (_sel_VxA_ (iv, a).z, b.z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_SxA(name, op, and_or) \ -inline bool[d:shp] \ -name (struct Vector3 a, struct Vector3[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - and_or (op (a.x, _sel_VxA_ (iv, b).x), \ - and_or (op (a.y, _sel_VxA_ (iv, b).y), \ - op (a.z, _sel_VxA_ (iv, b).z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_AxD(name, op, and_or) \ -inline bool[d:shp] \ -name (struct Vector3[d:shp] a, double b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - and_or (op (_sel_VxA_ (iv, a).x, b), \ - and_or (op (_sel_VxA_ (iv, a).y, b), \ - op (_sel_VxA_ (iv, a).z, b))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_DxA(name, op, and_or) \ -inline bool[d:shp] \ -name (double a, struct Vector3[d:shp] b) \ -{ \ - return with { \ - (_mul_SxV_ (0, shp) <= iv < shp) : \ - and_or (op (a, _sel_VxA_ (iv, b).x), \ - and_or (op (a, _sel_VxA_ (iv, b).y), \ - op (a, _sel_VxA_ (iv, b).z))); \ - } : genarray (shp, true); \ -} - -#define VEC3D_EQ_SxS(name, op, and_or) \ -inline bool \ -name (struct Vector3 a, struct Vector3 b) \ -{ \ - return and_or (op (a.x, b.x), \ - and_or (op (a.y, b.y), \ - op (a.z, b.z))); \ -} - -#define VEC3D_EQ_SxD(name, op, and_or) \ -inline bool \ -name (struct Vector3 a, double b) \ -{ \ - return and_or (op (a.x, b), \ - and_or (op (a.y, b), \ - op (a.z, b))); \ -} - -#define VEC3D_EQ_DxS(name, op, and_or) \ -inline bool \ -name (double a, struct Vector3 b) \ -{ \ - return and_or (op (a, b.x), \ - and_or (op (a, b.y), \ - op (a, b.z))); \ -} - -#define VEC3D_EQ(name, op, and_or) \ -VEC3D_EQ_AxA(name, op, and_or) \ -VEC3D_EQ_AxS(name, op, and_or) \ -VEC3D_EQ_SxA(name, op, and_or) \ -VEC3D_EQ_AxD(name, op, and_or) \ -VEC3D_EQ_DxA(name, op, and_or) \ -VEC3D_EQ_SxS(name, op, and_or) \ -VEC3D_EQ_SxD(name, op, and_or) \ -VEC3D_EQ_DxS(name, op, and_or) - -VEC3D_EQ(==, _eq_SxS_, _and_SxS_) -VEC3D_EQ(!=, _neq_SxS_, _or_SxS_ ) +#include "Vector3.mac" diff --git a/src/structures/Vector3f.sac b/src/structures/Vector3f.sac new file mode 100644 index 00000000..d83c1979 --- /dev/null +++ b/src/structures/Vector3f.sac @@ -0,0 +1,5 @@ +#define VECTOR3 Vector3f +#define REAL float +#define ZERO 0f + +#include "Vector3.mac" From d04e0dacb407ec68bc470566e0e125e9e9669349 Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Tue, 7 Jan 2025 22:18:07 +0100 Subject: [PATCH 09/10] add missing undefs --- src/structures/Vector3.sac | 4 ++++ src/structures/Vector3f.sac | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/src/structures/Vector3.sac b/src/structures/Vector3.sac index f40c14e2..a0c37754 100644 --- a/src/structures/Vector3.sac +++ b/src/structures/Vector3.sac @@ -3,3 +3,7 @@ #define ZERO 0d #include "Vector3.mac" + +#undef VECTOR3 +#undef REAL +#undef ZERO diff --git a/src/structures/Vector3f.sac b/src/structures/Vector3f.sac index d83c1979..ee7da200 100644 --- a/src/structures/Vector3f.sac +++ b/src/structures/Vector3f.sac @@ -3,3 +3,7 @@ #define ZERO 0f #include "Vector3.mac" + +#undef VECTOR3 +#undef REAL +#undef ZERO From 59dced7916033121e28fb4c6c15197648742f22b Mon Sep 17 00:00:00 2001 From: Jordy Aaldering Date: Thu, 13 Feb 2025 10:43:45 +0100 Subject: [PATCH 10/10] Fix spacing --- src/structures/Structures.sac | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/structures/Structures.sac b/src/structures/Structures.sac index a7bfdc71..1925ad00 100644 --- a/src/structures/Structures.sac +++ b/src/structures/Structures.sac @@ -5,10 +5,10 @@ import Bits: all; import Char: all; import String: all; #ifdef EXT_STDLIB -import Complex : all; -import Quaternion : all; -import Vector3 : all; -import Vector3f : all; +import Complex: all; +import Quaternion: all; +import Vector3: all; +import Vector3f: all; #ifndef SAC_BACKEND_MUTC import Color8: all; import List: all;