pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3803 - trunk/pingus/src/math


From: grumbel at BerliOS
Subject: [Pingus-CVS] r3803 - trunk/pingus/src/math
Date: Sun, 13 Jul 2008 11:45:02 +0200

Author: grumbel
Date: 2008-07-13 11:45:01 +0200 (Sun, 13 Jul 2008)
New Revision: 3803

Modified:
   trunk/pingus/src/math/rect.cpp
   trunk/pingus/src/math/size.hpp
   trunk/pingus/src/math/vector2f.cpp
   trunk/pingus/src/math/vector2f.hpp
   trunk/pingus/src/math/vector2i.cpp
   trunk/pingus/src/math/vector2i.hpp
   trunk/pingus/src/math/vector3f.cpp
   trunk/pingus/src/math/vector3f.hpp
Log:
Added some operator<< and moved some code from the .cpp to the .hpp to allow 
the compiler to do inlining

Modified: trunk/pingus/src/math/rect.cpp
===================================================================
--- trunk/pingus/src/math/rect.cpp      2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/rect.cpp      2008-07-13 09:45:01 UTC (rev 3803)
@@ -62,8 +62,8 @@
 
 std::ostream& operator<<(std::ostream& s, const Rect& rect)
 {
-  return s << "rect[" << rect.left << ", " << rect.top << ", "
-           << rect.right << ", " << rect.bottom << "]";
+  return s << "rect(" << rect.left << ", " << rect.top << ", "
+           << rect.right << ", " << rect.bottom << ")";
 }
 
 /* EOF */

Modified: trunk/pingus/src/math/size.hpp
===================================================================
--- trunk/pingus/src/math/size.hpp      2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/size.hpp      2008-07-13 09:45:01 UTC (rev 3803)
@@ -37,8 +37,10 @@
 #pragma once
 #endif
 
+#include <iosfwd>
+
 class Sizef;
-
+
 //: 2D (width,height) size structure.
 //- !group=Core/Math!
 //- !header=core.h!
@@ -94,7 +96,7 @@
        bool operator!=(const Size &s) const
        { return (width != s.width) || (height != s.height); }
 };
-
+
 //: 2D (width,height) floating point size structure.
 class Sizef
 {
@@ -151,10 +153,12 @@
        bool operator!=(const Size &s) const
        { return (width != s.width) || (height != s.height); }
 };
-
+
 inline Size::Size(const Sizef& s)
        : width(static_cast<int>(s.width)),
          height(static_cast<int>(s.height))
 {}
-
+
+std::ostream& operator<<(std::ostream& os, const Size& size);
+
 #endif

Modified: trunk/pingus/src/math/vector2f.cpp
===================================================================
--- trunk/pingus/src/math/vector2f.cpp  2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/vector2f.cpp  2008-07-13 09:45:01 UTC (rev 3803)
@@ -19,7 +19,7 @@
 #include <iostream>
 #include "math.hpp"
 #include "math/vector2f.hpp"
-
+
 void
 Vector2f::normalize()
 {
@@ -39,17 +39,17 @@
   return Math::sqrt(x*x + y*y);
 }
 
-std::ostream& operator<<(std::ostream& s, const Vector2f& v)
-{
-  s << "(" << v.x << ", " << v.y << ")";
-  return s;
-}
-
 Vector2f
 Vector2f::rotate(float angle) const
 {
   float len = magnitude();
   return Vector2f(len * Math::cos(angle), len * Math::sin(angle));
 }
-
+
+std::ostream& operator<<(std::ostream& s, const Vector2f& v)
+{
+  s << "vector2f(" << v.x << ", " << v.y << ")";
+  return s;
+}
+
 /* EOF */

Modified: trunk/pingus/src/math/vector2f.hpp
===================================================================
--- trunk/pingus/src/math/vector2f.hpp  2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/vector2f.hpp  2008-07-13 09:45:01 UTC (rev 3803)
@@ -20,33 +20,33 @@
 
 #include <iosfwd>
 #include "vector2i.hpp"
