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

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

Copyright © 1997-2005 Jeroen van der Zijp