Minor adjustments

This commit is contained in:
Wojtek Figat
2022-05-21 11:48:54 +02:00
parent b7459c7311
commit 5e6c518c39
2 changed files with 117 additions and 226 deletions

View File

@@ -50,46 +50,46 @@ public:
};
public:
// Vector with all components equal 0
// Vector with all components equal 0.
static const Double3 Zero;
// Vector with all components equal 1
// Vector with all components equal 1.
static const Double3 One;
// Vector with all components equal half (0.5, 0.5, 0.5)
// Vector with all components equal half (0.5, 0.5, 0.5).
static const Double3 Half;
// Vector X=1, Y=0, Z=0
// Vector X=1, Y=0, Z=0.
static const Double3 UnitX;
// Vector X=0, Y=1, Z=0
// Vector X=0, Y=1, Z=0.
static const Double3 UnitY;
// Vector X=0, Y=0, Z=1
// Vector X=0, Y=0, Z=1.
static const Double3 UnitZ;
// A unit vector designating up (0, 1, 0)
// A unit vector designating up (0, 1, 0).
static const Double3 Up;
// A unit vector designating down (0, -1, 0)
// A unit vector designating down (0, -1, 0).
static const Double3 Down;
// A unit vector designating a (-1, 0, 0)
// A unit vector designating a (-1, 0, 0).
static const Double3 Left;
// A unit vector designating b (1, 0, 0)
// A unit vector designating b (1, 0, 0).
static const Double3 Right;
// A unit vector designating forward in a a-handed coordinate system (0, 0, 1)
// A unit vector designating forward in a a-handed coordinate system (0, 0, 1).
static const Double3 Forward;
// A unit vector designating backward in a a-handed coordinate system (0, 0, -1)
// A unit vector designating backward in a a-handed coordinate system (0, 0, -1).
static const Double3 Backward;
// A minimum Double3
// A minimum Double3.
static const Double3 Minimum;
// A maximum Double3
// A maximum Double3.
static const Double3 Maximum;
public:
@@ -131,114 +131,75 @@ public:
{
}
// Init
// @param xy Vector2 with X and Y components values
// @param z Z component value
explicit Double3(const Vector2& xy, double z);
// Init
// @param xy Vector2 value
explicit Double3(const Vector2& xy);
// Init
// @param xyz Vector3 value
Double3(const Vector3& xyz);
// Init
// @param xyz Vector4 value
explicit Double3(const Vector4& xyzw);
// Init
// @param xy Int2 with X and Y components values
// @param z Z component value
explicit Double3(const Int2& xy, double z);
// Init
// @param xyz Int3 value
explicit Double3(const Int3& xyz);
// Init
// @param xyzw Int4 value
explicit Double3(const Int4& xyzw);
// Init
// @param xy Double2 value
explicit Double3(const Double2& xy);
// Init
// @param xy Double2 value
// @param z Z component value
explicit Double3(const Double2& xy, double z);
// Init
// @param xyzw Double4 value
explicit Double3(const Double4& xyzw);
// Init
// @param color Color value
explicit Double3(const Color& color);
public:
String ToString() const;
public:
// Gets a value indicting whether this instance is normalized
// Gets a value indicting whether this instance is normalized.
bool IsNormalized() const
{
return Math::IsOne(X * X + Y * Y + Z * Z);
}
// Gets a value indicting whether this vector is zero
// Gets a value indicting whether this vector is zero.
bool IsZero() const
{
return Math::IsZero(X) && Math::IsZero(Y) && Math::IsZero(Z);
}
// Gets a value indicting whether any vector component is zero
// Gets a value indicting whether any vector component is zero.
bool IsAnyZero() const
{
return Math::IsZero(X) || Math::IsZero(Y) || Math::IsZero(Z);
}
// Gets a value indicting whether this vector is one
// Gets a value indicting whether this vector is one.
bool IsOne() const
{
return Math::IsOne(X) && Math::IsOne(Y) && Math::IsOne(Z);
}
// Calculates length of the vector
// @returns Length of the vector
// Calculates the length of the vector.
double Length() const
{
return Math::Sqrt(X * X + Y * Y + Z * Z);
}
// Calculates the squared length of the vector
// @returns The squared length of the vector
// Calculates the squared length of the vector.
double LengthSquared() const
{
return X * X + Y * Y + Z * Z;
}
// Calculates inverted length of the vector (1 / Length())
// Calculates inverted length of the vector (1 / length).
double InvLength() const
{
return 1.0 / Length();
}
/// <summary>
/// Calculates a vector with values being absolute values of that vector
/// Calculates a vector with values being absolute values of that vector.
/// </summary>
/// <returns>Absolute vector</returns>
Double3 GetAbsolute() const
{
return Double3(Math::Abs(X), Math::Abs(Y), Math::Abs(Z));
}
/// <summary>
/// Calculates a vector with values being opposite to values of that vector
/// Calculates a vector with values being opposite to values of that vector.
/// </summary>
/// <returns>Negative vector</returns>
Double3 GetNegative() const
{
return Double3(-X, -Y, -Z);
@@ -247,7 +208,6 @@ public:
/// <summary>
/// Calculates a normalized vector that has length equal to 1.
/// </summary>
/// <returns>The normalized vector.</returns>
Double3 GetNormalized() const
{
const double rcp = 1.0 / Length();
@@ -255,63 +215,56 @@ public:
}
/// <summary>
/// Returns average arithmetic of all the components
/// Returns average arithmetic of all the components.
/// </summary>
/// <returns>Average arithmetic of all the components</returns>
double AverageArithmetic() const
{
return (X + Y + Z) * 0.333333334;
}
/// <summary>
/// Gets sum of all vector components values
/// Gets sum of all vector components values.
/// </summary>
/// <returns>Sum of X,Y and Z</returns>
double SumValues() const
{
return X + Y + Z;
}
/// <summary>
/// Returns minimum value of all the components
/// Returns minimum value of all the components.
/// </summary>
/// <returns>Minimum value</returns>
double MinValue() const
{
return Math::Min(X, Y, Z);
}
/// <summary>
/// Returns maximum value of all the components
/// Returns maximum value of all the components.
/// </summary>
/// <returns>Maximum value</returns>
double MaxValue() const
{
return Math::Max(X, Y, Z);
}
/// <summary>
/// Returns true if vector has one or more components is not a number (NaN)
/// Returns true if vector has one or more components is not a number (NaN).
/// </summary>
/// <returns>True if one or more components is not a number (NaN)</returns>
bool IsNaN() const
{
return isnan(X) || isnan(Y) || isnan(Z);
}
/// <summary>
/// Returns true if vector has one or more components equal to +/- infinity
/// Returns true if vector has one or more components equal to +/- infinity.
/// </summary>
/// <returns>True if one or more components equal to +/- infinity</returns>
bool IsInfinity() const
{
return isinf(X) || isinf(Y) || isinf(Z);
}
/// <summary>
/// Returns true if vector has one or more components equal to +/- infinity or NaN
/// Returns true if vector has one or more components equal to +/- infinity or NaN.
/// </summary>
/// <returns>True if one or more components equal to +/- infinity or NaN</returns>
bool IsNanOrInfinity() const
{
return IsInfinity() || IsNaN();
@@ -319,7 +272,7 @@ public:
public:
/// <summary>
/// Performs vector normalization (scales vector up to unit length)
/// Performs vector normalization (scales vector up to unit length).
/// </summary>
void Normalize()
{
@@ -334,7 +287,7 @@ public:
}
/// <summary>
/// Performs fast vector normalization (scales vector up to unit length)
/// Performs fast vector normalization (scales vector up to unit length).
/// </summary>
void NormalizeFast()
{
@@ -345,7 +298,7 @@ public:
}
/// <summary>
/// Sets all vector components to the absolute values
/// Sets all vector components to the absolute values.
/// </summary>
void Absolute()
{
@@ -355,7 +308,7 @@ public:
}
/// <summary>
/// Negates all components of that vector
/// Negates all components of that vector.
/// </summary>
void Negate()
{
@@ -365,12 +318,11 @@ public:
}
/// <summary>
/// When this vector contains Euler angles (degrees), ensure that angles are between +/-180
/// When this vector contains Euler angles (degrees), ensure that angles are between +/-180.
/// </summary>
void UnwindEuler();
public:
// Arithmetic operators with Double3
Double3 operator+(const Double3& b) const
{
return Double3(X + b.X, Y + b.Y, Z + b.Z);
@@ -406,7 +358,6 @@ public:
return Dot(*this, b);
}
// op= operators with Vector3
Double3& operator+=(const Double3& b)
{
X += b.X;
@@ -439,7 +390,6 @@ public:
return *this;
}
// Arithmetic operators with double
Double3 operator+(double b) const
{
return Double3(X + b, Y + b, Z + b);
@@ -460,7 +410,6 @@ public:
return Double3(X / b, Y / b, Z / b);
}
// op= operators with double
Double3& operator+=(double b)
{
*this = Add(*this, b);
@@ -485,7 +434,6 @@ public:
return *this;
}
// Comparison operators
bool operator==(const Double3& b) const
{
return X == b.X && Y == b.Y && Z == b.Z;
@@ -595,80 +543,80 @@ public:
}
public:
// Restricts a value to be within a specified range
// @param value The value to clamp
// @param min The minimum value,
// @param max The maximum value
// Restricts a value to be within a specified range.
// @param value The value to clamp.
// @param min The minimum value.
// @param max The maximum value.
// @returns Clamped value
static Double3 Clamp(const Double3& value, const Double3& min, const Double3& max);
// Restricts a value to be within a specified range
// @param value The value to clamp
// @param min The minimum value,
// @param max The maximum value
// @param result When the method completes, contains the clamped value
// Restricts a value to be within a specified range.
// @param value The value to clamp.
// @param min The minimum value.
// @param max The maximum value.
// @param result When the method completes, contains the clamped value.
static void Clamp(const Double3& value, const Double3& min, const Double3& max, Double3& result);
// Calculates the distance between two vectors
// @param value1 The first vector
// @param value2 The second vector
// @returns The distance between the two vectors
// Calculates the distance between two vectors.
// @param value1 The first vector.
// @param value2 The second vector.
// @returns The distance between the two vectors.
static double Distance(const Double3& value1, const Double3& value2);
// Calculates the squared distance between two vectors
// @param value1 The first vector
// @param value2 The second vector
// @returns The squared distance between the two vectors
// Calculates the squared distance between two vectors.
// @param value1 The first vector.
// @param value2 The second vector.
// @returns The squared distance between the two vectors.
static double DistanceSquared(const Double3& value1, const Double3& value2);
// Performs vector normalization (scales vector up to unit length)
// @param inout Input vector to normalize
// @returns Output vector that is normalized (has unit length)
// Performs vector normalization (scales vector up to unit length).
// @param inout Input vector to normalize.
// @returns Output vector that is normalized (has unit length).
static Double3 Normalize(const Double3& input);
// Performs vector normalization (scales vector up to unit length). This is a faster version that does not performs check for length equal 0 (it assumes that input vector is not empty).
// @param inout Input vector to normalize (cannot be zero).
// @returns Output vector that is normalized (has unit length)
// @returns Output vector that is normalized (has unit length).
static Double3 NormalizeFast(const Double3& input)
{
const double inv = 1.0 / input.Length();
return Double3(input.X * inv, input.Y * inv, input.Z * inv);
}
// Performs vector normalization (scales vector up to unit length)
// @param inout Input vector to normalize
// @param output Output vector that is normalized (has unit length)
// Performs vector normalization (scales vector up to unit length).
// @param inout Input vector to normalize.
// @param output Output vector that is normalized (has unit length).
static void Normalize(const Double3& input, Double3& result);
// dot product with another vector
// dot product with another vector.
static double Dot(const Double3& a, const Double3& b)
{
return a.X * b.X + a.Y * b.Y + a.Z * b.Z;
}
// Calculates the cross product of two vectors
// @param a First source vector
// @param b Second source vector
// @param result When the method completes, contains the cross product of the two vectors
// Calculates the cross product of two vectors.
// @param a First source vector.
// @param b Second source vector.
// @param result When the method completes, contains the cross product of the two vectors.
static void Cross(const Double3& a, const Double3& b, Double3& result)
{
result = Double3(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
}
// Calculates the cross product of two vectors
// @param a First source vector
// @param b Second source vector
// @returns Cross product of the two vectors
// Calculates the cross product of two vectors.
// @param a First source vector.
// @param b Second source vector.
// @returns Cross product of the two vectors.
static Double3 Cross(const Double3& a, const Double3& b)
{
return Double3(a.Y * b.Z - a.Z * b.Y, a.Z * b.X - a.X * b.Z, a.X * b.Y - a.Y * b.X);
}
// Performs a linear interpolation between two vectors
// @param start Start vector
// @param end End vector
// @param amount Value between 0 and 1 indicating the weight of end
// @param result When the method completes, contains the linear interpolation of the two vectors
// Performs a linear interpolation between two vectors.
// @param start Start vector.
// @param end End vector.
// @param amount Value between 0 and 1 indicating the weight of end.
// @param result When the method completes, contains the linear interpolation of the two vectors.
static void Lerp(const Double3& start, const Double3& end, double amount, Double3& result)
{
result.X = Math::Lerp(start.X, end.X, amount);
@@ -676,13 +624,9 @@ public:
result.Z = Math::Lerp(start.Z, end.Z, amount);
}
// <summary>
// Performs a linear interpolation between two vectors.
// </summary>
// @param start Start vector,
// @param end End vector,
// @param amount Value between 0 and 1 indicating the weight of @paramref end"/>,
// @returns The linear interpolation of the two vectors
/// <summary>
/// Performs a linear interpolation between two vectors.
/// </summary>
static Double3 Lerp(const Double3& start, const Double3& end, double amount)
{
Double3 result;
@@ -690,11 +634,9 @@ public:
return result;
}
// Performs a cubic interpolation between two vectors
// @param start Start vector
// @param end End vector
// @param amount Value between 0 and 1 indicating the weight of end
// @param result When the method completes, contains the cubic interpolation of the two vectors
/// <summary>
/// Performs a cubic interpolation between two vectors
/// </summary>
static void SmoothStep(const Double3& start, const Double3& end, double amount, Double3& result)
{
amount = Math::SmoothStep(amount);