Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/math/rect2D.h @ 8372

Last change on this file since 8372 was 8035, checked in by bensch, 18 years ago

gui: merged the gui back to the trunk

File size: 4.2 KB
Line 
1/*
2   orxonox - the future of 3D-vertical-scrollers
3
4   Copyright (C) 2004 orx
5
6   This program is free software; you can redistribute it and/or modify
7   it under the terms of the GNU General Public License as published by
8   the Free Software Foundation; either version 2, or (at your option)
9   any later version.
10
11### File Specific:
12   main-programmer: Benjamin Grauer
13   co-programmer: ...
14*/
15
16/*!
17 * @file vector2D.h
18 * A basic 2D Vector math framework
19 *
20 * Contains classes to handle vectors, lines, rotations and planes
21*/
22
23#ifndef __RECT2D_H_
24#define __RECT2D_H_
25
26#include "vector2D.h"
27
28//! 2D Rectangle 2D
29/**
30 *       Class to handle 2-Dimensional Rectangles.
31 */
32class Rect2D
33{
34public:
35  Rect2D() { };
36  Rect2D(float x, float y, float width, float height);
37  Rect2D(const Vector2D& topLeft, const Vector2D& bottomRight );
38  Rect2D(const Rect2D& rect);
39
40  Rect2D& operator=(const Rect2D& rect);
41  bool operator==(const Rect2D& rect) const;
42  bool operator!=(const Rect2D& rect) const;
43
44  Rect2D operator+(const Rect2D& rect) const;
45  Rect2D& operator+=(const Rect2D& rect);
46
47  Rect2D operator-(const Rect2D& rect) const;
48  Rect2D& operator-=(const Rect2D& rect);
49
50  Rect2D operator&(const Rect2D& rect) const;
51  Rect2D& operator&=(const Rect2D& rect);
52
53  Rect2D operator*(const Vector2D& scaling) const;
54
55
56
57  /** @returns the top of the Rectangle */
58  inline float top() const { return _topLeft.y; };
59  /** @returns the bottom of the Rectangle */
60  inline float bottom() const { return _bottomRight.y; };
61  /** @returns the left border of the Rectangle */
62  inline float left() const { return _topLeft.x; };
63  /** @returns the right border of the rectangle */
64  inline float right() const { return _bottomRight.x; };
65  /** @returns the Center of the Rectangle */
66  inline Vector2D center() const { return (_topLeft+_bottomRight)/ 2.0; }
67  /** @returns the width of the Rectangle */
68  inline float width() const { return (right() - left()); };
69  /** @returns the height of the rectangle */
70  inline float height() const { return (bottom() - top()); };
71  /** @returns the Size of the Rectangle */
72  inline Vector2D size() const { return Vector2D(width(), height()); }
73  /** @returns the area of the Rectangle */
74  float area() const { return width()*height(); }
75
76  /** @param top sets the top border of the Rectangle */
77  inline void setTop(float top) { _topLeft.y = top; };
78  /** @param bottom the bottom border of the Rectangle */
79  inline void setBottom(float bottom) { _bottomRight.y = bottom; };
80  /** @param left the left border of the Rectangle */
81  inline void setLeft(float left) { _topLeft.x = left; };
82  /** @param right the right border of the Rectangle */
83  inline void setRight(float right) { _bottomRight.x = right; };
84  /** @param topLeft the top left corner of the Rectangle */
85  inline void setTopLeft(const Vector2D& topLeft) { _topLeft = topLeft; };
86  /** @param x the left border of the Rectangle @param y the top border */
87  inline void setTopLeft(float x, float y) { this->setTopLeft(Vector2D(x,y)); };
88  /** @param bottomRight the lower right corner of the Rectangle */
89  inline void setBottomRight(const Vector2D& bottomRight) { _bottomRight = bottomRight; };
90  /** @param x the right border of the Rectangle @param y the bottom border */
91  inline void setBottomRight(float x, float y) { this->setBottomRight(Vector2D(x,y)); };
92
93  void setWidth(float width);
94  void setHeight(float height);
95  void setSize(float width, float height);
96  void setSize(const Vector2D& size);
97  void setCenter(const Vector2D& center);
98
99  void scaleX(float x);
100  void scaleY(float y);
101  void scale(float x, float y);
102  void scale(const Vector2D& v);
103  void scaleCentered(float x, float y);
104  void scaleCentered(const Vector2D& v);
105
106  void moveX(float x);
107  void moveY(float y);
108  void move(float x, float y);
109  void move(const Vector2D& v);
110
111  void swapTopBottom();
112  void swapLeftRight();
113  void normalize();
114  Rect2D normalized() const;
115
116
117  Rect2D intersection(const Rect2D& intersector) const;
118  bool intersects(const Rect2D& intersector) const;
119  Rect2D unite(const Rect2D& rect);
120  bool contains(const Rect2D& rect) const;
121  bool contains(const Vector2D& point) const;
122
123  const Rect2D& slerp(const Rect2D& rect, float value);
124
125private:
126  Vector2D _topLeft;
127  Vector2D _bottomRight;
128};
129
130
131#endif /* __RECT2D_H_ */
132
Note: See TracBrowser for help on using the repository browser.