7#include "MRPch/MRBindingMacros.h"
22#pragma warning(disable: 4804)
23#pragma warning(disable: 4146)
41 static_assert(
elements == 3,
"Invalid number of elements" );
60 constexpr explicit Vector3(
const Vector3<U> & v ) noexcept :
x( T( v.x ) ),
y( T( v.y ) ),
z( T( v.z ) ) { }
79 return ( 1 / len ) * (*this);
93 return xf ? ( *xf )( *this ) : *
this;
99 for (
auto i = 0; i <
elements; ++i )
100 if ( (*
this)[i] == 0.f && std::signbit( (*
this)[i] ) )
106 return std::isfinite(
x ) && std::isfinite(
y ) && std::isfinite(
z );
123 if constexpr ( std::is_integral_v<T> )
124 return { b.x / a, b.y / a, b.z / a };
126 return b * ( 1 / a );
134 if constexpr ( std::is_integral_v<T> )
135 { a.
x /= b; a.
y /= b; a.
z /= b;
return a; }
137 return a *= ( 1 / b );
142 return s << vec.
x <<
' ' << vec.
y <<
' ' << vec.
z;
147 return s >> vec.
x >> vec.
y >> vec.
z;
159 return ( a - b ).lengthSq();
166 return ( a - b ).length();
174 a.
y * b.
z - a.
z * b.
y,
175 a.
z * b.
x - a.
x * b.
z,
176 a.
x * b.
y - a.
y * b.
x
184 return a.x * b.x + a.y * b.y + a.z * b.z;
198 return dot( a, cross( b, c ) );
205 return { a.
x * b.
x,a.
y * b.
y,a.
z * b.
z };
212 return { a.
x / b.
x, a.
y / b.
y, a.
z / b.
z };
221 return std::atan2( cross( a, b ).
length(), dot( a, b ) );
231 if ( abs( x ) < abs( y ) )
232 return ( abs( x ) < abs( z ) ) ?
Vector3( 1, 0, 0 ) :
Vector3( 0, 0, 1 );
234 return ( abs( y ) < abs( z ) ) ?
Vector3( 0, 1, 0 ) :
Vector3( 0, 0, 1 );
238inline std::pair<Vector3<T>, Vector3<T>> Vector3<T>::perpendicular() const
MR_REQUIRES_IF_SUPPORTED( std::floating_point<T> )
240 std::pair<Vector3<T>, Vector3<T>> res;
241 auto c1 = furthestBasisVector();
242 res.first = cross( *
this, c1 ).normalized();
243 res.second = cross( *
this, res.first ).normalized();
251 const auto zenithAngle = T( PI2 ) - altitude;
254 std::sin( zenithAngle ) * std::cos( azimuth ),
255 std::sin( zenithAngle ) * std::sin( azimuth ),
256 std::cos( zenithAngle )
282struct std::hash<
MR::Vector3f>
284 size_t operator()( MR::Vector3f
const& p )
const noexcept
290 static_assert(
sizeof( float ) ==
sizeof( std::uint32_t ) );
291 std::memcpy( &xy, &p.x,
sizeof( std::uint64_t ) );
292 std::memcpy( &z, &p.z,
sizeof( std::uint32_t ) );
293 return size_t( xy ) ^ ( size_t( z ) << 16 );
#define MR_SAME_TYPE_TEMPLATE_PARAM(target_, name_)
Definition MRMacros.h:35
#define MR_REQUIRES_IF_SUPPORTED(...)
Definition MRMacros.h:34
length
Definition MRObjectDimensionsEnum.h:14
MR_BIND_IGNORE auto begin(const BitSet &a)
Definition MRMesh/MRBitSet.h:380
MR_BIND_IGNORE auto end(const BitSet &)
Definition MRMesh/MRBitSet.h:382
constexpr T abs(T value)
Definition MRUnsigned.h:18
Definition MRCameraOrientationPlugin.h:8
std::array< Vector3f, 3 > MR_BIND_IGNORE
Definition MRMeshBuilderTypes.h:10
Definition MRMesh/MRAffineXf.h:23
Definition MRMesh/MRMatrix3.h:21
Definition MRMeshFwd.h:94
Definition MRSymMatrix3.h:15
Definition MRVector2.h:29
Definition MRMesh/MRVector3.h:30
static constexpr Vector3 plusX() noexcept
Definition MRMesh/MRVector3.h:50
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:97
static constexpr Vector3 minusX() noexcept MR_REQUIRES_IF_SUPPORTED(!std
Definition MRMesh/MRVector3.h:53
auto dot(const Vector3< T > &a, const Vector3< T > &b) -> decltype(a.x *b.x)
dot product
Definition MRMesh/MRVector3.h:182
Vector3< T > unitVector3(T azimuth, T altitude)
returns a point on unit sphere given two angles
Definition MRMesh/MRVector3.h:249
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:157
friend constexpr bool operator!=(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:110
static constexpr Vector3 minusY() noexcept MR_REQUIRES_IF_SUPPORTED(!std
Definition MRMesh/MRVector3.h:54
static constexpr Vector3 minusZ() noexcept MR_REQUIRES_IF_SUPPORTED(!std
Definition MRMesh/MRVector3.h:55
Vector3< T > div(const Vector3< T > &a, const Vector3< T > &b)
per component division
Definition MRMesh/MRVector3.h:210
friend constexpr auto operator*(T a, const Vector3< T > &b) -> Vector3< decltype(std::declval< T >() *std::declval< T >())>
Definition MRMesh/MRVector3.h:119
friend constexpr auto operator-(const Vector3< T > &a) -> Vector3< decltype(-std::declval< T >())>
Definition MRMesh/MRVector3.h:115
T x
Definition MRMesh/MRVector3.h:36
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:91
T y
Definition MRMesh/MRVector3.h:36
static constexpr int elements
Definition MRMesh/MRVector3.h:34
friend std::istream & operator>>(std::istream &s, Vector3 &vec)
Definition MRMesh/MRVector3.h:145
friend std::ostream & operator<<(std::ostream &s, const Vector3 &vec)
Definition MRMesh/MRVector3.h:140
friend constexpr const Vector3< T > & operator+(const Vector3< T > &a)
Definition MRMesh/MRVector3.h:114
friend constexpr Vector3< T > & operator/=(Vector3< T > &a, T b)
Definition MRMesh/MRVector3.h:132
MR_REQUIRES_IF_SUPPORTED(!std::is_same_v< T, U >) const expr explicit Vector3(const Vector3< U > &v) noexcept
Definition MRMesh/MRVector3.h:59
Vector3(NoInit) noexcept
Definition MRMesh/MRVector3.h:43
T ValueType
Definition MRMesh/MRVector3.h:31
constexpr const T & operator[](int e) const noexcept
Definition MRMesh/MRVector3.h:62
auto length() const
Definition MRMesh/MRVector3.h:66
MR_REQUIRES_IF_SUPPORTED(std::constructible_from< T, U >) explicit const expr Vector3(const Vector2< U > &v) noexcept
Definition MRMesh/MRVector3.h:46
constexpr Vector3(T x, T y, T z) noexcept
Definition MRMesh/MRVector3.h:44
friend constexpr bool operator==(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:109
friend constexpr Vector3< T > & operator*=(Vector3< T > &a, T b)
Definition MRMesh/MRVector3.h:131
T distance(const Vector3< T > &a, const Vector3< T > &b)
distance between two points, better use distanceSq for higher performance
Definition MRMesh/MRVector3.h:164
T mixed(const Vector3< T > &a, const Vector3< T > &b, const Vector3< T > &c)
mixed product
Definition MRMesh/MRVector3.h:196
static constexpr Vector3 plusZ() noexcept
Definition MRMesh/MRVector3.h:52
Vector3 normalized() const MR_REQUIRES_IF_SUPPORTED(std
Definition MRMesh/MRVector3.h:74
friend constexpr auto operator/(Vector3< T > b, T a) -> Vector3< decltype(std::declval< T >()/std::declval< T >())>
Definition MRMesh/MRVector3.h:121
T sqr(const Vector3< T > &a)
squared length
Definition MRMesh/MRVector3.h:189
T angle(const Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:219
constexpr Vector3() noexcept
Definition MRMesh/MRVector3.h:38
Vector3< T > mult(const Vector3< T > &a, const Vector3< T > &b)
per component multiplication
Definition MRMesh/MRVector3.h:203
T z
Definition MRMesh/MRVector3.h:36
friend constexpr Vector3< T > & operator-=(Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:130
T lengthSq() const
Definition MRMesh/MRVector3.h:65
static constexpr Vector3 plusY() noexcept
Definition MRMesh/MRVector3.h:51
bool isFinite() const MR_REQUIRES_IF_SUPPORTED(std
Definition MRMesh/MRVector3.h:104
static constexpr Vector3 diagonal(T a) noexcept
Definition MRMesh/MRVector3.h:49
Vector3< T > cross(const Vector3< T > &a, const Vector3< T > &b)
cross product
Definition MRMesh/MRVector3.h:171
friend constexpr Vector3< T > & operator+=(Vector3< T > &a, const Vector3< T > &b)
Definition MRMesh/MRVector3.h:129