BoundingRectangle.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #include "rqt_multiplot/BoundingRectangle.h"
00020 
00021 namespace rqt_multiplot {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 BoundingRectangle::BoundingRectangle(const QPointF& minimum, const QPointF&
00028     maximum) :
00029   minimum_(minimum),
00030   maximum_(maximum) {
00031 }
00032 
00033 BoundingRectangle::BoundingRectangle(const QRectF& rectangle) :
00034   minimum_(rectangle.left(), rectangle.top()),
00035   maximum_(rectangle.right(), rectangle.bottom()) {
00036 }
00037 
00038 BoundingRectangle::BoundingRectangle(const BoundingRectangle& src) :
00039   minimum_(src.minimum_),
00040   maximum_(src.maximum_) {
00041 }
00042 
00043 BoundingRectangle::~BoundingRectangle() {
00044 }
00045 
00046 /*****************************************************************************/
00047 /* Accessors                                                                 */
00048 /*****************************************************************************/
00049 
00050 void BoundingRectangle::setMinimum(const QPointF& minimum) {
00051   minimum_ = minimum;
00052 }
00053 
00054 QPointF& BoundingRectangle::getMinimum() {
00055   return minimum_;
00056 }
00057 
00058 const QPointF& BoundingRectangle::getMinimum() const {
00059   return minimum_;
00060 }
00061 
00062 void BoundingRectangle::setMaximum(const QPointF& maximum) {
00063   maximum_ = maximum;
00064 }
00065 
00066 QPointF& BoundingRectangle::getMaximum() {
00067   return maximum_;
00068 }
00069 
00070 const QPointF& BoundingRectangle::getMaximum() const {
00071   return maximum_;
00072 }
00073 
00074 QRectF BoundingRectangle::getRectangle() const {
00075   return QRectF(minimum_, maximum_).normalized();
00076 }
00077 
00078 bool BoundingRectangle::isValid() const {
00079   return (maximum_.x() >= minimum_.x()) && (maximum_.y() >= minimum_.y()); 
00080 }
00081 
00082 bool BoundingRectangle::isEmpty() const {
00083   return (maximum_.x() <= minimum_.x()) || (maximum_.y() <= minimum_.y()); 
00084 }
00085 
00086 bool BoundingRectangle::contains(const QPointF& point) const {
00087   return (point.x() >= minimum_.x()) && (point.y() >= minimum_.y()) &&
00088     (point.x() <= maximum_.x()) && (point.y() <= maximum_.y());
00089 }
00090 
00091 /*****************************************************************************/
00092 /* Methods                                                                   */
00093 /*****************************************************************************/
00094 
00095 void BoundingRectangle::initialize(const QPointF& point) {
00096   minimum_ = point;
00097   maximum_ = point;
00098 }
00099 
00100 void BoundingRectangle::clear() {
00101   minimum_ = QPointF(0.0, 0.0);
00102   maximum_ = QPointF(-1.0, -1.0);
00103 }
00104 
00105 /*****************************************************************************/
00106 /* Operators                                                                 */
00107 /*****************************************************************************/
00108 
00109 bool BoundingRectangle::operator==(const BoundingRectangle& rectangle) const {
00110   return (minimum_ == rectangle.minimum_) && (maximum_ == rectangle.maximum_);
00111 }
00112 
00113 bool BoundingRectangle::operator!=(const BoundingRectangle& rectangle) const {
00114   return (minimum_ != rectangle.minimum_) || (maximum_ != rectangle.maximum_);
00115 }
00116 
00117 BoundingRectangle& BoundingRectangle::operator+=(const QPointF& point) {
00118   if (maximum_.x() >= minimum_.x()) {
00119     minimum_.setX(std::min(minimum_.x(), point.x()));
00120     maximum_.setX(std::max(maximum_.x(), point.x()));
00121   }
00122   else {
00123     minimum_.setX(point.x());
00124     maximum_.setX(point.x());
00125   }
00126         
00127   if (maximum_.y() >= minimum_.y()) {
00128     minimum_.setY(std::min(minimum_.y(), point.y()));
00129     maximum_.setY(std::max(maximum_.y(), point.y()));
00130   }
00131   else {
00132     minimum_.setY(point.y());
00133     maximum_.setY(point.y());
00134   }
00135   
00136   return *this;
00137 }
00138 
00139 BoundingRectangle& BoundingRectangle::operator+=(const BoundingRectangle&
00140     rectangle) {
00141   if (rectangle.maximum_.x() >= rectangle.minimum_.x()) {
00142     if (maximum_.x() >= minimum_.x()) {
00143       minimum_.setX(std::min(minimum_.x(), rectangle.minimum_.x()));
00144       maximum_.setX(std::max(maximum_.x(), rectangle.maximum_.x()));
00145     }
00146     else {
00147       minimum_.setX(rectangle.minimum_.x());
00148       maximum_.setX(rectangle.maximum_.x());
00149     }
00150   }
00151   
00152   if (rectangle.maximum_.y() >= rectangle.minimum_.y()) {
00153     if (maximum_.y() >= minimum_.y()) {
00154       minimum_.setY(std::min(minimum_.y(), rectangle.minimum_.y()));
00155       maximum_.setY(std::max(maximum_.y(), rectangle.maximum_.y()));
00156     }
00157     else {
00158       minimum_.setY(rectangle.minimum_.y());
00159       maximum_.setY(rectangle.maximum_.y());
00160     }
00161   }
00162   
00163   return *this;
00164 }
00165 
00166 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:10