diff --git a/src/db/db/dbPoint.h b/src/db/db/dbPoint.h index ca281f080..a3d44bfa6 100644 --- a/src/db/db/dbPoint.h +++ b/src/db/db/dbPoint.h @@ -47,7 +47,7 @@ class ArrayRepository; */ template -class DB_PUBLIC_TEMPLATE point +class DB_PUBLIC point { public: typedef C coord_type; @@ -131,27 +131,48 @@ public: /** * @brief Add to operation */ - point &operator+= (const vector &v); + point &operator+= (const vector &v) + { + m_x += v.x (); + m_y += v.y (); + return *this; + } /** * @brief method version of operator+ (mainly for automation purposes) */ - point add (const vector &v) const; + point add (const vector &v) const + { + point r (*this); + r += v; + return r; + } /** * @brief Subtract from operation */ - point &operator-= (const vector &v); + point &operator-= (const vector &v) + { + m_x -= v.x (); + m_y -= v.y (); + return *this; + } /** * @brief method version of operator- (mainly for automation purposes) */ - point subtract (const vector &v) const; + point subtract (const vector &v) const + { + return *this - v; + } /** * @brief method version of operator- (mainly for automation purposes) */ - vector subtract (const point &p) const; + vector subtract (const point &p) const + { + return *this - p; + } /** * @brief "less" comparison operator @@ -159,17 +180,26 @@ public: * This operator is provided to establish a sorting * order */ - bool operator< (const point &p) const; + bool operator< (const point &p) const + { + return m_y < p.m_y || (m_y == p.m_y && m_x < p.m_x); + } /** * @brief Equality test operator */ - bool operator== (const point &p) const; + bool operator== (const point &p) const + { + return m_x == p.m_x && m_y == p.m_y; + } /** * @brief Inequality test operator */ - bool operator!= (const point &p) const; + bool operator!= (const point &p) const + { + return !operator== (p); + } /** * @brief Const transform @@ -181,7 +211,10 @@ public: * @return The transformed point */ template - point transformed (const Tr &t) const; + point transformed (const Tr &t) const + { + return t (*this); + } /** * @brief In-place transformation @@ -193,27 +226,43 @@ public: * @return The transformed point */ template - point &transform (const Tr &t); + point &transform (const Tr &t) + { + *this = t (*this); + return *this; + } /** * @brief Accessor to the x coordinate */ - C x () const; + C x () const + { + return m_x; + } /** * @brief Accessor to the y coordinate */ - C y () const; + C y () const + { + return m_y; + } /** * @brief Write accessor to the x coordinate */ - void set_x (C _x); + void set_x (C _x) + { + m_x = _x; + } /** * @brief Write accessor to the y coordinate */ - void set_y (C _y); + void set_y (C _y) + { + m_y = _y; + } /** * @brief Scaling self by some factor @@ -313,7 +362,10 @@ public: /** * @brief Fuzzy comparison of points */ - bool equal (const point &p) const; + bool equal (const point &p) const + { + return coord_traits::equal (x (), p.x ()) && coord_traits::equal (y (), p.y ()); + } /** * @brief Fuzzy comparison of points for inequality @@ -326,7 +378,16 @@ public: /** * @brief Fuzzy "less" comparison of points */ - bool less (const point &p) const; + bool less (const point &p) const + { + if (! coord_traits::equal (y (), p.y ())) { + return y () < p.y (); + } + if (! coord_traits::equal (x (), p.x ())) { + return x () < p.x (); + } + return false; + } /** * @brief The (dummy) translation operator @@ -350,131 +411,6 @@ private: C m_x, m_y; }; -template -inline point & -point::operator+= (const vector &v) -{ - m_x += v.x (); - m_y += v.y (); - return *this; -} - -template -inline point -point::add (const vector &v) const -{ - point r (*this); - r += v; - return r; -} - -template -inline point & -point::operator-= (const vector &v) -{ - m_x -= v.x (); - m_y -= v.y (); - return *this; -} - -template -inline point -point::subtract (const vector &v) const -{ - return *this - v; -} - -template -inline vector -point::subtract (const point &p) const -{ - return *this - p; -} - -template -inline bool -point::operator< (const point &p) const -{ - return m_y < p.m_y || (m_y == p.m_y && m_x < p.m_x); -} - -template -inline bool -point::less (const point &p) const -{ - if (! coord_traits::equal (y (), p.y ())) { - return y () < p.y (); - } - if (! coord_traits::equal (x (), p.x ())) { - return x () < p.x (); - } - return false; -} - -template -inline bool -point::operator== (const point &p) const -{ - return m_x == p.m_x && m_y == p.m_y; -} - -template -inline bool -point::equal (const point &p) const -{ - return coord_traits::equal (x (), p.x ()) && coord_traits::equal (y (), p.y ()); -} - -template -inline bool -point::operator!= (const point &p) const -{ - return !operator== (p); -} - -template template -inline point -point::transformed (const Tr &t) const -{ - return t (*this); -} - -template template -inline point & -point::transform (const Tr &t) -{ - *this = t (*this); - return *this; -} - -template -inline C -point::x () const -{ - return m_x; -} - -template -inline C -point::y () const -{ - return m_y; -} - -template -inline void -point::set_x (C _x) -{ - m_x = _x; -} - -template -inline void -point::set_y (C _y) -{ - m_y = _y; -} - template inline point operator* (const db::point &p, double s) diff --git a/src/db/db/dbVector.h b/src/db/db/dbVector.h index 7f7e9c154..87faa90fa 100644 --- a/src/db/db/dbVector.h +++ b/src/db/db/dbVector.h @@ -45,7 +45,7 @@ template class point; */ template -class DB_PUBLIC_TEMPLATE vector +class DB_PUBLIC vector { public: typedef C coord_type; @@ -171,22 +171,42 @@ public: /** * @brief Add to operation */ - vector &operator+= (const vector &p); + vector &operator+= (const vector &p) + { + m_x += p.x (); + m_y += p.y (); + return *this; + } /** * @brief method version of operator+ (mainly for automation purposes) */ - vector add (const vector &p) const; + vector add (const vector &p) const + { + vector r (*this); + r += p; + return r; + } /** * @brief Subtract from operation */ - vector &operator-= (const vector &p); + vector &operator-= (const vector &p) + { + m_x -= p.x (); + m_y -= p.y (); + return *this; + } /** * @brief method version of operator- (mainly for automation purposes) */ - vector subtract (const vector &p) const; + vector subtract (const vector &p) const + { + vector r (*this); + r -= p; + return r; + } /** * @brief "less" comparison operator @@ -194,17 +214,26 @@ public: * This operator is provided to establish a sorting * order */ - bool operator< (const vector &p) const; + bool operator< (const vector &p) const + { + return m_y < p.m_y || (m_y == p.m_y && m_x < p.m_x); + } /** * @brief Equality test operator */ - bool operator== (const vector &p) const; + bool operator== (const vector &p) const + { + return m_x == p.m_x && m_y == p.m_y; + } /** * @brief Inequality test operator */ - bool operator!= (const vector &p) const; + bool operator!= (const vector &p) const + { + return !operator== (p); + } /** * @brief Const transform @@ -217,7 +246,10 @@ public: * @return The transformed vector */ template - vector transformed (const Tr &t) const; + vector transformed (const Tr &t) const + { + return t (vector (*this)); + } /** * @brief In-place transformation @@ -229,32 +261,51 @@ public: * @return The transformed vector */ template - vector &transform (const Tr &t); + vector &transform (const Tr &t) + { + *this = vector (t (*this)); + return *this; + } /** * @brief Accessor to the x coordinate */ - C x () const; + C x () const + { + return m_x; + } /** * @brief Accessor to the y coordinate */ - C y () const; + C y () const + { + return m_y; + } /** * @brief Write accessor to the x coordinate */ - void set_x (C _x); + void set_x (C _x) + { + m_x = _x; + } /** * @brief Write accessor to the y coordinate */ - void set_y (C _y); + void set_y (C _y) + { + m_y = _y; + } /** * @brief Fuzzy comparison of vectors */ - bool equal (const vector &p) const; + bool equal (const vector &p) const + { + return coord_traits::equal (x (), p.x ()) && coord_traits::equal (y (), p.y ()); + } /** * @brief Fuzzy comparison of vectors for inequality @@ -267,31 +318,56 @@ public: /** * @brief Fuzzy "less" comparison of vectors */ - bool less (const vector &p) const; + bool less (const vector &p) const + { + if (! coord_traits::equal (y (), p.y ())) { + return y () < p.y (); + } + if (! coord_traits::equal (x (), p.x ())) { + return x () < p.x (); + } + return false; + } /** * @brief Scaling by some factor * * To avoid round effects, the result vector is of double coordinate type. */ - vector operator* (double s) const; + vector operator* (double s) const + { + return vector (m_x * s, m_y * s); + } /** * @brief Scaling by some factor */ - vector operator* (long s) const; + vector operator* (long s) const + { + return vector (m_x * s, m_y * s); + } /** * @brief Scaling self by some factor * * Scaling by a double value in general involves rounding when the coordinate type is integer. */ - vector operator*= (double s); + vector operator*= (double s) + { + m_x = coord_traits::rounded (m_x * s); + m_y = coord_traits::rounded (m_y * s); + return *this; + } /** * @brief Scaling self by some integer factor */ - vector operator*= (long s); + vector operator*= (long s) + { + m_x *= s; + m_y *= s; + return *this; + } /** * @brief Division by some divisor. @@ -300,32 +376,60 @@ public: * with the coord_traits scheme. */ - vector &operator/= (double s); + vector &operator/= (double s) + { + double mult = 1.0 / static_cast(s); + *this *= mult; + return *this; + } /** * @brief Dividing self by some integer divisor */ - vector &operator/= (long s); + vector &operator/= (long s) + { + double mult = 1.0 / static_cast(s); + *this *= mult; + return *this; + } /** * @brief The euclidian length */ - distance_type length () const; + distance_type length () const + { + double ddx (x ()); + double ddy (y ()); + return coord_traits::rounded_distance (sqrt (ddx * ddx + ddy * ddy)); + } /** * @brief The euclidian length of the vector */ - double double_length () const; + double double_length () const + { + double ddx (x ()); + double ddy (y ()); + return sqrt (ddx * ddx + ddy * ddy); + } /** * @brief The square euclidian length of the vector */ - area_type sq_length () const; + area_type sq_length () const + { + return coord_traits::sq_length (0, 0, x (), y ()); + } /** * @brief The square of the euclidian length of the vector */ - double sq_double_length () const; + double sq_double_length () const + { + double ddx (x ()); + double ddy (y ()); + return ddx * ddx + ddy * ddy; + } /** * @brief String conversion @@ -349,140 +453,6 @@ private: C m_x, m_y; }; -template -inline vector & -vector::operator+= (const vector &p) -{ - m_x += p.x (); - m_y += p.y (); - return *this; -} - -template -inline vector -vector::add (const vector &p) const -{ - vector r (*this); - r += p; - return r; -} - -template -inline vector & -vector::operator-= (const vector &p) -{ - m_x -= p.x (); - m_y -= p.y (); - return *this; -} - -template -inline vector -vector::subtract (const vector &p) const -{ - vector r (*this); - r -= p; - return r; -} - -template -inline bool -vector::operator< (const vector &p) const -{ - return m_y < p.m_y || (m_y == p.m_y && m_x < p.m_x); -} - -template -inline bool -vector::less (const vector &p) const -{ - if (! coord_traits::equal (y (), p.y ())) { - return y () < p.y (); - } - if (! coord_traits::equal (x (), p.x ())) { - return x () < p.x (); - } - return false; -} - -template -inline bool -vector::operator== (const vector &p) const -{ - return m_x == p.m_x && m_y == p.m_y; -} - -template -inline bool -vector::equal (const vector &p) const -{ - return coord_traits::equal (x (), p.x ()) && coord_traits::equal (y (), p.y ()); -} - -template -inline bool -vector::operator!= (const vector &p) const -{ - return !operator== (p); -} - -template template -inline vector -vector::transformed (const Tr &t) const -{ - return t (vector (*this)); -} - -template template -inline vector & -vector::transform (const Tr &t) -{ - *this = vector (t (*this)); - return *this; -} - -template -inline C -vector::x () const -{ - return m_x; -} - -template -inline C -vector::y () const -{ - return m_y; -} - -template -inline void -vector::set_x (C _x) -{ - m_x = _x; -} - -template -inline void -vector::set_y (C _y) -{ - m_y = _y; -} - -template -inline vector -vector::operator* (double s) const -{ - return vector (m_x * s, m_y * s); -} - -template -inline vector -vector::operator* (long s) const -{ - return vector (m_x * s, m_y * s); -} - template inline vector operator/ (const db::vector &p, Number s) @@ -491,76 +461,6 @@ operator/ (const db::vector &p, Number s) return vector (p.x () * mult, p.y () * mult); } -template -inline vector & -vector::operator/= (double s) -{ - double mult = 1.0 / static_cast(s); - *this *= mult; - return *this; -} - -template -inline vector & -vector::operator/= (long s) -{ - double mult = 1.0 / static_cast(s); - *this *= mult; - return *this; -} - -template -inline vector -vector::operator*= (double s) -{ - m_x = coord_traits::rounded (m_x * s); - m_y = coord_traits::rounded (m_y * s); - return *this; -} - -template -inline vector -vector::operator*= (long s) -{ - m_x *= s; - m_y *= s; - return *this; -} - -template -inline typename vector::distance_type -vector::length () const -{ - double ddx (x ()); - double ddy (y ()); - return coord_traits::rounded_distance (sqrt (ddx * ddx + ddy * ddy)); -} - -template -inline double -vector::double_length () const -{ - double ddx (x ()); - double ddy (y ()); - return sqrt (ddx * ddx + ddy * ddy); -} - -template -inline typename vector::area_type -vector::sq_length () const -{ - return coord_traits::sq_length (0, 0, x (), y ()); -} - -template -inline double -vector::sq_double_length () const -{ - double ddx (x ()); - double ddy (y ()); - return ddx * ddx + ddy * ddy; -} - /** * @brief The binary + operator (addition of vectors) *