From 5dee2731e6fb3deb2c44e269d12c2b7db62c74cb Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 7 Jun 2012 13:35:23 +0200 Subject: Finished implementation of math functions --- src/math/point.h | 131 +------------------------------------------------------ 1 file changed, 2 insertions(+), 129 deletions(-) (limited to 'src/math/point.h') diff --git a/src/math/point.h b/src/math/point.h index 7000138..fdb3051 100644 --- a/src/math/point.h +++ b/src/math/point.h @@ -70,7 +70,7 @@ struct Point //! Returns the distance from (0,0) to the point (x,y) inline float Length() { - return sqrt(x*x + y*y); + return sqrtf(x*x + y*y); } //! Returns the inverted point @@ -163,134 +163,7 @@ inline void Swap(Point &a, Point &b) //! Returns the distance between two points inline float Distance(const Point &a, const Point &b) { - return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y)); -} - -//! Returns py up on the line \a a - \a b -inline float MidPoint(const Point &a, const Point &b, float px) -{ - if (IsEqual(a.x, b.x)) - { - if (a.y < b.y) - return HUGE; - else - return -HUGE; - } - return (b.y-a.y) * (px-a.x) / (b.x-a.x) + a.y; -} - -//! Calculates the parameters a and b of the linear function passing through \a p1 and \a p2 -/** Returns \c false if the line is vertical. - \param p1,p2 points - \param a,b linear function parameters */ -inline bool LinearFunction(const Point &p1, const Point &p2, float &a, float &b) -{ - if ( IsZero(p1.x-p2.x) ) - { - a = HUGE; - b = p2.x; - return false; - } - - a = (p2.y-p1.y) / (p2.x-p1.x); - b = p2.y - p2.x*a; - - return true; -} - -//! Checks if the point is inside triangle defined by vertices \a a, \a b, \a c -inline bool IsInsideTriangle(Point a, Point b, Point c, const Point &p) -{ - if ( p.x < a.x && p.x < b.x && p.x < c.x ) return false; - if ( p.x > a.x && p.x > b.x && p.x > c.x ) return false; - if ( p.y < a.y && p.y < b.y && p.y < c.y ) return false; - if ( p.y > a.y && p.y > b.y && p.y > c.y ) return false; - - if ( a.x > b.x ) Swap(a,b); - if ( a.x > c.x ) Swap(a,c); - if ( c.x < a.x ) Swap(c,a); - if ( c.x < b.x ) Swap(c,b); - - float n, m; - - n = MidPoint(a, b, p.x); - m = MidPoint(a, c, p.x); - if ( (n>p.y || p.y>m) && (np.y || p.y>m) && (n