-
+
 /** Simple two dimensional vector. */
 class Vector2f
 {
 public:
   Vector2f(float nx, float ny)
-      : x(nx), y(ny)
+    : x(nx), y(ny)
   { }
   Vector2f(const Vector2f& other)
-      : x(other.x), y(other.y)
+    : x(other.x), y(other.y)
   { }
   Vector2f(const Vector2i& other)
     : x((float)other.x), y((float)other.y)
   {}
   Vector2f()
-      : x(0), y(0)
+    : x(0), y(0)
   { }
 
   bool operator ==(const Vector2f& other) const
-    {
-      return x == other.x && y == other.y;
-    }
+  {
+    return x == other.x && y == other.y;
+  }
 
   bool operator !=(const Vector2f& other) const
-    {
-      return !(x == other.x && y == other.y);
-    }
+  {
+    return !(x == other.x && y == other.y);
+  }
 
   const Vector2f& operator=(const Vector2f& other)
   {
@@ -56,29 +56,29 @@
   }
 
   Vector2f operator+(const Vector2f& other) const
-    {
-      return Vector2f(x + other.x, y + other.y);
-    }
+  {
+    return Vector2f(x + other.x, y + other.y);
+  }
 
   Vector2f operator-(const Vector2f& other) const
-    {
-      return Vector2f(x - other.x, y - other.y);
-    }
+  {
+    return Vector2f(x - other.x, y - other.y);
+  }
 
   Vector2f operator*(float s) const
-    {
-      return Vector2f(x * s, y * s);
-    }
+  {
+    return Vector2f(x * s, y * s);
+  }
 
   Vector2f operator/(float s) const
-    {
-      return Vector2f(x / s, y / s);
-    }
+  {
+    return Vector2f(x / s, y / s);
+  }
 
   Vector2f operator-() const
-    {
-      return Vector2f(-x, -y);
-    }
+  {
+    return Vector2f(-x, -y);
+  }
 
   const Vector2f& operator +=(const Vector2f& other)
   {
@@ -114,9 +114,9 @@
 
   /// Scalar product of 2 vectors
   float operator*(const Vector2f& other) const
-    {
-      return x*other.x + y*other.y;
-    }
+  {
+    return x*other.x + y*other.y;
+  }
 
   float magnitude() const;
   float length() const { return magnitude(); }
@@ -129,8 +129,8 @@
   float x, y; // leave this public, get/set methods just give me headaches
   // for such simple stuff :)
 };
-
+
 std::ostream& operator<<(std::ostream& s, const Vector2f& v);
-
+
 #endif
 

Modified: trunk/pingus/src/math/vector2i.cpp
===================================================================
--- trunk/pingus/src/math/vector2i.cpp  2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/vector2i.cpp  2008-07-13 09:45:01 UTC (rev 3803)
@@ -14,59 +14,18 @@
 //  You should have received a copy of the GNU General Public License
 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
+#include <iostream>
 #include "vector2f.hpp"
 #include "vector2i.hpp"
-
+
 Vector2i::Vector2i(const Vector2f& v)
   : x(int(v.x)), y(int(v.y))
 {}
-
-Vector2i
-Vector2i::operator+ (const Vector2i& add) const
+
+std::ostream& operator<<(std::ostream& s, const Vector2i& v)
 {
-  return Vector2i(x + add.x, y + add.y);
+  s << "vector2i(" << v.x << ", " << v.y << ")";
+  return s;
 }
-
-Vector2i
-Vector2i::operator- (const Vector2i& sub) const
-{
-  return Vector2i(x - sub.x, y - sub.y);
-}
-
-Vector2i
-Vector2i::operator* (int  mul) const
-{
-  return Vector2i(x * mul, y * mul);
-}
-
-Vector2i&
-Vector2i::operator+= (const Vector2i& add)
-{
-  x += add.x;
-  y += add.y;
-  return *this;
-}
-
-Vector2i&
-Vector2i::operator-= (const Vector2i& sub)
-{
-  x -= sub.x;
-  y -= sub.y;
-  return *this;
-}
-
-Vector2i&
-Vector2i::operator*= (int mul)
-{
-  x *= mul;
-  y *= mul;
-  return *this;
-}
-
-bool
-Vector2i::operator== (const Vector2i& other)
-{
-  return (other.x == x && other.y == y);
-}
-
+
 /* EOF */

Modified: trunk/pingus/src/math/vector2i.hpp
===================================================================
--- trunk/pingus/src/math/vector2i.hpp  2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/vector2i.hpp  2008-07-13 09:45:01 UTC (rev 3803)
@@ -17,8 +17,10 @@
 #ifndef HEADER_VECTOR2_HPP
 #define HEADER_VECTOR2_HPP
 
+#include <iosfwd>
+
 class Vector2f;
-
+
 /** */
 class Vector2i
 {
@@ -34,19 +36,51 @@
   Vector2i(int x_, int y_) 
     : x(x_), y(y_) {}
 
-  Vector2i operator- () const;
 
-  Vector2i operator+ (const Vector2i& add) const;
-  Vector2i operator- (const Vector2i& sub) const;
-  Vector2i operator* (int  mul) const;
+  Vector2i operator+ (const Vector2i& add) const
+  {
+    return Vector2i(x + add.x, y + add.y);
+  }
 
-  Vector2i& operator+= (const Vector2i& add);
-  Vector2i& operator-= (const Vector2i& sub);
-  Vector2i& operator*= (int mul);
+  Vector2i operator- (const Vector2i& sub) const
+  {
+    return Vector2i(x - sub.x, y - sub.y);
+  }
 
-  bool operator== (const Vector2i& other);
+  Vector2i operator* (int  mul) const
+  {
+    return Vector2i(x * mul, y * mul);
+  }
+
+  Vector2i& operator+= (const Vector2i& add)
+  {
+    x += add.x;
+    y += add.y;
+    return *this;
+  }
+
+  Vector2i& operator-= (const Vector2i& sub)
+  {
+    x -= sub.x;
+    y -= sub.y;
+    return *this;
+  }
+
+  Vector2i& operator*= (int mul)
+  {
+    x *= mul;
+    y *= mul;
+    return *this;
+  }
+
+  bool operator== (const Vector2i& other)
+  {
+    return (other.x == x && other.y == y);
+  }
 };
-
+
+std::ostream& operator<<(std::ostream& s, const Vector2i& v);
+
 #endif
 
 /* EOF */

Modified: trunk/pingus/src/math/vector3f.cpp
===================================================================
--- trunk/pingus/src/math/vector3f.cpp  2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/vector3f.cpp  2008-07-13 09:45:01 UTC (rev 3803)
@@ -163,10 +163,10 @@
   Vector3f c = b - a;
   return a + (c * perc);
 }
