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

Copyright © 1997-2022 Jeroen van der Zijp