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

FXPoint.h
1 /********************************************************************************
2 * *
3 * P o i n t C l a s s *
4 * *
5 *********************************************************************************
6 * Copyright (C) 1994,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 FXPOINT_H
22 #define FXPOINT_H
23 
24 #ifndef FXSIZE_H
25 #include "FXSize.h"
26 #endif
27 
28 namespace FX {
29 
30 
32 class FXAPI FXPoint {
33 public:
34  FXshort x;
35  FXshort y;
36 public:
37 
39  FXPoint(){ }
40  FXPoint(const FXSize& s):x(s.w),y(s.h){ }
41  FXPoint(const FXPoint& p):x(p.x),y(p.y){ }
42  FXPoint(FXshort xx,FXshort yy):x(xx),y(yy){ }
43 
45  FXshort& operator[](FXint i){return (&x)[i];}
46 
48  const FXshort& operator[](FXint i) const {return (&x)[i];}
49 
51  FXPoint& operator=(const FXPoint& p){ x=p.x; y=p.y; return *this; }
52 
54  FXPoint& set(const FXPoint& p){ x=p.x; y=p.y; return *this; }
55 
57  FXPoint& set(FXshort xx,FXshort yy){ x=xx; y=yy; return *this; }
58 
60  FXPoint& operator*=(FXshort c){ x*=c; y*=c; return *this; }
61  FXPoint& operator/=(FXshort c){ x/=c; y/=c; return *this; }
62  FXPoint& operator+=(const FXPoint& p){ x+=p.x; y+=p.y; return *this; }
63  FXPoint& operator-=(const FXPoint& p){ x-=p.x; y-=p.y; return *this; }
64 
66  FXbool operator!() const { return x==0 && y==0; }
67 
69  FXPoint operator+() const { return *this; }
70  FXPoint operator-(){ return FXPoint(-x,-y); }
71  };
72 
73 
75 inline FXPoint operator*(const FXPoint& p,FXshort c){ return FXPoint(p.x*c,p.y*c); }
76 inline FXPoint operator*(FXshort c,const FXPoint& p){ return FXPoint(c*p.x,c*p.y); }
77 inline FXPoint operator/(const FXPoint& p,FXshort c){ return FXPoint(p.x/c,p.y/c); }
78 inline FXPoint operator/(FXshort c,const FXPoint& p){ return FXPoint(c/p.x,c/p.y); }
79 
81 inline FXPoint operator+(const FXPoint& a,const FXPoint& b){ return FXPoint(a.x+b.x,a.y+b.y); }
82 inline FXPoint operator-(const FXPoint& a,const FXPoint& b){ return FXPoint(a.x-b.x,a.y-b.y); }
83 
85 inline FXbool operator==(const FXPoint& a,FXshort n){ return a.x==n && a.y==n; }
86 inline FXbool operator!=(const FXPoint& a,FXshort n){ return a.x!=n || a.y!=n; }
87 inline FXbool operator==(FXshort n,const FXPoint& a){ return n==a.x && n==a.y; }
88 inline FXbool operator!=(FXshort n,const FXPoint& a){ return n!=a.x || n!=a.y; }
89 
91 inline FXbool operator==(const FXPoint& a,const FXPoint& b){ return a.x==b.x && a.y==b.y; }
92 inline FXbool operator!=(const FXPoint& a,const FXPoint& b){ return a.x!=b.x || a.y!=b.y; }
93 
95 inline FXbool operator<(const FXPoint& a,FXshort n){ return a.x<n && a.y<n; }
96 inline FXbool operator<=(const FXPoint& a,FXshort n){ return a.x<=n && a.y<=n; }
97 inline FXbool operator>(const FXPoint& a,FXshort n){ return a.x>n && a.y>n; }
98 inline FXbool operator>=(const FXPoint& a,FXshort n){ return a.x>=n && a.y>=n; }
99 
101 inline FXbool operator<(FXshort n,const FXPoint& a){ return n<a.x && n<a.y; }
102 inline FXbool operator<=(FXshort n,const FXPoint& a){ return n<=a.x && n<=a.y; }
103 inline FXbool operator>(FXshort n,const FXPoint& a){ return n>a.x && n>a.y; }
104 inline FXbool operator>=(FXshort n,const FXPoint& a){ return n>=a.x && n>=a.y; }
105 
107 inline FXbool operator<(const FXPoint& a,const FXPoint& b){ return a.x<b.x && a.y<b.y; }
108 inline FXbool operator<=(const FXPoint& a,const FXPoint& b){ return a.x<=b.x && a.y<=b.y; }
109 inline FXbool operator>(const FXPoint& a,const FXPoint& b){ return a.x>b.x && a.y>b.y; }
110 inline FXbool operator>=(const FXPoint& a,const FXPoint& b){ return a.x>=b.x && a.y>=b.y; }
111 
113 inline FXPoint lo(const FXPoint& a,const FXPoint& b){ return FXPoint(FXMIN(a.x,b.x),FXMIN(a.y,b.y)); }
114 inline FXPoint hi(const FXPoint& a,const FXPoint& b){ return FXPoint(FXMAX(a.x,b.x),FXMAX(a.y,b.y)); }
115 
117 extern FXAPI FXStream& operator<<(FXStream& store,const FXPoint& p);
118 
120 extern FXAPI FXStream& operator>>(FXStream& store,FXPoint& p);
121 
122 }
123 
124 #endif

Copyright © 1997-2016 Jeroen van der Zijp