-
+
 std::ostream& operator<<(std::ostream& os, const Vector3f& v)
 {
-  return os << v.x << " " << v.y << " " << v.z;
+  return os << "vector3f(" << v.x << ", " << v.y << ", " << v.z << ")";
 }
-
+
 /* EOF */

Modified: trunk/pingus/src/math/vector3f.hpp
===================================================================
--- trunk/pingus/src/math/vector3f.hpp  2008-07-13 07:11:52 UTC (rev 3802)
+++ trunk/pingus/src/math/vector3f.hpp  2008-07-13 09:45:01 UTC (rev 3803)
@@ -18,10 +18,10 @@
 #define HEADER_PINGUS_MATH_VECTOR3F_HPP
 
 #include <iosfwd>
-#include "../pingus.hpp"
 
 class Vector2f;
 class Vector2i;
+
 class Vector3f
 {
 public:
@@ -59,12 +59,10 @@
   /** Calculate a position between a and b, relative to the value of
       \a perc (perc == 0 -> a, perc == 1.0 -> b) */
   static Vector3f interpolate(const Vector3f& a, const Vector3f& b, float 
perc);
-
-  friend std::ostream& operator<< (std::ostream& os, const Vector3f& v);
 };
-
+
 std::ostream& operator<< (std::ostream& os, const Vector3f& v);
-
+
 #endif
 
 /* EOF */





reply via email to

[Prev in Thread] Current Thread [Next in Thread]