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,2006 by Jeroen van der Zijp. All Rights Reserved. * 00007 ********************************************************************************* 00008 * This library is free software; you can redistribute it and/or * 00009 * modify it under the terms of the GNU Lesser General Public * 00010 * License as published by the Free Software Foundation; either * 00011 * version 2.1 of the License, or (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 GNU * 00016 * Lesser General Public License for more details. * 00017 * * 00018 * You should have received a copy of the GNU Lesser General Public * 00019 * License along with this library; if not, write to the Free Software * 00020 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * 00021 ********************************************************************************* 00022 * $Id: FXExtentd.h,v 1.8 2006/01/22 17:58:01 fox Exp $ * 00023 ********************************************************************************/ 00024 #ifndef FXEXTENTD_H 00025 #define FXEXTENTD_H 00026 00027 00028 namespace FX { 00029 00030 00031 /// Extent 00032 class FXExtentd { 00033 public: 00034 FXVec2d lower; 00035 FXVec2d upper; 00036 public: 00037 00038 /// Default constructor 00039 FXExtentd(){} 00040 00041 /// Copy constructor 00042 FXExtentd(const FXExtentd& ext):lower(ext.lower),upper(ext.upper){} 00043 00044 /// Initialize from two vectors 00045 FXExtentd(const FXVec2d& lo,const FXVec2d& hi):lower(lo),upper(hi){} 00046 00047 /// Initialize from six numbers 00048 FXExtentd(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi):lower(xlo,ylo),upper(xhi,yhi){} 00049 00050 /// Assignment 00051 FXExtentd& operator=(const FXExtentd& ext){ lower=ext.lower; upper=ext.upper; return *this; } 00052 00053 /// Indexing with 0..1 00054 FXVec2d& operator[](FXint i){ return (&lower)[i]; } 00055 00056 /// Indexing with 0..1 00057 const FXVec2d& operator[](FXint i) const { return (&lower)[i]; } 00058 00059 /// Comparison 00060 bool operator==(const FXExtentd& ext) const { return lower==ext.lower && upper==ext.upper;} 00061 bool operator!=(const FXExtentd& ext) const { return lower!=ext.lower || upper!=ext.upper;} 00062 00063 /// Width of box 00064 FXdouble width() const { return upper.x-lower.x; } 00065 00066 /// Height of box 00067 FXdouble height() const { return upper.y-lower.y; } 00068 00069 /// Longest side 00070 FXdouble longest() const; 00071 00072 /// shortest side 00073 FXdouble shortest() const; 00074 00075 /// Length of diagonal 00076 FXdouble diameter() const; 00077 00078 /// Get radius of box 00079 FXdouble radius() const; 00080 00081 /// Compute diagonal 00082 FXVec2d diagonal() const; 00083 00084 /// Get center of box 00085 FXVec2d center() const; 00086 00087 /// Test if empty 00088 bool empty() const; 00089 00090 /// Test if box contains point x,y 00091 bool contains(FXdouble x,FXdouble y) const; 00092 00093 /// Test if box contains point p 00094 bool contains(const FXVec2d& p) const; 00095 00096 /// Test if box properly contains another box 00097 bool contains(const FXExtentd& ext) const; 00098 00099 /// Include point 00100 FXExtentd& include(FXdouble x,FXdouble y); 00101 00102 /// Include point 00103 FXExtentd& include(const FXVec2d& v); 00104 00105 /// Include given range into extent 00106 FXExtentd& include(const FXExtentd& ext); 00107 00108 /// Test if bounds overlap 00109 friend FXAPI bool overlap(const FXExtentd& a,const FXExtentd& b); 00110 00111 /// Get corner number 0..3 00112 FXVec2d corner(FXint c) const { return FXVec2d((&lower)[c&1].x, (&lower)[(c>>1)&1].y); } 00113 00114 /// Union of two boxes 00115 friend FXAPI FXExtentd unite(const FXExtentd& a,const FXExtentd& b); 00116 00117 /// Intersection of two boxes 00118 friend FXAPI FXExtentd intersect(const FXExtentd& a,const FXExtentd& b); 00119 00120 /// Save object to a stream 00121 friend FXAPI FXStream& operator<<(FXStream& store,const FXExtentd& ext); 00122 00123 /// Load object from a stream 00124 friend FXAPI FXStream& operator>>(FXStream& store,FXExtentd& ext); 00125 }; 00126 00127 00128 extern FXAPI bool overlap(const FXExtentd& a,const FXExtentd& b); 00129 00130 extern FXAPI FXExtentd unite(const FXExtentd& a,const FXExtentd& b); 00131 extern FXAPI FXExtentd intersect(const FXExtentd& a,const FXExtentd& b); 00132 00133 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentd& ext); 00134 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentd& ext); 00135 00136 } 00137 00138 #endif 00139
Copyright © 1997-2005 Jeroen van der Zijp |