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

FXExtentf.h
Go to the documentation of this file.
1 /********************************************************************************
2 * *
3 * S i n g l e - P r e c i s i o n E x t e n t 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: FXExtentf.h,v 1.8.2.1 2006/07/25 01:35:36 fox Exp $ *
23 ********************************************************************************/
24 #ifndef FXEXTENTF_H
25 #define FXEXTENTF_H
26 
27 
28 namespace FX {
29 
30 
31 /// Extent
33 public:
36 public:
37 
38  /// Default constructor
40 
41  /// Copy constructor
42  FXExtentf(const FXExtentf& ext):lower(ext.lower),upper(ext.upper){}
43 
44  /// Initialize from two vectors
45  FXExtentf(const FXVec2f& lo,const FXVec2f& hi):lower(lo),upper(hi){}
46 
47  /// Initialize from six numbers
48  FXExtentf(FXfloat xlo,FXfloat xhi,FXfloat ylo,FXfloat yhi):lower(xlo,ylo),upper(xhi,yhi){}
49 
50  /// Assignment
51  FXExtentf& operator=(const FXExtentf& ext){ lower=ext.lower; upper=ext.upper; return *this; }
52 
53  /// Indexing with 0..1
54  FXVec2f& operator[](FXint i){ return (&lower)[i]; }
55 
56  /// Indexing with 0..1
57  const FXVec2f& operator[](FXint i) const { return (&lower)[i]; }
58 
59  /// Comparison
60  bool operator==(const FXExtentf& ext) const { return lower==ext.lower && upper==ext.upper;}
61  bool operator!=(const FXExtentf& ext) const { return lower!=ext.lower || upper!=ext.upper;}
62 
63  /// Width of box
64  FXfloat width() const { return upper.x-lower.x; }
65 
66  /// Height of box
67  FXfloat height() const { return upper.y-lower.y; }
68 
69  /// Longest side
70  FXfloat longest() const;
71 
72  /// shortest side
73  FXfloat shortest() const;
74 
75  /// Length of diagonal
76  FXfloat diameter() const;
77 
78  /// Get radius of box
79  FXfloat radius() const;
80 
81  /// Compute diagonal
82  FXVec2f diagonal() const;
83 
84  /// Get center of box
85  FXVec2f center() const;
86 
87  /// Test if empty
88  bool empty() const;
89 
90  /// Test if box contains point x,y
91  bool contains(FXfloat x,FXfloat y) const;
92 
93  /// Test if box contains point p
94  bool contains(const FXVec2f& p) const;
95 
96  /// Test if box properly contains another box
97  bool contains(const FXExtentf& ext) const;
98 
99  /// Include point
100  FXExtentf& include(FXfloat x,FXfloat y);
101 
102  /// Include point
103  FXExtentf& include(const FXVec2f& v);
104 
105  /// Include given range into extent
106  FXExtentf& include(const FXExtentf& ext);
107 
108  /// Test if bounds overlap
109  friend FXAPI bool overlap(const FXExtentf& a,const FXExtentf& b);
110 
111  /// Get corner number 0..3
112  FXVec2f corner(FXint c) const { return FXVec2f((&lower)[c&1].x, (&lower)[(c>>1)&1].y); }
113 
114  /// Union of two boxes
115  friend FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b);
116 
117  /// Intersection of two boxes
118  friend FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b);
119 
120  /// Save object to a stream
121  friend FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext);
122 
123  /// Load object from a stream
124  friend FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext);
125  };
126 
127 
128 extern FXAPI bool overlap(const FXExtentf& a,const FXExtentf& b);
129 
130 extern FXAPI FXExtentf unite(const FXExtentf& a,const FXExtentf& b);
131 extern FXAPI FXExtentf intersect(const FXExtentf& a,const FXExtentf& b);
132 
133 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentf& ext);
134 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentf& ext);
135 
136 }
137 
138 #endif
139 
FXVec2d lo(const FXVec2d &a, const FXVec2d &b)
Definition: FXVec2d.h:174
FXStream & operator>>(FXStream &store, FXDate &d)
Extent.
Definition: FXExtentf.h:32
Single-precision 2-element vector.
Definition: FXVec2f.h:35
FXExtentf(FXfloat xlo, FXfloat xhi, FXfloat ylo, FXfloat yhi)
Initialize from six numbers.
Definition: FXExtentf.h:48
FXVec2f corner(FXint c) const
Get corner number 0..3.
Definition: FXExtentf.h:112
bool operator==(const FXExtentf &ext) const
Comparison.
Definition: FXExtentf.h:60
FXfloat width() const
Width of box.
Definition: FXExtentf.h:64
FXExtentd intersect(const FXExtentd &a, const FXExtentd &b)
#define FXAPI
Definition: fxdefs.h:122
FXExtentd unite(const FXExtentd &a, const FXExtentd &b)
FXVec2f lower
Definition: FXExtentf.h:34
A stream is a way to serialize data and objects into a byte stream.
Definition: FXStream.h:99
FXVec2f & operator[](FXint i)
Indexing with 0..1.
Definition: FXExtentf.h:54
Definition: FX4Splitter.h:31
int FXint
Definition: fxdefs.h:390
bool overlap(const FXExtentd &a, const FXExtentd &b)
FXVec2d hi(const FXVec2d &a, const FXVec2d &b)
Definition: FXVec2d.h:175
FXExtentf(const FXExtentf &ext)
Copy constructor.
Definition: FXExtentf.h:42
FXExtentf()
Default constructor.
Definition: FXExtentf.h:39
bool operator!=(const FXExtentf &ext) const
Definition: FXExtentf.h:61
float FXfloat
Definition: fxdefs.h:391
FXfloat y
Definition: FXVec2f.h:38
const FXVec2f & operator[](FXint i) const
Indexing with 0..1.
Definition: FXExtentf.h:57
FXfloat x
Definition: FXVec2f.h:37
FXVec2f upper
Definition: FXExtentf.h:35
FXStream & operator<<(FXStream &store, const FXDate &d)
FXfloat height() const
Height of box.
Definition: FXExtentf.h:67
FXExtentf & operator=(const FXExtentf &ext)
Assignment.
Definition: FXExtentf.h:51
FXExtentf(const FXVec2f &lo, const FXVec2f &hi)
Initialize from two vectors.
Definition: FXExtentf.h:45

Copyright © 1997-2005 Jeroen van der Zijp