1 /* GG is a GUI for OpenGL.
2    Copyright (C) 2003-2008 T. Zachary Laine
3 
4    This library is free software; you can redistribute it and/or
5    modify it under the terms of the GNU Lesser General Public License
6    as published by the Free Software Foundation; either version 2.1
7    of the License, or (at your option) any later version.
8 
9    This library is distributed in the hope that it will be useful,
10    but WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13 
14    You should have received a copy of the GNU Lesser General Public
15    License along with this library; if not, write to the Free
16    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
17    02111-1307 USA
18 
19    If you do not wish to comply with the terms of the LGPL please
20    contact the author as other terms are available for a fee.
21 
22    Zach Laine
23    whatwasthataddress@gmail.com */
24 
25 #include <GG/PtRect.h>
26 
27 
28 using namespace GG;
29 
30 const X GG::X0(0);
31 const X GG::X1(1);
32 const Y GG::Y0(0);
33 const Y GG::Y1(1);
34 
35 ////////////////////////////////////////////////
36 // GG::Pt
37 ////////////////////////////////////////////////
Pt()38 Pt::Pt() :
39     x(0),
40     y(0)
41 {}
42 
Pt(X x_,Y y_)43 Pt::Pt(X x_, Y y_) :
44     x(x_),
45     y(y_)
46 {}
47 
Pt(X_d x_,Y y_)48 Pt::Pt(X_d x_, Y y_) :
49     x(x_),
50     y(y_)
51 {}
52 
Pt(X x_,Y_d y_)53 Pt::Pt(X x_, Y_d y_) :
54     x(x_),
55     y(y_)
56 {}
57 
Pt(X_d x_,Y_d y_)58 Pt::Pt(X_d x_, Y_d y_) :
59     x(x_),
60     y(y_)
61 {}
62 
operator <<(std::ostream & os,const Pt & pt)63 std::ostream& GG::operator<<(std::ostream& os, const Pt& pt)
64 {
65     os << "(" << pt.x << ", " << pt.y << ")";
66     return os;
67 }
68 
69 
70 ////////////////////////////////////////////////
71 // GG::Rect
72 ////////////////////////////////////////////////
Rect()73 Rect::Rect()
74 {}
75 
Rect(const Pt & pt1,const Pt & pt2)76 Rect::Rect(const Pt& pt1, const Pt& pt2)
77 {
78     ul.x = std::min(pt1.x, pt2.x);
79     ul.y = std::min(pt1.y, pt2.y);
80     lr.x = std::max(pt1.x, pt2.x);
81     lr.y = std::max(pt1.y, pt2.y);
82 }
83 
Rect(X x1,Y y1,X x2,Y y2)84 Rect::Rect(X x1, Y y1, X x2, Y y2) :
85     ul(Pt(x1, y1)),
86     lr(Pt(x2, y2))
87 {}
88 
Contains(const Pt & pt) const89 bool Rect::Contains(const Pt& pt) const
90 { return ul <= pt && pt < lr; }
91 
operator <<(std::ostream & os,const Rect & rect)92 std::ostream& GG::operator<<(std::ostream& os, const Rect& rect)
93 {
94     os << "[" << rect.ul << " - " << rect.lr << "]";
95     return os;
96 }
97