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,2017 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 

Copyright © 1997-2016 Jeroen van der Zijp