MeshLib C++ Docs
Loading...
Searching...
No Matches
MRAffineXf.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMacros.h"
4#include "MRMeshFwd.h"
5#include <iosfwd>
6#include <type_traits>
7
8#if MR_COMPILING_ANY_BINDINGS
12#include "MRMatrix2.h"
13#include "MRMatrix3.h"
14#endif
15
16namespace MR
17{
20
21
24template <typename V> MR_REQUIRES_IF_SUPPORTED( detail::AffineXf3f::IsValidTemplateArg<V> )
25struct AffineXf
26{
27 using T = typename V::ValueType;
28 using M = typename V::MatrixType;
29
30 M A;
31 V b;
32
33 constexpr AffineXf() noexcept = default;
34 constexpr AffineXf( const M & A, const V & b ) noexcept : A( A ), b( b ) { }
35
38 template <typename U> MR_REQUIRES_IF_SUPPORTED( !std::is_same_v<U, V> )
39 constexpr explicit AffineXf( const AffineXf<U> & xf ) noexcept : A( xf.A ), b( xf.b ) { }
40
42 [[nodiscard]] static constexpr AffineXf translation( const V & b ) noexcept { return AffineXf{ M{}, b }; }
44 [[nodiscard]] static constexpr AffineXf linear( const M & A ) noexcept { return AffineXf{ A, V{} }; }
46 [[nodiscard]] static constexpr AffineXf xfAround( const M & A, const V & stable ) noexcept { return AffineXf{ A, stable - A * stable }; }
47
49 [[nodiscard]] constexpr V operator() ( const V & x ) const noexcept { return A * x + b; }
52 [[nodiscard]] constexpr V linearOnly( const V & x ) const noexcept { return A * x; }
54 [[nodiscard]] constexpr AffineXf inverse() const noexcept MR_REQUIRES_IF_SUPPORTED( !std::is_integral_v<T> )
55 {
56 AffineXf<V> res;
57 res.A = A.inverse();
58 res.b = -( res.A * b );
59 return res;
60 }
61
64 friend AffineXf<V> operator * ( const AffineXf<V> & u, const AffineXf<V> & v )
65 { return { u.A * v.A, u.A * v.b + u.b }; }
66
68 friend bool operator == ( const AffineXf<V> & a, const AffineXf<V> & b )
69 {
70 return a.A == b.A && a.b == b.b;
71 }
72
74 friend bool operator != ( const AffineXf<V> & a, const AffineXf<V> & b )
75 {
76 return !( a == b );
77 }
78
79 friend std::ostream& operator<<( std::ostream& s, const AffineXf& xf )
80 {
81 return s << xf.A << xf.b;
82 }
83
84 friend std::istream& operator>>( std::istream& s, AffineXf& xf )
85 {
86 return s >> xf.A >> xf.b;
87 }
88};
89
90}
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:33
#define M(T)
bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
bool operator!=(const Color &a, const Color &b)
Definition MRColor.h:104
Color operator*(float a, const Color &b)
Definition MRColor.h:119
AffineXf
Definition MRMeshFwd.h:290
only for bindings generation
Definition MRCameraOrientationPlugin.h:8