![]() |
Main Page Class Hierarchy Alphabetical List Compound List File List Compound Members
![]() |
00001 /******************************************************************************** 00002 * * 00003 * S i n g 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: FXExtentf.h,v 1.18 2009/01/26 09:40:22 fox Exp $ * 00022 ********************************************************************************/ 00023 #ifndef FXEXTENTF_H 00024 #define FXEXTENTF_H 00025 00026 00027 namespace FX { 00028 00029 00030 /// Extent 00031 class FXAPI FXExtentf { 00032 public: 00033 FXVec2f lower; 00034 FXVec2f upper; 00035 public: 00036 00037 /// Default constructor; value is not initialized 00038 FXExtentf(){} 00039 00040 /// Copy constructor 00041 FXExtentf(const FXExtentf& ext):lower(ext.lower),upper(ext.upper){} 00042 00043 /// Initialize with a single point 00044 FXExtentf(const FXVec2f& p):lower(p),upper(p){} 00045 00046 /// Initialize from corner points 00047 FXExtentf(const FXVec2f& lo,const FXVec2f& hi):lower(lo),upper(hi){} 00048 00049 /// Initialize with a single point 00050 FXExtentf(FXfloat x,FXfloat y):lower(x,y),upper(x,y){} 00051 00052 /// Initialize with explicit values 00053 FXExtentf(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh):lower(xl,yl),upper(xh,yh){} 00054 00055 /// Assignment 00056 FXExtentf& operator=(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; } 00057 00058 /// Set value from another range 00059 FXExtentf& set(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; } 00060 00061 /// Set value from single point 00062 FXExtentf& set(const FXVec2f& p){ lower=upper=p; return *this; } 00063 00064 /// Set value from corner points 00065 FXExtentf& set(const FXVec2f& lo,const FXVec2f& hi){ lower=lo; upper=hi; return *this; } 00066 00067 /// Set value from single point 00068 FXExtentf& set(FXfloat x,FXfloat y){ lower.x=upper.x=x; lower.y=upper.y=y; return *this; } 00069 00070 /// Set value from explicit values 00071 FXExtentf& set(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh){ lower.set(xl,yl); upper.set(xh,yh); return *this; } 00072 00073 /// Indexing with 0..1 00074 FXVec2f& operator[](FXint i){ return (&lower)[i]; } 00075 00076 /// Indexing with 0..1 00077 const FXVec2f& operator[](FXint i) const { return (&lower)[i]; } 00078 00079 /// Comparison 00080 FXbool operator==(const FXExtentf& ext) const { return lower==ext.lower && upper==ext.upper;} 00081 FXbool operator!=(const FXExtentf& ext) const { return lower!=ext.lower || upper!=ext.upper;} 00082 00083 /// Width of box 00084 FXfloat width() const { return upper.x-lower.x; } 00085 00086 /// Height of box 00087 FXfloat height() const { return upper.y-lower.y; } 00088 00089 /// Longest side 00090 FXfloat longest() const; 00091 00092 /// shortest side 00093 FXfloat shortest() const; 00094 00095 /// Length of diagonal 00096 FXfloat diameter() const; 00097 00098 /// Get radius of box 00099 FXfloat radius() const; 00100 00101 /// Compute diagonal 00102 FXVec2f diagonal() const; 00103 00104 /// Get center of box 00105 FXVec2f center() const; 00106 00107 /// Test if empty 00108 FXbool empty() const; 00109 00110 /// Test if box contains point x,y 00111 FXbool contains(FXfloat x,FXfloat y) const; 00112 00113 /// Test if box contains point p 00114 FXbool contains(const FXVec2f& p) const; 00115 00116 /// Test if box properly contains another box 00117 FXbool contains(const FXExtentf& ext) const; 00118 00119 /// Include point 00120 FXExtentf& include(FXfloat x,FXfloat y); 00121 00122 /// Include point 00123 FXExtentf& include(const FXVec2f& v); 00124 00125 /// Include given range into extent 00126 FXExtentf& include(const FXExtentf& ext); 00127 00128 /// Test if bounds overlap 00129 friend FXAPI FXbool overlap(const FXExtentf& a,const FXExtentf& b); 00130 00131 /// Get corner number 0..3 00132 FXVec2f corner(FXint c) const { return FXVec2f((&lower)[c&1].x, (&lower)[(c>>1)&1].y); } 00133 00134 /// Union of two boxes 00135 friend FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b); 00136 00137 /// Intersection of two boxes 00138 friend FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b); 00139 00140 /// Save object to a stream 00141 friend FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext); 00142 00143 /// Load object from a stream 00144 friend FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext); 00145 }; 00146 00147 00148 extern FXAPI FXbool overlap(const FXExtentf& a,const FXExtentf& b); 00149 00150 extern FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b); 00151 extern FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b); 00152 00153 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext); 00154 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext); 00155 00156 } 00157 00158 #endif 00159
![]() |