21 constexpr
Vector3(T a_x, T a_y, T a_z) :
x(a_x),
y(a_y),
z(a_z) {}
24 #ifdef TOLUA_EXPOSITION
33 template <typename U, typename = typename std::enable_if<!std::is_same<U, T>::value>::type>
35 x(static_cast<T>(a_Rhs.
x)),
36 y(static_cast<T>(a_Rhs.
y)),
37 z(static_cast<T>(a_Rhs.
z))
42 inline void Set(T a_x, T a_y, T a_z)
51 double Len = 1.0 /
Length();
53 x =
static_cast<T
>(
x * Len);
54 y =
static_cast<T
>(
y * Len);
55 z =
static_cast<T
>(
z * Len);
60 double Len = 1.0 /
Length();
63 static_cast<T
>(
x * Len),
64 static_cast<T
>(
y * Len),
65 static_cast<T
>(
z * Len)
75 double Len = 1.0 /
Length();
78 static_cast<T
>(
x * Len),
79 static_cast<T
>(
y * Len),
80 static_cast<T
>(
z * Len)
89 #pragma clang diagnostic push
90 #pragma clang diagnostic ignored "-Wfloat-equal"
93 return ((
x != 0) || (
y != 0) || (
z != 0));
96 #pragma clang diagnostic pop
102 return sqrt(
static_cast<double>(
x *
x +
y *
y +
z *
z));
107 return x *
x +
y *
y +
z *
z;
112 return x * a_Rhs.
x +
y * a_Rhs.
y +
z * a_Rhs.
z;
134 y * a_Rhs.
z -
z * a_Rhs.
y,
135 z * a_Rhs.
x -
x * a_Rhs.
z,
136 x * a_Rhs.
y -
y * a_Rhs.
x
146 #pragma clang diagnostic push
147 #pragma clang diagnostic ignored "-Wfloat-equal"
150 return !((
x != a_Rhs.
x) || (
y != a_Rhs.
y) || (
z != a_Rhs.
z));
153 #pragma clang diagnostic pop
159 return (std::abs(
x - a_Rhs.
x) < a_Eps) && (std::abs(
y - a_Rhs.
y) < a_Eps) && (std::abs(
z - a_Rhs.
z) < a_Eps);
162 inline void Move(T a_X, T a_Y, T a_Z)
338 if (std::abs(
z - a_OtherEnd.
z) <
EPS)
343 return (a_Z -
z) / (a_OtherEnd.
z -
z);
353 if (std::abs(
y - a_OtherEnd.
y) <
EPS)
358 return (a_Y -
y) / (a_OtherEnd.
y -
y);
368 if (std::abs(
x - a_OtherEnd.
x) <
EPS)
373 return (a_X -
x) / (a_OtherEnd.
x -
x);
406 template <
typename What>
407 class fmt::formatter<
Vector3<What>> :
public fmt::formatter<What>
411 template <
typename FormatContext,
size_t Len>
412 void Write(FormatContext & a_Ctx,
const char (& a_Str)[Len])
414 const auto Itr = std::copy_n(&a_Str[0], Len - 1, a_Ctx.out());
415 a_Ctx.advance_to(Itr);
418 template <
typename FormatContext>
419 void Write(FormatContext & a_Ctx,
const What & a_Arg)
421 const auto Itr = Super::format(a_Arg, a_Ctx);
422 a_Ctx.advance_to(Itr);
427 template <
typename FormatContext>
454 template <
typename What>
462 size_t Hash =
static_cast<size_t>(a_Vector.
y);
464 Hash ^=
static_cast<size_t>(a_Vector.
x);
465 Hash ^=
static_cast<size_t>(a_Vector.
z) << 8;
474 template <
typename T>
477 template <
typename T>
#define TOLUA_TEMPLATE_BIND(x)
std::enable_if< std::is_arithmetic< T >::value, C >::type CeilC(T a_Value)
Ceils a value, then casts it to C (an int by default).
std::enable_if< std::is_arithmetic< T >::value, C >::type FloorC(T a_Value)
Floors a value, then casts it to C (an int by default).
Vector3< double > Vector3d
std::vector< Vector3i > cVector3iArray
Vector3< float > Vector3f
void Write(const std::string &a_FileName, ContiguousByteBufferView a_Contents)
Writes a_Contents into file, compressing it along the way.
Vector3< T > addedY(T a_AddY) const
Returns a copy of this vector moved by the specified amount on the y axis.
bool HasNonZeroLength(void) const
void Move(const Vector3< T > &a_Diff)
T Dot(const Vector3< T > &a_Rhs) const
static const double EPS
The max difference between two coords for which the coords are assumed equal.
bool operator!=(const Vector3< T > &a_Rhs) const
double LineCoeffToXZPlane(const Vector3< T > &a_OtherEnd, T a_Y) const
Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Y coord.
Vector3< int > Floor(void) const
Returns a new Vector3i with coords set to std::floor() of this vector's coords.
bool EqualsEps(const Vector3< T > &a_Rhs, T a_Eps) const
static const double NO_INTERSECTION
Return value of LineCoeffToPlane() if the line is parallel to the plane.
Vector3< T > addedXZ(T a_AddX, T a_AddZ) const
Returns a copy of this vector moved by the specified amount on the X and Z axes.
void Move(T a_X, T a_Y, T a_Z)
double Length(void) const
Vector3< T > operator+(const Vector3< T > &a_Rhs) const
Vector3< T > addedZ(T a_AddZ) const
Returns a copy of this vector moved by the specified amount on the Z axis.
Vector3< T > operator*(const Vector3< T > &a_Rhs) const
bool operator==(const Vector3< T > &a_Rhs) const
void TurnCCW(void)
Rotates the vector 90 degrees counterclockwise around the vertical axis.
Vector3< T > Cross(const Vector3< T > &a_Rhs) const
bool operator<(const Vector3< T > &a_Rhs) const
constexpr Vector3(T a_x, T a_y, T a_z)
void TurnCW(void)
Rotates the vector 90 degrees clockwise around the vertical axis.
void Clamp(T a_Min, T a_Max)
Clamps each coord into the specified range.
void Set(T a_x, T a_y, T a_z)
void operator+=(const Vector3< T > &a_Rhs)
void Abs()
Updates each coord to its absolute value.
void operator-=(const Vector3< T > &a_Rhs)
Vector3< int > Ceil() const
Returns a new Vector3i with coords set to std::ceil() of this vector's coords.
Vector3< T > operator/(const Vector3< T > &a_Rhs)
Vector3< T > addedX(T a_AddX) const
Returns a copy of this vector moved by the specified amount on the X axis.
Vector3< T > NormalizeCopy(void) const
void operator*=(const Vector3< T > &a_Rhs)
bool operator>(const Vector3< T > &a_Rhs) const
constexpr Vector3(const Vector3< U > &a_Rhs)
Vector3< T > operator-(void) const
double SqrLength(void) const
double LineCoeffToYZPlane(const Vector3< T > &a_OtherEnd, T a_X) const
Returns the coefficient for the (a_OtherEnd - this) line to reach the specified X coord.
bool Equals(const Vector3< T > &a_Rhs) const
double LineCoeffToXYPlane(const Vector3< T > &a_OtherEnd, T a_Z) const
Returns the coefficient for the (a_OtherEnd - this) line to reach the specified Z coord.
void NormalizeCopy(Vector3< T > &a_Rhs) const
Sets the given vector to the normalized version of this vector.
auto format(const Vector3< What > &a_Vec, FormatContext &a_Ctx)
void Write(FormatContext &a_Ctx, const What &a_Arg)
fmt::formatter< What > Super
void Write(FormatContext &a_Ctx, const char(&a_Str)[Len])
size_t operator()(const Vector3< What > &a_Vector) const
Provides a hash of a vector's contents.