Index: branches/gui/src/lib/math/rect2D.h
===================================================================
--- branches/gui/src/lib/math/vector2D.h	(revision 7876)
+++ branches/gui/src/lib/math/rect2D.h	(revision 7914)
@@ -21,83 +21,107 @@
 */
 
-#ifndef __VECTOR2D_H_
-#define __VECTOR2D_H_
+#ifndef __RECT2D_H_
+#define __RECT2D_H_
 
-#include <math.h>
-#include "compiler.h"
+#include <cmath>
+#include "vector2D.h"
 
-//! small and performant 2D vector
-typedef float sVec2D[2];
+//! 2D Rectangle 2D
+/**
+ *       Class to handle 2-Dimensional Rectangles.
+ */
+class Rect2D
+{
+public:
+  Rect2D(float x, float y, float width, float height);
+  Rect2D(const Vector2D& topLeft, const Vector2D& bottomRight );
+  Rect2D(const Rect2D& rect);
 
-//! 2D Vector2D
-/**
- *       Class to handle 2D Vector2Ds
- */
-class Vector2D {
- public:
-  Vector2D (float x, float y) : x(x), y(y) {}  //!< assignment constructor
-  Vector2D () : x(0), y(0) {}
+  Rect2D& operator=(const Rect2D& rect);
+  bool operator==(const Rect2D& rect) const;
+  bool operator!=(const Rect2D& rect) const;
 
-  /** @param v: the Vecor to compare with this one @returns true, if the Vecors are the same, false otherwise */
-  inline bool operator== (const Vector2D& v) const { return (this->x==v.x && this->y==v.y); };
-  /** @param v: the Vector to negative-compare with this one @returns true if the two vectors are different */
-  inline bool operator!= (const Vector2D& v) const { return (this->x!=v.x && this->y!=v.y); };
-  /** @param index The index of the "array" @returns the x/y coordinate */
-  inline float operator[] (float index) const { return ( index == 0)? this->x : this->y; }
-  /** @param v The vector to add @returns the addition between two vectors (this + v) */
-  inline Vector2D operator+ (const Vector2D& v) const { return Vector2D(x + v.x, y + v.y); };
-  /** @param v The vector to add @returns the addition between two vectors (this + v) */
-  inline Vector2D operator+ (const sVec2D& v) const { return Vector2D(x + v[0], y + v[1]); };
-  /** @param v The vector to add  @returns the addition between two vectors (this += v) */
-  inline const Vector2D& operator+= (const Vector2D& v) { this->x += v.x; this->y += v.y; return *this; };
-  /** @param v The vector to substract  @returns the substraction between two vectors (this - v) */
-  inline const Vector2D& operator+= (const sVec2D& v) { this->x += v[0]; this->y += v[1]; return *this; };
-  /** @param v The vector to substract  @returns the substraction between two vectors (this - v) */
-  inline Vector2D operator- (const Vector2D& v) const { return Vector2D(x - v.x, y - v.y); }
-  /** @param v The vector to substract  @returns the substraction between two vectors (this - v) */
-  inline Vector2D operator- (const sVec2D& v) const { return Vector2D(x - v[0], y - v[1]); }
-  /** @param v The vector to substract  @returns the substraction between two vectors (this -= v) */
-  inline const Vector2D& operator-= (const Vector2D& v) { this->x -= v.x; this->y -= v.y; return *this; };
-  /** @param v The vector to substract  @returns the substraction between two vectors (this -= v) */
-  inline const Vector2D& operator-= (const sVec2D& v) { this->x -= v[0]; this->y -= v[1]; return *this; };
-  /** @param v the second vector  @returns The dotProduct between two vector (this (dot) v) */
-  inline float operator* (const Vector2D& v) const { return x * v.x + y * v.y; };
-  /** @todo strange */
-  inline const Vector2D& operator*= (const Vector2D& v) { this->x *= v.x; this->y *= v.y; return *this; };
-  /** @param f a factor to multiply the vector with @returns the vector multiplied by f (this * f) */
-  inline Vector2D operator* (float f) const { return Vector2D(x * f, y * f); };
-  /** @param f a factor to multiply the vector with @returns the vector multiplied by f (this *= f) */
-  inline const Vector2D& operator*= (float f) { this->x *= f; this->y *= f; return *this; };
-  /** @param f a factor to divide the vector with @returns the vector divided by f (this / f) */
-  inline Vector2D operator/ (float f) const { return (unlikely(f == 0.0)) ? Vector2D(0,0):Vector2D(this->x / f, this->y / f); };
-  /** @param f a factor to divide the vector with @returns the vector divided by f (this /= f) */
-  inline const Vector2D& operator/= (float f) {if (unlikely(f == 0.0)) {this->x=0;this->y=0;} else {this->x /= f; this->y /= f;} return *this; };
-  /**  copy constructor @todo (i do not know it this is faster) @param v the vector to assign to this vector. @returns the vector v */
-  inline const Vector2D& operator= (const Vector2D& v) { this->x = v.x; this->y = v.y; return *this; };
-  /** copy constructor* @param v the sVec3D to assign to this vector. @returns the vector v */
-  inline const Vector2D& operator= (const sVec2D& v) { this->x = v[0]; this->y = v[1]; }
-  /** @param v: the other vector \return the dot product of the vectors */
-  float dot (const Vector2D& v) const { return x*v.x+y*v.y; };
-  /** scales the this vector with v* @param v the vector to scale this with */
-  void scale(const Vector2D& v) {   x *= v.x;  y *= v.y; };
-  /** @returns the length of the vector */
-  inline float len() const { return sqrt (x*x+y*y); }
-  /** normalizes the vector */
-  inline void normalize() { float l = len(); if( unlikely(l == 0.0))return; this->x=this->x/l; this->y=this->y/l; };
-  Vector2D getNormalized() const;
-  Vector2D abs();
+  Rect2D operator+(const Rect2D& rect) const;
+  Rect2D& operator+=(const Rect2D& rect);
 
-  void debug() const;
+  Rect2D operator-(const Rect2D& rect) const;
+  Rect2D& operator-=(const Rect2D& rect);
 
- public:
-  float    x;     //!< The x Coordinate of the Vector2D.
-  float    y;     //!< The y Coordinate of the Vector2D.
+  Rect2D operator&(const Rect2D& rect) const;
+  Rect2D& operator&=(const Rect2D& rect);
+
+  Rect2D operator*(const Vector2D& scaling) const;
+
+
+
+  /** @returns the top of the Rectangle */
+  inline float top() const { return _topLeft.y; };
+  /** @returns the bottom of the Rectangle */
+  inline float bottom() const { return _bottomRight.y; };
+  /** @returns the left border of the Rectangle */
+  inline float left() const { return _topLeft.x; };
+  /** @returns the right border of the rectangle */
+  inline float right() const { return _bottomRight.x; };
+  /** @returns the Center of the Rectangle */
+  inline Vector2D center() const { return (_topLeft+_bottomRight)/ 2.0; }
+  /** @returns the width of the Rectangle */
+  inline float width() const { return (right() - left()); };
+  /** @returns the height of the rectangle */
+  inline float height() const { return (bottom() - top()); };
+  /** @returns the Size of the Rectangle */
+  inline Vector2D size() const { return Vector2D(width(), height()); }
+  /** @returns the area of the Rectangle */
+  float area() const { return width()*height(); }
+
+  /** @param top sets the top border of the Rectangle */
+  inline void setTop(float top) { _topLeft.y = top; };
+  /** @param bottom the bottom border of the Rectangle */
+  inline void setBottom(float bottom) { _bottomRight.y = bottom; };
+  /** @param left the left border of the Rectangle */
+  inline void setLeft(float left) { _topLeft.x = left; };
+  /** @param right the right border of the Rectangle */
+  inline void setRight(float right) { _bottomRight.x = right; };
+  /** @param topLeft the top left corner of the Rectangle */
+  void setTopLeft(const Vector2D& topLeft) { _topLeft = topLeft; };
+  /** @param bottomRight the lower right corner of the Rectangle */
+  void setBottomRight(const Vector2D& bottomRight) { _bottomRight = bottomRight; };
+
+  void setWidth(float width);
+  void setHeight(float height);
+  void setSize(float width, float height);
+  void setSize(const Vector2D& size);
+  void setCenter(const Vector2D& center);
+
+  void scaleX(float x);
+  void scaleY(float y);
+  void scale(float x, float y);
+  void scale(const Vector2D& v);
+  void scaleCentered(float x, float y);
+  void scaleCentered(const Vector2D& v);
+
+  void moveX(float x);
+  void moveY(float y);
+  void move(const Vector2D& v);
+
+  void swapTopBottom();
+  void swapLeftRight();
+  void normalize();
+  Rect2D normalized() const;
+
+
+  Rect2D intersection(const Rect2D& intersector) const;
+  bool intersects(const Rect2D& intersector) const;
+  Rect2D unite(const Rect2D& rect);
+  bool contains(const Rect2D& rect) const;
+  bool contains(const Vector2D& point) const;
+
+  const Rect2D& slerp(const Rect2D& rect, float value);
+
+private:
+  Vector2D _topLeft;
+  Vector2D _bottomRight;
 };
 
 
-/** an easy way to create a Random Vector2D @param sideLength the length of the Vector2D (x not sqrt(x^2...)) */
-#define VECTOR2D_RAND(sideLength)  (Vector2D((float)rand()/RAND_MAX -.5, (float)rand()/RAND_MAX -.5) * sideLength)
+#endif /* __RECT2D_H_ */
 
-
-#endif /* __VECTOR2D_H_ */
-
