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

FXExtentd.h
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,2022 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 FXEXTENTD_H
22 #define FXEXTENTD_H
23 
24 namespace FX {
25 
26 
28 class FXAPI FXExtentd {
29 public:
30  FXVec2d lower;
31  FXVec2d upper;
32 public:
33 
36 
38  FXExtentd(const FXExtentd& ext):lower(ext.lower),upper(ext.upper){}
39 
41  FXExtentd(const FXVec2d& p):lower(p),upper(p){}
42 
44  FXExtentd(const FXVec2d& lo,const FXVec2d& hi):lower(lo),upper(hi){}
45 
47  FXExtentd(FXdouble x,FXdouble y):lower(x,y),upper(x,y){}
48 
50  FXExtentd(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh):lower(xl,yl),upper(xh,yh){}
51 
53  FXExtentd& operator=(const FXExtentd& ext){ lower=ext.lower; upper=ext.upper; return *this; }
54 
56  FXExtentd& set(const FXExtentd& ext){ lower=ext.lower; upper=ext.upper; return *this; }
57 
59  FXExtentd& set(const FXVec2d& p){ lower=upper=p; return *this; }
60 
62  FXExtentd& set(const FXVec2d& lo,const FXVec2d& hi){ lower=lo; upper=hi; return *this; }
63 
65  FXExtentd& set(FXdouble x,FXdouble y){ lower.x=upper.x=x; lower.y=upper.y=y; return *this; }
66 
68  FXExtentd& set(FXdouble xl,FXdouble xh,FXdouble yl,FXdouble yh){ lower.set(xl,yl); upper.set(xh,yh); return *this; }
69 
71  FXVec2d& operator[](FXint i){ return (&lower)[i]; }
72 
74  const FXVec2d& operator[](FXint i) const { return (&lower)[i]; }
75 
77  FXbool operator==(const FXExtentd& ext) const { return lower==ext.lower && upper==ext.upper;}
78  FXbool operator!=(const FXExtentd& ext) const { return lower!=ext.lower || upper!=ext.upper;}
79 
81  FXdouble width() const { return upper.x-lower.x; }
82 
84  FXdouble height() const { return upper.y-lower.y; }
85 
87  FXdouble area() const { return width()*height(); }
88 
90  FXdouble longest() const;
91 
93  FXdouble shortest() const;
94 
96  FXdouble diameter() const;
97 
99  FXdouble radius() const;
100 
102  FXVec2d diagonal() const;
103 
105  FXVec2d center() const;
106 
108  FXbool empty() const;
109 
111  FXbool contains(FXdouble x,FXdouble y) const;
112 
114  FXbool contains(const FXVec2d& p) const;
115 
117  FXbool contains(const FXExtentd& ext) const;
118 
120  FXExtentd& include(FXdouble x,FXdouble y);
121 
123  FXExtentd& include(const FXVec2d& v);
124 
126  FXExtentd& include(const FXExtentd& ext);
127 
129  FXbool intersect(const FXVec2d& u,const FXVec2d& v) const;
130 
132  FXbool intersect(const FXVec2d& pos,const FXVec2d& dir,FXdouble hit[]) const;
133 
135  FXVec2d corner(FXint c) const { return FXVec2d((&lower)[c&1].x, (&lower)[(c>>1)&1].y); }
136 
139  };
140 
141 
143 extern FXAPI FXbool overlap(const FXExtentd& a,const FXExtentd& b);
144 
146 extern FXAPI FXExtentd unite(const FXExtentd& a,const FXExtentd& b);
147 
149 extern FXAPI FXExtentd intersect(const FXExtentd& a,const FXExtentd& b);
150 
152 extern FXAPI FXStream& operator<<(FXStream& store,const FXExtentd& ext);
153 
155 extern FXAPI FXStream& operator>>(FXStream& store,FXExtentd& ext);
156 
157 }
158 
159 #endif
160 
FXExtentd(FXdouble x, FXdouble y)
Initialize with a single point.
Definition: FXExtentd.h:47
FXExtentd(const FXExtentd &ext)
Copy constructor.
Definition: FXExtentd.h:38
FXExtentd(FXdouble xl, FXdouble xh, FXdouble yl, FXdouble yh)
Initialize with explicit values.
Definition: FXExtentd.h:50
FXVec2d & set(const FXVec2d &v)
Set value from another vector.
Definition: FXVec2d.h:59
const FXVec2d & operator[](FXint i) const
Indexing with 0..1.
Definition: FXExtentd.h:74
FXVec2d corner(FXint c) const
Get corner number 0..3.
Definition: FXExtentd.h:135
FXdouble width() const
Width of box.
Definition: FXExtentd.h:81
FXExtentd(const FXVec2d &lo, const FXVec2d &hi)
Initialize from corner points.
Definition: FXExtentd.h:44
FXdouble height() const
Height of box.
Definition: FXExtentd.h:84
Extent.
Definition: FXExtentd.h:28
Definition: FX4Splitter.h:28
FXVec2d & operator[](FXint i)
Indexing with 0..1.
Definition: FXExtentd.h:71
Double-precision 2-element vector.
Definition: FXVec2d.h:28
FXdouble area() const
Area.
Definition: FXExtentd.h:87
FXExtentd()
Default constructor; value is not initialized.
Definition: FXExtentd.h:35
~FXExtentd()
Destructor.
Definition: FXExtentd.h:138
FXbool operator==(const FXExtentd &ext) const
Comparison.
Definition: FXExtentd.h:77
FXExtentd & operator=(const FXExtentd &ext)
Assignment.
Definition: FXExtentd.h:53
FXExtentd(const FXVec2d &p)
Initialize with a single point.
Definition: FXExtentd.h:41

Copyright © 1997-2022 Jeroen van der Zijp