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

Copyright © 1997-2022 Jeroen van der Zijp