BoundingRectangle.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
20 
21 namespace rqt_multiplot {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
27 BoundingRectangle::BoundingRectangle(const QPointF& minimum, const QPointF&
28  maximum) :
29  minimum_(minimum),
30  maximum_(maximum) {
31 }
32 
33 BoundingRectangle::BoundingRectangle(const QRectF& rectangle) :
34  minimum_(rectangle.left(), rectangle.top()),
35  maximum_(rectangle.right(), rectangle.bottom()) {
36 }
37 
39  minimum_(src.minimum_),
40  maximum_(src.maximum_) {
41 }
42 
44 }
45 
46 /*****************************************************************************/
47 /* Accessors */
48 /*****************************************************************************/
49 
50 void BoundingRectangle::setMinimum(const QPointF& minimum) {
51  minimum_ = minimum;
52 }
53 
55  return minimum_;
56 }
57 
58 const QPointF& BoundingRectangle::getMinimum() const {
59  return minimum_;
60 }
61 
62 void BoundingRectangle::setMaximum(const QPointF& maximum) {
63  maximum_ = maximum;
64 }
65 
67  return maximum_;
68 }
69 
70 const QPointF& BoundingRectangle::getMaximum() const {
71  return maximum_;
72 }
73 
75  return QRectF(minimum_, maximum_).normalized();
76 }
77 
79  return (maximum_.x() >= minimum_.x()) && (maximum_.y() >= minimum_.y());
80 }
81 
83  return (maximum_.x() <= minimum_.x()) || (maximum_.y() <= minimum_.y());
84 }
85 
86 bool BoundingRectangle::contains(const QPointF& point) const {
87  return (point.x() >= minimum_.x()) && (point.y() >= minimum_.y()) &&
88  (point.x() <= maximum_.x()) && (point.y() <= maximum_.y());
89 }
90 
91 /*****************************************************************************/
92 /* Methods */
93 /*****************************************************************************/
94 
95 void BoundingRectangle::initialize(const QPointF& point) {
96  minimum_ = point;
97  maximum_ = point;
98 }
99 
101  minimum_ = QPointF(0.0, 0.0);
102  maximum_ = QPointF(-1.0, -1.0);
103 }
104 
105 /*****************************************************************************/
106 /* Operators */
107 /*****************************************************************************/
108 
109 bool BoundingRectangle::operator==(const BoundingRectangle& rectangle) const {
110  return (minimum_ == rectangle.minimum_) && (maximum_ == rectangle.maximum_);
111 }
112 
113 bool BoundingRectangle::operator!=(const BoundingRectangle& rectangle) const {
114  return (minimum_ != rectangle.minimum_) || (maximum_ != rectangle.maximum_);
115 }
116 
118  if (maximum_.x() >= minimum_.x()) {
119  minimum_.setX(std::min(minimum_.x(), point.x()));
120  maximum_.setX(std::max(maximum_.x(), point.x()));
121  }
122  else {
123  minimum_.setX(point.x());
124  maximum_.setX(point.x());
125  }
126 
127  if (maximum_.y() >= minimum_.y()) {
128  minimum_.setY(std::min(minimum_.y(), point.y()));
129  maximum_.setY(std::max(maximum_.y(), point.y()));
130  }
131  else {
132  minimum_.setY(point.y());
133  maximum_.setY(point.y());
134  }
135 
136  return *this;
137 }
138 
140  rectangle) {
141  if (rectangle.maximum_.x() >= rectangle.minimum_.x()) {
142  if (maximum_.x() >= minimum_.x()) {
143  minimum_.setX(std::min(minimum_.x(), rectangle.minimum_.x()));
144  maximum_.setX(std::max(maximum_.x(), rectangle.maximum_.x()));
145  }
146  else {
147  minimum_.setX(rectangle.minimum_.x());
148  maximum_.setX(rectangle.maximum_.x());
149  }
150  }
151 
152  if (rectangle.maximum_.y() >= rectangle.minimum_.y()) {
153  if (maximum_.y() >= minimum_.y()) {
154  minimum_.setY(std::min(minimum_.y(), rectangle.minimum_.y()));
155  maximum_.setY(std::max(maximum_.y(), rectangle.maximum_.y()));
156  }
157  else {
158  minimum_.setY(rectangle.minimum_.y());
159  maximum_.setY(rectangle.maximum_.y());
160  }
161  }
162 
163  return *this;
164 }
165 
166 }
BoundingRectangle(const QPointF &minimum=QPointF(0.0, 0.0), const QPointF &maximum=QPointF(-1.0,-1.0))
bool operator!=(const BoundingRectangle &rectangle) const
bool contains(const QPointF &point) const
void setMaximum(const QPointF &maximum)
void setMinimum(const QPointF &minimum)
BoundingRectangle & operator+=(const QPointF &point)
bool operator==(const BoundingRectangle &rectangle) const
void initialize(const QPointF &point)


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44