Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members

FXRanged.h
1 /********************************************************************************
2 * *
3 * D o u b l e - P r e c i s i o n R a n g e C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 2004,2017 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU Lesser General Public License as published by *
10 * the Free Software Foundation; either version 3 of the License, or *
11 * (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public License *
19 * along with this program. If not, see <http://www.gnu.org/licenses/> *
20 ********************************************************************************/
21 #ifndef FXRANGED_H
22 #define FXRANGED_H
23 
24 namespace FX {
25 
26 
27 class FXSphered;
28 class FXMat4d;
29 
30 
32 class FXAPI FXRanged {
33 public:
34  FXVec3d lower;
35  FXVec3d upper;
36 public:
37 
40 
42  FXRanged(const FXRanged& bounds):lower(bounds.lower),upper(bounds.upper){}
43 
45  FXRanged(const FXVec3d& p):lower(p),upper(p){}
46 
48  FXRanged(const FXVec3d& l,const FXVec3d& h):lower(l),upper(h){}
49 
51  FXRanged(FXdouble x,FXdouble y,FXdouble z):lower(x,y,z),upper(x,y,z){}
52 
54  FXRanged(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh,FXdouble zl,FXdouble zh):lower(xl,yl,zl),upper(xh,yh,zh){}
55 
57  FXRanged(const FXSphered& sphere);
58 
60  FXRanged& operator=(const FXRanged& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
61 
63  FXRanged& set(const FXRanged& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
64 
66  FXRanged& set(const FXVec3d& p){ lower=upper=p; return *this; }
67 
69  FXRanged& set(const FXVec3d& l,const FXVec3d& h){ lower=l; upper=h; return *this; }
70 
72  FXRanged& set(FXdouble x,FXdouble y,FXdouble z){ lower.x=upper.x=x; lower.y=upper.y=y; lower.z=upper.z=z; return *this; }
73 
75  FXRanged& set(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh,FXdouble zl,FXdouble zh){ lower.set(xl,yl,zl); upper.set(xh,yh,zh); return *this; }
76 
78  FXVec3d& operator[](FXint i){ return (&lower)[i]; }
79 
81  const FXVec3d& operator[](FXint i) const { return (&lower)[i]; }
82 
84  FXbool operator==(const FXRanged& r) const { return lower==r.lower && upper==r.upper; }
85  FXbool operator!=(const FXRanged& r) const { return lower!=r.lower || upper!=r.upper; }
86 
88  FXdouble width() const { return upper.x-lower.x; }
89 
91  FXdouble height() const { return upper.y-lower.y; }
92 
94  FXdouble depth() const { return upper.z-lower.z; }
95 
97  FXdouble area() const { return (width()*height()+width()*depth()+height()*depth())*2.0; }
98 
100  FXdouble volume() const { return width()*height()*depth(); }
101 
103  FXdouble longest() const;
104 
106  FXdouble shortest() const;
107 
109  FXdouble diameter() const;
110 
112  FXdouble radius() const;
113 
115  FXVec3d diagonal() const;
116 
118  FXVec3d center() const;
119 
121  FXbool empty() const;
122 
124  FXbool contains(FXdouble x,FXdouble y,FXdouble z) const;
125 
127  FXbool contains(const FXVec3d& p) const;
128 
130  FXbool contains(const FXRanged& bounds) const;
131 
133  FXbool contains(const FXSphered& sphere) const;
134 
136  FXRanged& include(FXdouble x,FXdouble y,FXdouble z);
137 
139  FXRanged& include(const FXVec3d& v);
140 
142  FXRanged& include(const FXRanged& box);
143 
145  FXRanged& include(const FXSphered& sphere);
146 
148  FXint intersect(const FXVec4d &plane) const;
149 
151  FXbool intersect(const FXVec3d& u,const FXVec3d& v) const;
152 
154  FXbool intersect(const FXVec3d& pos,const FXVec3d& dir,FXdouble hit[]) const;
155 
157  FXVec3d corner(FXint c) const { return FXVec3d((&lower)[c&1].x, (&lower)[(c>>1)&1].y, (&lower)[c>>2].z); }
158 
160  FXRanged transform(const FXMat4d& mat) const;
161 
164  };
165 
166 
168 extern FXAPI FXbool overlap(const FXRanged& a,const FXRanged& b);
169 
171 extern FXAPI FXRanged unite(const FXRanged& a,const FXRanged& b);
172 
174 extern FXAPI FXRanged intersect(const FXRanged& a,const FXRanged& b);
175 
177 extern FXAPI FXStream& operator<<(FXStream& store,const FXRanged& bounds);
178 
180 extern FXAPI FXStream& operator>>(FXStream& store,FXRanged& bounds);
181 
182 }
183 
184 #endif
185 

Copyright © 1997-2016 Jeroen van der Zijp