Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

Last change on this file since 7952 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
RevLine 
[5420]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:
[6616]12   main-programmer: Benjamin Grauer
[5420]13   co-programmer: ...
14*/
15
[4578]16/*!
[6616]17 * @file vector2D.h
18 * A basic 2D Vector math framework
[5008]19 *
20 * Contains classes to handle vectors, lines, rotations and planes
[4578]21*/
[2043]22
[7914]23#ifndef __RECT2D_H_
24#define __RECT2D_H_
[2043]25
[7914]26#include "vector2D.h"
[2043]27
[7914]28//! 2D Rectangle 2D
[2043]29/**
[7914]30 *       Class to handle 2-Dimensional Rectangles.
[6615]31 */
[7914]32class Rect2D
33{
34public:
[7917]35  Rect2D() { };
[7914]36  Rect2D(float x, float y, float width, float height);
37  Rect2D(const Vector2D& topLeft, const Vector2D& bottomRight );
38  Rect2D(const Rect2D& rect);
[2043]39
[7914]40  Rect2D& operator=(const Rect2D& rect);
41  bool operator==(const Rect2D& rect) const;
42  bool operator!=(const Rect2D& rect) const;
[3541]43
[7914]44  Rect2D operator+(const Rect2D& rect) const;
45  Rect2D& operator+=(const Rect2D& rect);
[4476]46
[7914]47  Rect2D operator-(const Rect2D& rect) const;
48  Rect2D& operator-=(const Rect2D& rect);
[2043]49
[7914]50  Rect2D operator&(const Rect2D& rect) const;
51  Rect2D& operator&=(const Rect2D& rect);
[2043]52
[7914]53  Rect2D operator*(const Vector2D& scaling) const;
[4476]54
[5008]55
[5052]56
[7914]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);
[7915]104  void move(float x, float y);
[7914]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.