dmprectangle.cpp
2.0 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
/**************************************************************************
* file: dmprectangle.cpp
* Author: qingxiongf
* Date: 2021-08-08 23:21:54
* Email: qingxiongf@chinadci.com
* copyright: 广州城市信息研究所有限公司
***************************************************************************/
#include "dmprectangle.h"
#include <iostream>
void DmpRectangle::set( double xmin, double ymin, double xmax, double ymax )
{
xmin_ = xmin;
ymin_ = ymin;
xmax_ = xmax;
ymax_ = ymax;
normalize();
}
void DmpRectangle::normalize()
{
if (isNull())
return;
if (xmin_ > xmax_)
{
std::swap(xmin_, xmax_);
}
if (ymin_ > ymax_)
{
std::swap(ymin_, ymax_);
}
}
void DmpRectangle::merge(DmpRectangle &rectangle)
{
if(xmin_ == 0 && ymin_ ==0 && xmax_ ==0 && ymax_ ==0 )
{
this->xmin_ = rectangle.xmin();
this->ymin_ = rectangle.ymin();
this->xmax_ = rectangle.xmax();
this->ymax_ = rectangle.ymax();
}
else
{
if(rectangle.xmin() < this->xmin_ ) this->xmin_ = rectangle.xmin();
if(rectangle.ymin() < this->ymin_ ) this->ymin_ = rectangle.ymin();
if(rectangle.xmax() > this->xmax_ ) this->xmax_ = rectangle.xmax();
if(rectangle.ymax() < this->ymax_ ) this->ymax_ = rectangle.ymax();
}
}
bool DmpRectangle::isNull()
{
// rectangle created QgsRectangle() or with rect.setMinimal() ?
// return ( qgsDoubleNear( xmin_, 0.0 ) && qgsDoubleNear( mXmax, 0.0 ) && qgsDoubleNear( mYmin, 0.0 ) && qgsDoubleNear( mYmax, 0.0 ) ) ||
// ( qgsDoubleNear(xmin_, std::numeric_limits<double>::max() ) && qgsDoubleNear( mYmin, std::numeric_limits<double>::max() ) &&
// qgsDoubleNear(xmax_, -std::numeric_limits<double>::max() ) && qgsDoubleNear( mYmax, -std::numeric_limits<double>::max() ) );
return false;
}