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

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

Copyright © 1997-2022 Jeroen van der Zijp