dmprectangle.cpp 2.0 KB
/**************************************************************************
* 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;
}