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,2024 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 FXVec3f& p){ lower=upper=p; return *this; }
61 
63  FXRangef& operator=(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
64 
66  FXRangef& set(const FXRangef& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
67 
69  FXRangef& set(const FXVec3f& p){ lower=upper=p; return *this; }
70 
72  FXRangef& set(const FXVec3f& l,const FXVec3f& h){ lower=l; upper=h; return *this; }
73 
75  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; }
76 
78  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; }
79 
81  FXVec3f& operator[](FXint i){ return (&lower)[i]; }
82 
84  const FXVec3f& operator[](FXint i) const { return (&lower)[i]; }
85 
87  FXbool operator==(const FXRangef& r) const { return lower==r.lower && upper==r.upper; }
88  FXbool operator!=(const FXRangef& r) const { return lower!=r.lower || upper!=r.upper; }
89 
91  FXfloat width() const { return upper.x-lower.x; }
92 
94  FXfloat height() const { return upper.y-lower.y; }
95 
97  FXfloat depth() const { return upper.z-lower.z; }
98 
100  FXfloat area() const { return (width()*height()+width()*depth()+height()*depth())*2.0f; }
101 
103  FXfloat volume() const { return width()*height()*depth(); }
104 
106  FXfloat longest() const;
107 
109  FXfloat shortest() const;
110 
112  FXfloat diameter() const;
113 
115  FXfloat radius() const;
116 
118  FXVec3f diagonal() const;
119 
121  FXVec3f center() const;
122 
124  FXbool empty() const;
125 
127  FXbool contains(FXfloat x,FXfloat y,FXfloat z) const;
128 
130  FXbool contains(const FXVec3f& p) const;
131 
133  FXbool contains(const FXRangef& bounds) const;
134 
136  FXbool contains(const FXSpheref& sphere) const;
137 
139  FXRangef& include(FXfloat x,FXfloat y,FXfloat z);
140 
142  FXRangef& include(const FXVec3f& v);
143 
145  FXRangef& include(const FXRangef& box);
146 
148  FXRangef& include(const FXSpheref& sphere);
149 
151  FXint intersect(const FXVec4f& plane) const;
152 
154  FXbool intersect(const FXVec3f& u,const FXVec3f& v) const;
155 
157  FXbool intersect(const FXVec3f& pos,const FXVec3f& dir,FXfloat hit[]) const;
158 
160  FXVec3f corner(FXint c) const { return FXVec3f((&lower)[c&1].x,(&lower)[(c>>1)&1].y,(&lower)[c>>2].z); }
161 
163  FXRangef transform(const FXMat4f& mat) const;
164 
167  };
168 
169 
171 extern FXAPI FXbool overlap(const FXRangef& a,const FXRangef& b);
172 
174 extern FXAPI FXRangef unite(const FXRangef& a,const FXRangef& b);
175 
177 extern FXAPI FXRangef intersect(const FXRangef& a,const FXRangef& b);
178 
180 extern FXAPI FXStream& operator<<(FXStream& store,const FXRangef& bounds);
181 
183 extern FXAPI FXStream& operator>>(FXStream& store,FXRangef& bounds);
184 
185 }
186 
187 #endif
188 
FXVec3f & set(FXfloat d)
Assign with constant.
Definition: FXVec3f.h:66
FXfloat volume() const
Volume of box.
Definition: FXRangef.h:103
FXRangef(const FXVec3f &p)
Initialize with a single point.
Definition: FXRangef.h:45
~FXRangef()
Destructor.
Definition: FXRangef.h:166
FXfloat area() const
Area of box.
Definition: FXRangef.h:100
FXVec3f corner(FXint c) const
Get corner number 0..7.
Definition: FXRangef.h:160
FXRangef(const FXRangef &bounds)
Initialize with another range.
Definition: FXRangef.h:42
FXfloat width() const
Width of box.
Definition: FXRangef.h:91
Definition: FX4Splitter.h:28
FXVec3f & operator[](FXint i)
Indexing with 0..1.
Definition: FXRangef.h:81
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
FXRangef & operator=(const FXVec3f &p)
Assign with vector.
Definition: FXRangef.h:60
Spherical bounds.
Definition: FXSpheref.h:32
Bounds.
Definition: FXRangef.h:32
FXfloat height() const
Height of box.
Definition: FXRangef.h:94
const FXVec3f & operator[](FXint i) const
Indexing with 0..1.
Definition: FXRangef.h:84
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
FXbool operator==(const FXRangef &r) const
Comparison.
Definition: FXRangef.h:87
FXfloat depth() const
Depth of box.
Definition: FXRangef.h:97
FXRangef & operator=(const FXRangef &bounds)
Assignment.
Definition: FXRangef.h:63
Single-precision 4-element vector.
Definition: FXVec4f.h:28

Copyright © 1997-2022 Jeroen van der Zijp