Commit dd78e37b by VAN TOLL Wouter

Merge branch '86-clockwise' into 'master'

```Bugfix #86

Closes #86

See merge request !99```
parents 86c7358e 9181b04b
 ... ... @@ -59,7 +59,7 @@ public: /// Normalizes this Vector2D to unit length, by dividing both x and y by the magnitude. inline void normalize() { { float mag = magnitude(); if (mag > 0) { ... ... @@ -81,8 +81,8 @@ public: /// Another vector. /// The dot product of the current Vector2D and 'other', i.e. x*other.x + y*other.y. inline float dot(const Vector2D& other) const { return x_ * other.x_ + y_ * other.y_; { return x_ * other.x_ + y_ * other.y_; } /// Sets the x and y components of this Vector2D to the given values. ... ... @@ -102,7 +102,7 @@ public: x_ += rhs.x(); y_ += rhs.y(); return *this; } /// Subtracts another Vector2D to the current Vector2D. /// Another vector. /// A reference to the current Vector2D after the operation has been performed. ... ... @@ -115,8 +115,8 @@ public: /// Checks and returns whether this Vector2D is the zero vector. /// true if both x and y are 0; false otherwise. inline bool isZero() const { return x_ == 0 && y_ == 0; { return x_ == 0 && y_ == 0; } }; ... ... @@ -204,6 +204,12 @@ inline float cosAngle(const Vector2D& va, const Vector2D& vb) } inline bool isClockwise(const Vector2D &vector1, const Vector2D &vector2) { float cross = vector1.x() * vector2.y() - vector1.y() * vector2.x(); return cross < 0; } inline bool isCounterClockwise(const Vector2D &vector1, const Vector2D &vector2) { float cross = vector1.x() * vector2.y() - vector1.y() * vector2.x(); return cross > 0; ... ... @@ -217,11 +223,29 @@ inline float counterClockwiseAngle(const Vector2D& va, const Vector2D& vb) return ang; } inline float clockwiseAngle(const Vector2D& va, const Vector2D& vb) { float ang = angle(va, vb); if (isCounterClockwise(va, vb)) return -ang; return ang; } inline bool isPointLeftOfLine(const Vector2D& p, const Vector2D& la, const Vector2D& lb) { return isClockwise(p - la, lb - la); } inline bool isPointRightOfLine(const Vector2D& p, const Vector2D& la, const Vector2D& lb) { return isCounterClockwise(p - la, lb - la); } #pragma endregion template T clamp(T v, T min, T max) { if (v < min) if (v < min) return min; if (v > max) return max; ... ... @@ -236,7 +260,7 @@ inline Vector2D clamp(const Vector2D& v, float maxLength) return v.getnormalized() * maxLength; } inline bool getLineIntersection(const Vector2D& a, const Vector2D& b, const Vector2D& c, const Vector2D& d, Vector2D& result) inline bool getLineIntersection(const Vector2D& a, const Vector2D& b, const Vector2D& c, const Vector2D& d, Vector2D& result) { // Line AB represented as a1x + b1y = c1 double a1 = b.y() - a.y(); ... ... @@ -252,7 +276,7 @@ inline bool getLineIntersection(const Vector2D& a, const Vector2D& b, const Vect if (fabs(determinant) < 0.00001) // The lines are parallel. return false; result = Vector2D( (float)((b2*c1 - b1 * c2) / determinant), (float)((a1*c2 - a2 * c1) / determinant) ... ...
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment