Removed Vector2.tofactor
This commit is contained in:
parent
159bdaec8e
commit
dc601a1746
@ -140,7 +140,3 @@ Vector2 Vector2::Lerp(Vector2 from, Vector2 to, float f) {
|
|||||||
Vector2 v = from + (to - from) * f;
|
Vector2 v = from + (to - from) * f;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
float Vector2::ToFactor(Vector2 a, Vector2 b) {
|
|
||||||
return (1 - Vector2::Dot(a, b)) / 2;
|
|
||||||
}
|
|
||||||
|
36
Vector2.h
36
Vector2.h
@ -6,12 +6,12 @@
|
|||||||
#define VECTOR2_H
|
#define VECTOR2_H
|
||||||
|
|
||||||
extern "C" {
|
extern "C" {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 2-dimensional Vector representation
|
/// 2-dimensional Vector representation
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// This is a C-style implementation
|
/// This is a C-style implementation
|
||||||
/// This uses the right-handed coordinate system.
|
/// This uses the right-handed coordinate system.
|
||||||
typedef struct Vec2 {
|
typedef struct Vec2 {
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The right axis of the vector
|
/// The right axis of the vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -21,7 +21,7 @@ extern "C" {
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
float y;
|
float y;
|
||||||
|
|
||||||
} Vec2;
|
} Vec2;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -59,7 +59,7 @@ public:
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// A vector with values (1, 0)
|
/// A vector with values (1, 0)
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
const static Vector2 right;
|
const static Vector2 right;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A vector3 with values (-1, 0)
|
/// A vector3 with values (-1, 0)
|
||||||
@ -87,7 +87,7 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vector">The vector for which you need the length</param>
|
/// <param name="vector">The vector for which you need the length</param>
|
||||||
/// <returns>The length of the given vector</returns>
|
/// <returns>The length of the given vector</returns>
|
||||||
static float Magnitude(const Vector2& vector);
|
static float Magnitude(const Vector2 &vector);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The length of this vector
|
/// The length of this vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -100,7 +100,7 @@ public:
|
|||||||
/// length</param> <returns>The squatred length</returns> The squared length
|
/// length</param> <returns>The squatred length</returns> The squared length
|
||||||
/// is computationally simpler than the real length. Think of Pythagoras A^2 +
|
/// is computationally simpler than the real length. Think of Pythagoras A^2 +
|
||||||
/// B^2 = C^2. This leaves out the calculation of the squared root of C.
|
/// B^2 = C^2. This leaves out the calculation of the squared root of C.
|
||||||
static float SqrMagnitude(const Vector2& vector);
|
static float SqrMagnitude(const Vector2 &vector);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The squared length of this vector
|
/// The squared length of this vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -132,14 +132,14 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vector">The vector to subtract from this vector</param>
|
/// <param name="vector">The vector to subtract from this vector</param>
|
||||||
/// <returns>The result of the subtraction</returns>
|
/// <returns>The result of the subtraction</returns>
|
||||||
Vector2 operator-(const Vector2& vector) const;
|
Vector2 operator-(const Vector2 &vector) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Add another vector to this vector
|
/// Add another vector to this vector
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="vector2">The vector to add</param>
|
/// <param name="vector2">The vector to add</param>
|
||||||
/// <returns>The result of adding the vector</returns>
|
/// <returns>The result of adding the vector</returns>
|
||||||
Vector2 operator+(const Vector2& vector2) const;
|
Vector2 operator+(const Vector2 &vector2) const;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scale a vector using another vector
|
/// Scale a vector using another vector
|
||||||
@ -149,7 +149,7 @@ public:
|
|||||||
/// <returns>The scaled vector</returns>
|
/// <returns>The scaled vector</returns>
|
||||||
/// Each component of the vector v1 will be multiplied with the
|
/// Each component of the vector v1 will be multiplied with the
|
||||||
/// component from the scaling vector v2.
|
/// component from the scaling vector v2.
|
||||||
static Vector2 Scale(const Vector2& vector1, const Vector2& vector2);
|
static Vector2 Scale(const Vector2 &vector1, const Vector2 &vector2);
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Scale a vector uniformly up
|
/// Scale a vector uniformly up
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@ -163,7 +163,7 @@ public:
|
|||||||
/// <param name="factor">The scaling factor</param>
|
/// <param name="factor">The scaling factor</param>
|
||||||
/// <returns>The scaled vector</returns>
|
/// <returns>The scaled vector</returns>
|
||||||
/// Each componet of the vector will be divided by the same factor.
|
/// Each componet of the vector will be divided by the same factor.
|
||||||
Vector2 operator/(const float& factor);
|
Vector2 operator/(const float &factor);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The dot product of two vectors
|
/// The dot product of two vectors
|
||||||
@ -171,7 +171,7 @@ public:
|
|||||||
/// <param name="vector1">The first vector</param>
|
/// <param name="vector1">The first vector</param>
|
||||||
/// <param name="vector2">The second vector</param>
|
/// <param name="vector2">The second vector</param>
|
||||||
/// <returns>The dot product of the two vectors</returns>
|
/// <returns>The dot product of the two vectors</returns>
|
||||||
static float Dot(const Vector2& vector1, const Vector2& vector2);
|
static float Dot(const Vector2 &vector1, const Vector2 &vector2);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Check is this vector is equal to the given vector
|
/// Check is this vector is equal to the given vector
|
||||||
@ -180,7 +180,7 @@ public:
|
|||||||
/// <returns>True if it is identical to the given vector</returns>
|
/// <returns>True if it is identical to the given vector</returns>
|
||||||
/// Note this uses float comparison to check equality which
|
/// Note this uses float comparison to check equality which
|
||||||
/// may have strange effects. Equality on float should be avoided.
|
/// may have strange effects. Equality on float should be avoided.
|
||||||
bool operator==(const Vector2& vector);
|
bool operator==(const Vector2 &vector);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The distance between two vectors
|
/// The distance between two vectors
|
||||||
@ -188,7 +188,7 @@ public:
|
|||||||
/// <param name="vector1">The first vector</param>
|
/// <param name="vector1">The first vector</param>
|
||||||
/// <param name="vector2">The second vectors</param>
|
/// <param name="vector2">The second vectors</param>
|
||||||
/// <returns>The distance between the two vectors</returns>
|
/// <returns>The distance between the two vectors</returns>
|
||||||
static float Distance(const Vector2& vector1, const Vector2& vector2);
|
static float Distance(const Vector2 &vector1, const Vector2 &vector2);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculate the angle between two vectors
|
/// Calculate the angle between two vectors
|
||||||
@ -229,8 +229,6 @@ public:
|
|||||||
/// matches the *to* vector Value -1 is *from* vector minus the difference
|
/// matches the *to* vector Value -1 is *from* vector minus the difference
|
||||||
/// between *from* and *to* etc.
|
/// between *from* and *to* etc.
|
||||||
static Vector2 Lerp(Vector2 from, Vector2 to, float f);
|
static Vector2 Lerp(Vector2 from, Vector2 to, float f);
|
||||||
|
|
||||||
static float ToFactor(Vector2 a, Vector2 b);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
@ -460,6 +460,4 @@ TEST(Vector2, Lerp) {
|
|||||||
EXPECT_FLOAT_EQ(Vector2::Distance(r, Vector2(-2.0, -1.0f)), 0);
|
EXPECT_FLOAT_EQ(Vector2::Distance(r, Vector2(-2.0, -1.0f)), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST(Vector2, DISABLED_ToFactor) {}
|
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user