Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/multi_player_map/src/lib/math/rect2D.h @ 9012

Last change on this file since 9012 was 8619, checked in by bensch, 18 years ago

trunk: merged the gui-branche back.
merged with command:
svn merge -r8520:HEAD https://svn.orxonox.net/orxonox/branches/gui
no conflicts

File size: 4.3 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  void setCenter(float x, float y);
99  void setCenterX(float x);
100  void setCenterY(float y);
101
102
103  void scaleX(float x);
104  void scaleY(float y);
105  void scale(float x, float y);
106  void scale(const Vector2D& v);
107  void scaleCentered(float x, float y);
108  void scaleCentered(const Vector2D& v);
109
110  void moveX(float x);
111  void moveY(float y);
112  void move(float x, float y);
113  void move(const Vector2D& v);
114
115  void swapTopBottom();
116  void swapLeftRight();
117  void normalize();
118  Rect2D normalized() const;
119
120
121  Rect2D intersection(const Rect2D& intersector) const;
122  bool intersects(const Rect2D& intersector) const;
123  Rect2D unite(const Rect2D& rect);
124  bool contains(const Rect2D& rect) const;
125  bool contains(const Vector2D& point) const;
126
127  const Rect2D& slerp(const Rect2D& rect, float value);
128
129  void debug() const;
130
131private:
132  Vector2D _topLeft;
133  Vector2D _bottomRight;
134};
135
136
137#endif /* __RECT2D_H_ */
138
Note: See TracBrowser for help on using the repository browser.