![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * D o u b l e - P r e c i s i o n E x t e n t C l a s s * 00004 * * 00005 ********************************************************************************* 00006 * Copyright (C) 2004,2009 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or modify * 00009 * it under the terms of the GNU Lesser General Public License as published by * 00010 * the Free Software Foundation; either version 3 of the License, or * 00011 * (at your option) any later version. * 00012 * * 00013 * This library is distributed in the hope that it will be useful, * 00014 * but WITHOUT ANY WARRANTY; without even the implied warranty of * 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * 00016 * GNU Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public License * 00019 * along with this program. If not, see <http://www.gnu.org/licenses/> * 00020 ********************************************************************************* 00021 * $Id: FXExtentd.h,v 1.18 2009/01/26 09:40:22 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXEXTENTD_H 00024 #define FXEXTENTD_H 00025 00026 00027 namespace FX { 00028 00029 00030 /// Extent 00031 class FXAPI FXExtentd { 00032 public: 00033 FXVec2d lower; 00034 FXVec2d upper; 00035 public: 00036 00037 /// Default constructor; value is not initialized 00038 FXExtentd(){} 00039 00040 /// Copy constructor 00041 FXExtentd(const FXExtentd& ext):lower(ext.lower),upper(ext.upper){} 00042 00043 /// Initialize with a single point 00044 FXExtentd(const FXVec2d& p):lower(p),upper(p){} 00045 00046 /// Initialize from corner points 00047 FXExtentd(const FXVec2d& lo,const FXVec2d& hi):lower(lo),upper(hi){} 00048 00049 /// Initialize with a single point 00050 FXExtentd(FXdouble x,FXdouble y):lower(x,y),upper(x,y){} 00051 00052 /// Initialize with explicit values 00053 FXExtentd(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh):lower(xl,yl),upper(xh,yh){} 00054 00055 /// Assignment 00056 FXExtentd& operator=(const FXExtentd& ext){ lower=ext.lower; upper=ext.upper; return *this; } 00057 00058 /// Set value from another range 00059 FXExtentd& set(const FXExtentd& ext){ lower=ext.lower; upper=ext.upper; return *this; } 00060 00061 /// Set value from single point 00062 FXExtentd& set(const FXVec2d& p){ lower=upper=p; return *this; } 00063 00064 /// Set value from corner points 00065 FXExtentd& set(const FXVec2d& lo,const FXVec2d& hi){ lower=lo; upper=hi; return *this; } 00066 00067 /// Set value from single point 00068 FXExtentd& set(FXdouble x,FXdouble y){ lower.x=upper.x=x; lower.y=upper.y=y; return *this; } 00069 00070 /// Set value from explicit values 00071 FXExtentd& set(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh){ lower.set(xl,yl); upper.set(xh,yh); return *this; } 00072 00073 /// Indexing with 0..1 00074 FXVec2d& operator[](FXint i){ return (&lower)[i]; } 00075 00076 /// Indexing with 0..1 00077 const FXVec2d& operator[](FXint i) const { return (&lower)[i]; } 00078 00079 /// Comparison 00080 FXbool operator==(const FXExtentd& ext) const { return lower==ext.lower && upper==ext.upper;} 00081 FXbool operator!=(const FXExtentd& ext) const { return lower!=ext.lower || upper!=ext.upper;} 00082 00083 /// Width of box 00084 FXdouble width() const { return upper.x-lower.x; } 00085 00086 /// Height of box 00087 FXdouble height() const { return upper.y-lower.y; } 00088 00089 /// Longest side 00090 FXdouble longest() const; 00091 00092 /// shortest side 00093 FXdouble shortest() const; 00094 00095 /// Length of diagonal 00096 FXdouble diameter() const; 00097 00098 /// Get radius of box 00099 FXdouble radius() const; 00100 00101 /// Compute diagonal 00102 FXVec2d diagonal() const; 00103 00104 /// Get center of box 00105 FXVec2d center() const; 00106 00107 /// Test if empty 00108 FXbool empty() const; 00109 00110 /// Test if box contains point x,y 00111 FXbool contains(FXdouble x,FXdouble y) const; 00112 00113 /// Test if box contains point p 00114 FXbool contains(const FXVec2d& p) const; 00115 00116 /// Test if box properly contains another box 00117 FXbool contains(const FXExtentd& ext) const; 00118 00119 /// Include point 00120 FXExtentd& include(FXdouble x,FXdouble y); 00121 00122 /// Include point 00123 FXExtentd& include(const FXVec2d& v); 00124 00125 /// Include given range into extent 00126 FXExtentd& include(const FXExtentd& ext); 00127 00128 /// Test if bounds overlap 00129 friend FXAPI FXbool overlap(const FXExtentd& a,const FXExtentd& b); 00130 00131 /// Get corner number 0..3 00132 FXVec2d corner(FXint c) const { return FXVec2d((&lower)[c&1].x, (&lower)[(c>>1)&1].y); } 00133 00134 /// Union of two boxes 00135 friend FXAPI FXExtentd unite(const FXExtentd& a,const FXExtentd& b); 00136 00137 /// Intersection of two boxes 00138 friend FXAPI FXExtentd intersect(const FXExtentd& a,const FXExtentd& b); 00139 00140 /// Save object to a stream 00141 friend FXAPI FXStream& operator<<(FXStream& store,const FXExtentd& ext); 00142 00143 /// Load object from a stream 00144 friend FXAPI FXStream& operator>>(FXStream& store,FXExtentd& ext); 00145 }; 00146 00147 00148 extern FXAPI FXbool overlap(const FXExtentd& a,const FXExtentd& b); 00149 00150 extern FXAPI FXExtentd unite(const FXExtentd& a,const FXExtentd& b); 00151 extern FXAPI FXExtentd intersect(const FXExtentd& a,const FXExtentd& b); 00152 00153 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentd& ext); 00154 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentd& ext); 00155 00156 } 00157 00158 #endif 00159
![]() |