Nebula
Loading...
Searching...
No Matches
rectangle.h
Go to the documentation of this file.
1#pragma once
2#ifndef MATH_RECTANGLE_H
3#define MATH_RECTANGLE_H
4//------------------------------------------------------------------------------
14#include "core/types.h"
15
16//------------------------------------------------------------------------------
17namespace Math
18{
19template<class TYPE> class rectangle
20{
21public:
25 rectangle(TYPE l, TYPE t, TYPE r, TYPE b);
27 void set(TYPE l, TYPE t, TYPE r, TYPE b);
29 bool inside(TYPE x, TYPE y) const;
31 TYPE width() const;
33 TYPE height() const;
35 TYPE centerX() const;
37 TYPE centerY() const;
38
39 TYPE left;
40 TYPE top;
41 TYPE right;
42 TYPE bottom;
43};
44
47
48//------------------------------------------------------------------------------
51template<class TYPE>
53{
54 // empty
55}
56
57//------------------------------------------------------------------------------
60template<class TYPE>
61rectangle<TYPE>::rectangle(TYPE l, TYPE t, TYPE r, TYPE b) :
62 left(l),
63 top(t),
64 right(r),
65 bottom(b)
66{
69}
70
71//------------------------------------------------------------------------------
74template<class TYPE> void
75rectangle<TYPE>::set(TYPE l, TYPE t, TYPE r, TYPE b)
76{
77 n_assert(l <= r);
78 n_assert(t <= b);
79 this->left = l;
80 this->top = t;
81 this->right = r;
82 this->bottom = b;
83}
84
85//------------------------------------------------------------------------------
88template<class TYPE> bool
89rectangle<TYPE>::inside(TYPE x, TYPE y) const
90{
91 return (this->left <= x) && (x <= this->right) && (this->top <= y) && (y <= this->bottom);
92}
93
94//------------------------------------------------------------------------------
97template<class TYPE> TYPE
99{
100 return this->right - this->left;
101}
102
103//------------------------------------------------------------------------------
106template<class TYPE> TYPE
108{
109 return this->bottom - this->top;
110}
111
112//------------------------------------------------------------------------------
115template<class TYPE> TYPE
117{
118 return (this->left + this->right) / 2;
119}
120
121//------------------------------------------------------------------------------
124template<class TYPE> TYPE
126{
127 return (this->top + this->bottom) / 2;
128}
129} // namespace Math
130//------------------------------------------------------------------------------
131#endif
132
133
134
A 2d rectangle class.
Definition rectangle.h:20
TYPE height() const
return height
Definition rectangle.h:107
rectangle()
default constructor
Definition rectangle.h:52
TYPE width() const
return width
Definition rectangle.h:98
bool inside(TYPE x, TYPE y) const
return true if point is inside
Definition rectangle.h:89
TYPE centerX() const
return center x
Definition rectangle.h:116
TYPE top
Definition rectangle.h:40
TYPE centerY() const
return center y
Definition rectangle.h:125
void set(TYPE l, TYPE t, TYPE r, TYPE b)
set content
Definition rectangle.h:75
TYPE right
Definition rectangle.h:41
rectangle(TYPE l, TYPE t, TYPE r, TYPE b)
constructor 1
Definition rectangle.h:61
TYPE bottom
Definition rectangle.h:42
TYPE left
Definition rectangle.h:39
#define n_assert(exp)
Definition debug.h:50
Different curves.
Definition angularpfeedbackloop.h:17
rectangle< float > floatRectangle
Definition rectangle.h:45
rectangle< int > intRectangle
Definition rectangle.h:46