1
///////////////////////////////////////////////////////////////////////////
3
// Copyright (c) 2002, Industrial Light & Magic, a division of Lucas
6
// All rights reserved.
8
// Redistribution and use in source and binary forms, with or without
9
// modification, are permitted provided that the following conditions are
11
// * Redistributions of source code must retain the above copyright
12
// notice, this list of conditions and the following disclaimer.
13
// * Redistributions in binary form must reproduce the above
14
// copyright notice, this list of conditions and the following disclaimer
15
// in the documentation and/or other materials provided with the
17
// * Neither the name of Industrial Light & Magic nor the names of
18
// its contributors may be used to endorse or promote products derived
19
// from this software without specific prior written permission.
21
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33
///////////////////////////////////////////////////////////////////////////
37
#ifndef INCLUDED_IMATHINTERVAL_H
38
#define INCLUDED_IMATHINTERVAL_H
41
//-------------------------------------------------------------------
43
// class Imath::Interval<class T>
44
// --------------------------------
46
// An Interval has a min and a max and some miscellaneous
47
// functions. It is basically a Box<T> that allows T to be
50
//-------------------------------------------------------------------
62
//-------------------------
63
// Data Members are public
64
//-------------------------
69
//-----------------------------------------------------
70
// Constructors - an "empty" Interval is created by default
71
//-----------------------------------------------------
74
Interval(const T& point);
75
Interval(const T& minT, const T& maxT);
77
//--------------------------------
78
// Operators: we get != from STL
79
//--------------------------------
81
bool operator == (const Interval<T> &src) const;
84
// Interval manipulation
88
void extendBy(const T& point);
89
void extendBy(const Interval<T>& interval);
91
//---------------------------------------------------
92
// Query functions - these compute results each time
93
//---------------------------------------------------
97
bool intersects(const T &point) const;
98
bool intersects(const Interval<T> &interval) const;
104
bool hasVolume() const;
105
bool isEmpty() const;
109
//--------------------
110
// Convenient typedefs
111
//--------------------
114
typedef Interval <float> Intervalf;
115
typedef Interval <double> Intervald;
116
typedef Interval <short> Intervals;
117
typedef Interval <int> Intervali;
125
inline Interval<T>::Interval()
131
inline Interval<T>::Interval(const T& point)
138
inline Interval<T>::Interval(const T& minV, const T& maxV)
146
Interval<T>::operator == (const Interval<T> &src) const
148
return (min == src.min && max == src.max);
153
Interval<T>::makeEmpty()
155
min = limits<T>::max();
156
max = limits<T>::min();
161
Interval<T>::extendBy(const T& point)
172
Interval<T>::extendBy(const Interval<T>& interval)
174
if ( interval.min < min )
177
if ( interval.max > max )
183
Interval<T>::intersects(const T& point) const
185
return point >= min && point <= max;
190
Interval<T>::intersects(const Interval<T>& interval) const
192
return interval.max >= min && interval.min <= max;
197
Interval<T>::size() const
204
Interval<T>::center() const
211
Interval<T>::isEmpty() const
217
inline bool Interval<T>::hasVolume() const