Переход на парадигму Destination first в порядке параметров функий

This commit is contained in:
Andrey Pokidov 2026-02-01 23:42:51 +07:00
parent f7e41645fe
commit 03627f4401
41 changed files with 1570 additions and 1978 deletions

View file

@ -2,7 +2,7 @@
#define _BGC_AFFINE2_H_INCLUDED_
#include "vector2.h"
#include "matrixes.h"
#include "matrices.h"
#include "matrix2x2.h"
// ==================== Types ==================== //
@ -19,13 +19,13 @@ typedef struct {
// ==================== Reset ==================== //
inline void bgc_fp32_affine2_reset(BGC_FP32_Affine2 * affine)
inline void bgc_fp32_affine2_reset(BGC_FP32_Affine2* affine)
{
bgc_fp32_matrix2x2_make_identity(&affine->distortion);
bgc_fp32_vector2_reset(&affine->shift);
}
inline void bgc_fp64_affine2_reset(BGC_FP64_Affine2 * affine)
inline void bgc_fp64_affine2_reset(BGC_FP64_Affine2* affine)
{
bgc_fp64_matrix2x2_make_identity(&affine->distortion);
bgc_fp64_vector2_reset(&affine->shift);
@ -33,31 +33,31 @@ inline void bgc_fp64_affine2_reset(BGC_FP64_Affine2 * affine)
// ==================== Make ===================== //
inline void bgc_fp32_affine2_make(const BGC_FP32_Matrix2x2 * distortion, const BGC_FP32_Vector2 * shift, BGC_FP32_Affine2 * affine)
inline void bgc_fp32_affine2_make(BGC_FP32_Affine2* affine, const BGC_FP32_Matrix2x2* distortion, const BGC_FP32_Vector2* shift)
{
bgc_fp32_matrix2x2_copy(distortion, &affine->distortion);
bgc_fp32_vector2_copy(shift, &affine->shift);
bgc_fp32_matrix2x2_copy(&affine->distortion, distortion);
bgc_fp32_vector2_copy(&affine->shift, shift);
}
inline void bgc_fp64_affine2_make(const BGC_FP64_Matrix2x2 * distortion, const BGC_FP64_Vector2 * shift, BGC_FP64_Affine2 * affine)
inline void bgc_fp64_affine2_make(BGC_FP64_Affine2* affine, const BGC_FP64_Matrix2x2* distortion, const BGC_FP64_Vector2* shift)
{
bgc_fp64_matrix2x2_copy(distortion, &affine->distortion);
bgc_fp64_vector2_copy(shift, &affine->shift);
bgc_fp64_matrix2x2_copy(&affine->distortion, distortion);
bgc_fp64_vector2_copy(&affine->shift, shift);
}
// ==================== Copy ===================== //
inline void bgc_fp32_affine2_copy(const BGC_FP32_Affine2 * source, BGC_FP32_Affine2 * destination)
inline void bgc_fp32_affine2_copy(BGC_FP32_Affine2* destination, const BGC_FP32_Affine2* source)
{
bgc_fp32_matrix2x2_copy(&source->distortion, &destination->distortion);
bgc_fp32_vector2_copy(&source->shift, &destination->shift);
bgc_fp32_matrix2x2_copy(&destination->distortion, &source->distortion);
bgc_fp32_vector2_copy(&destination->shift, &source->shift);
}
inline void bgc_fp64_affine2_copy(const BGC_FP64_Affine2 * source, BGC_FP64_Affine2 * destination)
inline void bgc_fp64_affine2_copy(BGC_FP64_Affine2* destination, const BGC_FP64_Affine2* source)
{
bgc_fp64_matrix2x2_copy(&source->distortion, &destination->distortion);
bgc_fp64_vector2_copy(&source->shift, &destination->shift);
bgc_fp64_matrix2x2_copy(&destination->distortion, &source->distortion);
bgc_fp64_vector2_copy(&destination->shift, &source->shift);
}
// ==================== Swap ===================== //
@ -76,16 +76,16 @@ inline void bgc_fp64_affine2_swap(BGC_FP64_Affine2 * first, BGC_FP64_Affine2 * s
// =================== Convert =================== //
inline void bgc_fp64_affine2_convert_to_fp32(const BGC_FP64_Affine2 * source, BGC_FP32_Affine2 * destination)
inline void bgc_fp32_affine2_convert_to_fp64(BGC_FP64_Affine2* destination, const BGC_FP32_Affine2* source)
{
bgc_fp64_matrix2x2_convert_to_fp32(&source->distortion, &destination->distortion);
bgc_fp64_vector2_convert_to_fp32(&source->shift, &destination->shift);
bgc_fp32_matrix2x2_convert_to_fp64(&destination->distortion, &source->distortion);
bgc_fp32_vector2_convert_to_fp64(&destination->shift, &source->shift);
}
inline void bgc_fp32_affine2_convert_to_fp64(const BGC_FP32_Affine2 * source, BGC_FP64_Affine2 * destination)
inline void bgc_fp64_affine2_convert_to_fp32(BGC_FP32_Affine2* destination, const BGC_FP64_Affine2 * source)
{
bgc_fp32_matrix2x2_convert_to_fp64(&source->distortion, &destination->distortion);
bgc_fp32_vector2_convert_to_fp64(&source->shift, &destination->shift);
bgc_fp64_matrix2x2_convert_to_fp32(&destination->distortion, &source->distortion);
bgc_fp64_vector2_convert_to_fp32(&destination->shift, &source->shift);
}
// =================== Invert ==================== //
@ -96,7 +96,7 @@ inline int bgc_fp32_affine2_invert(BGC_FP32_Affine2 * affine)
return 0;
}
bgc_fp32_multiply_matrix2x2_by_vector2(&affine->distortion, &affine->shift, &affine->shift);
bgc_fp32_multiply_matrix2x2_by_vector2(&affine->shift, &affine->distortion, &affine->shift);
bgc_fp32_vector2_revert(&affine->shift);
return 1;
@ -108,7 +108,7 @@ inline int bgc_fp64_affine2_invert(BGC_FP64_Affine2 * affine)
return 0;
}
bgc_fp64_multiply_matrix2x2_by_vector2(&affine->distortion, &affine->shift, &affine->shift);
bgc_fp64_multiply_matrix2x2_by_vector2(&affine->shift, &affine->distortion, &affine->shift);
bgc_fp64_vector2_revert(&affine->shift);
return 1;
@ -116,74 +116,74 @@ inline int bgc_fp64_affine2_invert(BGC_FP64_Affine2 * affine)
// ================= Get Inverse ================= //
inline int bgc_fp32_affine2_get_inverse(const BGC_FP32_Affine2 * source, BGC_FP32_Affine2 * destination)
inline int bgc_fp32_affine2_get_inverse(BGC_FP32_Affine2* inverse, const BGC_FP32_Affine2 * affine)
{
if (!bgc_fp32_matrix2x2_get_inverse(&source->distortion, &destination->distortion)) {
if (!bgc_fp32_matrix2x2_get_inverse(&inverse->distortion, &affine->distortion)) {
return 0;
}
bgc_fp32_multiply_matrix2x2_by_vector2(&destination->distortion, &source->shift, &destination->shift);
bgc_fp32_vector2_revert(&destination->shift);
bgc_fp32_multiply_matrix2x2_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift);
bgc_fp32_vector2_revert(&inverse->shift);
return 1;
}
inline int bgc_fp64_affine2_get_inverse(const BGC_FP64_Affine2 * source, BGC_FP64_Affine2 * destination)
inline int bgc_fp64_affine2_get_inverse(BGC_FP64_Affine2* inverse, const BGC_FP64_Affine2 * affine)
{
if (!bgc_fp64_matrix2x2_get_inverse(&source->distortion, &destination->distortion)) {
if (!bgc_fp64_matrix2x2_get_inverse(&inverse->distortion, &affine->distortion)) {
return 0;
}
bgc_fp64_multiply_matrix2x2_by_vector2(&destination->distortion, &source->shift, &destination->shift);
bgc_fp64_vector2_revert(&destination->shift);
bgc_fp64_multiply_matrix2x2_by_vector2(&inverse->shift, &inverse->distortion, &affine->shift);
bgc_fp64_vector2_revert(&inverse->shift);
return 1;
}
// =================== Combine =================== //
inline void bgc_fp32_affine2_combine(const BGC_FP32_Affine2 * first, const BGC_FP32_Affine2 * second, BGC_FP32_Affine2 * combination)
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(&second->distortion, &first->shift, &first_shift);
bgc_fp32_multiply_matrix2x2_by_matrix2x2(&second->distortion, &first->distortion, &combination->distortion);
bgc_fp32_vector2_add(&first_shift, &second->shift, &combination->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_vector2_add(&combination->shift, &second->shift, &first_shift);
}
inline void bgc_fp64_affine2_combine(const BGC_FP64_Affine2 * first, const BGC_FP64_Affine2 * second, BGC_FP64_Affine2 * combination)
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(&second->distortion, &first->shift, &first_shift);
bgc_fp64_multiply_matrix2x2_by_matrix2x2(&second->distortion, &first->distortion, &combination->distortion);
bgc_fp64_vector2_add(&first_shift, &second->shift, &combination->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_vector2_add(&combination->shift, &second->shift, &first_shift);
}
// =============== Transform Point =============== //
inline void bgc_fp32_affine2_transform_point(const BGC_FP32_Affine2 * affine, const BGC_FP32_Vector2 * initial_point, BGC_FP32_Vector2 * transformed_point)
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(&affine->distortion, initial_point, &distorted);
bgc_fp32_vector2_add(&affine->shift, &distorted, transformed_point);
bgc_fp32_multiply_matrix2x2_by_vector2(&distorted, &affine->distortion, initial_point);
bgc_fp32_vector2_add(transformed_point, &affine->shift, &distorted);
}
inline void bgc_fp64_affine2_transform_point(const BGC_FP64_Affine2 * affine, const BGC_FP64_Vector2 * initial_point, BGC_FP64_Vector2 * transformed_point)
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(&affine->distortion, initial_point, &distorted);
bgc_fp64_vector2_add(&affine->shift, &distorted, transformed_point);
bgc_fp64_multiply_matrix2x2_by_vector2(&distorted, &affine->distortion, initial_point);
bgc_fp64_vector2_add(transformed_point, &affine->shift, &distorted);
}
// ============== Transform Vector =============== //
inline void bgc_fp32_affine2_transform_vector(const BGC_FP32_Affine2 * affine, const BGC_FP32_Vector2 * initial_vector, BGC_FP32_Vector2 * transformed_vector)
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(&affine->distortion, initial_vector, transformed_vector);
bgc_fp32_multiply_matrix2x2_by_vector2(transformed_vector, &affine->distortion, initial_vector);
}
inline void bgc_fp64_affine2_transform_vector(const BGC_FP64_Affine2 * affine, const BGC_FP64_Vector2 * initial_vector, BGC_FP64_Vector2 * transformed_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(&affine->distortion, initial_vector, transformed_vector);
bgc_fp64_multiply_matrix2x2_by_vector2(transformed_vector, &affine->distortion, initial_vector);
}
#endif