-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathrect.cpp
More file actions
49 lines (39 loc) · 721 Bytes
/
rect.cpp
File metadata and controls
49 lines (39 loc) · 721 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include "Rect.h"
#include <algorithm>
Rect::Rect(void) :
m_left(0), m_right(0), m_bottom(0), m_top(0)
{
}
Rect::Rect(const float left, const float right,
const float bottom, const float top) :
m_left(left), m_right(right), m_bottom(bottom), m_top(top)
{
validate();
}
void Rect::bottomLeft(const float x, const float y)
{
m_left = x;
m_bottom = y;
}
void Rect::topRight(const float x, const float y)
{
m_right = x;
m_top = y;
}
float Rect::width(void) const
{
return (m_right - m_left);
}
float Rect::height(void) const
{
return (m_top - m_bottom);
}
void Rect::validate(void)
{
if (m_left > m_right) {
std::swap(m_left, m_right);
}
if (m_bottom > m_top) {
std::swap(m_bottom, m_top);
}
}