Добавлеие позиционирования и аффинного преобразования для 2-мерного пространства, добавление функций для аффинных преобразований и позиционирования
This commit is contained in:
parent
3c2b89f369
commit
101df9f089
12 changed files with 734 additions and 322 deletions
175
basic-geometry/affine2.h
Normal file
175
basic-geometry/affine2.h
Normal file
|
|
@ -0,0 +1,175 @@
|
|||
#ifndef _BGC_AFFINE2_H_INCLUDED_
|
||||
#define _BGC_AFFINE2_H_INCLUDED_
|
||||
|
||||
#include "vector2.h"
|
||||
#include "matrixes.h"
|
||||
#include "matrix2x2.h"
|
||||
|
||||
// ==================== Types ==================== //
|
||||
|
||||
typedef struct {
|
||||
BgcMatrix2x2FP32 distortion;
|
||||
BgcVector2FP32 shift;
|
||||
} BgcAffine2FP32;
|
||||
|
||||
typedef struct {
|
||||
BgcMatrix2x2FP64 distortion;
|
||||
BgcVector2FP64 shift;
|
||||
} BgcAffine2FP64;
|
||||
|
||||
// ==================== Reset ==================== //
|
||||
|
||||
inline void bgc_affine2_reset_fp32(BgcAffine2FP32 * affine)
|
||||
{
|
||||
bgc_matrix2x2_set_to_identity_fp32(&affine->distortion);
|
||||
bgc_vector2_reset_fp32(&affine->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_reset_fp64(BgcAffine2FP64 * affine)
|
||||
{
|
||||
bgc_matrix2x2_set_to_identity_fp64(&affine->distortion);
|
||||
bgc_vector2_reset_fp64(&affine->shift);
|
||||
}
|
||||
|
||||
// ==================== Make ===================== //
|
||||
|
||||
inline void bgc_affine2_make_fp32(const BgcMatrix2x2FP32 * distortion, const BgcVector2FP32 * shift, BgcAffine2FP32 * affine)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp32(distortion, &affine->distortion);
|
||||
bgc_vector2_copy_fp32(shift, &affine->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_make_fp64(const BgcMatrix2x2FP64 * distortion, const BgcVector2FP64 * shift, BgcAffine2FP64 * affine)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp64(distortion, &affine->distortion);
|
||||
bgc_vector2_copy_fp64(shift, &affine->shift);
|
||||
}
|
||||
|
||||
|
||||
// ==================== Copy ===================== //
|
||||
|
||||
inline void bgc_affine2_copy_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_copy_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_copy_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
bgc_matrix2x2_copy_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_copy_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Convert =================== //
|
||||
|
||||
inline void bgc_affine2_convert_fp64_to_fp32(const BgcAffine2FP64 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
bgc_matrix2x2_convert_fp64_to_fp32(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_convert_fp64_to_fp32(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_convert_fp32_to_fp64(const BgcAffine2FP32 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
bgc_matrix2x2_convert_fp32_to_fp64(&source->distortion, &destination->distortion);
|
||||
bgc_vector2_convert_fp32_to_fp64(&source->shift, &destination->shift);
|
||||
}
|
||||
|
||||
// =================== Invert ==================== //
|
||||
|
||||
inline int bgc_affine2_invert_fp32(BgcAffine2FP32 * affine)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp32(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector2_make_opposite_fp32(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine2_invert_fp64(BgcAffine2FP64 * affine)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp64(&affine->distortion, &affine->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, &affine->shift, &affine->shift);
|
||||
bgc_vector2_make_opposite_fp64(&affine->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// ================= Get Inverse ================= //
|
||||
|
||||
inline int bgc_affine2_get_inverse_fp32(const BgcAffine2FP32 * source, BgcAffine2FP32 * destination)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp32(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp32(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector2_make_opposite_fp32(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
inline int bgc_affine2_get_inverse_fp64(const BgcAffine2FP64 * source, BgcAffine2FP64 * destination)
|
||||
{
|
||||
if (!bgc_matrix2x2_invert_fp64(&source->distortion, &destination->distortion)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
bgc_matrix2x2_get_right_product_fp64(&destination->distortion, &source->shift, &destination->shift);
|
||||
bgc_vector2_make_opposite_fp64(&destination->shift);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
// =================== Combine =================== //
|
||||
|
||||
inline void bgc_affine2_combine_fp32(const BgcAffine2FP32 * parent, const BgcAffine2FP32 * child, BgcAffine2FP32 * combination)
|
||||
{
|
||||
BgcVector2FP32 child_shift;
|
||||
bgc_matrix2x2_get_right_product_fp32(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_2x2_at_2x2_fp32(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector2_add_fp32(&parent->shift, &child_shift, &combination->shift);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_combine_fp64(const BgcAffine2FP64 * parent, const BgcAffine2FP64 * child, BgcAffine2FP64 * combination)
|
||||
{
|
||||
BgcVector2FP64 child_shift;
|
||||
bgc_matrix2x2_get_right_product_fp64(&parent->distortion, &child->shift, &child_shift);
|
||||
bgc_matrix_product_2x2_at_2x2_fp64(&parent->distortion, &child->distortion, &combination->distortion);
|
||||
bgc_vector2_add_fp64(&parent->shift, &child_shift, &combination->shift);
|
||||
}
|
||||
|
||||
// =============== Transform Point =============== //
|
||||
|
||||
inline void bgc_affine2_transform_point_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_point, BgcVector2FP32 * transformed_point)
|
||||
{
|
||||
BgcVector2FP32 distorted;
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector2_add_fp32(&affine->shift, &distorted, transformed_point);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_transform_point_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_point, BgcVector2FP64 * transformed_point)
|
||||
{
|
||||
BgcVector2FP64 distorted;
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, initial_point, &distorted);
|
||||
bgc_vector2_add_fp64(&affine->shift, &distorted, transformed_point);
|
||||
}
|
||||
|
||||
// ============== Transform Vector =============== //
|
||||
|
||||
inline void bgc_affine2_transform_vector_fp32(const BgcAffine2FP32 * affine, const BgcVector2FP32 * initial_vector, BgcVector2FP32 * transformed_vector)
|
||||
{
|
||||
bgc_matrix2x2_get_right_product_fp32(&affine->distortion, initial_vector, transformed_vector);
|
||||
}
|
||||
|
||||
inline void bgc_affine2_transform_vector_fp64(const BgcAffine2FP64 * affine, const BgcVector2FP64 * initial_vector, BgcVector2FP64 * transformed_vector)
|
||||
{
|
||||
bgc_matrix2x2_get_right_product_fp64(&affine->distortion, initial_vector, transformed_vector);
|
||||
}
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue