Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/branches/cr/src/lib/math/rect2D.h @ 7946

Last change on this file since 7946 was 7919, checked in by bensch, 19 years ago

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

File size: 3.9 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  void setTopLeft(const Vector2D& topLeft) { _topLeft = topLeft; };
86  /** @param bottomRight the lower right corner of the Rectangle */
87  void setBottomRight(const Vector2D& bottomRight) { _bottomRight = bottomRight; };
88
89  void setWidth(float width);
90  void setHeight(float height);
91  void setSize(float width, float height);
92  void setSize(const Vector2D& size);
93  void setCenter(const Vector2D& center);
94
95  void scaleX(float x);
96  void scaleY(float y);
97  void scale(float x, float y);
98  void scale(const Vector2D& v);
99  void scaleCentered(float x, float y);
100  void scaleCentered(const Vector2D& v);
101
102  void moveX(float x);
103  void moveY(float y);
104  void move(float x, float y);
105  void move(const Vector2D& v);
106
107  void swapTopBottom();
108  void swapLeftRight();
109  void normalize();
110  Rect2D normalized() const;
111
112
113  Rect2D intersection(const Rect2D& intersector) const;
114  bool intersects(const Rect2D& intersector) const;
115  Rect2D unite(const Rect2D& rect);
116  bool contains(const Rect2D& rect) const;
117  bool contains(const Vector2D& point) const;
118
119  const Rect2D& slerp(const Rect2D& rect, float value);
120
121private:
122  Vector2D _topLeft;
123  Vector2D _bottomRight;
124};
125
126
127#endif /* __RECT2D_H_ */
128
Note: See TracBrowser for help on using the repository browser.