Nebula
Toggle main menu visibility
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
//------------------------------------------------------------------------------
17
namespace
Math
18
{
19
template
<
class
TYPE>
class
rectangle
20
{
21
public
:
23
rectangle
();
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
45
typedef
rectangle<float>
floatRectangle
;
46
typedef
rectangle<int>
intRectangle
;
47
48
//------------------------------------------------------------------------------
51
template
<
class
TYPE>
52
rectangle<TYPE>::rectangle
()
53
{
54
// empty
55
}
56
57
//------------------------------------------------------------------------------
60
template
<
class
TYPE>
61
rectangle<TYPE>::rectangle
(TYPE l, TYPE t, TYPE r, TYPE b) :
62
left
(l),
63
top
(t),
64
right
(r),
65
bottom
(b)
66
{
67
n_assert
(this->
left <= this->
right
);
68
n_assert
(this->
top <= this->
bottom
);
69
}
70
71
//------------------------------------------------------------------------------
74
template
<
class
TYPE>
void
75
rectangle<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
//------------------------------------------------------------------------------
88
template
<
class
TYPE>
bool
89
rectangle<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
//------------------------------------------------------------------------------
97
template
<
class
TYPE> TYPE
98
rectangle<TYPE>::width
()
const
99
{
100
return
this->
right
- this->
left
;
101
}
102
103
//------------------------------------------------------------------------------
106
template
<
class
TYPE> TYPE
107
rectangle<TYPE>::height
()
const
108
{
109
return
this->
bottom
- this->
top
;
110
}
111
112
//------------------------------------------------------------------------------
115
template
<
class
TYPE> TYPE
116
rectangle<TYPE>::centerX
()
const
117
{
118
return
(this->
left
+ this->
right
) / 2;
119
}
120
121
//------------------------------------------------------------------------------
124
template
<
class
TYPE> TYPE
125
rectangle<TYPE>::centerY
()
const
126
{
127
return
(this->
top
+ this->
bottom
) / 2;
128
}
129
}
// namespace Math
130
//------------------------------------------------------------------------------
131
#endif
132
133
134
Math::rectangle
A 2d rectangle class.
Definition
rectangle.h:20
Math::rectangle::height
TYPE height() const
return height
Definition
rectangle.h:107
Math::rectangle::rectangle
rectangle()
default constructor
Definition
rectangle.h:52
Math::rectangle::width
TYPE width() const
return width
Definition
rectangle.h:98
Math::rectangle::inside
bool inside(TYPE x, TYPE y) const
return true if point is inside
Definition
rectangle.h:89
Math::rectangle::centerX
TYPE centerX() const
return center x
Definition
rectangle.h:116
Math::rectangle< float >::top
float top
Definition
rectangle.h:40
Math::rectangle::centerY
TYPE centerY() const
return center y
Definition
rectangle.h:125
Math::rectangle::set
void set(TYPE l, TYPE t, TYPE r, TYPE b)
set content
Definition
rectangle.h:75
Math::rectangle< float >::right
float right
Definition
rectangle.h:41
Math::rectangle::rectangle
rectangle(TYPE l, TYPE t, TYPE r, TYPE b)
constructor 1
Definition
rectangle.h:61
Math::rectangle< float >::bottom
float bottom
Definition
rectangle.h:42
Math::rectangle< float >::left
float left
Definition
rectangle.h:39
n_assert
#define n_assert(exp)
Definition
debug.h:50
Math
Different curves.
Definition
angularpfeedbackloop.h:17
Math::floatRectangle
rectangle< float > floatRectangle
Definition
rectangle.h:45
Math::intRectangle
rectangle< int > intRectangle
Definition
rectangle.h:46
types.h
code
foundation
math
rectangle.h
Generated on
for Nebula. Dark theme by
Tilen Majerle
. All rights reserved.