clsRect.cpp
1.9 KB
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "clsRect.h"
#include <math.h>
using namespace std;
namespace DmapCore_30
{
Rect::Rect()
{
m_dTop = 0;
m_dRight = 0;
m_dBottom = 0;
m_dLeft = 0;
}
Rect::Rect(double top, double right, double bottom, double left)
{
m_dTop = top;
m_dRight = right;
m_dBottom = bottom;
m_dLeft = left;
}
Rect::~Rect()
{
}
Rect * Rect::CreateNew()
{
Rect * dest = new Rect();
return dest;
}
Rect * Rect::CreateNew(double top, double right, double bottom, double left)
{
Rect* dest = new Rect(top, right, bottom, left);
return dest;
}
bool Rect::Normal()
{
double temp;
if (m_dLeft > m_dRight)
{
temp = m_dLeft;
m_dLeft = m_dRight;
m_dRight = temp;
}
if (m_dBottom > m_dTop)
{
temp = m_dTop;
m_dTop = m_dBottom;
m_dBottom = temp;
}
return true;
}
bool Rect::Scale(double num)
{
//中心点为标准?
this->Normal();
double w = m_dRight - m_dLeft;
double h = m_dTop - m_dBottom;
double x = (m_dRight + m_dLeft) / 2;
double y = (m_dTop + m_dBottom) / 2;
double w_ = w * num;
double h_ = h * num;
m_dTop = y + h_ / 2;
m_dRight = x + w_ / 2;
m_dBottom = y - h_ / 2;
m_dLeft = x - w_ / 2;
return true;
}
double Rect::GetArea()
{
this->Normal();
double area = (m_dRight - m_dLeft)* (m_dTop - m_dBottom);
return area;
}
bool Rect::GetExtent(double &boxX1, double& boxX2, double &boxY1, double &boxY2)
{
if (std::fmin(boxX1, boxX2) > this->m_dRight || std::fmax(boxX1, boxX2) < this->m_dLeft ||
std::fmin(boxY1, boxY2) > this->m_dTop || std::fmax(boxY1, boxY2) < this->m_dBottom)
{
if (!(std::fmin(boxY1, boxY2) > this->m_dRight || std::fmax(boxY1, boxY2) < this->m_dLeft ||
std::fmin(boxX1, boxX2) > this->m_dTop || std::fmax(boxX1, boxX2) < this->m_dBottom))
{
double x1 = boxX1;
boxX1 = boxY1;
boxY1 = x1;
double x2 = boxX2;
boxX2 = boxY2;
boxY2 = x2;
return true;
}
}
return false;
}
}