dmprectangle.h 1.6 KB
/**************************************************************************
* file:              dmprectangle.h

* Author:            qingxiongf
* Date:              2021-08-03 13:48:43
* Email:             qingxiongf@chinadci.com
* copyright:         广州城市信息研究所有限公司
***************************************************************************/

#ifndef __dmprectangle_h__
#define __dmprectangle_h__
#include "dmap_core.h"

class CORE_EXPORT DmpRectangle
{
 public:
    DmpRectangle() = default;
     //! Constructor
    explicit DmpRectangle(double xmin, double ymin = 0, double xmax = 0, double ymax = 0) 
    : xmin_( xmin )
    , ymin_( ymin )
    , xmax_( xmax )
    , ymax_( ymax )
    {
      normalize(); 
    }

    ~DmpRectangle() = default;
    
    bool isNull();
    void set(double xmin, double ymin, double xmax, double ymax);
    void normalize(); //规范化矩形,使其具有非负宽度/高度。

    double xmax() const { return xmax_; }
    double xmin() const { return xmin_; }
    double ymax() const { return ymax_; }
    double ymin() const { return ymin_; }
    double width() const  { return xmax_ - xmin_; }
    double height() const { return ymax_ - ymin_; }

    void setXmax(double xmax){xmax_ = xmax; }
    void setYmax(double ymax){ymax_ = ymax; }
    void setXmin(double xmin){xmin_ = xmin; }
    void setYmin(double ymin){ymin_ = ymin; }

    void merge(DmpRectangle &rectangle);

 private:
    double xmin_ = 0.0;
    double ymin_ = 0.0;
    double xmax_ = 0.0;
    double ymax_ = 0.0;
};


#endif