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> )
26{
27 using T = typename V::ValueType;
28 using M = typename V::MatrixType;
29
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
bool operator==(const Allocator< T > &, const Allocator< U > &) noexcept
Definition MRAllocator.h:95
typename V::ValueType T
Definition MRAffineXf.h:27
struct
Definition MRMeshFwd.h:189
static constexpr AffineXf linear(const M &A) noexcept
creates linear-only transformation (without translation)
Definition MRAffineXf.h:44
bool operator!=(const Color &a, const Color &b)
Definition MRColor.h:107
static constexpr AffineXf xfAround(const M &A, const V &stable) noexcept
creates transformation with given linear part with given stable point
Definition MRAffineXf.h:46
typename V::MatrixType M
Definition MRAffineXf.h:28
friend std::istream & operator>>(std::istream &s, AffineXf &xf)
Definition MRAffineXf.h:84
Color operator*(float a, const Color &b)
Definition MRColor.h:122
constexpr AffineXf inverse() const noexcept
computes inverse transformation
Definition MRAffineXf.h:54
constexpr AffineXf() noexcept=default
Vector3< T > b
Definition MRAffineXf.h:31
M A
Definition MRAffineXf.h:30
static constexpr AffineXf translation(const V &b) noexcept
creates translation-only transformation (with identity linear component)
Definition MRAffineXf.h:42
constexpr V linearOnly(const V &x) const noexcept
Definition MRAffineXf.h:52
friend std::ostream & operator<<(std::ostream &s, const AffineXf &xf)
Definition MRAffineXf.h:79
Only strictly necessary for the bindings (to make MR::MeshIntersectionResult a complete type).
Definition MRCameraOrientationPlugin.h:8