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

FXRangef.h
1 /********************************************************************************
2 * *
3 * S i n g 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,2022 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 FXRANGEF_H
22 #define FXRANGEF_H
23 
24 namespace FX {
25 
26 
27 class FXSpheref;
28 class FXMat4f;
29 
30 
32 class FXAPI FXRangef {
33 public:
34  FXVec3f lower;
35  FXVec3f upper;
36 public:
37 
40 
42  FXRangef(const FXRangef& bounds):lower(bounds.lower),upper(bounds.upper){}
43 
45  FXRangef(const FXVec3f& p):lower(p),upper(p){}
46 
48  FXRangef(const FXVec3f& l,const FXVec3f& h):lower(l),upper(h){}
49 
51  FXRangef(FXfloat x,FXfloat y,FXfloat z):lower(x,y,z),upper(x,y,z){}
52 
54  FXRangef(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh,FXfloat zl,FXfloat zh):lower(xl,yl,zl),upper(xh,yh,zh){}
55 
57  FXRangef(const FXSpheref& sphere);
58 
60  FXRangef& operator=(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
61 
63  FXRangef& set(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
64 
66  FXRangef& set(const FXVec3f& p){ lower=upper=p; return *this; }
67 
69  FXRangef& set(const FXVec3f& l,const FXVec3f& h){ lower=l; upper=h; return *this; }
70 
72  FXRangef& set(FXfloat x,FXfloat y,FXfloat z){ lower.x=upper.x=x; lower.y=upper.y=y; lower.z=upper.z=z; return *this; }
73 
75  FXRangef& set(FXfloat xl,FXfloat xh,FXfloat yl,FXfloat yh,FXfloat zl,FXfloat zh){ lower.set(xl,yl,zl); upper.set(xh,yh,zh); return *this; }
76 
78  FXVec3f& operator[](FXint i){ return (&lower)[i]; }
79 
81  const FXVec3f& operator[](FXint i) const { return (&lower)[i]; }
82 
84  FXbool operator==(const FXRangef& r) const { return lower==r.lower && upper==r.upper; }
85  FXbool operator!=(const FXRangef& r) const { return lower!=r.lower || upper!=r.upper; }
86 
88  FXfloat width() const { return upper.x-lower.x; }
89 
91  FXfloat height() const { return upper.y-lower.y; }
92 
94  FXfloat depth() const { return upper.z-lower.z; }
95 
97  FXfloat area() const { return (width()*height()+width()*depth()+height()*depth())*2.0f; }
98 
100  FXfloat volume() const { return width()*height()*depth(); }
101 
103  FXfloat longest() const;
104 
106  FXfloat shortest() const;
107 
109  FXfloat diameter() const;
110 
112  FXfloat radius() const;
113 
115  FXVec3f diagonal() const;
116 
118  FXVec3f center() const;
119 
121  FXbool empty() const;
122 
124  FXbool contains(FXfloat x,FXfloat y,FXfloat z) const;
125 
127  FXbool contains(const FXVec3f& p) const;
128 
130  FXbool contains(const FXRangef& bounds) const;
131 
133  FXbool contains(const FXSpheref& sphere) const;
134 
136  FXRangef& include(FXfloat x,FXfloat y,FXfloat z);
137 
139  FXRangef& include(const FXVec3f& v);
140 
142  FXRangef& include(const FXRangef& box);
143 
145  FXRangef& include(const FXSpheref& sphere);
146 
148  FXint intersect(const FXVec4f& plane) const;
149 
151  FXbool intersect(const FXVec3f& u,const FXVec3f& v) const;
152 
154  FXbool intersect(const FXVec3f& pos,const FXVec3f& dir,FXfloat hit[]) const;
155 
157  FXVec3f corner(FXint c) const { return FXVec3f((&lower)[c&1].x,(&lower)[(c>>1)&1].y,(&lower)[c>>2].z); }
158 
160  FXRangef transform(const FXMat4f& mat) const;
161 
164  };
165 
166 
168 extern FXAPI FXbool overlap(const FXRangef& a,const FXRangef& b);
169 
171 extern FXAPI FXRangef unite(const FXRangef& a,const FXRangef& b);
172 
174 extern FXAPI FXRangef intersect(const FXRangef& a,const FXRangef& b);
175 
177 extern FXAPI FXStream& operator<<(FXStream& store,const FXRangef& bounds);
178 
180 extern FXAPI FXStream& operator>>(FXStream& store,FXRangef& bounds);
181 
182 }
183 
184 #endif
185 
FXfloat volume() const
Volume of box.
Definition: FXRangef.h:100
FXRangef(const FXVec3f &p)
Initialize with a single point.
Definition: FXRangef.h:45
~FXRangef()
Destructor.
Definition: FXRangef.h:163
FXfloat area() const
Area of box.
Definition: FXRangef.h:97
FXVec3f corner(FXint c) const
Get corner number 0..7.
Definition: FXRangef.h:157
FXRangef(const FXRangef &bounds)
Initialize with another range.
Definition: FXRangef.h:42
FXfloat width() const
Width of box.
Definition: FXRangef.h:88
Definition: FX4Splitter.h:28
FXVec3f & operator[](FXint i)
Indexing with 0..1.
Definition: FXRangef.h:78
FXRangef(FXfloat x, FXfloat y, FXfloat z)
Initialize with a single point.
Definition: FXRangef.h:51
FXRangef(FXfloat xl, FXfloat xh, FXfloat yl, FXfloat yh, FXfloat zl, FXfloat zh)
Initialize with explicit values.
Definition: FXRangef.h:54
Single-precision 3-element vector.
Definition: FXVec3f.h:28
Single-precision 4x4 matrix.
Definition: FXMat4f.h:32
Spherical bounds.
Definition: FXSpheref.h:32
Bounds.
Definition: FXRangef.h:32
FXfloat height() const
Height of box.
Definition: FXRangef.h:91
const FXVec3f & operator[](FXint i) const
Indexing with 0..1.
Definition: FXRangef.h:81
FXRangef()
Default constructor; value is not initialized.
Definition: FXRangef.h:39
FXRangef(const FXVec3f &l, const FXVec3f &h)
Initialize with corner points.
Definition: FXRangef.h:48
FXVec3f & set(const FXVec3f &v)
Set value from another vector.
Definition: FXVec3f.h:63
FXbool operator==(const FXRangef &r) const
Comparison.
Definition: FXRangef.h:84
FXfloat depth() const
Depth of box.
Definition: FXRangef.h:94
FXRangef & operator=(const FXRangef &bounds)
Assignment.
Definition: FXRangef.h:60
Single-precision 4-element vector.
Definition: FXVec4f.h:28

Copyright © 1997-2022 Jeroen van der Zijp