6#include "MRPch/MRBindingMacros.h"
20#pragma warning(disable: 4804)
21#pragma warning(disable: 4146)
36 constexpr Vector3() noexcept :
x( 0 ),
y( 0 ),
z( 0 ) { }
54 constexpr explicit Vector3(
const Vector3<U> & v ) noexcept :
x( T( v.x ) ),
y( T( v.y ) ),
z( T( v.z ) ) { }
56 constexpr const T &
operator [](
int e )
const noexcept {
return *( &
x + e ); }
57 constexpr T &
operator [](
int e )
noexcept {
return *( &
x + e ); }
73 return ( 1 / len ) * (*this);
87 return xf ? ( *xf )( *this ) : *
this;
93 for (
auto i = 0; i <
elements; ++i )
94 if ( (*
this)[i] == 0.f && std::signbit( (*
this)[i] ) )
100 return std::isfinite(
x ) && std::isfinite(
y ) && std::isfinite(
z );
117 if constexpr ( std::is_integral_v<T> )
118 return { b.x / a, b.y / a, b.z / a };
120 return b * ( 1 / a );
128 if constexpr ( std::is_integral_v<T> )
129 { a.
x /= b; a.
y /= b; a.
z /= b;
return a; }
131 return a *= ( 1 / b );
143 return ( a - b ).lengthSq();
150 return ( a - b ).length();
158 a.
y * b.
z - a.
z * b.
y,
159 a.
z * b.
x - a.
x * b.
z,
160 a.
x * b.
y - a.
y * b.
x
168 return a.x * b.x + a.y * b.y + a.z * b.z;
182 return dot( a, cross( b, c ) );
189 return { a.
x * b.
x,a.
y * b.
y,a.
z * b.
z };
196 return { a.
x / b.
x, a.
y / b.
y, a.
z / b.
z };
205 return std::atan2( cross( a, b ).
length(), dot( a, b ) );
214 if ( abs( x ) < abs( y ) )
215 return ( abs( x ) < abs( z ) ) ?
Vector3( 1, 0, 0 ) :
Vector3( 0, 0, 1 );
217 return ( abs( y ) < abs( z ) ) ?
Vector3( 0, 1, 0 ) :
Vector3( 0, 0, 1 );
221inline std::pair<Vector3<T>, Vector3<T>> Vector3<T>::perpendicular() const
MR_REQUIRES_IF_SUPPORTED( std::floating_point<T> )
223 std::pair<Vector3<T>, Vector3<T>> res;
224 auto c1 = furthestBasisVector();
225 res.first = cross( *
this, c1 ).normalized();
226 res.second = cross( *
this, res.first ).normalized();
234 const auto zenithAngle = T( PI2 ) - altitude;
237 std::sin( zenithAngle ) * std::cos( azimuth ),
238 std::sin( zenithAngle ) * std::sin( azimuth ),
239 std::cos( zenithAngle )
265struct std::hash<
MR::Vector3f>
267 size_t operator()( MR::Vector3f
const& p )
const noexcept
273 static_assert(
sizeof( float ) ==
sizeof( std::uint32_t ) );
274 std::memcpy( &xy, &p.x,
sizeof( std::uint64_t ) );
275 std::memcpy( &z, &p.z,
sizeof( std::uint32_t ) );
276 return size_t( xy ) ^ ( size_t( z ) << 16 );
#define MR_SAME_TYPE_TEMPLATE_PARAM(target_, name_)
Definition MRMacros.h:32
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:31
length
Definition MRObjectDimensionsEnum.h:14
MR_BIND_IGNORE auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:308
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:310
Definition MRCameraOrientationPlugin.h:8
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:10
Definition MRMesh/MRAffineXf.h:21
Definition MRMesh/MRMatrix3.h:19
Definition MRMesh/MRMeshFwd.h:90
Definition MRSymMatrix3.h:15
Definition MRVector2.h:27
Definition MRMesh/MRVector3.h:28
static constexpr Vector3 plusX() noexcept
Definition MRMesh/MRVector3.h:44
void unsignZeroValues() MR_REQUIRES_IF_SUPPORTED(std
get rid of signed zero values to be sure that equal vectors have identical binary representation
Definition MRMesh/MRVector3.h:91
auto dot(const Vector3< T > &a, const Vector3< T > &b) -> decltype(a.x *b.x)
dot product
Definition MRMesh/MRVector3.h:166
Vector3< T > unitVector3(T azimuth, T altitude)
returns a point on unit sphere given two angles
Definition MRMesh/MRVector3.h:232
T distanceSq(const Vector3< T > &a, const Vector3< T > &b)
squared distance between two points, which is faster to compute than just distance
Definition MRMesh/MRVector3.h:141
friend constexpr bool operator!=(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:104
Vector3< T > div(const Vector3< T > &a, const Vector3< T > &b)
per component division
Definition MRMesh/MRVector3.h:194
friend constexpr auto operator*(T a, const Vector3< T > &b) -> Vector3< decltype(std::declval< T >() *std::declval< T >())>
Definition MRMesh/MRVector3.h:113
friend constexpr auto operator-(const Vector3< T > &a) -> Vector3< decltype(-std::declval< T >())>
Definition MRMesh/MRVector3.h:109
T x
Definition MRMesh/MRVector3.h:34
static constexpr Vector3 minusX() noexcept
Definition MRMesh/MRVector3.h:47
Vector3 furthestBasisVector() const MR_REQUIRES_IF_SUPPORTED(!std std::pair< Vector3, Vector3 > perpendicular() const MR_REQUIRES_IF_SUPPORTED(std Vector3 transformed(const AffineXf3< TT > *xf) const MR_REQUIRES_IF_SUPPORTED(std
returns one of 3 basis unit vector that makes the biggest angle with the direction specified by this
Definition MRMesh/MRVector3.h:85
static constexpr Vector3 minusY() noexcept
Definition MRMesh/MRVector3.h:48
T y
Definition MRMesh/MRVector3.h:34
static constexpr int elements
Definition MRMesh/MRVector3.h:32
friend constexpr const Vector3< T > & operator+(const Vector3< T > &a)
Definition MRMesh/MRVector3.h:108
friend constexpr Vector3< T > & operator/=(Vector3< T > &a, T b)
Definition MRMesh/MRVector3.h:126
MR_REQUIRES_IF_SUPPORTED(!std::is_same_v< T, U >) const expr explicit Vector3(const Vector3< U > &v) noexcept
Definition MRMesh/MRVector3.h:53
Vector3(NoInit) noexcept
Definition MRMesh/MRVector3.h:37
T ValueType
Definition MRMesh/MRVector3.h:29
constexpr const T & operator[](int e) const noexcept
Definition MRMesh/MRVector3.h:56
auto length() const
Definition MRMesh/MRVector3.h:60
MR_REQUIRES_IF_SUPPORTED(std::constructible_from< T, U >) explicit const expr Vector3(const Vector2< U > &v) noexcept
Definition MRMesh/MRVector3.h:40
constexpr Vector3(T x, T y, T z) noexcept
Definition MRMesh/MRVector3.h:38
friend constexpr bool operator==(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:103
friend constexpr Vector3< T > & operator*=(Vector3< T > &a, T b)
Definition MRMesh/MRVector3.h:125
T distance(const Vector3< T > &a, const Vector3< T > &b)
distance between two points, better use distanceSq for higher performance
Definition MRMesh/MRVector3.h:148
T mixed(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
mixed product
Definition MRMesh/MRVector3.h:180
static constexpr Vector3 plusZ() noexcept
Definition MRMesh/MRVector3.h:46
Vector3 normalized() const MR_REQUIRES_IF_SUPPORTED(std
Definition MRMesh/MRVector3.h:68
friend constexpr auto operator/(Vector3< T > b, T a) -> Vector3< decltype(std::declval< T >()/std::declval< T >())>
Definition MRMesh/MRVector3.h:115
T sqr(const Vector3< T > &a)
squared length
Definition MRMesh/MRVector3.h:173
T angle(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:203
constexpr Vector3() noexcept
Definition MRMesh/MRVector3.h:36
static constexpr Vector3 minusZ() noexcept
Definition MRMesh/MRVector3.h:49
Vector3< T > mult(const Vector3< T > &a, const Vector3< T > &b)
per component multiplication
Definition MRMesh/MRVector3.h:187
T z
Definition MRMesh/MRVector3.h:34
friend constexpr Vector3< T > & operator-=(Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:124
T lengthSq() const
Definition MRMesh/MRVector3.h:59
static constexpr Vector3 plusY() noexcept
Definition MRMesh/MRVector3.h:45
bool isFinite() const MR_REQUIRES_IF_SUPPORTED(std
Definition MRMesh/MRVector3.h:98
static constexpr Vector3 diagonal(T a) noexcept
Definition MRMesh/MRVector3.h:43
Vector3< T > cross(const Vector3< T > &a, const Vector3< T > &b)
cross product
Definition MRMesh/MRVector3.h:155
friend constexpr Vector3< T > & operator+=(Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:123