Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members | Related Pages

qwt_double_rect.cpp

00001 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- ***************************** 00002 * Qwt Widget Library 00003 * Copyright (C) 1997 Josef Wilgen 00004 * Copyright (C) 2002 Uwe Rathmann 00005 * 00006 * This library is free software; you can redistribute it and/or 00007 * modify it under the terms of the Qwt License, Version 1.0 00008 *****************************************************************************/ 00009 00010 #include "qwt_double_rect.h" 00011 00013 00014 QwtDoublePoint::QwtDoublePoint(): 00015 d_x(0.0), 00016 d_y(0.0) 00017 { 00018 } 00019 00021 00022 QwtDoublePoint::QwtDoublePoint(double x, double y ): 00023 d_x(x), 00024 d_y(y) 00025 { 00026 } 00027 00029 QwtDoublePoint::QwtDoublePoint(const QPoint &p): 00030 d_x(double(p.x())), 00031 d_y(double(p.y())) 00032 { 00033 } 00034 00036 bool QwtDoublePoint::operator==(const QwtDoublePoint &other) const 00037 { 00038 return (d_x == other.d_x) && (d_y == other.d_y); 00039 } 00040 00042 bool QwtDoublePoint::operator!=(const QwtDoublePoint &other) const 00043 { 00044 return !operator==(other); 00045 } 00046 00052 const QwtDoublePoint QwtDoublePoint::operator-() const 00053 { 00054 return QwtDoublePoint(-d_x, -d_y); 00055 } 00056 00062 const QwtDoublePoint QwtDoublePoint::operator+( 00063 const QwtDoublePoint &other) const 00064 { 00065 return QwtDoublePoint(d_x + other.d_x, d_y + other.d_y); 00066 } 00067 00073 const QwtDoublePoint QwtDoublePoint::operator-( 00074 const QwtDoublePoint &other) const 00075 { 00076 return QwtDoublePoint(d_x - other.d_x, d_y - other.d_y); 00077 } 00078 00080 00081 const QwtDoublePoint QwtDoublePoint::operator*(double c) const 00082 { 00083 return QwtDoublePoint(d_x * c, d_y * c); 00084 } 00085 00087 00088 const QwtDoublePoint QwtDoublePoint::operator/(double c) const 00089 { 00090 return QwtDoublePoint(d_x / c, d_y / c); 00091 } 00092 00094 00095 QwtDoublePoint &QwtDoublePoint::operator+=(const QwtDoublePoint &other) 00096 { 00097 d_x += other.d_x; 00098 d_y += other.d_y; 00099 return *this; 00100 } 00101 00103 00104 QwtDoublePoint &QwtDoublePoint::operator-=(const QwtDoublePoint &other) 00105 { 00106 d_x -= other.d_x; 00107 d_y -= other.d_y; 00108 return *this; 00109 } 00110 00112 00113 QwtDoublePoint &QwtDoublePoint::operator*=(double c) 00114 { 00115 d_x *= c; 00116 d_y *= c; 00117 return *this; 00118 } 00119 00121 00122 QwtDoublePoint &QwtDoublePoint::operator/=(double c) 00123 { 00124 d_x /= c; 00125 d_y /= c; 00126 return *this; 00127 } 00128 00130 00131 QwtDoubleSize::QwtDoubleSize(): 00132 d_width(0.0), 00133 d_height(0.0) 00134 { 00135 } 00136 00138 00139 QwtDoubleSize::QwtDoubleSize( double w, double h ): 00140 d_width(w), 00141 d_height(h) 00142 { 00143 } 00144 00146 00147 QwtDoubleSize::QwtDoubleSize(const QSize &sz): 00148 d_width(double(sz.width())), 00149 d_height(double(sz.height())) 00150 { 00151 } 00152 00154 00155 void QwtDoubleSize::transpose() 00156 { 00157 double tmp = d_width; 00158 d_width = d_height; 00159 d_height = tmp; 00160 } 00161 00167 QwtDoubleSize QwtDoubleSize::expandedTo( 00168 const QwtDoubleSize &other) const 00169 { 00170 return QwtDoubleSize( 00171 QMAX(d_width, other.d_width), 00172 QMAX(d_height, other.d_height) 00173 ); 00174 } 00175 00181 QwtDoubleSize QwtDoubleSize::boundedTo( 00182 const QwtDoubleSize &other) const 00183 { 00184 return QwtDoubleSize( 00185 QMIN(d_width, other.d_width), 00186 QMIN(d_height, other.d_height) 00187 ); 00188 } 00189 00191 00192 bool QwtDoubleSize::operator==(const QwtDoubleSize &other) const 00193 { 00194 return d_width == other.d_width && d_height == other.d_height; 00195 } 00196 00198 00199 bool QwtDoubleSize::operator!=(const QwtDoubleSize &other) const 00200 { 00201 return !operator==(other); 00202 } 00203 00209 const QwtDoubleSize QwtDoubleSize::operator-() const 00210 { 00211 return QwtDoubleSize(-d_width, -d_height); 00212 } 00213 00219 const QwtDoubleSize QwtDoubleSize::operator+( 00220 const QwtDoubleSize &other) const 00221 { 00222 return QwtDoubleSize(d_width + other.d_width, 00223 d_height + other.d_height); 00224 } 00225 00231 const QwtDoubleSize QwtDoubleSize::operator-( 00232 const QwtDoubleSize &other) const 00233 { 00234 return QwtDoubleSize(d_width - other.d_width, 00235 d_height - other.d_height); 00236 } 00237 00239 00240 const QwtDoubleSize QwtDoubleSize::operator*(double c) const 00241 { 00242 return QwtDoubleSize(d_width * c, d_height * c); 00243 } 00244 00246 00247 const QwtDoubleSize QwtDoubleSize::operator/(double c) const 00248 { 00249 return QwtDoubleSize(d_width / c, d_height / c); 00250 } 00251 00253 00254 QwtDoubleSize &QwtDoubleSize::operator+=(const QwtDoubleSize &other) 00255 { 00256 d_width += other.d_width; 00257 d_height += other.d_height; 00258 return *this; 00259 } 00260 00262 00263 QwtDoubleSize &QwtDoubleSize::operator-=(const QwtDoubleSize &other) 00264 { 00265 d_width -= other.d_width; 00266 d_height -= other.d_height; 00267 return *this; 00268 } 00269 00270 /* 00271 Multiplies this size's width and height by c, 00272 and returns a reference to this size. 00273 */ 00274 00275 QwtDoubleSize &QwtDoubleSize::operator*=(double c) 00276 { 00277 d_width *= c; 00278 d_height *= c; 00279 return *this; 00280 } 00281 00282 /* 00283 Devides this size's width and height by c, 00284 and returns a reference to this size. 00285 */ 00286 00287 QwtDoubleSize &QwtDoubleSize::operator/=(double c) 00288 { 00289 d_width /= c; 00290 d_height /= c; 00291 return *this; 00292 } 00293 00295 QwtDoubleRect::QwtDoubleRect(): 00296 d_x1(0.0), 00297 d_x2(0.0), 00298 d_y1(0.0), 00299 d_y2(0.0) 00300 { 00301 } 00302 00308 QwtDoubleRect::QwtDoubleRect(double x1, double x2, 00309 double y1, double y2): 00310 d_x1(x1), 00311 d_x2(x2), 00312 d_y1(y1), 00313 d_y2(y2) 00314 { 00315 } 00316 00322 QwtDoubleRect::QwtDoubleRect(double x, double y, const QwtDoubleSize &size): 00323 d_x1(x), 00324 d_x2(x + size.width()), 00325 d_y1(y), 00326 d_y2(y + size.height()) 00327 { 00328 } 00329 00333 void QwtDoubleRect::setRect(double x1, double x2, double y1, double y2) 00334 { 00335 d_x1 = x1; 00336 d_x2 = x2; 00337 d_y1 = y1; 00338 d_y2 = y2; 00339 } 00340 00346 void QwtDoubleRect::setSize(const QwtDoubleSize &size) 00347 { 00348 setWidth(size.width()); 00349 setHeight(size.height()); 00350 } 00351 00359 QwtDoubleRect QwtDoubleRect::normalize() const 00360 { 00361 QwtDoubleRect r; 00362 if ( d_x2 < d_x1 ) 00363 { 00364 r.d_x1 = d_x2; 00365 r.d_x2 = d_x1; 00366 } 00367 else 00368 { 00369 r.d_x1 = d_x1; 00370 r.d_x2 = d_x2; 00371 } 00372 if ( d_y2 < d_y1 ) 00373 { 00374 r.d_y1 = d_y2; 00375 r.d_y2 = d_y1; 00376 } 00377 else 00378 { 00379 r.d_y1 = d_y1; 00380 r.d_y2 = d_y2; 00381 } 00382 return r; 00383 } 00384 00390 QwtDoubleRect QwtDoubleRect::unite(const QwtDoubleRect &other) const 00391 { 00392 return *this | other; 00393 } 00394 00400 QwtDoubleRect QwtDoubleRect::intersect(const QwtDoubleRect &other) const 00401 { 00402 return *this & other; 00403 } 00404 00410 bool QwtDoubleRect::intersects(const QwtDoubleRect &other) const 00411 { 00412 return ( QMAX(d_x1, other.d_x1) <= QMIN(d_x2, other.d_x2) ) && 00413 ( QMAX(d_y1, other.d_y1 ) <= QMIN(d_y2, other.d_y2) ); 00414 } 00415 00417 00418 bool QwtDoubleRect::operator==(const QwtDoubleRect &other) const 00419 { 00420 return d_x1 == other.d_x1 && d_x2 == other.d_x2 && 00421 d_y1 == other.d_y1 && d_y2 == other.d_y2; 00422 } 00423 00425 00426 bool QwtDoubleRect::operator!=(const QwtDoubleRect &other) const 00427 { 00428 return !operator==(other); 00429 } 00430 00437 QwtDoubleRect QwtDoubleRect::operator|(const QwtDoubleRect &other) const 00438 { 00439 if ( !isValid() ) 00440 return other; 00441 00442 if ( !other.isValid() ) 00443 return *this; 00444 00445 return QwtDoubleRect(QMIN(d_x1, other.d_x1), QMAX(d_x2, other.d_x2), 00446 QMIN(d_y1, other.d_y1), QMAX(d_y2, other.d_y2) ); 00447 } 00448 00454 QwtDoubleRect QwtDoubleRect::operator&(const QwtDoubleRect &other) const 00455 { 00456 return QwtDoubleRect(QMAX(d_x1, other.d_x1), QMIN(d_x2, other.d_x2), 00457 QMAX(d_y1, other.d_y1), QMIN(d_y2, other.d_y2)); 00458 } 00459 00461 00462 QwtDoubleRect &QwtDoubleRect::operator|=(const QwtDoubleRect &other) 00463 { 00464 *this = *this | other; 00465 return *this; 00466 } 00467 00469 00470 QwtDoubleRect &QwtDoubleRect::operator&=(const QwtDoubleRect &other) 00471 { 00472 *this = *this & other; 00473 return *this; 00474 } 00475 00477 00478 QwtDoublePoint QwtDoubleRect::center() const 00479 { 00480 return QwtDoublePoint(d_x1 + (d_x2 - d_x1) / 2.0, 00481 d_y1 + (d_y2 - d_y1) / 2.0); 00482 } 00483 00492 bool QwtDoubleRect::contains(double x, double y, bool proper) const 00493 { 00494 if ( proper ) 00495 return x > d_x1 && x < d_x2 && y > d_y1 && y < d_y2; 00496 else 00497 return x >= d_x1 && x <= d_x2 && y >= d_y1 && y <= d_y2; 00498 } 00499 00508 bool QwtDoubleRect::contains(const QwtDoublePoint &p, bool proper) const 00509 { 00510 return contains(p.x(), p.y(), proper); 00511 } 00512 00521 bool QwtDoubleRect::contains(const QwtDoubleRect &other, bool proper) const 00522 { 00523 return contains(other.d_x1, other.d_y1, proper) && 00524 contains(other.d_x2, other.d_y2, proper); 00525 } 00526 00528 00529 void QwtDoubleRect::moveX(double x) 00530 { 00531 const double w = width(); 00532 d_x1 = x; 00533 d_x2 = d_x1 + w; 00534 } 00535 00537 00538 void QwtDoubleRect::moveY(double y) 00539 { 00540 const double h = height(); 00541 d_y1 = y; 00542 d_y2 = d_y1 + h; 00543 } 00544 00546 00547 void QwtDoubleRect::move(double x, double y) 00548 { 00549 moveX(x); 00550 moveY(y); 00551 } 00552 00554 00555 void QwtDoubleRect::moveBy(double dx, double dy) 00556 { 00557 d_x1 += dx; 00558 d_x2 += dx; 00559 d_y1 += dy; 00560 d_y2 += dy; 00561 } 00562 00564 00565 void QwtDoubleRect::moveCenter(const QwtDoublePoint &pos) 00566 { 00567 moveCenter(pos.x(), pos.y()); 00568 } 00569 00571 00572 void QwtDoubleRect::moveCenter(double x, double y) 00573 { 00574 move(x - width() / 2.0, y - height() / 2.0); 00575 }

Generated on Tue Nov 16 21:12:20 2004 for Qwt User's Guide by doxygen 1.3.8