MeshLib C++ Docs
Loading...
Searching...
No Matches
MRMesh/MRAffineXf.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMacros.h"
4#include "MRMeshFwd.h"
5#include <type_traits>
6
7#if MR_COMPILING_C_BINDINGS
8// Include the headers for the matrices that are otherwise missing in the C bindings.
9// I'm not sure how the binding generator could possibly guess that it needs to include those.
10#include "MRMatrix2.h"
11#include "MRMatrix3.h"
12#endif
13
14namespace MR
15{
16
19template <typename V>
21{
22 using T = typename V::ValueType;
23 using M = typename V::MatrixType;
24
26 V b;
27
28 constexpr AffineXf() noexcept = default;
29 constexpr AffineXf( const M & A, const V & b ) noexcept : A( A ), b( b ) { }
30 template <typename U>
31 constexpr explicit AffineXf( const AffineXf<U> & xf ) noexcept : A( xf.A ), b( xf.b ) { }
33 [[nodiscard]] static constexpr AffineXf translation( const V & b ) noexcept { return AffineXf{ M{}, b }; }
35 [[nodiscard]] static constexpr AffineXf linear( const M & A ) noexcept { return AffineXf{ A, V{} }; }
37 [[nodiscard]] static constexpr AffineXf xfAround( const M & A, const V & stable ) noexcept { return AffineXf{ A, stable - A * stable }; }
38
40 [[nodiscard]] constexpr V operator() ( const V & x ) const noexcept { return A * x + b; }
43 [[nodiscard]] constexpr V linearOnly( const V & x ) const noexcept { return A * x; }
45 [[nodiscard]] constexpr AffineXf inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> );
46
49 friend AffineXf<V> operator * ( const AffineXf<V> & u, const AffineXf<V> & v )
50 { return { u.A * v.A, u.A * v.b + u.b }; }
51
53 friend bool operator == ( const AffineXf<V> & a, const AffineXf<V> & b )
54 {
55 return a.A == b.A && a.b == b.b;
56 }
57
59 friend bool operator != ( const AffineXf<V> & a, const AffineXf<V> & b )
60 {
61 return !( a == b );
62 }
63};
64
67
68template <typename V>
69inline constexpr AffineXf<V> AffineXf<V>::inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> )
70{
71 AffineXf<V> res;
72 res.A = A.inverse();
73 res.b = -( res.A * b );
74 return res;
75}
76
78
79} // namespace MR
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:31
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRAffineXf.h:21
typename V::ValueType T
Definition MRMesh/MRAffineXf.h:22
friend bool operator!=(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRMesh/MRAffineXf.h:59
static constexpr AffineXf linear(const M &A) noexcept
creates linear-only transformation (without translation)
Definition MRMesh/MRAffineXf.h:35
static constexpr AffineXf xfAround(const M &A, const V &stable) noexcept
creates transformation with given linear part with given stable point
Definition MRMesh/MRAffineXf.h:37
friend bool operator==(const AffineXf< V > &a, const AffineXf< V > &b)
Definition MRMesh/MRAffineXf.h:53
constexpr V operator()(const V &x) const noexcept
application of the transformation to a point
Definition MRMesh/MRAffineXf.h:40
typename V::MatrixType M
Definition MRMesh/MRAffineXf.h:23
constexpr AffineXf() noexcept=default
V b
Definition MRMesh/MRAffineXf.h:26
M A
Definition MRMesh/MRAffineXf.h:25
static constexpr AffineXf translation(const V &b) noexcept
creates translation-only transformation (with identity linear component)
Definition MRMesh/MRAffineXf.h:33
constexpr V linearOnly(const V &x) const noexcept
Definition MRMesh/MRAffineXf.h:43
constexpr AffineXf(const AffineXf< U > &xf) noexcept
Definition MRMesh/MRAffineXf.h:31