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

FXRanged.h
Go to the documentation of this file.
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,2006 by Jeroen van der Zijp. All Rights Reserved. *
7 *********************************************************************************
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU Lesser General Public *
10 * License as published by the Free Software Foundation; either *
11 * version 2.1 of the License, or (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 GNU *
16 * Lesser General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU Lesser General Public *
19 * License along with this library; if not, write to the Free Software *
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
21 *********************************************************************************
22 * $Id: FXRanged.h,v 1.17 2006/01/22 17:58:08 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXRANGED_H
25 #define FXRANGED_H
26 
27 
28 namespace FX {
29 
30 
31 class FXSphered;
32 
33 
34 /// Bounds
35 class FXAPI FXRanged {
36 public:
39 public:
40 
41  /// Default constructor
43 
44  /// Initialize from another range
45  FXRanged(const FXRanged& bounds):lower(bounds.lower),upper(bounds.upper){}
46 
47  /// Initialize from two vectors
48  FXRanged(const FXVec3d& lo,const FXVec3d& hi):lower(lo),upper(hi){}
49 
50  /// Initialize from six numbers
51  FXRanged(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi):lower(xlo,ylo,zlo),upper(xhi,yhi,zhi){}
52 
53  /// Initialize box to fully contain the given bounding sphere
54  FXRanged(const FXSphered& sphere);
55 
56  /// Assignment
57  FXRanged& operator=(const FXRanged& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
58 
59  /// Set value from another range
60  FXRanged& set(const FXRanged& bounds){ lower=bounds.lower; upper=bounds.upper; return *this; }
61 
62  /// Set value from two vectors
63  FXRanged& set(const FXVec3d& lo,const FXVec3d& hi){ lower=lo; upper=hi; return *this; }
64 
65  /// Set value from six numbers
66  FXRanged& set(FXdouble xlo,FXdouble xhi,FXdouble ylo,FXdouble yhi,FXdouble zlo,FXdouble zhi){ lower.set(xlo,ylo,zlo); upper.set(xhi,yhi,zhi); return *this; }
67 
68  /// Indexing with 0..1
69  FXVec3d& operator[](FXint i){ return (&lower)[i]; }
70 
71  /// Indexing with 0..1
72  const FXVec3d& operator[](FXint i) const { return (&lower)[i]; }
73 
74  /// Comparison
75  bool operator==(const FXRanged& r) const { return lower==r.lower && upper==r.upper; }
76  bool operator!=(const FXRanged& r) const { return lower!=r.lower || upper!=r.upper; }
77 
78  /// Width of box
79  FXdouble width() const { return upper.x-lower.x; }
80 
81  /// Height of box
82  FXdouble height() const { return upper.y-lower.y; }
83 
84  /// Depth of box
85  FXdouble depth() const { return upper.z-lower.z; }
86 
87  /// Longest side
88  FXdouble longest() const;
89 
90  /// shortest side
91  FXdouble shortest() const;
92 
93  /// Length of diagonal
94  FXdouble diameter() const;
95 
96  /// Get radius of box
97  FXdouble radius() const;
98 
99  /// Compute diagonal
100  FXVec3d diagonal() const;
101 
102  /// Get center of box
103  FXVec3d center() const;
104 
105  /// Test if empty
106  bool empty() const;
107 
108  /// Test if box contains point x,y,z
109  bool contains(FXdouble x,FXdouble y,FXdouble z) const;
110 
111  /// Test if box contains point p
112  bool contains(const FXVec3d& p) const;
113 
114  /// Test if box properly contains another box
115  bool contains(const FXRanged& bounds) const;
116 
117  /// Test if box properly contains sphere
118  bool contains(const FXSphered& sphere) const;
119 
120  /// Include point
121  FXRanged& include(FXdouble x,FXdouble y,FXdouble z);
122 
123  /// Include point
124  FXRanged& include(const FXVec3d& v);
125 
126  /// Include given range into box
127  FXRanged& include(const FXRanged& box);
128 
129  /// Include given sphere into this box
130  FXRanged& include(const FXSphered& sphere);
131 
132  /// Intersect box with normalized plane ax+by+cz+w; returns -1,0,+1
133  FXint intersect(const FXVec4d &plane) const;
134 
135  /// Intersect box with ray u-v
136  bool intersect(const FXVec3d& u,const FXVec3d& v);
137 
138  /// Test if bounds overlap
139  friend FXAPI bool overlap(const FXRanged& a,const FXRanged& b);
140 
141  /// Get corner number 0..7
142  FXVec3d corner(FXint c) const { return FXVec3d((&lower)[c&1].x, (&lower)[(c>>1)&1].y, (&lower)[c>>2].z); }
143 
144  /// Union of two boxes
145  friend FXAPI FXRanged unite(const FXRanged& a,const FXRanged& b);
146 
147  /// Intersection of two boxes
148  friend FXAPI FXRanged intersect(const FXRanged& a,const FXRanged& b);
149 
150  /// Save object to a stream
151  friend FXAPI FXStream& operator<<(FXStream& store,const FXRanged& bounds);
152 
153  /// Load object from a stream
154  friend FXAPI FXStream& operator>>(FXStream& store,FXRanged& bounds);
155  };
156 
157 
158 extern FXAPI bool overlap(const FXRanged& a,const FXRanged& b);
159 
160 extern FXAPI FXRanged unite(const FXRanged& a,const FXRanged& b);
161 extern FXAPI FXRanged intersect(const FXRanged& a,const FXRanged& b);
162 
163 extern FXAPI FXStream& operator<<(FXStream& store,const FXRanged& bounds);
164 extern FXAPI FXStream& operator>>(FXStream& store,FXRanged& bounds);
165 
166 }
167 
168 #endif
169 
FXVec2d lo(const FXVec2d &a, const FXVec2d &b)
Definition: FXVec2d.h:174
FXStream & operator>>(FXStream &store, FXDate &d)
FXRanged & set(const FXVec3d &lo, const FXVec3d &hi)
Set value from two vectors.
Definition: FXRanged.h:63
FXRanged(const FXRanged &bounds)
Initialize from another range.
Definition: FXRanged.h:45
Bounds.
Definition: FXRanged.h:35
FXVec3d upper
Definition: FXRanged.h:38
FXdouble depth() const
Depth of box.
Definition: FXRanged.h:85
Double-precision 3-element vector.
Definition: FXVec3d.h:36
FXExtentd intersect(const FXExtentd &a, const FXExtentd &b)
Spherical bounds.
Definition: FXSphered.h:35
FXVec3d & set(const FXVec3d &v)
Set value from another vector.
Definition: FXVec3d.h:74
#define FXAPI
Definition: fxdefs.h:122
FXExtentd unite(const FXExtentd &a, const FXExtentd &b)
const FXVec3d & operator[](FXint i) const
Indexing with 0..1.
Definition: FXRanged.h:72
FXRanged & set(const FXRanged &bounds)
Set value from another range.
Definition: FXRanged.h:60
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
FXdouble y
Definition: FXVec3d.h:39
double FXdouble
Definition: fxdefs.h:399
FXdouble x
Definition: FXVec3d.h:38
FXdouble width() const
Width of box.
Definition: FXRanged.h:79
FXVec3d lower
Definition: FXRanged.h:37
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:397
FXVec3d corner(FXint c) const
Get corner number 0..7.
Definition: FXRanged.h:142
Double-precision 4-element vector.
Definition: FXVec4d.h:35
bool overlap(const FXExtentd &a, const FXExtentd &b)
FXdouble z
Definition: FXVec3d.h:40
FXVec2d hi(const FXVec2d &a, const FXVec2d &b)
Definition: FXVec2d.h:175
FXdouble height() const
Height of box.
Definition: FXRanged.h:82
bool operator!=(const FXRanged &r) const
Definition: FXRanged.h:76
bool operator==(const FXRanged &r) const
Comparison.
Definition: FXRanged.h:75
FXRanged & set(FXdouble xlo, FXdouble xhi, FXdouble ylo, FXdouble yhi, FXdouble zlo, FXdouble zhi)
Set value from six numbers.
Definition: FXRanged.h:66
FXRanged(const FXVec3d &lo, const FXVec3d &hi)
Initialize from two vectors.
Definition: FXRanged.h:48
FXRanged()
Default constructor.
Definition: FXRanged.h:42
FXRanged(FXdouble xlo, FXdouble xhi, FXdouble ylo, FXdouble yhi, FXdouble zlo, FXdouble zhi)
Initialize from six numbers.
Definition: FXRanged.h:51
FXVec4d plane(const FXVec4d &vec)
FXStream & operator<<(FXStream &store, const FXDate &d)
FXVec3d & operator[](FXint i)
Indexing with 0..1.
Definition: FXRanged.h:69
FXRanged & operator=(const FXRanged &bounds)
Assignment.
Definition: FXRanged.h:57

Copyright © 1997-2005 Jeroen van der Zijp