diff --git a/basic-geometry/affine2.c b/basic-geometry/affine2.c index 9810d0a..e40bef6 100644 --- a/basic-geometry/affine2.c +++ b/basic-geometry/affine2.c @@ -1,4 +1,4 @@ -#include "affine2.h" +#include "./affine2.h" extern inline void bgc_fp32_affine2_reset(BGC_FP32_Affine2* affine); extern inline void bgc_fp64_affine2_reset(BGC_FP64_Affine2* affine); diff --git a/basic-geometry/affine2.h b/basic-geometry/affine2.h index e0b6ff0..d75e978 100644 --- a/basic-geometry/affine2.h +++ b/basic-geometry/affine2.h @@ -1,21 +1,9 @@ #ifndef _BGC_AFFINE2_H_INCLUDED_ #define _BGC_AFFINE2_H_INCLUDED_ -#include "vector2.h" -#include "matrices.h" -#include "matrix2x2.h" - -// ==================== Types ==================== // - -typedef struct { - BGC_FP32_Matrix2x2 distortion; - BGC_FP32_Vector2 shift; -} BGC_FP32_Affine2; - -typedef struct { - BGC_FP64_Matrix2x2 distortion; - BGC_FP64_Vector2 shift; -} BGC_FP64_Affine2; +#include "./vector2.h" +#include "./types.h" +#include "./matrix2x2.h" // ==================== Reset ==================== // @@ -96,7 +84,7 @@ inline int bgc_fp32_affine2_invert(BGC_FP32_Affine2 * affine) return BGC_FAILURE; } - bgc_fp32_multiply_matrix2x2_by_vector2(&affine->shift, &affine->distortion, &affine->shift); + bgc_fp32_matrix2x2_multiply_by_vector2(&affine->shift, &affine->distortion, &affine->shift); bgc_fp32_vector2_revert(&affine->shift); return BGC_SUCCESS; @@ -108,7 +96,7 @@ inline int bgc_fp64_affine2_invert(BGC_FP64_Affine2 * affine) return BGC_FAILURE; } - bgc_fp64_multiply_matrix2x2_by_vector2(&affine->shift, &affine->distortion, &affine->shift); + bgc_fp64_matrix2x2_multiply_by_vector2(&affine->shift, &affine->distortion, &affine->shift); bgc_fp64_vector2_revert(&affine->shift); return BGC_SUCCESS; @@ -122,7 +110,7 @@ inline int bgc_fp32_affine2_get_inverse(BGC_FP32_Affine2* inverse, const BGC_FP3 return BGC_FAILURE; } - bgc_fp32_multiply_matrix2x2_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift); + bgc_fp32_matrix2x2_multiply_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift); bgc_fp32_vector2_revert(&inverse->shift); return BGC_SUCCESS; @@ -134,7 +122,7 @@ inline int bgc_fp64_affine2_get_inverse(BGC_FP64_Affine2* inverse, const BGC_FP6 return BGC_FAILURE; } - bgc_fp64_multiply_matrix2x2_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift); + bgc_fp64_matrix2x2_multiply_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift); bgc_fp64_vector2_revert(&inverse->shift); return BGC_SUCCESS; @@ -145,16 +133,16 @@ inline int bgc_fp64_affine2_get_inverse(BGC_FP64_Affine2* inverse, const BGC_FP6 inline void bgc_fp32_affine2_combine(BGC_FP32_Affine2* combination, const BGC_FP32_Affine2 * first, const BGC_FP32_Affine2 * second) { BGC_FP32_Vector2 first_shift; - bgc_fp32_multiply_matrix2x2_by_vector2(&first_shift, &second->distortion, &first->shift); - bgc_fp32_multiply_matrix2x2_by_matrix2x2(&combination->distortion, &second->distortion, &first->distortion); + bgc_fp32_matrix2x2_multiply_by_vector2(&first_shift, &second->distortion, &first->shift); + bgc_fp32_matrix2x2_multiply_by_matrix2x2(&combination->distortion, &second->distortion, &first->distortion); bgc_fp32_vector2_add(&combination->shift, &second->shift, &first_shift); } inline void bgc_fp64_affine2_combine(BGC_FP64_Affine2* combination, const BGC_FP64_Affine2 * first, const BGC_FP64_Affine2 * second) { BGC_FP64_Vector2 first_shift; - bgc_fp64_multiply_matrix2x2_by_vector2(&first_shift, &second->distortion, &first->shift); - bgc_fp64_multiply_matrix2x2_by_matrix2x2(&combination->distortion, &second->distortion, &first->distortion); + bgc_fp64_matrix2x2_multiply_by_vector2(&first_shift, &second->distortion, &first->shift); + bgc_fp64_matrix2x2_multiply_by_matrix2x2(&combination->distortion, &second->distortion, &first->distortion); bgc_fp64_vector2_add(&combination->shift, &second->shift, &first_shift); } @@ -163,14 +151,14 @@ inline void bgc_fp64_affine2_combine(BGC_FP64_Affine2* combination, const BGC_FP inline void bgc_fp32_affine2_transform_point(BGC_FP32_Vector2* transformed_point, const BGC_FP32_Affine2 * affine, const BGC_FP32_Vector2 * initial_point) { BGC_FP32_Vector2 distorted; - bgc_fp32_multiply_matrix2x2_by_vector2(&distorted, &affine->distortion, initial_point); + bgc_fp32_matrix2x2_multiply_by_vector2(&distorted, &affine->distortion, initial_point); bgc_fp32_vector2_add(transformed_point, &affine->shift, &distorted); } inline void bgc_fp64_affine2_transform_point(BGC_FP64_Vector2* transformed_point, const BGC_FP64_Affine2 * affine, const BGC_FP64_Vector2 * initial_point) { BGC_FP64_Vector2 distorted; - bgc_fp64_multiply_matrix2x2_by_vector2(&distorted, &affine->distortion, initial_point); + bgc_fp64_matrix2x2_multiply_by_vector2(&distorted, &affine->distortion, initial_point); bgc_fp64_vector2_add(transformed_point, &affine->shift, &distorted); } @@ -178,12 +166,12 @@ inline void bgc_fp64_affine2_transform_point(BGC_FP64_Vector2* transformed_point inline void bgc_fp32_affine2_transform_vector(BGC_FP32_Vector2* transformed_vector, const BGC_FP32_Affine2 * affine, const BGC_FP32_Vector2 * initial_vector) { - bgc_fp32_multiply_matrix2x2_by_vector2(transformed_vector, &affine->distortion, initial_vector); + bgc_fp32_matrix2x2_multiply_by_vector2(transformed_vector, &affine->distortion, initial_vector); } inline void bgc_fp64_affine2_transform_vector(BGC_FP64_Vector2* transformed_vector, const BGC_FP64_Affine2 * affine, const BGC_FP64_Vector2 * initial_vector) { - bgc_fp64_multiply_matrix2x2_by_vector2(transformed_vector, &affine->distortion, initial_vector); + bgc_fp64_matrix2x2_multiply_by_vector2(transformed_vector, &affine->distortion, initial_vector); } #endif diff --git a/basic-geometry/affine3.c b/basic-geometry/affine3.c index 70ad5b5..37ac046 100644 --- a/basic-geometry/affine3.c +++ b/basic-geometry/affine3.c @@ -1,4 +1,4 @@ -#include "affine3.h" +#include "./affine3.h" extern inline void bgc_fp32_affine3_reset(BGC_FP32_Affine3* affine); extern inline void bgc_fp64_affine3_reset(BGC_FP64_Affine3* affine); diff --git a/basic-geometry/affine3.h b/basic-geometry/affine3.h index 172c9e6..c54ebb6 100644 --- a/basic-geometry/affine3.h +++ b/basic-geometry/affine3.h @@ -1,21 +1,9 @@ #ifndef _BGC_AFFINE3_H_INCLUDED_ #define _BGC_AFFINE3_H_INCLUDED_ -#include "vector3.h" -#include "matrices.h" -#include "matrix3x3.h" - -// ==================== Types ==================== // - -typedef struct { - BGC_FP32_Matrix3x3 distortion; - BGC_FP32_Vector3 shift; -} BGC_FP32_Affine3; - -typedef struct { - BGC_FP64_Matrix3x3 distortion; - BGC_FP64_Vector3 shift; -} BGC_FP64_Affine3; +#include "./vector3.h" +#include "./types.h" +#include "./matrix3x3.h" // ==================== Reset ==================== // @@ -95,7 +83,7 @@ inline int bgc_fp32_affine3_invert(BGC_FP32_Affine3 * affine) return BGC_FAILURE; } - bgc_fp32_multiply_matrix3x3_by_vector3(&affine->shift, &affine->distortion, &affine->shift); + bgc_fp32_matrix3x3_multiply_by_vector3(&affine->shift, &affine->distortion, &affine->shift); bgc_fp32_vector3_revert(&affine->shift); return BGC_SUCCESS; @@ -107,7 +95,7 @@ inline int bgc_fp64_affine3_invert(BGC_FP64_Affine3 * affine) return BGC_FAILURE; } - bgc_fp64_multiply_matrix3x3_by_vector3(&affine->shift, &affine->distortion, &affine->shift); + bgc_fp64_matrix3x3_multiply_by_vector3(&affine->shift, &affine->distortion, &affine->shift); bgc_fp64_vector3_revert(&affine->shift); return BGC_SUCCESS; @@ -121,7 +109,7 @@ inline int bgc_fp32_affine3_get_inverse(BGC_FP32_Affine3* destination, const BGC return BGC_FAILURE; } - bgc_fp32_multiply_matrix3x3_by_vector3(&destination->shift, &destination->distortion, &source->shift); + bgc_fp32_matrix3x3_multiply_by_vector3(&destination->shift, &destination->distortion, &source->shift); bgc_fp32_vector3_revert(&destination->shift); return BGC_SUCCESS; @@ -133,7 +121,7 @@ inline int bgc_fp64_affine3_get_inverse(BGC_FP64_Affine3* destination, const BGC return BGC_FAILURE; } - bgc_fp64_multiply_matrix3x3_by_vector3(&destination->shift, &destination->distortion, &source->shift); + bgc_fp64_matrix3x3_multiply_by_vector3(&destination->shift, &destination->distortion, &source->shift); bgc_fp64_vector3_revert(&destination->shift); return BGC_SUCCESS; @@ -144,16 +132,16 @@ inline int bgc_fp64_affine3_get_inverse(BGC_FP64_Affine3* destination, const BGC inline void bgc_fp32_affine3_combine(BGC_FP32_Affine3* combination, const BGC_FP32_Affine3 * first, const BGC_FP32_Affine3 * second) { BGC_FP32_Vector3 first_shift; - bgc_fp32_multiply_matrix3x3_by_vector3(&first_shift, &second->distortion, &first->shift); - bgc_fp32_multiply_matrix3x3_by_matrix3x3(&combination->distortion, &second->distortion, &first->distortion); + bgc_fp32_matrix3x3_multiply_by_vector3(&first_shift, &second->distortion, &first->shift); + bgc_fp32_matrix3x3_multiply_by_matrix3x3(&combination->distortion, &second->distortion, &first->distortion); bgc_fp32_vector3_add(&combination->shift, &first_shift, &second->shift); } inline void bgc_fp64_affine3_combine(BGC_FP64_Affine3* combination, const BGC_FP64_Affine3 * first, const BGC_FP64_Affine3 * second) { BGC_FP64_Vector3 first_shift; - bgc_fp64_multiply_matrix3x3_by_vector3(&first_shift, &second->distortion, &first->shift); - bgc_fp64_multiply_matrix3x3_by_matrix3x3(&combination->distortion, &second->distortion, &first->distortion); + bgc_fp64_matrix3x3_multiply_by_vector3(&first_shift, &second->distortion, &first->shift); + bgc_fp64_matrix3x3_multiply_by_matrix3x3(&combination->distortion, &second->distortion, &first->distortion); bgc_fp64_vector3_add(&combination->shift, &first_shift, &second->shift); } @@ -162,14 +150,14 @@ inline void bgc_fp64_affine3_combine(BGC_FP64_Affine3* combination, const BGC_FP inline void bgc_fp32_affine3_transform_point(BGC_FP32_Vector3* transformed_point, const BGC_FP32_Affine3 * affine, const BGC_FP32_Vector3 * initial_point) { BGC_FP32_Vector3 distorted; - bgc_fp32_multiply_matrix3x3_by_vector3(&distorted, &affine->distortion, initial_point); + bgc_fp32_matrix3x3_multiply_by_vector3(&distorted, &affine->distortion, initial_point); bgc_fp32_vector3_add(transformed_point, &affine->shift, &distorted); } inline void bgc_fp64_affine3_transform_point(BGC_FP64_Vector3* transformed_point, const BGC_FP64_Affine3 * affine, const BGC_FP64_Vector3 * initial_point) { BGC_FP64_Vector3 distorted; - bgc_fp64_multiply_matrix3x3_by_vector3(&distorted, &affine->distortion, initial_point); + bgc_fp64_matrix3x3_multiply_by_vector3(&distorted, &affine->distortion, initial_point); bgc_fp64_vector3_add(transformed_point, &affine->shift, &distorted); } @@ -177,12 +165,12 @@ inline void bgc_fp64_affine3_transform_point(BGC_FP64_Vector3* transformed_point inline void bgc_fp32_affine3_transform_vector(BGC_FP32_Vector3* transformed_vector, const BGC_FP32_Affine3 * affine, const BGC_FP32_Vector3 * initial_vector) { - bgc_fp32_multiply_matrix3x3_by_vector3(transformed_vector, &affine->distortion, initial_vector); + bgc_fp32_matrix3x3_multiply_by_vector3(transformed_vector, &affine->distortion, initial_vector); } inline void bgc_fp64_affine3_transform_vector(BGC_FP64_Vector3* transformed_vector, const BGC_FP64_Affine3 * affine, const BGC_FP64_Vector3 * initial_vector) { - bgc_fp64_multiply_matrix3x3_by_vector3(transformed_vector, &affine->distortion, initial_vector); + bgc_fp64_matrix3x3_multiply_by_vector3(transformed_vector, &affine->distortion, initial_vector); } #endif diff --git a/basic-geometry/angle.c b/basic-geometry/angle.c index 2f9798f..16360c3 100644 --- a/basic-geometry/angle.c +++ b/basic-geometry/angle.c @@ -1,5 +1,5 @@ -#include "utilities.h" -#include "angle.h" +#include "./utilities.h" +#include "./angle.h" // !================= Radians ==================! // diff --git a/basic-geometry/angle.h b/basic-geometry/angle.h index 81bc004..69ebaa7 100644 --- a/basic-geometry/angle.h +++ b/basic-geometry/angle.h @@ -2,7 +2,7 @@ #define _BGC_ANGLE_H_INCLUDED_ #include -#include "utilities.h" +#include "./utilities.h" #define BGC_FP32_PI 3.1415926536f #define BGC_FP32_TWO_PI 6.2831853072f diff --git a/basic-geometry/basic-geometry.h b/basic-geometry/basic-geometry.h index e8c4598..5384baa 100644 --- a/basic-geometry/basic-geometry.h +++ b/basic-geometry/basic-geometry.h @@ -5,10 +5,11 @@ #include "./angle.h" +#include "./types.h" + #include "./vector2.h" #include "./vector3.h" -#include "./matrices.h" #include "./matrix2x2.h" #include "./matrix2x3.h" #include "./matrix3x2.h" diff --git a/basic-geometry/basic-geometry.vcxproj b/basic-geometry/basic-geometry.vcxproj index f392d21..02dec81 100644 --- a/basic-geometry/basic-geometry.vcxproj +++ b/basic-geometry/basic-geometry.vcxproj @@ -33,7 +33,7 @@ - + @@ -63,7 +63,6 @@ - diff --git a/basic-geometry/basic-geometry.vcxproj.filters b/basic-geometry/basic-geometry.vcxproj.filters index 1163028..f25fcbd 100644 --- a/basic-geometry/basic-geometry.vcxproj.filters +++ b/basic-geometry/basic-geometry.vcxproj.filters @@ -48,7 +48,7 @@ Файлы заголовков - + Файлы заголовков @@ -113,9 +113,6 @@ Исходные файлы - - Исходные файлы - Исходные файлы diff --git a/basic-geometry/complex.h b/basic-geometry/complex.h index a3ee423..417bb84 100644 --- a/basic-geometry/complex.h +++ b/basic-geometry/complex.h @@ -1,20 +1,11 @@ #ifndef _BGC_COMPLEX_H_INCLUDED_ #define _BGC_COMPLEX_H_INCLUDED_ -#include "utilities.h" -#include "angle.h" - #include -typedef struct -{ - float real, imaginary; -} BGC_FP32_Complex; - -typedef struct -{ - double real, imaginary; -} BGC_FP64_Complex; +#include "./utilities.h" +#include "./types.h" +#include "./angle.h" // =================== Reset ==================== // diff --git a/basic-geometry/dual-number.c b/basic-geometry/dual-number.c index 665226a..fb9cfed 100644 --- a/basic-geometry/dual-number.c +++ b/basic-geometry/dual-number.c @@ -1,4 +1,4 @@ -#include "dual-number.h" +#include "./dual-number.h" extern inline void bgc_fp32_dual_number_reset(BGC_FP32_DualNumber* number); extern inline void bgc_fp64_dual_number_reset(BGC_FP64_DualNumber* number); diff --git a/basic-geometry/dual-number.h b/basic-geometry/dual-number.h index b94f287..41a4840 100644 --- a/basic-geometry/dual-number.h +++ b/basic-geometry/dual-number.h @@ -1,17 +1,8 @@ #ifndef _BGC_DUAL_NUMBER_H_INCLUDED_ #define _BGC_DUAL_NUMBER_H_INCLUDED_ -#include "utilities.h" - -// =================== Types ==================== // - -typedef struct { - float real, dual; -} BGC_FP32_DualNumber; - -typedef struct { - double real, dual; -} BGC_FP64_DualNumber; +#include "./utilities.h" +#include "./types.h" // =================== Reset ==================== // diff --git a/basic-geometry/dual-quaternion.c b/basic-geometry/dual-quaternion.c index 89ae825..b3e7dc0 100644 --- a/basic-geometry/dual-quaternion.c +++ b/basic-geometry/dual-quaternion.c @@ -1,4 +1,4 @@ -#include "dual-quaternion.h" +#include "./dual-quaternion.h" extern inline void bgc_fp32_dual_quaternion_reset(BGC_FP32_DualQuaternion* quaternion); extern inline void bgc_fp64_dual_quaternion_reset(BGC_FP64_DualQuaternion* quaternion); diff --git a/basic-geometry/dual-quaternion.h b/basic-geometry/dual-quaternion.h index 7ef4bd5..8ac3236 100644 --- a/basic-geometry/dual-quaternion.h +++ b/basic-geometry/dual-quaternion.h @@ -1,17 +1,8 @@ #ifndef _BGC_DUAL_QUATERNION_H_INCLUDED_ #define _BGC_DUAL_QUATERNION_H_INCLUDED_ -#include "quaternion.h" - -// =================== Types ==================== // - -typedef struct { - BGC_FP32_Quaternion real, dual; -} BGC_FP32_DualQuaternion; - -typedef struct { - BGC_FP64_Quaternion real, dual; -} BGC_FP64_DualQuaternion; +#include "./types.h" +#include "./quaternion.h" // =================== Reset ==================== // diff --git a/basic-geometry/dual-vector3.h b/basic-geometry/dual-vector3.h index ca5db35..324274c 100644 --- a/basic-geometry/dual-vector3.h +++ b/basic-geometry/dual-vector3.h @@ -1,18 +1,9 @@ #ifndef _BGC_DUAL_VECTOR3_H_INCLUDED_ #define _BGC_DUAL_VECTOR3_H_INCLUDED_ +#include "./types.h" #include "./vector3.h" -// =================== Types ==================== // - -typedef struct { - BGC_FP32_Vector3 real, dual; -} BGC_FP32_DualVector3; - -typedef struct { - BGC_FP64_Vector3 real, dual; -} BGC_FP64_DualVector3; - // =================== Reset ==================== // inline void bgc_fp32_dual_vector3_reset(BGC_FP32_DualVector3* vector) @@ -147,14 +138,14 @@ inline void bgc_fp64_dual_vector3_subtract(BGC_FP64_DualVector3* difference, con inline void bgc_fp32_dual_vector3_multiply(BGC_FP32_DualVector3* product, const BGC_FP32_DualVector3* multiplicand, const float multiplier) { - bgc_fp32_vector3_multiply(&product->real, &multiplicand->real, multiplier); - bgc_fp32_vector3_multiply(&product->dual, &multiplicand->dual, multiplier); + bgc_fp32_vector3_multiply_by_real(&product->real, &multiplicand->real, multiplier); + bgc_fp32_vector3_multiply_by_real(&product->dual, &multiplicand->dual, multiplier); } inline void bgc_fp64_dual_vector3_multiply(BGC_FP64_DualVector3* product, const BGC_FP64_DualVector3* multiplicand, const double multiplier) { - bgc_fp64_vector3_multiply(&product->real, &multiplicand->real, multiplier); - bgc_fp64_vector3_multiply(&product->dual, &multiplicand->dual, multiplier); + bgc_fp64_vector3_multiply_by_real(&product->real, &multiplicand->real, multiplier); + bgc_fp64_vector3_multiply_by_real(&product->dual, &multiplicand->dual, multiplier); } // =================== Divide =================== // @@ -167,8 +158,8 @@ inline int bgc_fp32_dual_vector3_divide(BGC_FP32_DualVector3* quotient, const BG const float multiplier = 1.0f / divisor; - bgc_fp32_vector3_multiply("ient->real, ÷nd->real, multiplier); - bgc_fp32_vector3_multiply("ient->dual, ÷nd->dual, multiplier); + bgc_fp32_vector3_multiply_by_real("ient->real, ÷nd->real, multiplier); + bgc_fp32_vector3_multiply_by_real("ient->dual, ÷nd->dual, multiplier); return BGC_SUCCESS; } @@ -181,8 +172,8 @@ inline int bgc_fp64_dual_vector3_divide(BGC_FP64_DualVector3* quotient, const BG const double multiplier = 1.0 / divisor; - bgc_fp64_vector3_multiply("ient->real, ÷nd->real, multiplier); - bgc_fp64_vector3_multiply("ient->dual, ÷nd->dual, multiplier); + bgc_fp64_vector3_multiply_by_real("ient->real, ÷nd->real, multiplier); + bgc_fp64_vector3_multiply_by_real("ient->dual, ÷nd->dual, multiplier); return BGC_SUCCESS; } diff --git a/basic-geometry/hg-matrix3x3.c b/basic-geometry/hg-matrix3x3.c index af76aa4..e0155ee 100644 --- a/basic-geometry/hg-matrix3x3.c +++ b/basic-geometry/hg-matrix3x3.c @@ -1,4 +1,4 @@ -#include "hg-matrix3x3.h" +#include "./hg-matrix3x3.h" inline void bgc_fp32_hg_matrix3x3_reset(BGC_FP32_HgMatrix3x3* homogeneous_matrix); inline void bgc_fp64_hg_matrix3x3_reset(BGC_FP64_HgMatrix3x3* homogeneous_matrix); diff --git a/basic-geometry/hg-matrix3x3.h b/basic-geometry/hg-matrix3x3.h index 340f598..9261acb 100644 --- a/basic-geometry/hg-matrix3x3.h +++ b/basic-geometry/hg-matrix3x3.h @@ -1,28 +1,10 @@ #ifndef _BGC_HG_MATRIX3X3_H_INCLUDED_ #define _BGC_HG_MATRIX3X3_H_INCLUDED_ -#include "vector3.h" -#include "matrices.h" +#include "./vector3.h" +#include "./types.h" -#include "hg-vector3.h" - -// =================== Types ==================== // - -typedef struct -{ - float r1c1, r1c2, r1c3, r1d0; - float r2c1, r2c2, r2c3, r2d0; - float r3c1, r3c2, r3c3, r3d0; - float d0c1, d0c2, d0c3, d0d0; -} BGC_FP32_HgMatrix3x3; - -typedef struct -{ - double r1c1, r1c2, r1c3, r1d0; - double r2c1, r2c2, r2c3, r2d0; - double r3c1, r3c2, r3c3, r3d0; - double d0c1, d0c2, d0c3, d0d0; -} BGC_FP64_HgMatrix3x3; +#include "./hg-vector3.h" // =================== Reset ==================== // diff --git a/basic-geometry/hg-vector3.h b/basic-geometry/hg-vector3.h index 573eaa1..47bf0e5 100644 --- a/basic-geometry/hg-vector3.h +++ b/basic-geometry/hg-vector3.h @@ -1,21 +1,8 @@ #ifndef _BGC_HG_VECTOR3_H_INCLUDED_ #define _BGC_HG_VECTOR3_H_INCLUDED_ -#include "./vector3.h" - -// ================== Vector3 =================== // - -// Homogeneous 3D Vector -typedef struct -{ - float x1, x2, x3, d0; -} BGC_FP32_HgVector3; - -// Homogeneous 3D Vector -typedef struct -{ - double x1, x2, x3, d0; -} BGC_FP64_HgVector3; +#include "./types.h" +#include "./utilities.h" // ================ Reset Point ================= // diff --git a/basic-geometry/matrices.c b/basic-geometry/matrices.c deleted file mode 100644 index 450f51a..0000000 --- a/basic-geometry/matrices.c +++ /dev/null @@ -1,25 +0,0 @@ -#include "matrices.h" - -extern inline void bgc_fp32_multiply_matrix2x2_by_matrix2x2(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix2x2* matrix2); -extern inline void bgc_fp64_multiply_matrix2x2_by_matrix2x2(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix2x2* matrix2); - -extern inline void bgc_fp32_multiply_matrix2x2_by_matrix3x2(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix3x2* matrix2); -extern inline void bgc_fp64_multiply_matrix2x2_by_matrix3x2(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix3x2* matrix2); - -extern inline void bgc_fp32_multiply_matrix2x3_by_matrix2x2(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix2x2* matrix2); -extern inline void bgc_fp64_multiply_matrix2x3_by_matrix2x2(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix2x2* matrix2); - -extern inline void bgc_fp32_multiply_matrix2x3_by_matrix3x2(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix3x2* matrix2); -extern inline void bgc_fp64_multiply_matrix2x3_by_matrix3x2(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix3x2* matrix2); - -extern inline void bgc_fp32_multiply_matrix3x2_by_matrix2x3(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix2x3* matrix2); -extern inline void bgc_fp64_multiply_matrix3x2_by_matrix2x3(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix2x3* matrix2); - -extern inline void bgc_fp32_multiply_matrix3x2_by_matrix3x3(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix3x3* matrix2); -extern inline void bgc_fp64_multiply_matrix3x2_by_matrix3x3(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix3x3* matrix2); - -extern inline void bgc_fp32_multiply_matrix3x3_by_matrix2x3(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix2x3* matrix2); -extern inline void bgc_fp64_multiply_matrix3x3_by_matrix2x3(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix2x3* matrix2); - -extern inline void bgc_fp32_multiply_matrix3x3_by_matrix3x3(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix3x3* matrix2); -extern inline void bgc_fp64_multiply_matrix3x3_by_matrix3x3(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix3x3* matrix2); diff --git a/basic-geometry/matrices.h b/basic-geometry/matrices.h deleted file mode 100644 index d500a33..0000000 --- a/basic-geometry/matrices.h +++ /dev/null @@ -1,364 +0,0 @@ -#ifndef _BGC_MATRICES_H_INCLUDED_ -#define _BGC_MATRICES_H_INCLUDED_ - -// ================== Matrix2x2 ================= // - -typedef struct { - float r1c1, r1c2; - float r2c1, r2c2; -} BGC_FP32_Matrix2x2; - -typedef struct { - double r1c1, r1c2; - double r2c1, r2c2; -} BGC_FP64_Matrix2x2; - -// ================== Matrix2x3 ================= // - -typedef struct { - float r1c1, r1c2; - float r2c1, r2c2; - float r3c1, r3c2; -} BGC_FP32_Matrix2x3; - -typedef struct { - double r1c1, r1c2; - double r2c1, r2c2; - double r3c1, r3c2; -} BGC_FP64_Matrix2x3; - -// ================== Matrix3x2 ================= // - -typedef struct { - float r1c1, r1c2, r1c3; - float r2c1, r2c2, r2c3; -} BGC_FP32_Matrix3x2; - -typedef struct { - double r1c1, r1c2, r1c3; - double r2c1, r2c2, r2c3; -} BGC_FP64_Matrix3x2; - -// ================== Matrix3x3 ================= // - -typedef struct { - float r1c1, r1c2, r1c3; - float r2c1, r2c2, r2c3; - float r3c1, r3c2, r3c3; -} BGC_FP32_Matrix3x3; - -typedef struct { - double r1c1, r1c2, r1c3; - double r2c1, r2c2, r2c3; - double r3c1, r3c2, r3c3; -} BGC_FP64_Matrix3x3; - -// ========== Matrix Product 2x2 at 2x2 ========= // - -inline void bgc_fp32_multiply_matrix2x2_by_matrix2x2(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix2x2* matrix2) -{ - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - - const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; -} - -inline void bgc_fp64_multiply_matrix2x2_by_matrix2x2(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix2x2* matrix2) -{ - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - - const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; -} - -// ========== Matrix Product 2x2 at 3x2 ========= // - -inline void bgc_fp32_multiply_matrix2x2_by_matrix3x2(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix3x2* matrix2) -{ - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; - - const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - product->r1c3 = r1c3; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - product->r2c3 = r2c3; -} - -inline void bgc_fp64_multiply_matrix2x2_by_matrix3x2(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix3x2* matrix2) -{ - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; - - const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - product->r1c3 = r1c3; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - product->r2c3 = r2c3; -} - -// ========== Matrix Product 2x3 at 2x2 ========= // - -inline void bgc_fp32_multiply_matrix2x3_by_matrix2x2(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix2x2* matrix2) -{ - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - - const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - - const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - - product->r3c1 = r3c1; - product->r3c2 = r3c2; -} - -inline void bgc_fp64_multiply_matrix2x3_by_matrix2x2(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix2x2* matrix2) -{ - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - - const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - - const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - - product->r3c1 = r3c1; - product->r3c2 = r3c2; -} - -// ========== Matrix Product 2x3 at 3x2 ========= // - -inline void bgc_fp32_multiply_matrix2x3_by_matrix3x2(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix3x2* matrix2) -{ - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - product->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; - - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - product->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; - - product->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - product->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; - product->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3; -} - -inline void bgc_fp64_multiply_matrix2x3_by_matrix3x2(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix3x2* matrix2) -{ - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; - product->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; - - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; - product->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; - - product->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; - product->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; - product->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3; -} - -// ========== Matrix Product 3x2 at 2x3 ========= // - -inline void bgc_fp32_multiply_matrix3x2_by_matrix2x3(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix2x3* matrix2) -{ - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; -} - -inline void bgc_fp64_multiply_matrix3x2_by_matrix2x3(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix2x3* matrix2) -{ - product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - - product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; -} - -// ========== Matrix Product 3x2 at 3x3 ========= // - -inline void bgc_fp32_multiply_matrix3x2_by_matrix3x3(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix3x3* matrix2) -{ - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; - - const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; - const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - product->r1c3 = r1c3; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - product->r2c3 = r2c3; -} - -inline void bgc_fp64_multiply_matrix3x2_by_matrix3x3(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix3x3* matrix2) -{ - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; - - const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; - const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - product->r1c3 = r1c3; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - product->r2c3 = r2c3; -} - -// ========== Matrix Product 3x3 at 2x3 ========= // - -inline void bgc_fp32_multiply_matrix3x3_by_matrix2x3(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix2x3* matrix2) -{ - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - - const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; - - const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; - const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - - product->r3c1 = r3c1; - product->r3c2 = r3c2; -} - -inline void bgc_fp64_multiply_matrix3x3_by_matrix2x3(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix2x3* matrix2) -{ - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - - const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; - - const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; - const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - - product->r3c1 = r3c1; - product->r3c2 = r3c2; -} - -// ========== Matrix Product 3x3 at 3x3 ========= // - -inline void bgc_fp32_multiply_matrix3x3_by_matrix3x3(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix3x3* matrix2) -{ - const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; - - const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; - const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; - - const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; - const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; - const float r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - product->r1c3 = r1c3; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - product->r2c3 = r2c3; - - product->r3c1 = r3c1; - product->r3c2 = r3c2; - product->r3c3 = r3c3; -} - -inline void bgc_fp64_multiply_matrix3x3_by_matrix3x3(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix3x3* matrix2) -{ - const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; - const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; - const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; - - const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; - const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; - const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; - - const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; - const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; - const double r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3; - - product->r1c1 = r1c1; - product->r1c2 = r1c2; - product->r1c3 = r1c3; - - product->r2c1 = r2c1; - product->r2c2 = r2c2; - product->r2c3 = r2c3; - - product->r3c1 = r3c1; - product->r3c2 = r3c2; - product->r3c3 = r3c3; -} - -#endif // _BGC_MATRIX_TYPES_H_ diff --git a/basic-geometry/matrix2x2.c b/basic-geometry/matrix2x2.c index bc36e7b..5218a68 100644 --- a/basic-geometry/matrix2x2.c +++ b/basic-geometry/matrix2x2.c @@ -1,4 +1,4 @@ -#include "matrix2x2.h" +#include "./matrix2x2.h" extern inline void bgc_fp32_matrix2x2_reset(BGC_FP32_Matrix2x2* matrix); extern inline void bgc_fp64_matrix2x2_reset(BGC_FP64_Matrix2x2* matrix); @@ -66,17 +66,20 @@ extern inline void bgc_fp64_matrix2x2_add_scaled(BGC_FP64_Matrix2x2* sum, const extern inline void bgc_fp32_matrix2x2_subtract(BGC_FP32_Matrix2x2* difference, const BGC_FP32_Matrix2x2* minuend, const BGC_FP32_Matrix2x2* subtrahend); extern inline void bgc_fp64_matrix2x2_subtract(BGC_FP64_Matrix2x2* difference, const BGC_FP64_Matrix2x2* minuend, const BGC_FP64_Matrix2x2* subtrahend); -extern inline void bgc_fp32_matrix2x2_multiply(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* multiplicand, const float multiplier); -extern inline void bgc_fp64_matrix2x2_multiply(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* multiplicand, const double multiplier); +extern inline void bgc_fp32_matrix2x2_multiply_by_real(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* multiplicand, const float multiplier); +extern inline void bgc_fp64_matrix2x2_multiply_by_real(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* multiplicand, const double multiplier); -extern inline int bgc_fp32_matrix2x2_divide(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor); -extern inline int bgc_fp64_matrix2x2_divide(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor); +extern inline void bgc_fp32_matrix2x2_multiply_by_vector2(BGC_FP32_Vector2* product, const BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Vector2* vector); +extern inline void bgc_fp64_matrix2x2_multiply_by_vector2(BGC_FP64_Vector2* product, const BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Vector2* vector); + +extern inline void bgc_fp32_matrix2x2_multiply_by_matrix2x2(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix2x2* matrix2); +extern inline void bgc_fp64_matrix2x2_multiply_by_matrix2x2(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix2x2* matrix2); + +extern inline void bgc_fp32_matrix2x2_multiply_by_matrix3x2(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix3x2* matrix2); +extern inline void bgc_fp64_matrix2x2_multiply_by_matrix3x2(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix3x2* matrix2); + +extern inline int bgc_fp32_matrix2x2_divide_by_real(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor); +extern inline int bgc_fp64_matrix2x2_divide_by_real(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor); extern inline void bgc_fp32_matrix2x2_interpolate(BGC_FP32_Matrix2x2* interpolation, const BGC_FP32_Matrix2x2* first, const BGC_FP32_Matrix2x2* second, const float phase); extern inline void bgc_fp64_matrix2x2_interpolate(BGC_FP64_Matrix2x2* interpolation, const BGC_FP64_Matrix2x2* first, const BGC_FP64_Matrix2x2* second, const double phase); - -extern inline void bgc_fp32_multiply_matrix2x2_by_vector2(BGC_FP32_Vector2* product, const BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Vector2* vector); -extern inline void bgc_fp64_multiply_matrix2x2_by_vector2(BGC_FP64_Vector2* product, const BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Vector2* vector); - -extern inline void bgc_fp32_multiply_vector2_by_matrix2x2(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix2x2* matrix); -extern inline void bgc_fp64_multiply_vector2_by_matrix2x2(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix2x2* matrix); diff --git a/basic-geometry/matrix2x2.h b/basic-geometry/matrix2x2.h index f6b86d3..a019478 100644 --- a/basic-geometry/matrix2x2.h +++ b/basic-geometry/matrix2x2.h @@ -1,9 +1,11 @@ #ifndef _BGC_MATRIX2X2_H_INCLUDED_ #define _BGC_MATRIX2X2_H_INCLUDED_ -#include "angle.h" -#include "vector2.h" -#include "matrices.h" +#include + +#include "./utilities.h" +#include "./types.h" +#include "./angle.h" // =================== Reset ==================== // @@ -537,7 +539,7 @@ inline void bgc_fp64_matrix2x2_subtract(BGC_FP64_Matrix2x2* difference, const BG // ================== Multiply ================== // -inline void bgc_fp32_matrix2x2_multiply(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* multiplicand, const float multiplier) +inline void bgc_fp32_matrix2x2_multiply_by_real(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* multiplicand, const float multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -546,7 +548,7 @@ inline void bgc_fp32_matrix2x2_multiply(BGC_FP32_Matrix2x2* product, const BGC_F product->r2c2 = multiplicand->r2c2 * multiplier; } -inline void bgc_fp64_matrix2x2_multiply(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* multiplicand, const double multiplier) +inline void bgc_fp64_matrix2x2_multiply_by_real(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* multiplicand, const double multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -555,25 +557,117 @@ inline void bgc_fp64_matrix2x2_multiply(BGC_FP64_Matrix2x2* product, const BGC_F product->r2c2 = multiplicand->r2c2 * multiplier; } +// ============ Right Vector Product ============ // + +inline void bgc_fp32_matrix2x2_multiply_by_vector2(BGC_FP32_Vector2* product, const BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Vector2* vector) +{ + const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; + const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + + product->x1 = x1; + product->x2 = x2; +} + +inline void bgc_fp64_matrix2x2_multiply_by_vector2(BGC_FP64_Vector2* product, const BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Vector2* vector) +{ + const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; + const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + + product->x1 = x1; + product->x2 = x2; +} + +// ========== Matrix Product 2x2 at 2x2 ========= // + +inline void bgc_fp32_matrix2x2_multiply_by_matrix2x2(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix2x2* matrix2) +{ + const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + + const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; +} + +inline void bgc_fp64_matrix2x2_multiply_by_matrix2x2(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix2x2* matrix2) +{ + const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + + const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; +} + +// ========== Matrix Product 2x2 at 3x2 ========= // + +inline void bgc_fp32_matrix2x2_multiply_by_matrix3x2(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix2x2* matrix1, const BGC_FP32_Matrix3x2* matrix2) +{ + const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; + + const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + product->r1c3 = r1c3; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + product->r2c3 = r2c3; +} + +inline void bgc_fp64_matrix2x2_multiply_by_matrix3x2(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix2x2* matrix1, const BGC_FP64_Matrix3x2* matrix2) +{ + const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; + + const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + product->r1c3 = r1c3; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + product->r2c3 = r2c3; +} + // =================== Divide =================== // -inline int bgc_fp32_matrix2x2_divide(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor) +inline int bgc_fp32_matrix2x2_divide_by_real(BGC_FP32_Matrix2x2* quotient, const BGC_FP32_Matrix2x2* dividend, const float divisor) { if (bgc_fp32_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp32_matrix2x2_multiply(quotient, dividend, 1.0f / divisor); + bgc_fp32_matrix2x2_multiply_by_real(quotient, dividend, 1.0f / divisor); return BGC_SUCCESS; } -inline int bgc_fp64_matrix2x2_divide(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor) +inline int bgc_fp64_matrix2x2_divide_by_real(BGC_FP64_Matrix2x2* quotient, const BGC_FP64_Matrix2x2* dividend, const double divisor) { if (bgc_fp64_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp64_matrix2x2_multiply(quotient, dividend, 1.0 / divisor); + bgc_fp64_matrix2x2_multiply_by_real(quotient, dividend, 1.0 / divisor); return BGC_SUCCESS; } @@ -601,44 +695,4 @@ inline void bgc_fp64_matrix2x2_interpolate(BGC_FP64_Matrix2x2* interpolation, co interpolation->r2c2 = first->r2c2 * counter_phase + second->r2c2 * phase; } -// ============ Right Vector Product ============ // - -inline void bgc_fp32_multiply_matrix2x2_by_vector2(BGC_FP32_Vector2* product, const BGC_FP32_Matrix2x2* matrix, const BGC_FP32_Vector2* vector) -{ - const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; - - product->x1 = x1; - product->x2 = x2; -} - -inline void bgc_fp64_multiply_matrix2x2_by_vector2(BGC_FP64_Vector2* product, const BGC_FP64_Matrix2x2* matrix, const BGC_FP64_Vector2* vector) -{ - const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; - - product->x1 = x1; - product->x2 = x2; -} - -// ============ Left Vector Product ============= // - -inline void bgc_fp32_multiply_vector2_by_matrix2x2(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix2x2* matrix) -{ - const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; - - product->x1 = x1; - product->x2 = x2; -} - -inline void bgc_fp64_multiply_vector2_by_matrix2x2(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix2x2* matrix) -{ - const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; - - product->x1 = x1; - product->x2 = x2; -} - #endif diff --git a/basic-geometry/matrix2x3.c b/basic-geometry/matrix2x3.c index 8e1fca4..7584726 100644 --- a/basic-geometry/matrix2x3.c +++ b/basic-geometry/matrix2x3.c @@ -1,4 +1,4 @@ -#include "matrix2x3.h" +#include "./matrix2x3.h" extern inline void bgc_fp32_matrix2x3_reset(BGC_FP32_Matrix2x3* matrix); extern inline void bgc_fp64_matrix2x3_reset(BGC_FP64_Matrix2x3* matrix); @@ -36,17 +36,20 @@ extern inline void bgc_fp64_matrix2x3_add_scaled(BGC_FP64_Matrix2x3* sum, const extern inline void bgc_fp32_matrix2x3_subtract(BGC_FP32_Matrix2x3* difference, const BGC_FP32_Matrix2x3* minuend, const BGC_FP32_Matrix2x3* subtrahend); extern inline void bgc_fp64_matrix2x3_subtract(BGC_FP64_Matrix2x3* difference, const BGC_FP64_Matrix2x3* minuend, const BGC_FP64_Matrix2x3* subtrahend); -extern inline void bgc_fp32_matrix2x3_multiply(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* multiplicand, const float multiplier); -extern inline void bgc_fp64_matrix2x3_multiply(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* multiplicand, const double multiplier); +extern inline void bgc_fp32_matrix2x3_multiply_by_real(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* multiplicand, const float multiplier); +extern inline void bgc_fp64_matrix2x3_multiply_by_real(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* multiplicand, const double multiplier); -extern inline int bgc_fp32_matrix2x3_divide(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor); -extern inline int bgc_fp64_matrix2x3_divide(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor); +extern inline void bgc_fp32_matrix2x3_multiply_by_vector2(BGC_FP32_Vector3* product, const BGC_FP32_Matrix2x3* matrix, const BGC_FP32_Vector2* vector); +extern inline void bgc_fp64_matrix2x3_multiply_by_vector2(BGC_FP64_Vector3* product, const BGC_FP64_Matrix2x3* matrix, const BGC_FP64_Vector2* vector); + +extern inline void bgc_fp32_matrix2x3_multiply_by_matrix2x2(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix2x2* matrix2); +extern inline void bgc_fp64_matrix2x3_multiply_by_matrix2x2(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix2x2* matrix2); + +extern inline void bgc_fp32_matrix2x3_multiply_by_matrix3x2(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix3x2* matrix2); +extern inline void bgc_fp64_matrix2x3_multiply_by_matrix3x2(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix3x2* matrix2); + +extern inline int bgc_fp32_matrix2x3_divide_by_real(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor); +extern inline int bgc_fp64_matrix2x3_divide_by_real(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor); extern inline void bgc_fp32_matrix2x3_interpolate(BGC_FP32_Matrix2x3* interpolation, const BGC_FP32_Matrix2x3* first, const BGC_FP32_Matrix2x3* second, const float phase); extern inline void bgc_fp64_matrix2x3_interpolate(BGC_FP64_Matrix2x3* interpolation, const BGC_FP64_Matrix2x3* first, const BGC_FP64_Matrix2x3* second, const double phase); - -extern inline void bgc_fp32_multiply_vector3_by_matrix2x3(BGC_FP32_Vector2* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix2x3* matrix); -extern inline void bgc_fp64_multiply_vector3_by_matrix2x3(BGC_FP64_Vector2* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix2x3* matrix); - -extern inline void bgc_fp32_multiply_matrix2x3_by_vector2(BGC_FP32_Vector3* product, const BGC_FP32_Matrix2x3* matrix, const BGC_FP32_Vector2* vector); -extern inline void bgc_fp64_multiply_matrix2x3_by_vector2(BGC_FP64_Vector3* product, const BGC_FP64_Matrix2x3* matrix, const BGC_FP64_Vector2* vector); diff --git a/basic-geometry/matrix2x3.h b/basic-geometry/matrix2x3.h index 9adb8b1..4bb9c9b 100644 --- a/basic-geometry/matrix2x3.h +++ b/basic-geometry/matrix2x3.h @@ -1,9 +1,10 @@ #ifndef _BGC_MATRIX2X3_H_INCLUDED_ #define _BGC_MATRIX2X3_H_INCLUDED_ -#include "vector2.h" -#include "vector3.h" -#include "matrices.h" +#include + +#include "./utilities.h" +#include "./types.h" // =================== Reset ==================== // @@ -411,7 +412,7 @@ inline void bgc_fp64_matrix2x3_subtract(BGC_FP64_Matrix2x3* difference, const BG // ================== Multiply ================== // -inline void bgc_fp32_matrix2x3_multiply(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* multiplicand, const float multiplier) +inline void bgc_fp32_matrix2x3_multiply_by_real(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* multiplicand, const float multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -423,7 +424,7 @@ inline void bgc_fp32_matrix2x3_multiply(BGC_FP32_Matrix2x3* product, const BGC_F product->r3c2 = multiplicand->r3c2 * multiplier; } -inline void bgc_fp64_matrix2x3_multiply(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* multiplicand, const double multiplier) +inline void bgc_fp64_matrix2x3_multiply_by_real(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* multiplicand, const double multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -435,25 +436,118 @@ inline void bgc_fp64_matrix2x3_multiply(BGC_FP64_Matrix2x3* product, const BGC_F product->r3c2 = multiplicand->r3c2 * multiplier; } +// ============ Right Vector Product ============ // + +inline void bgc_fp32_matrix2x3_multiply_by_vector2(BGC_FP32_Vector3* product, const BGC_FP32_Matrix2x3* matrix, const BGC_FP32_Vector2* vector) +{ + product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; + product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2; +} + +inline void bgc_fp64_matrix2x3_multiply_by_vector2(BGC_FP64_Vector3* product, const BGC_FP64_Matrix2x3* matrix, const BGC_FP64_Vector2* vector) +{ + product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; + product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; + product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2; +} + + +// ========== Matrix Product 2x3 at 2x2 ========= // + +inline void bgc_fp32_matrix2x3_multiply_by_matrix2x2(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix2x2* matrix2) +{ + const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + + const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + + const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; + const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + + product->r3c1 = r3c1; + product->r3c2 = r3c2; +} + +inline void bgc_fp64_matrix2x3_multiply_by_matrix2x2(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix2x2* matrix2) +{ + const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + + const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + + const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; + const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + + product->r3c1 = r3c1; + product->r3c2 = r3c2; +} + +// ========== Matrix Product 2x3 at 3x2 ========= // + +inline void bgc_fp32_matrix2x3_multiply_by_matrix3x2(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix2x3* matrix1, const BGC_FP32_Matrix3x2* matrix2) +{ + product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + product->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; + + product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + product->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; + + product->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; + product->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; + product->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3; +} + +inline void bgc_fp64_matrix2x3_multiply_by_matrix3x2(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix2x3* matrix1, const BGC_FP64_Matrix3x2* matrix2) +{ + product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1; + product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2; + product->r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3; + + product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1; + product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2; + product->r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3; + + product->r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1; + product->r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2; + product->r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3; +} + // =================== Divide =================== // -inline int bgc_fp32_matrix2x3_divide(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor) +inline int bgc_fp32_matrix2x3_divide_by_real(BGC_FP32_Matrix2x3* quotient, const BGC_FP32_Matrix2x3* dividend, const float divisor) { if (bgc_fp32_is_zero(divisor)) { return BGC_FAILURE; } - bgc_fp32_matrix2x3_multiply(quotient, dividend, 1.0f / divisor); + bgc_fp32_matrix2x3_multiply_by_real(quotient, dividend, 1.0f / divisor); return BGC_SUCCESS; } -inline int bgc_fp64_matrix2x3_divide(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor) +inline int bgc_fp64_matrix2x3_divide_by_real(BGC_FP64_Matrix2x3* quotient, const BGC_FP64_Matrix2x3* dividend, const double divisor) { if (bgc_fp64_is_zero(divisor)) { return BGC_FAILURE; } - bgc_fp64_matrix2x3_multiply(quotient, dividend, 1.0 / divisor); + bgc_fp64_matrix2x3_multiply_by_real(quotient, dividend, 1.0 / divisor); return BGC_SUCCESS; } @@ -487,34 +581,4 @@ inline void bgc_fp64_matrix2x3_interpolate(BGC_FP64_Matrix2x3* interpolation, co interpolation->r3c2 = first->r3c2 * couter_phase + second->r3c2 * phase; } -// ============ Left Vector Product ============= // - -inline void bgc_fp32_multiply_vector3_by_matrix2x3(BGC_FP32_Vector2* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix2x3* matrix) -{ - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; -} - -inline void bgc_fp64_multiply_vector3_by_matrix2x3(BGC_FP64_Vector2* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix2x3* matrix) -{ - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; -} - -// ============ Right Vector Product ============ // - -inline void bgc_fp32_multiply_matrix2x3_by_vector2(BGC_FP32_Vector3* product, const BGC_FP32_Matrix2x3* matrix, const BGC_FP32_Vector2* vector) -{ - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; - product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2; -} - -inline void bgc_fp64_multiply_matrix2x3_by_vector2(BGC_FP64_Vector3* product, const BGC_FP64_Matrix2x3* matrix, const BGC_FP64_Vector2* vector) -{ - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2; - product->x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2; -} - #endif diff --git a/basic-geometry/matrix3x2.c b/basic-geometry/matrix3x2.c index 55736dd..c5cf500 100644 --- a/basic-geometry/matrix3x2.c +++ b/basic-geometry/matrix3x2.c @@ -1,4 +1,4 @@ -#include "matrix3x2.h" +#include "./matrix3x2.h" extern inline void bgc_fp32_matrix3x2_reset(BGC_FP32_Matrix3x2* matrix); extern inline void bgc_fp64_matrix3x2_reset(BGC_FP64_Matrix3x2* matrix); @@ -36,17 +36,20 @@ extern inline void bgc_fp64_matrix3x2_add_scaled(BGC_FP64_Matrix3x2* sum, const extern inline void bgc_fp32_matrix3x2_subtract(BGC_FP32_Matrix3x2* difference, const BGC_FP32_Matrix3x2* minuend, const BGC_FP32_Matrix3x2* subtrahend); extern inline void bgc_fp64_matrix3x2_subtract(BGC_FP64_Matrix3x2* difference, const BGC_FP64_Matrix3x2* minuend, const BGC_FP64_Matrix3x2* subtrahend); -extern inline void bgc_fp32_matrix3x2_multiply(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* multiplicand, const float multiplier); -extern inline void bgc_fp64_matrix3x2_multiply(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* multiplicand, const double multiplier); +extern inline void bgc_fp32_matrix3x2_multiply_by_real(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* multiplicand, const float multiplier); +extern inline void bgc_fp64_matrix3x2_multiply_by_real(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* multiplicand, const double multiplier); -extern inline int bgc_fp32_matrix3x2_divide(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor); -extern inline int bgc_fp64_matrix3x2_divide(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor); +extern inline void bgc_fp32_matrix3x2_multiply_by_vector3(BGC_FP32_Vector2* product, const BGC_FP32_Matrix3x2* matrix, const BGC_FP32_Vector3* vector); +extern inline void bgc_fp64_matrix3x2_multiply_by_vector3(BGC_FP64_Vector2* product, const BGC_FP64_Matrix3x2* matrix, const BGC_FP64_Vector3* vector); + +extern inline void bgc_fp32_matrix3x2_multiply_by_matrix2x3(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix2x3* matrix2); +extern inline void bgc_fp64_matrix3x2_multiply_by_matrix2x3(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix2x3* matrix2); + +extern inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix3x3* matrix2); +extern inline void bgc_fp64_matrix3x2_multiply_by_matrix3x3(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix3x3* matrix2); + +extern inline int bgc_fp32_matrix3x2_divide_by_real(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor); +extern inline int bgc_fp64_matrix3x2_divide_by_real(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor); extern inline void bgc_fp32_matrix3x2_interpolate(BGC_FP32_Matrix3x2* interpolation, const BGC_FP32_Matrix3x2* first, const BGC_FP32_Matrix3x2* second, const float phase); extern inline void bgc_fp64_matrix3x2_interpolate(BGC_FP64_Matrix3x2* interpolation, const BGC_FP64_Matrix3x2* first, const BGC_FP64_Matrix3x2* second, const double phase); - -extern inline void bgc_fp32_multiply_vector2_by_matrix3x2(BGC_FP32_Vector3* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix3x2* matrix); -extern inline void bgc_fp64_multiply_vector2_by_matrix3x2(BGC_FP64_Vector3* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix3x2* matrix); - -extern inline void bgc_fp32_multiply_matrix3x2_by_vector3(BGC_FP32_Vector2* product, const BGC_FP32_Matrix3x2* matrix, const BGC_FP32_Vector3* vector); -extern inline void bgc_fp64_multiply_matrix3x2_by_vector3(BGC_FP64_Vector2* product, const BGC_FP64_Matrix3x2* matrix, const BGC_FP64_Vector3* vector); diff --git a/basic-geometry/matrix3x2.h b/basic-geometry/matrix3x2.h index 968d56c..14bbc1b 100644 --- a/basic-geometry/matrix3x2.h +++ b/basic-geometry/matrix3x2.h @@ -1,9 +1,10 @@ #ifndef _BGC_MATRIX3X2_H_INCLUDED_ #define _BGC_MATRIX3X2_H_INCLUDED_ -#include "vector2.h" -#include "vector3.h" -#include "matrices.h" +#include + +#include "./utilities.h" +#include "./types.h" // =================== Reset ==================== // @@ -421,7 +422,7 @@ inline void bgc_fp64_matrix3x2_subtract(BGC_FP64_Matrix3x2* difference, const BG // ================== Multiply ================== // -inline void bgc_fp32_matrix3x2_multiply(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* multiplicand, const float multiplier) +inline void bgc_fp32_matrix3x2_multiply_by_real(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* multiplicand, const float multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -432,7 +433,7 @@ inline void bgc_fp32_matrix3x2_multiply(BGC_FP32_Matrix3x2* product, const BGC_F product->r2c3 = multiplicand->r2c3 * multiplier; } -inline void bgc_fp64_matrix3x2_multiply(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* multiplicand, const double multiplier) +inline void bgc_fp64_matrix3x2_multiply_by_real(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* multiplicand, const double multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -443,25 +444,99 @@ inline void bgc_fp64_matrix3x2_multiply(BGC_FP64_Matrix3x2* product, const BGC_F product->r2c3 = multiplicand->r2c3 * multiplier; } +// ============ Right Vector Product ============ // + +inline void bgc_fp32_matrix3x2_multiply_by_vector3(BGC_FP32_Vector2* product, const BGC_FP32_Matrix3x2* matrix, const BGC_FP32_Vector3* vector) +{ + product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; + product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; +} + +inline void bgc_fp64_matrix3x2_multiply_by_vector3(BGC_FP64_Vector2* product, const BGC_FP64_Matrix3x2* matrix, const BGC_FP64_Vector3* vector) +{ + product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; + product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; +} + +// ========== Matrix Product 3x2 at 2x3 ========= // + +inline void bgc_fp32_matrix3x2_multiply_by_matrix2x3(BGC_FP32_Matrix2x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix2x3* matrix2) +{ + product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + + product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; +} + +inline void bgc_fp64_matrix3x2_multiply_by_matrix2x3(BGC_FP64_Matrix2x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix2x3* matrix2) +{ + product->r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + product->r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + + product->r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + product->r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; +} + +// ========== Matrix Product 3x2 at 3x3 ========= // + +inline void bgc_fp32_matrix3x2_multiply_by_matrix3x3(BGC_FP32_Matrix3x2* product, const BGC_FP32_Matrix3x2* matrix1, const BGC_FP32_Matrix3x3* matrix2) +{ + const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; + + const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + product->r1c3 = r1c3; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + product->r2c3 = r2c3; +} + +inline void bgc_fp64_matrix3x2_multiply_by_matrix3x3(BGC_FP64_Matrix3x2* product, const BGC_FP64_Matrix3x2* matrix1, const BGC_FP64_Matrix3x3* matrix2) +{ + const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; + + const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + product->r1c3 = r1c3; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + product->r2c3 = r2c3; +} + // =================== Divide =================== // -inline int bgc_fp32_matrix3x2_divide(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor) +inline int bgc_fp32_matrix3x2_divide_by_real(BGC_FP32_Matrix3x2* quotient, const BGC_FP32_Matrix3x2* dividend, const float divisor) { if (bgc_fp32_is_zero(divisor)) { return BGC_FAILURE; } - bgc_fp32_matrix3x2_multiply(quotient, dividend, 1.0f / divisor); + bgc_fp32_matrix3x2_multiply_by_real(quotient, dividend, 1.0f / divisor); return BGC_SUCCESS; } -inline int bgc_fp64_matrix3x2_divide(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor) +inline int bgc_fp64_matrix3x2_divide_by_real(BGC_FP64_Matrix3x2* quotient, const BGC_FP64_Matrix3x2* dividend, const double divisor) { if (bgc_fp64_is_zero(divisor)) { return BGC_FAILURE; } - bgc_fp64_matrix3x2_multiply(quotient, dividend, 1.0 / divisor); + bgc_fp64_matrix3x2_multiply_by_real(quotient, dividend, 1.0 / divisor); return BGC_SUCCESS; } @@ -493,34 +568,4 @@ inline void bgc_fp64_matrix3x2_interpolate(BGC_FP64_Matrix3x2* interpolation, co interpolation->r2c3 = first->r2c3 * couter_phase + second->r2c3 * phase; } -// ============ Left Vector Product ============= // - -inline void bgc_fp32_multiply_vector2_by_matrix3x2(BGC_FP32_Vector3* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix3x2* matrix) -{ - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; - product->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3; -} - -inline void bgc_fp64_multiply_vector2_by_matrix3x2(BGC_FP64_Vector3* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix3x2* matrix) -{ - product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; - product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; - product->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3; -} - -// ============ Right Vector Product ============ // - -inline void bgc_fp32_multiply_matrix3x2_by_vector3(BGC_FP32_Vector2* product, const BGC_FP32_Matrix3x2* matrix, const BGC_FP32_Vector3* vector) -{ - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; -} - -inline void bgc_fp64_multiply_matrix3x2_by_vector3(BGC_FP64_Vector2* product, const BGC_FP64_Matrix3x2* matrix, const BGC_FP64_Vector3* vector) -{ - product->x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - product->x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; -} - #endif diff --git a/basic-geometry/matrix3x3.c b/basic-geometry/matrix3x3.c index 3b1bfeb..51a5117 100644 --- a/basic-geometry/matrix3x3.c +++ b/basic-geometry/matrix3x3.c @@ -1,4 +1,4 @@ -#include "matrix3x3.h" +#include "./matrix3x3.h" extern inline void bgc_fp32_matrix3x3_reset(BGC_FP32_Matrix3x3* matrix); extern inline void bgc_fp64_matrix3x3_reset(BGC_FP64_Matrix3x3* matrix); @@ -60,21 +60,24 @@ extern inline void bgc_fp64_matrix3x3_add_scaled(BGC_FP64_Matrix3x3* sum, const extern inline void bgc_fp32_matrix3x3_subtract(BGC_FP32_Matrix3x3* difference, const BGC_FP32_Matrix3x3* minuend, const BGC_FP32_Matrix3x3* subtrahend); extern inline void bgc_fp64_matrix3x3_subtract(BGC_FP64_Matrix3x3* difference, const BGC_FP64_Matrix3x3* minuend, const BGC_FP64_Matrix3x3* subtrahend); -extern inline void bgc_fp32_matrix3x3_multiply(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* multiplicand, const float multiplier); -extern inline void bgc_fp64_matrix3x3_multiply(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* multiplicand, const double multiplier); +extern inline void bgc_fp32_matrix3x3_multiply_by_real(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* multiplicand, const float multiplier); +extern inline void bgc_fp64_matrix3x3_multiply_by_real(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* multiplicand, const double multiplier); -extern inline int bgc_fp32_matrix3x3_divide(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor); -extern inline int bgc_fp64_matrix3x3_divide(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor); +extern inline void bgc_fp32_matrix3x3_multiply_by_vector3(BGC_FP32_Vector3* product, const BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Vector3* vector); +extern inline void bgc_fp64_matrix3x3_multiply_by_vector3(BGC_FP64_Vector3* product, const BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Vector3* vector); + +extern inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix2x3* matrix2); +extern inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix2x3* matrix2); + +extern inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix3x3* matrix2); +extern inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix3x3* matrix2); + +extern inline int bgc_fp32_matrix3x3_divide_by_real(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor); +extern inline int bgc_fp64_matrix3x3_divide_by_real(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor); extern inline void bgc_fp32_matrix3x3_interpolate(BGC_FP32_Matrix3x3* interpolation, const BGC_FP32_Matrix3x3* first, const BGC_FP32_Matrix3x3* second, const float phase); extern inline void bgc_fp64_matrix3x3_interpolate(BGC_FP64_Matrix3x3* interpolation, const BGC_FP64_Matrix3x3* first, const BGC_FP64_Matrix3x3* second, const double phase); -extern inline void bgc_fp32_multiply_vector3_by_matrix3x3(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix3x3* matrix); -extern inline void bgc_fp64_multiply_vector3_by_matrix3x3(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix3x3* matrix); - -extern inline void bgc_fp32_multiply_matrix3x3_by_vector3(BGC_FP32_Vector3* product, const BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Vector3* vector); -extern inline void bgc_fp64_multiply_matrix3x3_by_vector3(BGC_FP64_Vector3* product, const BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Vector3* vector); - // ================ Get Inverse ================= // int bgc_fp32_matrix3x3_get_inverse(BGC_FP32_Matrix3x3* inverse, const BGC_FP32_Matrix3x3* matrix) diff --git a/basic-geometry/matrix3x3.h b/basic-geometry/matrix3x3.h index 6986358..526dffa 100644 --- a/basic-geometry/matrix3x3.h +++ b/basic-geometry/matrix3x3.h @@ -1,8 +1,10 @@ #ifndef _BGC_MATRIX3X3_H_INCLUDED_ #define _BGC_MATRIX3X3_H_INCLUDED_ -#include "vector3.h" -#include "matrices.h" +#include + +#include "./utilities.h" +#include "./types.h" // =================== Reset ==================== // @@ -752,7 +754,7 @@ inline void bgc_fp64_matrix3x3_subtract(BGC_FP64_Matrix3x3* difference, const BG // ================== Multiply ================== // -inline void bgc_fp32_matrix3x3_multiply(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* multiplicand, const float multiplier) +inline void bgc_fp32_matrix3x3_multiply_by_real(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* multiplicand, const float multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -767,7 +769,7 @@ inline void bgc_fp32_matrix3x3_multiply(BGC_FP32_Matrix3x3* product, const BGC_F product->r3c3 = multiplicand->r3c3 * multiplier; } -inline void bgc_fp64_matrix3x3_multiply(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* multiplicand, const double multiplier) +inline void bgc_fp64_matrix3x3_multiply_by_real(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* multiplicand, const double multiplier) { product->r1c1 = multiplicand->r1c1 * multiplier; product->r1c2 = multiplicand->r1c2 * multiplier; @@ -782,25 +784,150 @@ inline void bgc_fp64_matrix3x3_multiply(BGC_FP64_Matrix3x3* product, const BGC_F product->r3c3 = multiplicand->r3c3 * multiplier; } +// ============ Right Vector Product ============ // + +inline void bgc_fp32_matrix3x3_multiply_by_vector3(BGC_FP32_Vector3* product, const BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Vector3* vector) +{ + const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; + const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; + const float x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; + + product->x1 = x1; + product->x2 = x2; + product->x3 = x3; +} + +inline void bgc_fp64_matrix3x3_multiply_by_vector3(BGC_FP64_Vector3* product, const BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Vector3* vector) +{ + const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; + const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; + const double x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; + + product->x1 = x1; + product->x2 = x2; + product->x3 = x3; +} + + +// ========== Matrix Product 3x3 at 2x3 ========= // + +inline void bgc_fp32_matrix3x3_multiply_by_matrix2x3(BGC_FP32_Matrix2x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix2x3* matrix2) +{ + const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + + const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + + const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; + const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + + product->r3c1 = r3c1; + product->r3c2 = r3c2; +} + +inline void bgc_fp64_matrix3x3_multiply_by_matrix2x3(BGC_FP64_Matrix2x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix2x3* matrix2) +{ + const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + + const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + + const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; + const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + + product->r3c1 = r3c1; + product->r3c2 = r3c2; +} + +// ========== Matrix Product 3x3 at 3x3 ========= // + +inline void bgc_fp32_matrix3x3_multiply_by_matrix3x3(BGC_FP32_Matrix3x3* product, const BGC_FP32_Matrix3x3* matrix1, const BGC_FP32_Matrix3x3* matrix2) +{ + const float r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + const float r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + const float r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; + + const float r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + const float r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + const float r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; + + const float r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; + const float r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; + const float r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + product->r1c3 = r1c3; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + product->r2c3 = r2c3; + + product->r3c1 = r3c1; + product->r3c2 = r3c2; + product->r3c3 = r3c3; +} + +inline void bgc_fp64_matrix3x3_multiply_by_matrix3x3(BGC_FP64_Matrix3x3* product, const BGC_FP64_Matrix3x3* matrix1, const BGC_FP64_Matrix3x3* matrix2) +{ + const double r1c1 = matrix1->r1c1 * matrix2->r1c1 + matrix1->r1c2 * matrix2->r2c1 + matrix1->r1c3 * matrix2->r3c1; + const double r1c2 = matrix1->r1c1 * matrix2->r1c2 + matrix1->r1c2 * matrix2->r2c2 + matrix1->r1c3 * matrix2->r3c2; + const double r1c3 = matrix1->r1c1 * matrix2->r1c3 + matrix1->r1c2 * matrix2->r2c3 + matrix1->r1c3 * matrix2->r3c3; + + const double r2c1 = matrix1->r2c1 * matrix2->r1c1 + matrix1->r2c2 * matrix2->r2c1 + matrix1->r2c3 * matrix2->r3c1; + const double r2c2 = matrix1->r2c1 * matrix2->r1c2 + matrix1->r2c2 * matrix2->r2c2 + matrix1->r2c3 * matrix2->r3c2; + const double r2c3 = matrix1->r2c1 * matrix2->r1c3 + matrix1->r2c2 * matrix2->r2c3 + matrix1->r2c3 * matrix2->r3c3; + + const double r3c1 = matrix1->r3c1 * matrix2->r1c1 + matrix1->r3c2 * matrix2->r2c1 + matrix1->r3c3 * matrix2->r3c1; + const double r3c2 = matrix1->r3c1 * matrix2->r1c2 + matrix1->r3c2 * matrix2->r2c2 + matrix1->r3c3 * matrix2->r3c2; + const double r3c3 = matrix1->r3c1 * matrix2->r1c3 + matrix1->r3c2 * matrix2->r2c3 + matrix1->r3c3 * matrix2->r3c3; + + product->r1c1 = r1c1; + product->r1c2 = r1c2; + product->r1c3 = r1c3; + + product->r2c1 = r2c1; + product->r2c2 = r2c2; + product->r2c3 = r2c3; + + product->r3c1 = r3c1; + product->r3c2 = r3c2; + product->r3c3 = r3c3; +} + // =================== Divide =================== // -inline int bgc_fp32_matrix3x3_divide(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor) +inline int bgc_fp32_matrix3x3_divide_by_real(BGC_FP32_Matrix3x3* quotient, const BGC_FP32_Matrix3x3* dividend, const float divisor) { if (bgc_fp32_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp32_matrix3x3_multiply(quotient, dividend, 1.0f / divisor); + bgc_fp32_matrix3x3_multiply_by_real(quotient, dividend, 1.0f / divisor); return BGC_SUCCESS; } -inline int bgc_fp64_matrix3x3_divide(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor) +inline int bgc_fp64_matrix3x3_divide_by_real(BGC_FP64_Matrix3x3* quotient, const BGC_FP64_Matrix3x3* dividend, const double divisor) { if (bgc_fp64_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp64_matrix3x3_multiply(quotient, dividend, 1.0 / divisor); + bgc_fp64_matrix3x3_multiply_by_real(quotient, dividend, 1.0 / divisor); return BGC_SUCCESS; } @@ -840,52 +967,4 @@ inline void bgc_fp64_matrix3x3_interpolate(BGC_FP64_Matrix3x3* interpolation, co interpolation->r3c3 = first->r3c3 * counter_phase + second->r3c3 * phase; } -// ============ Left Vector Product ============= // - -inline void bgc_fp32_multiply_vector3_by_matrix3x3(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix3x3* matrix) -{ - const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; - const float x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3; - - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; -} - -inline void bgc_fp64_multiply_vector3_by_matrix3x3(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix3x3* matrix) -{ - const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; - const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; - const double x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3; - - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; -} - -// ============ Right Vector Product ============ // - -inline void bgc_fp32_multiply_matrix3x3_by_vector3(BGC_FP32_Vector3* product, const BGC_FP32_Matrix3x3* matrix, const BGC_FP32_Vector3* vector) -{ - const float x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - const float x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; - const float x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; - - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; -} - -inline void bgc_fp64_multiply_matrix3x3_by_vector3(BGC_FP64_Vector3* product, const BGC_FP64_Matrix3x3* matrix, const BGC_FP64_Vector3* vector) -{ - const double x1 = matrix->r1c1 * vector->x1 + matrix->r1c2 * vector->x2 + matrix->r1c3 * vector->x3; - const double x2 = matrix->r2c1 * vector->x1 + matrix->r2c2 * vector->x2 + matrix->r2c3 * vector->x3; - const double x3 = matrix->r3c1 * vector->x1 + matrix->r3c2 * vector->x2 + matrix->r3c3 * vector->x3; - - product->x1 = x1; - product->x2 = x2; - product->x3 = x3; -} - #endif diff --git a/basic-geometry/position2.c b/basic-geometry/position2.c index e3f957b..de159ac 100644 --- a/basic-geometry/position2.c +++ b/basic-geometry/position2.c @@ -1,4 +1,4 @@ -#include "position2.h" +#include "./position2.h" extern inline void bgc_fp32_position2_reset(BGC_FP32_Position2* node); extern inline void bgc_fp64_position2_reset(BGC_FP64_Position2* node); diff --git a/basic-geometry/position2.h b/basic-geometry/position2.h index e6b0650..6706c3a 100644 --- a/basic-geometry/position2.h +++ b/basic-geometry/position2.h @@ -1,9 +1,9 @@ #ifndef _BGC_POSITION2_H_INCLUDED_ #define _BGC_POSITION2_H_INCLUDED_ -#include "vector2.h" -#include "affine2.h" -#include "turn2.h" +#include "./vector2.h" +#include "./affine2.h" +#include "./turn2.h" // ==================== Types ==================== // @@ -187,14 +187,14 @@ inline void bgc_fp64_position2_get_outward_affine(BGC_FP64_Affine2* outward_affi inline void bgc_fp32_position2_get_inward_affine(BGC_FP32_Affine2* inward_affine_map, const BGC_FP32_Position2 * position) { bgc_fp32_turn2_get_reverse_matrix(&inward_affine_map->distortion, &position->turn); - bgc_fp32_multiply_matrix2x2_by_vector2(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); + bgc_fp32_matrix2x2_multiply_by_vector2(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); bgc_fp32_vector2_revert(&inward_affine_map->shift); } inline void bgc_fp64_position2_get_inward_affine(BGC_FP64_Affine2* inward_affine_map, const BGC_FP64_Position2 * position) { bgc_fp64_turn2_get_reverse_matrix(&inward_affine_map->distortion, &position->turn); - bgc_fp64_multiply_matrix2x2_by_vector2(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); + bgc_fp64_matrix2x2_multiply_by_vector2(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); bgc_fp64_vector2_revert(&inward_affine_map->shift); } diff --git a/basic-geometry/position3.c b/basic-geometry/position3.c index 33b819a..edebacb 100644 --- a/basic-geometry/position3.c +++ b/basic-geometry/position3.c @@ -1,4 +1,4 @@ -#include "position3.h" +#include "./position3.h" extern inline void bgc_fp32_position3_reset(BGC_FP32_Position3 * node); extern inline void bgc_fp64_position3_reset(BGC_FP64_Position3 * node); diff --git a/basic-geometry/position3.h b/basic-geometry/position3.h index b366403..c91bf7b 100644 --- a/basic-geometry/position3.h +++ b/basic-geometry/position3.h @@ -1,9 +1,9 @@ #ifndef _BGC_POSITION3_H_INCLUDED_ #define _BGC_POSITION3_H_INCLUDED_ -#include "vector3.h" -#include "affine3.h" -#include "turn3.h" +#include "./vector3.h" +#include "./affine3.h" +#include "./turn3.h" // ==================== Types ==================== // @@ -186,14 +186,14 @@ inline void bgc_fp64_position3_get_outward_affine(BGC_FP64_Affine3* outward_affi inline void bgc_fp32_position3_get_inward_affine(BGC_FP32_Affine3* inward_affine_map, const BGC_FP32_Position3 * position) { bgc_fp32_turn3_get_reverse_matrix(&inward_affine_map->distortion, &position->turn); - bgc_fp32_multiply_matrix3x3_by_vector3(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); + bgc_fp32_matrix3x3_multiply_by_vector3(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); bgc_fp32_vector3_revert(&inward_affine_map->shift); } inline void bgc_fp64_position3_get_inward_affine(BGC_FP64_Affine3* inward_affine_map, const BGC_FP64_Position3 * position) { bgc_fp64_turn3_get_reverse_matrix(&inward_affine_map->distortion, &position->turn); - bgc_fp64_multiply_matrix3x3_by_vector3(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); + bgc_fp64_matrix3x3_multiply_by_vector3(&inward_affine_map->shift, &inward_affine_map->distortion, &position->shift); bgc_fp64_vector3_revert(&inward_affine_map->shift); } diff --git a/basic-geometry/quaternion.c b/basic-geometry/quaternion.c index 1252479..69bb2c3 100644 --- a/basic-geometry/quaternion.c +++ b/basic-geometry/quaternion.c @@ -1,5 +1,5 @@ #include -#include "quaternion.h" +#include "./quaternion.h" extern inline void bgc_fp32_quaternion_reset(BGC_FP32_Quaternion* quaternion); extern inline void bgc_fp64_quaternion_reset(BGC_FP64_Quaternion* quaternion); diff --git a/basic-geometry/quaternion.h b/basic-geometry/quaternion.h index 28a7e18..6ce3250 100644 --- a/basic-geometry/quaternion.h +++ b/basic-geometry/quaternion.h @@ -3,18 +3,10 @@ #include -#include "utilities.h" -#include "angle.h" -#include "vector3.h" -#include "matrix3x3.h" - -typedef struct { - float s0, x1, x2, x3; -} BGC_FP32_Quaternion; - -typedef struct { - double s0, x1, x2, x3; -} BGC_FP64_Quaternion; +#include "./utilities.h" +#include "./types.h" +#include "./angle.h" +#include "./matrix3x3.h" // ==================== Reset =================== // diff --git a/basic-geometry/slerp.c b/basic-geometry/slerp.c index a848842..2eca4a7 100644 --- a/basic-geometry/slerp.c +++ b/basic-geometry/slerp.c @@ -1,18 +1,18 @@ #include "./slerp.h" -extern inline void bgc_fp32_slerp_reset(BGC_FP32_Slerp* slerp); -extern inline void bgc_fp64_slerp_reset(BGC_FP64_Slerp* slerp); +extern inline void bgc_fp32_slerp_reset(BGC_FP32_Turn3Slerp* slerp); +extern inline void bgc_fp64_slerp_reset(BGC_FP64_Turn3Slerp* slerp); -extern inline void bgc_fp32_slerp_make_full(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end); -extern inline void bgc_fp64_slerp_make_full(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end); +extern inline void bgc_fp32_slerp_make_full(BGC_FP32_Turn3Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end); +extern inline void bgc_fp64_slerp_make_full(BGC_FP64_Turn3Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end); -extern inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end); -extern inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end); +extern inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Turn3Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end); +extern inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Turn3Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end); -extern inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Turn3* versor, const BGC_FP32_Slerp* slerp, const float phase); -extern inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Turn3* versor, const BGC_FP64_Slerp* slerp, const double phase); +extern inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Turn3* versor, const BGC_FP32_Turn3Slerp* slerp, const float phase); +extern inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Turn3* versor, const BGC_FP64_Turn3Slerp* slerp, const double phase); -void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* augment) +void bgc_fp32_slerp_make(BGC_FP32_Turn3Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* augment) { const float square_vector = augment->_versor.x1 * augment->_versor.x1 + augment->_versor.x2 * augment->_versor.x2 + augment->_versor.x3 * augment->_versor.x3; @@ -22,15 +22,15 @@ void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, con } if (square_vector <= BGC_FP32_SQUARE_EPSILON) { - slerp->s0_cos_weight = start->_versor.s0; - slerp->x1_cos_weight = start->_versor.x1; - slerp->x2_cos_weight = start->_versor.x2; - slerp->x3_cos_weight = start->_versor.x3; + slerp->_s0_cos_weight = start->_versor.s0; + slerp->_x1_cos_weight = start->_versor.x1; + slerp->_x2_cos_weight = start->_versor.x2; + slerp->_x3_cos_weight = start->_versor.x3; - slerp->s0_sin_weight = 0.0f; - slerp->x1_sin_weight = 0.0f; - slerp->x2_sin_weight = 0.0f; - slerp->x3_sin_weight = 0.0f; + slerp->_s0_sin_weight = 0.0f; + slerp->_x1_sin_weight = 0.0f; + slerp->_x2_sin_weight = 0.0f; + slerp->_x3_sin_weight = 0.0f; slerp->radians = 0.0f; return; @@ -42,18 +42,18 @@ void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, con const float multiplier = 1.0f / vector_modulus; - slerp->s0_cos_weight = start->_versor.s0; - slerp->x1_cos_weight = start->_versor.x1; - slerp->x2_cos_weight = start->_versor.x2; - slerp->x3_cos_weight = start->_versor.x3; + slerp->_s0_cos_weight = start->_versor.s0; + slerp->_x1_cos_weight = start->_versor.x1; + slerp->_x2_cos_weight = start->_versor.x2; + slerp->_x3_cos_weight = start->_versor.x3; - slerp->s0_sin_weight = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3); - slerp->x1_sin_weight = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2); - slerp->x2_sin_weight = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1); - slerp->x3_sin_weight = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2); + slerp->_s0_sin_weight = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3); + slerp->_x1_sin_weight = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2); + slerp->_x2_sin_weight = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1); + slerp->_x3_sin_weight = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2); } -void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* augment) +void bgc_fp64_slerp_make(BGC_FP64_Turn3Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* augment) { const double square_vector = augment->_versor.x1 * augment->_versor.x1 + augment->_versor.x2 * augment->_versor.x2 + augment->_versor.x3 * augment->_versor.x3; @@ -63,15 +63,15 @@ void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, con } if (square_vector <= BGC_FP64_SQUARE_EPSILON) { - slerp->s0_cos_weight = start->_versor.s0; - slerp->x1_cos_weight = start->_versor.x1; - slerp->x2_cos_weight = start->_versor.x2; - slerp->x3_cos_weight = start->_versor.x3; + slerp->_s0_cos_weight = start->_versor.s0; + slerp->_x1_cos_weight = start->_versor.x1; + slerp->_x2_cos_weight = start->_versor.x2; + slerp->_x3_cos_weight = start->_versor.x3; - slerp->s0_sin_weight = 0.0; - slerp->x1_sin_weight = 0.0; - slerp->x2_sin_weight = 0.0; - slerp->x3_sin_weight = 0.0; + slerp->_s0_sin_weight = 0.0; + slerp->_x1_sin_weight = 0.0; + slerp->_x2_sin_weight = 0.0; + slerp->_x3_sin_weight = 0.0; slerp->radians = 0.0; return; @@ -83,13 +83,13 @@ void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, con const double multiplier = 1.0 / vector_modulus; - slerp->s0_cos_weight = start->_versor.s0; - slerp->x1_cos_weight = start->_versor.x1; - slerp->x2_cos_weight = start->_versor.x2; - slerp->x3_cos_weight = start->_versor.x3; + slerp->_s0_cos_weight = start->_versor.s0; + slerp->_x1_cos_weight = start->_versor.x1; + slerp->_x2_cos_weight = start->_versor.x2; + slerp->_x3_cos_weight = start->_versor.x3; - slerp->s0_sin_weight = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3); - slerp->x1_sin_weight = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2); - slerp->x2_sin_weight = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1); - slerp->x3_sin_weight = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2); + slerp->_s0_sin_weight = -multiplier * (augment->_versor.x1 * start->_versor.x1 + augment->_versor.x2 * start->_versor.x2 + augment->_versor.x3 * start->_versor.x3); + slerp->_x1_sin_weight = multiplier * (augment->_versor.x1 * start->_versor.s0 + augment->_versor.x2 * start->_versor.x3 - augment->_versor.x3 * start->_versor.x2); + slerp->_x2_sin_weight = multiplier * (augment->_versor.x2 * start->_versor.s0 - augment->_versor.x1 * start->_versor.x3 + augment->_versor.x3 * start->_versor.x1); + slerp->_x3_sin_weight = multiplier * (augment->_versor.x3 * start->_versor.s0 - augment->_versor.x2 * start->_versor.x1 + augment->_versor.x1 * start->_versor.x2); } diff --git a/basic-geometry/slerp.h b/basic-geometry/slerp.h index 91dae68..b2595e5 100644 --- a/basic-geometry/slerp.h +++ b/basic-geometry/slerp.h @@ -1,62 +1,47 @@ #ifndef _BGC_SLERP_H_INCLUDED_ #define _BGC_SLERP_H_INCLUDED_ +#include "./types.h" #include "./turn3.h" -typedef struct { - float s0_cos_weight, s0_sin_weight; - float x1_cos_weight, x1_sin_weight; - float x2_cos_weight, x2_sin_weight; - float x3_cos_weight, x3_sin_weight; - float radians; -} BGC_FP32_Slerp; - -typedef struct { - double s0_cos_weight, s0_sin_weight; - double x1_cos_weight, x1_sin_weight; - double x2_cos_weight, x2_sin_weight; - double x3_cos_weight, x3_sin_weight; - double radians; -} BGC_FP64_Slerp; - -inline void bgc_fp32_slerp_reset(BGC_FP32_Slerp* slerp) +inline void bgc_fp32_slerp_reset(BGC_FP32_Turn3Slerp* slerp) { - slerp->s0_cos_weight = 1.0f; - slerp->s0_sin_weight = 0.0f; + slerp->_s0_cos_weight = 1.0f; + slerp->_s0_sin_weight = 0.0f; - slerp->x1_cos_weight = 0.0f; - slerp->x1_sin_weight = 0.0f; + slerp->_x1_cos_weight = 0.0f; + slerp->_x1_sin_weight = 0.0f; - slerp->x2_cos_weight = 0.0f; - slerp->x2_sin_weight = 0.0f; + slerp->_x2_cos_weight = 0.0f; + slerp->_x2_sin_weight = 0.0f; - slerp->x3_cos_weight = 0.0f; - slerp->x3_sin_weight = 0.0f; + slerp->_x3_cos_weight = 0.0f; + slerp->_x3_sin_weight = 0.0f; slerp->radians = 0.0f; } -inline void bgc_fp64_slerp_reset(BGC_FP64_Slerp* slerp) +inline void bgc_fp64_slerp_reset(BGC_FP64_Turn3Slerp* slerp) { - slerp->s0_cos_weight = 1.0; - slerp->s0_sin_weight = 0.0; + slerp->_s0_cos_weight = 1.0; + slerp->_s0_sin_weight = 0.0; - slerp->x1_cos_weight = 0.0; - slerp->x1_sin_weight = 0.0; + slerp->_x1_cos_weight = 0.0; + slerp->_x1_sin_weight = 0.0; - slerp->x2_cos_weight = 0.0; - slerp->x2_sin_weight = 0.0; + slerp->_x2_cos_weight = 0.0; + slerp->_x2_sin_weight = 0.0; - slerp->x3_cos_weight = 0.0; - slerp->x3_sin_weight = 0.0; + slerp->_x3_cos_weight = 0.0; + slerp->_x3_sin_weight = 0.0; slerp->radians = 0.0; } -void bgc_fp32_slerp_make(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* augment); -void bgc_fp64_slerp_make(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* augment); +void bgc_fp32_slerp_make(BGC_FP32_Turn3Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* augment); +void bgc_fp64_slerp_make(BGC_FP64_Turn3Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* augment); -inline void bgc_fp32_slerp_make_full(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end) +inline void bgc_fp32_slerp_make_full(BGC_FP32_Turn3Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end) { BGC_FP32_Turn3 augment; @@ -65,7 +50,7 @@ inline void bgc_fp32_slerp_make_full(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3 bgc_fp32_slerp_make(slerp, start, &augment); } -inline void bgc_fp64_slerp_make_full(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end) +inline void bgc_fp64_slerp_make_full(BGC_FP64_Turn3Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end) { BGC_FP64_Turn3 augment; @@ -74,7 +59,7 @@ inline void bgc_fp64_slerp_make_full(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3 bgc_fp64_slerp_make(slerp, start, &augment); } -inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end) +inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Turn3Slerp* slerp, const BGC_FP32_Turn3* start, const BGC_FP32_Turn3* end) { BGC_FP32_Turn3 augment; @@ -84,7 +69,7 @@ inline void bgc_fp32_slerp_make_shortened(BGC_FP32_Slerp* slerp, const BGC_FP32_ bgc_fp32_slerp_make(slerp, start, &augment); } -inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end) +inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Turn3Slerp* slerp, const BGC_FP64_Turn3* start, const BGC_FP64_Turn3* end) { BGC_FP64_Turn3 augment; @@ -94,7 +79,7 @@ inline void bgc_fp64_slerp_make_shortened(BGC_FP64_Slerp* slerp, const BGC_FP64_ bgc_fp64_slerp_make(slerp, start, &augment); } -inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Turn3* versor, const BGC_FP32_Slerp* slerp, const float phase) +inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Turn3* versor, const BGC_FP32_Turn3Slerp* slerp, const float phase) { const float angle = slerp->radians * phase; const float cosine = cosf(angle); @@ -102,14 +87,14 @@ inline void bgc_fp32_slerp_get_phase_versor(BGC_FP32_Turn3* versor, const BGC_FP bgc_fp32_turn3_set_raw_values( versor, - slerp->s0_cos_weight * cosine + slerp->s0_sin_weight * sine, - slerp->x1_cos_weight * cosine + slerp->x1_sin_weight * sine, - slerp->x2_cos_weight * cosine + slerp->x2_sin_weight * sine, - slerp->x3_cos_weight * cosine + slerp->x3_sin_weight * sine + slerp->_s0_cos_weight * cosine + slerp->_s0_sin_weight * sine, + slerp->_x1_cos_weight * cosine + slerp->_x1_sin_weight * sine, + slerp->_x2_cos_weight * cosine + slerp->_x2_sin_weight * sine, + slerp->_x3_cos_weight * cosine + slerp->_x3_sin_weight * sine ); } -inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Turn3* versor, const BGC_FP64_Slerp* slerp, const double phase) +inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Turn3* versor, const BGC_FP64_Turn3Slerp* slerp, const double phase) { const double angle = slerp->radians * phase; const double cosine = cos(angle); @@ -117,10 +102,10 @@ inline void bgc_fp64_slerp_get_phase_versor(BGC_FP64_Turn3* versor, const BGC_FP bgc_fp64_turn3_set_raw_values( versor, - slerp->s0_cos_weight * cosine + slerp->s0_sin_weight * sine, - slerp->x1_cos_weight * cosine + slerp->x1_sin_weight * sine, - slerp->x2_cos_weight * cosine + slerp->x2_sin_weight * sine, - slerp->x3_cos_weight * cosine + slerp->x3_sin_weight * sine + slerp->_s0_cos_weight * cosine + slerp->_s0_sin_weight * sine, + slerp->_x1_cos_weight * cosine + slerp->_x1_sin_weight * sine, + slerp->_x2_cos_weight * cosine + slerp->_x2_sin_weight * sine, + slerp->_x3_cos_weight * cosine + slerp->_x3_sin_weight * sine ); } diff --git a/basic-geometry/turn2.h b/basic-geometry/turn2.h index 667d2fc..f4d5f7b 100644 --- a/basic-geometry/turn2.h +++ b/basic-geometry/turn2.h @@ -3,22 +3,9 @@ #include -#include "utilities.h" -#include "angle.h" -#include "vector2.h" -#include "matrix2x2.h" - -// =================== Types ==================== // - -typedef struct -{ - float _cos, _sin; -} BGC_FP32_Turn2; - -typedef struct -{ - double _cos, _sin; -} BGC_FP64_Turn2; +#include "./utilities.h" +#include "./types.h" +#include "./angle.h" // ================= Constants ================== // diff --git a/basic-geometry/turn3.c b/basic-geometry/turn3.c index 93880eb..0918ee0 100644 --- a/basic-geometry/turn3.c +++ b/basic-geometry/turn3.c @@ -1,7 +1,8 @@ #include -#include "angle.h" -#include "turn3.h" +#include "./angle.h" +#include "./vector3.h" +#include "./turn3.h" const BGC_FP32_Turn3 BGC_FP32_IDLE_TURN3 = {{ 1.0f, 0.0f, 0.0f, 0.0f }}; @@ -308,7 +309,7 @@ static inline int _bgc_fp32_turn3_get_orthogonal_pair(BGC_FP32_Vector3* unit_mai return _BGC_ERROR_TURN3_EMPTY_BRANCH; } - bgc_fp32_vector3_multiply(unit_main, main, sqrtf(1.0f / main_square_modulus)); + bgc_fp32_vector3_multiply_by_real(unit_main, main, sqrtf(1.0f / main_square_modulus)); bgc_fp32_vector3_add_scaled(unit_branch, branch, unit_main, -bgc_fp32_vector3_get_dot_product(branch, unit_main)); @@ -318,7 +319,7 @@ static inline int _bgc_fp32_turn3_get_orthogonal_pair(BGC_FP32_Vector3* unit_mai return _BGC_ERROR_TURN3_PAIR_PARALLEL; } - bgc_fp32_vector3_multiply(unit_branch, unit_branch, sqrtf(1.0f / orthogonal_square_modulus)); + bgc_fp32_vector3_multiply_by_real(unit_branch, unit_branch, sqrtf(1.0f / orthogonal_square_modulus)); return BGC_SUCCESS; } @@ -337,7 +338,7 @@ static inline int _bgc_fp64_turn3_get_orthogonal_pair(BGC_FP64_Vector3* unit_mai return _BGC_ERROR_TURN3_EMPTY_BRANCH; } - bgc_fp64_vector3_multiply(unit_main, main, sqrt(1.0 / main_square_modulus)); + bgc_fp64_vector3_multiply_by_real(unit_main, main, sqrt(1.0 / main_square_modulus)); bgc_fp64_vector3_add_scaled(unit_branch, branch, unit_main, -bgc_fp64_vector3_get_dot_product(branch, unit_main)); @@ -347,7 +348,7 @@ static inline int _bgc_fp64_turn3_get_orthogonal_pair(BGC_FP64_Vector3* unit_mai return _BGC_ERROR_TURN3_PAIR_PARALLEL; } - bgc_fp64_vector3_multiply(unit_branch, unit_branch, sqrt(1.0 / orthogonal_square_modulus)); + bgc_fp64_vector3_multiply_by_real(unit_branch, unit_branch, sqrt(1.0 / orthogonal_square_modulus)); return BGC_SUCCESS; } diff --git a/basic-geometry/turn3.h b/basic-geometry/turn3.h index 8a48605..a56cdfe 100644 --- a/basic-geometry/turn3.h +++ b/basic-geometry/turn3.h @@ -3,11 +3,10 @@ #include -#include "utilities.h" -#include "angle.h" -#include "vector3.h" -#include "matrix3x3.h" -#include "quaternion.h" +#include "./utilities.h" +#include "./types.h" +#include "./angle.h" +#include "./quaternion.h" #define BGC_ERROR_TURN3_FIRST_VECTOR_ZERO -3010 #define BGC_ERROR_TURN3_SECOND_VECTOR_ZERO -3011 @@ -27,16 +26,6 @@ #define BGC_ERROR_TURN3_SECOND_PAIR_ZERO_BRANCH -3032 #define BGC_ERROR_TURN3_SECOND_PAIR_PARALLEL -3033 -// =================== Types ==================== // - -typedef struct { - BGC_FP32_Quaternion _versor; -} BGC_FP32_Turn3; - -typedef struct { - BGC_FP64_Quaternion _versor; -} BGC_FP64_Turn3; - // ================= Constants ================== // extern const BGC_FP32_Turn3 BGC_FP32_IDLE_TURN3; diff --git a/basic-geometry/types.h b/basic-geometry/types.h new file mode 100644 index 0000000..812ecff --- /dev/null +++ b/basic-geometry/types.h @@ -0,0 +1,230 @@ +#ifndef _BGC_TYPES_H_INCLUDED_ +#define _BGC_TYPES_H_INCLUDED_ + +// =================== Vector2 ================== // + +typedef struct +{ + float x1, x2; +} BGC_FP32_Vector2; + +typedef struct +{ + double x1, x2; +} BGC_FP64_Vector2; + +// ================== Vector3 =================== // + +typedef struct +{ + float x1, x2, x3; +} BGC_FP32_Vector3; + +typedef struct +{ + double x1, x2, x3; +} BGC_FP64_Vector3; + +// ================== Matrix2x2 ================= // + +typedef struct { + float r1c1, r1c2; + float r2c1, r2c2; +} BGC_FP32_Matrix2x2; + +typedef struct { + double r1c1, r1c2; + double r2c1, r2c2; +} BGC_FP64_Matrix2x2; + +// ================== Matrix2x3 ================= // + +typedef struct { + float r1c1, r1c2; + float r2c1, r2c2; + float r3c1, r3c2; +} BGC_FP32_Matrix2x3; + +typedef struct { + double r1c1, r1c2; + double r2c1, r2c2; + double r3c1, r3c2; +} BGC_FP64_Matrix2x3; + +// ================== Matrix3x2 ================= // + +typedef struct { + float r1c1, r1c2, r1c3; + float r2c1, r2c2, r2c3; +} BGC_FP32_Matrix3x2; + +typedef struct { + double r1c1, r1c2, r1c3; + double r2c1, r2c2, r2c3; +} BGC_FP64_Matrix3x2; + +// ================== Matrix3x3 ================= // + +typedef struct { + float r1c1, r1c2, r1c3; + float r2c1, r2c2, r2c3; + float r3c1, r3c2, r3c3; +} BGC_FP32_Matrix3x3; + +typedef struct { + double r1c1, r1c2, r1c3; + double r2c1, r2c2, r2c3; + double r3c1, r3c2, r3c3; +} BGC_FP64_Matrix3x3; + +// ================ Affine Map 2D ================ // + +typedef struct { + BGC_FP32_Matrix2x2 distortion; + BGC_FP32_Vector2 shift; +} BGC_FP32_Affine2; + +typedef struct { + BGC_FP64_Matrix2x2 distortion; + BGC_FP64_Vector2 shift; +} BGC_FP64_Affine2; + +// ================ Affine Map 3D ================ // + +typedef struct { + BGC_FP32_Matrix3x3 distortion; + BGC_FP32_Vector3 shift; +} BGC_FP32_Affine3; + +typedef struct { + BGC_FP64_Matrix3x3 distortion; + BGC_FP64_Vector3 shift; +} BGC_FP64_Affine3; + +// =============== Complex Number =============== // + +typedef struct +{ + float real, imaginary; +} BGC_FP32_Complex; + +typedef struct +{ + double real, imaginary; +} BGC_FP64_Complex; + +// =================== Turn2 ==================== // + +typedef struct +{ + float _cos, _sin; +} BGC_FP32_Turn2; + +typedef struct +{ + double _cos, _sin; +} BGC_FP64_Turn2; + +// ================= Quaternion ================= // + +typedef struct { + float s0, x1, x2, x3; +} BGC_FP32_Quaternion; + +typedef struct { + double s0, x1, x2, x3; +} BGC_FP64_Quaternion; + +// =================== Turn3 ==================== // + +typedef struct { + BGC_FP32_Quaternion _versor; +} BGC_FP32_Turn3; + +typedef struct { + BGC_FP64_Quaternion _versor; +} BGC_FP64_Turn3; + +// ================ Turn3 Slerp ================= // + +typedef struct { + float _s0_cos_weight, _s0_sin_weight; + float _x1_cos_weight, _x1_sin_weight; + float _x2_cos_weight, _x2_sin_weight; + float _x3_cos_weight, _x3_sin_weight; + float radians; +} BGC_FP32_Turn3Slerp; + +typedef struct { + double _s0_cos_weight, _s0_sin_weight; + double _x1_cos_weight, _x1_sin_weight; + double _x2_cos_weight, _x2_sin_weight; + double _x3_cos_weight, _x3_sin_weight; + double radians; +} BGC_FP64_Turn3Slerp; + +// =========== Homogeneous 3D Vector ============ // + +// Homogeneous 3D Vector +typedef struct +{ + float x1, x2, x3, d0; +} BGC_FP32_HgVector3; + +// Homogeneous 3D Vector +typedef struct +{ + double x1, x2, x3, d0; +} BGC_FP64_HgVector3; + +// =========== Homogeneous Matrix3x3 ============ // + +// Homogeneous Matrix3x3 based on float type +typedef struct +{ + float r1c1, r1c2, r1c3, r1d0; + float r2c1, r2c2, r2c3, r2d0; + float r3c1, r3c2, r3c3, r3d0; + float d0c1, d0c2, d0c3, d0d0; +} BGC_FP32_HgMatrix3x3; + +// Homogeneous Matrix3x3 based on double type +typedef struct +{ + double r1c1, r1c2, r1c3, r1d0; + double r2c1, r2c2, r2c3, r2d0; + double r3c1, r3c2, r3c3, r3d0; + double d0c1, d0c2, d0c3, d0d0; +} BGC_FP64_HgMatrix3x3; + +// ================ Dual Number ================= // + +typedef struct { + float real, dual; +} BGC_FP32_DualNumber; + +typedef struct { + double real, dual; +} BGC_FP64_DualNumber; + +// ================ Dual Vector ================= // + +typedef struct { + BGC_FP32_Vector3 real, dual; +} BGC_FP32_DualVector3; + +typedef struct { + BGC_FP64_Vector3 real, dual; +} BGC_FP64_DualVector3; + +// ============== Dual Quaternion =============== // + +typedef struct { + BGC_FP32_Quaternion real, dual; +} BGC_FP32_DualQuaternion; + +typedef struct { + BGC_FP64_Quaternion real, dual; +} BGC_FP64_DualQuaternion; + +#endif // _BGC_MATRIX_TYPES_H_ diff --git a/basic-geometry/utilities.c b/basic-geometry/utilities.c index 61caa21..a614230 100644 --- a/basic-geometry/utilities.c +++ b/basic-geometry/utilities.c @@ -1,4 +1,4 @@ -#include "utilities.h" +#include "./utilities.h" extern inline int bgc_is_correct_axis(const int axis); diff --git a/basic-geometry/vector2.c b/basic-geometry/vector2.c index 0eea237..d2d83e0 100644 --- a/basic-geometry/vector2.c +++ b/basic-geometry/vector2.c @@ -1,4 +1,4 @@ -#include "vector2.h" +#include "./vector2.h" extern inline void bgc_fp32_vector2_reset(BGC_FP32_Vector2* vector); extern inline void bgc_fp64_vector2_reset(BGC_FP64_Vector2* vector); @@ -36,11 +36,17 @@ extern inline void bgc_fp64_vector2_add_scaled(BGC_FP64_Vector2* sum, const BGC_ extern inline void bgc_fp32_vector2_subtract(BGC_FP32_Vector2* difference, const BGC_FP32_Vector2* minuend, const BGC_FP32_Vector2* subtrahend); extern inline void bgc_fp64_vector2_subtract(BGC_FP64_Vector2* difference, const BGC_FP64_Vector2* minuend, const BGC_FP64_Vector2* subtrahend); -extern inline void bgc_fp32_vector2_multiply(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier); -extern inline void bgc_fp64_vector2_multiply(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier); +extern inline void bgc_fp32_vector2_multiply_by_real(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier); +extern inline void bgc_fp64_vector2_multiply_by_real(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier); -extern inline int bgc_fp32_vector2_divide(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor); -extern inline int bgc_fp64_vector2_divide(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor); +extern inline void bgc_fp32_vector2_multiply_by_matrix2x2(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix2x2* matrix); +extern inline void bgc_fp64_vector2_multiply_by_matrix2x2(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix2x2* matrix); + +extern inline void bgc_fp32_vector2_multiply_by_matrix3x2(BGC_FP32_Vector3* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix3x2* matrix); +extern inline void bgc_fp64_vector2_multiply_by_matrix3x2(BGC_FP64_Vector3* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix3x2* matrix); + +extern inline int bgc_fp32_vector2_divide_by_real(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor); +extern inline int bgc_fp64_vector2_divide_by_real(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor); extern inline void bgc_fp32_vector2_get_mean2(BGC_FP32_Vector2* mean, const BGC_FP32_Vector2* vector1, const BGC_FP32_Vector2* vector2); extern inline void bgc_fp64_vector2_get_mean2(BGC_FP64_Vector2* mean, const BGC_FP64_Vector2* vector1, const BGC_FP64_Vector2* vector2); diff --git a/basic-geometry/vector2.h b/basic-geometry/vector2.h index 7bdc27c..d3a7852 100644 --- a/basic-geometry/vector2.h +++ b/basic-geometry/vector2.h @@ -1,20 +1,11 @@ #ifndef _BGC_VECTOR2_H_INCLUDED_ #define _BGC_VECTOR2_H_INCLUDED_ -#include "utilities.h" -#include "angle.h" - #include -typedef struct -{ - float x1, x2; -} BGC_FP32_Vector2; - -typedef struct -{ - double x1, x2; -} BGC_FP64_Vector2; +#include "./utilities.h" +#include "./types.h" +#include "./angle.h" // =================== Reset ==================== // @@ -186,38 +177,74 @@ inline void bgc_fp64_vector2_subtract(BGC_FP64_Vector2* difference, const BGC_FP // ================== Multiply ================== // -inline void bgc_fp32_vector2_multiply(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier) +inline void bgc_fp32_vector2_multiply_by_real(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* multiplicand, const float multiplier) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; } -inline void bgc_fp64_vector2_multiply(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier) +inline void bgc_fp64_vector2_multiply_by_real(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* multiplicand, const double multiplier) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; } +// ============ Left Vector Product ============= // + +inline void bgc_fp32_vector2_multiply_by_matrix2x2(BGC_FP32_Vector2* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix2x2* matrix) +{ + const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; + const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; + + product->x1 = x1; + product->x2 = x2; +} + +inline void bgc_fp64_vector2_multiply_by_matrix2x2(BGC_FP64_Vector2* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix2x2* matrix) +{ + const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; + const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; + + product->x1 = x1; + product->x2 = x2; +} + +// ============ Left Vector Product ============= // + +inline void bgc_fp32_vector2_multiply_by_matrix3x2(BGC_FP32_Vector3* product, const BGC_FP32_Vector2* vector, const BGC_FP32_Matrix3x2* matrix) +{ + product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; + product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; + product->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3; +} + +inline void bgc_fp64_vector2_multiply_by_matrix3x2(BGC_FP64_Vector3* product, const BGC_FP64_Vector2* vector, const BGC_FP64_Matrix3x2* matrix) +{ + product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1; + product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2; + product->x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3; +} + // =================== Divide =================== // -inline int bgc_fp32_vector2_divide(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor) +inline int bgc_fp32_vector2_divide_by_real(BGC_FP32_Vector2* quotient, const BGC_FP32_Vector2* dividend, const float divisor) { if (bgc_fp32_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp32_vector2_multiply(quotient, dividend, 1.0f / divisor); + bgc_fp32_vector2_multiply_by_real(quotient, dividend, 1.0f / divisor); return BGC_SUCCESS; } -inline int bgc_fp64_vector2_divide(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor) +inline int bgc_fp64_vector2_divide_by_real(BGC_FP64_Vector2* quotient, const BGC_FP64_Vector2* dividend, const double divisor) { if (bgc_fp64_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp64_vector2_multiply(quotient, dividend, 1.0 / divisor); + bgc_fp64_vector2_multiply_by_real(quotient, dividend, 1.0 / divisor); return BGC_SUCCESS; } @@ -350,7 +377,7 @@ inline int bgc_fp32_vector2_get_normalized(BGC_FP32_Vector2* normalized, const B return BGC_SUCCESS; } - bgc_fp32_vector2_multiply(normalized, vector, sqrtf(1.0f / square_modulus)); + bgc_fp32_vector2_multiply_by_real(normalized, vector, sqrtf(1.0f / square_modulus)); return BGC_SUCCESS; } @@ -368,7 +395,7 @@ inline int bgc_fp64_vector2_get_normalized(BGC_FP64_Vector2* normalized, const B return BGC_SUCCESS; } - bgc_fp64_vector2_multiply(normalized, vector, sqrt(1.0 / square_modulus)); + bgc_fp64_vector2_multiply_by_real(normalized, vector, sqrt(1.0 / square_modulus)); return BGC_SUCCESS; } diff --git a/basic-geometry/vector3.c b/basic-geometry/vector3.c index da7de6b..b899bdf 100644 --- a/basic-geometry/vector3.c +++ b/basic-geometry/vector3.c @@ -1,4 +1,4 @@ -#include "vector3.h" +#include "./vector3.h" extern inline void bgc_fp32_vector3_reset(BGC_FP32_Vector3* vector); extern inline void bgc_fp64_vector3_reset(BGC_FP64_Vector3* vector); @@ -36,11 +36,17 @@ extern inline void bgc_fp64_vector3_add_scaled(BGC_FP64_Vector3* sum, const BGC_ extern inline void bgc_fp32_vector3_subtract(BGC_FP32_Vector3* difference, const BGC_FP32_Vector3* minuend, const BGC_FP32_Vector3* subtrahend); extern inline void bgc_fp64_vector3_subtract(BGC_FP64_Vector3* difference, const BGC_FP64_Vector3* minuend, const BGC_FP64_Vector3* subtrahend); -extern inline void bgc_fp32_vector3_multiply(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier); -extern inline void bgc_fp64_vector3_multiply(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier); +extern inline void bgc_fp32_vector3_multiply_by_real(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier); +extern inline void bgc_fp64_vector3_multiply_by_real(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier); -extern inline int bgc_fp32_vector3_divide(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor); -extern inline int bgc_fp64_vector3_divide(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor); +extern inline void bgc_fp32_vector3_multiply_by_matrix2x3(BGC_FP32_Vector2* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix2x3* matrix); +extern inline void bgc_fp64_vector3_multiply_by_matrix2x3(BGC_FP64_Vector2* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix2x3* matrix); + +extern inline void bgc_fp32_vector3_multiply_by_matrix3x3(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix3x3* matrix); +extern inline void bgc_fp64_vector3_multiply_by_matrix3x3(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix3x3* matrix); + +extern inline int bgc_fp32_vector3_divide_by_real(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor); +extern inline int bgc_fp64_vector3_divide_by_real(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor); extern inline void bgc_fp32_vector3_get_mean2(BGC_FP32_Vector3* mean, const BGC_FP32_Vector3* vector1, const BGC_FP32_Vector3* vector2); extern inline void bgc_fp64_vector3_get_mean2(BGC_FP64_Vector3* mean, const BGC_FP64_Vector3* vector1, const BGC_FP64_Vector3* vector2); diff --git a/basic-geometry/vector3.h b/basic-geometry/vector3.h index 6fba649..0240ad8 100644 --- a/basic-geometry/vector3.h +++ b/basic-geometry/vector3.h @@ -1,22 +1,11 @@ #ifndef _BGC_VECTOR3_H_INCLUDED_ #define _BGC_VECTOR3_H_INCLUDED_ -#include "utilities.h" -#include "angle.h" - #include -// ================== Vector3 =================== // - -typedef struct -{ - float x1, x2, x3; -} BGC_FP32_Vector3; - -typedef struct -{ - double x1, x2, x3; -} BGC_FP64_Vector3; +#include "./utilities.h" +#include "./types.h" +#include "./angle.h" // =================== Reset ==================== // @@ -208,40 +197,78 @@ inline void bgc_fp64_vector3_subtract(BGC_FP64_Vector3* difference, const BGC_FP // ================== Multiply ================== // -inline void bgc_fp32_vector3_multiply(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier) +inline void bgc_fp32_vector3_multiply_by_real(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* multiplicand, const float multiplier) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; product->x3 = multiplicand->x3 * multiplier; } -inline void bgc_fp64_vector3_multiply(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier) +inline void bgc_fp64_vector3_multiply_by_real(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* multiplicand, const double multiplier) { product->x1 = multiplicand->x1 * multiplier; product->x2 = multiplicand->x2 * multiplier; product->x3 = multiplicand->x3 * multiplier; } +// ============ Left Vector Product ============= // + +inline void bgc_fp32_vector3_multiply_by_matrix2x3(BGC_FP32_Vector2* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix2x3* matrix) +{ + product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; + product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; +} + +inline void bgc_fp64_vector3_multiply_by_matrix2x3(BGC_FP64_Vector2* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix2x3* matrix) +{ + product->x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; + product->x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; +} + +// ============ Left Vector Product ============= // + +inline void bgc_fp32_vector3_multiply_by_matrix3x3(BGC_FP32_Vector3* product, const BGC_FP32_Vector3* vector, const BGC_FP32_Matrix3x3* matrix) +{ + const float x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; + const float x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; + const float x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3; + + product->x1 = x1; + product->x2 = x2; + product->x3 = x3; +} + +inline void bgc_fp64_vector3_multiply_by_matrix3x3(BGC_FP64_Vector3* product, const BGC_FP64_Vector3* vector, const BGC_FP64_Matrix3x3* matrix) +{ + const double x1 = vector->x1 * matrix->r1c1 + vector->x2 * matrix->r2c1 + vector->x3 * matrix->r3c1; + const double x2 = vector->x1 * matrix->r1c2 + vector->x2 * matrix->r2c2 + vector->x3 * matrix->r3c2; + const double x3 = vector->x1 * matrix->r1c3 + vector->x2 * matrix->r2c3 + vector->x3 * matrix->r3c3; + + product->x1 = x1; + product->x2 = x2; + product->x3 = x3; +} + // =================== Divide =================== // -inline int bgc_fp32_vector3_divide(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor) +inline int bgc_fp32_vector3_divide_by_real(BGC_FP32_Vector3* quotient, const BGC_FP32_Vector3* dividend, const float divisor) { if (bgc_fp32_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp32_vector3_multiply(quotient, dividend, 1.0f / divisor); + bgc_fp32_vector3_multiply_by_real(quotient, dividend, 1.0f / divisor); return BGC_SUCCESS; } -inline int bgc_fp64_vector3_divide(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor) +inline int bgc_fp64_vector3_divide_by_real(BGC_FP64_Vector3* quotient, const BGC_FP64_Vector3* dividend, const double divisor) { if (bgc_fp64_is_zero(divisor) || isnan(divisor)) { return BGC_FAILURE; } - bgc_fp64_vector3_multiply(quotient, dividend, 1.0 / divisor); + bgc_fp64_vector3_multiply_by_real(quotient, dividend, 1.0 / divisor); return BGC_SUCCESS; } @@ -386,7 +413,7 @@ inline int bgc_fp32_vector3_get_normalized(BGC_FP32_Vector3* normalized, const B return BGC_SUCCESS; } - bgc_fp32_vector3_multiply(normalized, vector, sqrtf(1.0f / square_modulus)); + bgc_fp32_vector3_multiply_by_real(normalized, vector, sqrtf(1.0f / square_modulus)); return BGC_SUCCESS; } @@ -404,7 +431,7 @@ inline int bgc_fp64_vector3_get_normalized(BGC_FP64_Vector3* normalized, const B return BGC_SUCCESS; } - bgc_fp64_vector3_multiply(normalized, vector, sqrt(1.0 / square_modulus)); + bgc_fp64_vector3_multiply_by_real(normalized, vector, sqrt(1.0 / square_modulus)); return BGC_SUCCESS; }