quad.h
1 /*
2 ** ClanLib SDK
3 ** Copyright (c) 1997-2015 The ClanLib Team
4 **
5 ** This software is provided 'as-is', without any express or implied
6 ** warranty. In no event will the authors be held liable for any damages
7 ** arising from the use of this software.
8 **
9 ** Permission is granted to anyone to use this software for any purpose,
10 ** including commercial applications, and to alter it and redistribute it
11 ** freely, subject to the following restrictions:
12 **
13 ** 1. The origin of this software must not be misrepresented; you must not
14 ** claim that you wrote the original software. If you use this software
15 ** in a product, an acknowledgment in the product documentation would be
16 ** appreciated but is not required.
17 ** 2. Altered source versions must be plainly marked as such, and must not be
18 ** misrepresented as being the original software.
19 ** 3. This notice may not be removed or altered from any source distribution.
20 **
21 ** Note: Some of the libraries ClanLib may link to may have additional
22 ** requirements or restrictions.
23 **
24 ** File Author(s):
25 **
26 ** Magnus Norddahl
27 ** Mark Page
28 */
29
30
31 #pragma once
32
33 #include "rect.h"
34 #include "size.h"
35 #include "point.h"
36 #include "origin.h"
37
38 namespace clan
39 {
42
47 template<typename Type>
48 class Quadx
49 {
52
53 public:
55 Quadx() : p(), q(), r(), s() {}
56
63 Quadx(const Vec2<Type> &new_p, const Vec2<Type> &new_q, const Vec2<Type> &new_r, const Vec2<Type> &new_s)
64 : p(new_p), q(new_q), r(new_r), s(new_s) {}
65
77 Quadx(const Rectx<Type> &rect) : p(rect.left, rect.top), q(rect.right, rect.top),
78 r(rect.right, rect.bottom), s(rect.left, rect.bottom) {}
79
83 Quadx(const Quadx<Type> &quad) : p(quad.p), q(quad.q), r(quad.r), s(quad.s) {}
84
86 Quadx<Type> &operator+=(const Quadx<Type> &quad)
87 { p += quad.p; q += quad.q; r += quad.r; s += quad.s; return *this; }
88
90 Quadx<Type> &operator-=(const Quadx<Type> &quad)
91 { p -= quad.p; q -= quad.q; r -= quad.r; s -= quad.s; return *this; }
92
94 Quadx<Type> &operator+=(const Vec2<Type> &point)
95 { p += point; q += point; r += point; s += point; return *this; }
96
98 Quadx<Type> &operator-=(const Vec2<Type> &point)
99 { p -= point; q -= point; r -= point; s -= point; return *this; }
100
102 Quadx<Type> operator+(const Quadx<Type> &quad) const
103 { return Quadx(p + quad.p, q + quad.q, r + quad.r, s + quad.s); }
104
106 Quadx<Type> operator-(const Quadx<Type> &quad) const
107 { return Quadx(p - quad.p, q - quad.q, r - quad.r, s - quad.s); }
108
110 Quadx<Type> operator+(const Vec2<Type> &point) const
111 { return Quadx(p + point, q + point, r + point, s + point); }
112
114 Quadx<Type> operator-(const Vec2<Type> &point) const
115 { return Quadx(p - point, q - point, r - point, s - point); }
116
118 bool operator==(const Quadx<Type> &quad) const
119 { return (p == quad.p && q == quad.q && r == quad.r && s == quad.s); }
120
122 bool operator!=(const Quadx<Type> &quad) const
123 { return (p != quad.p || q != quad.q || r != quad.r || s != quad.s); }
124
128
129 public:
131 Vec2<Type> p;
132
134 Vec2<Type> q;
135
137 Vec2<Type> r;
138
140 Vec2<Type> s;
141
143 Type get_width() const;
144
146 Type get_height() const;
147
149 Sizex<Type> get_size() const { return Sizex<Type>(get_width(), get_height()); }
150
152 Rect get_bounds() const;
153
157
158 public:
165 Quadx<Type> &rotate(const Vec2<Type> &hotspot, const Angle &angle);
166
173 Quadx<Type> &scale(float sx, float sy);
174
182 Quadx<Type> &scale(const Vec2<Type> &hotspot, float sx, float sy);
183
185 Vec2<Type> center() const;
186
193 Quadx<Type> &apply_alignment(Origin origin, Type x, Type y);
194
196 bool is_inside(const Vec2<Type> &point) const;
197
199 };
200
202 class Quad : public Quadx<int>
203 {
204 public:
205 Quad() : Quadx<int>() {}
206 Quad(const Vec2<int> &new_p, const Vec2<int> &new_q, const Vec2<int> &new_r, const Vec2<int> &new_s) : Quadx<int>(new_p, new_q, new_r, new_s) {}
207 Quad(const Rect &rect) : Quadx<int>(rect) {}
208 Quad(const Quadx<int> &quad) : Quadx<int>(quad) {}
209 };
210
212 class Quadf : public Quadx<float>
213 {
214 public:
215 Quadf() : Quadx<float>() {}
216 Quadf(const Vec2<float> &new_p, const Vec2<float> &new_q, const Vec2<float> &new_r, const Vec2<float> &new_s) : Quadx<float>(new_p, new_q, new_r, new_s) {}
217 Quadf(const Rectf &rect) : Quadx<float>(rect) {}
218 Quadf(const Quadx<float> &quad) : Quadx<float>(quad) {}
219 };
220
222 class Quadd : public Quadx<double>
223 {
224 public:
225 Quadd() : Quadx<double>() {}
226 Quadd(const Vec2<double> &new_p, const Vec2<double> &new_q, const Vec2<double> &new_r, const Vec2<double> &new_s) : Quadx<double>(new_p, new_q, new_r, new_s) {}
227 Quadd(const Rectd &rect) : Quadx<double>(rect) {}
228 Quadd(const Quadx<double> &quad) : Quadx<double>(quad) {}
229 };
230
231 }
232
clan
Definition: clanapp.h:35
clan::Rectd
2D (left,top,right,bottom) rectangle structure - Double
Definition: rect.h:499
clan::Quadd::Quadd
Quadd(const Quadx< double > &quad)
Definition: quad.h:228
clan::Quadd
2D quad structure - Double
Definition: quad.h:222
clan::Angle
Angle class.
Definition: angle.h:62
clan::Quadx::s
Vec2< Type > s
Fourth Point.
Definition: quad.h:140
clan::Quadf::Quadf
Quadf(const Rectf &rect)
Definition: quad.h:217
clan::Quadf::Quadf
Quadf()
Definition: quad.h:215
clan::Quadf::Quadf
Quadf(const Quadx< float > &quad)
Definition: quad.h:218
clan::Quadx::get_width
Type get_width() const
Returns the width of the quad.
clan::Quadx::Quadx
Quadx(const Vec2< Type > &new_p, const Vec2< Type > &new_q, const Vec2< Type > &new_r, const Vec2< Type > &new_s)
Constructs a quad.
Definition: quad.h:63
clan::Origin
Origin
Alignment origins.
Definition: origin.h:40
clan::Key::x
clan::Quad::Quad
Quad(const Rect &rect)
Definition: quad.h:207
clan::Quadx::Quadx
Quadx(const Quadx< Type > &quad)
Constructs a quad.
Definition: quad.h:83
clan::Quadx::r
Vec2< Type > r
Third Point.
Definition: quad.h:137
clan::Quad::Quad
Quad()
Definition: quad.h:205
clan::Quadx::get_size
Sizex< Type > get_size() const
Returns the size of the rectangle.
Definition: quad.h:149
clan::Quadx::get_bounds
Rect get_bounds() const
Returns the bounding box of the quad as a Rect.
clan::Quadx::apply_alignment
Quadx< Type > & apply_alignment(Origin origin, Type x, Type y)
Applies an origin and offset pair to this rectangle.
clan::Quadx::operator+
Quadx< Type > operator+(const Vec2< Type > &point) const
Quad + Point operator.
Definition: quad.h:110
clan::Quadx::operator-=
Quadx< Type > & operator-=(const Quadx< Type > &quad)
Quad -= Quad operator.
Definition: quad.h:90
clan::Rect
2D (left,top,right,bottom) rectangle structure - Integer
Definition: rect.h:470
clan::Quadx::operator-
Quadx< Type > operator-(const Quadx< Type > &quad) const
Quad - Quad operator.
Definition: quad.h:106
clan::Quadx::Quadx
Quadx()
Constructs a quad.
Definition: quad.h:55
clan::Quad::Quad
Quad(const Vec2< int > &new_p, const Vec2< int > &new_q, const Vec2< int > &new_r, const Vec2< int > &new_s)
Definition: quad.h:206
clan::Rectf
2D (left,top,right,bottom) rectangle structure - Float
Definition: rect.h:484
clan::Key::y
clan::Quadf
2D quad structure - Float
Definition: quad.h:212
clan::Quadx::get_height
Type get_height() const
Returns the height of the quad.
clan::Quadx::p
Vec2< Type > p
First Point.
Definition: quad.h:131
clan::Quad
2D quad structure - Integer
Definition: quad.h:202
clan::Quadx::center
Vec2< Type > center() const
Returns the center point of the quad.
clan::StyleValueType::angle
value is a color
clan::Vec2
2D vector
Definition: line.h:48
clan::Quadx::operator+
Quadx< Type > operator+(const Quadx< Type > &quad) const
Quad + Quad operator.
Definition: quad.h:102
clan::Quadx::operator-=
Quadx< Type > & operator-=(const Vec2< Type > &point)
Quad -= Point operator.
Definition: quad.h:98
clan::Rectx
2D (left,top,right,bottom) rectangle structure.
Definition: line.h:45
clan::Quadf::Quadf
Quadf(const Vec2< float > &new_p, const Vec2< float > &new_q, const Vec2< float > &new_r, const Vec2< float > &new_s)
Definition: quad.h:216
clan::Quadx
2D quad structure.
Definition: quad.h:48
clan::Quad::Quad
Quad(const Quadx< int > &quad)
Definition: quad.h:208
clan::Quadx::operator+=
Quadx< Type > & operator+=(const Quadx< Type > &quad)
Quad += Quad operator.
Definition: quad.h:86
clan::Quadx::rotate
Quadx< Type > & rotate(const Vec2< Type > &hotspot, const Angle &angle)
Rotates the Quad.
clan::Key::left
clan::Quadx::q
Vec2< Type > q
Second Point.
Definition: quad.h:134
clan::Quadd::Quadd
Quadd()
Definition: quad.h:225
clan::Key::right
clan::Quadx::scale
Quadx< Type > & scale(float sx, float sy)
Scale the Quad.
clan::Quadx::is_inside
bool is_inside(const Vec2< Type > &point) const
Check if a point is inside or outside the quad.
clan::Quadx::operator-
Quadx< Type > operator-(const Vec2< Type > &point) const
Quad - Point operator.
Definition: quad.h:114
clan::Quadx::Quadx
Quadx(const Rectx< Type > &rect)
Constructs a quad.
Definition: quad.h:77
clan::Quadd::Quadd
Quadd(const Vec2< double > &new_p, const Vec2< double > &new_q, const Vec2< double > &new_r, const Vec2< double > &new_s)
Definition: quad.h:226
clan::Quadx::operator==
bool operator==(const Quadx< Type > &quad) const
Quad == Quad operator.
Definition: quad.h:118
clan::Quadx::operator!=
bool operator!=(const Quadx< Type > &quad) const
Quad != Quad operator.
Definition: quad.h:122
clan::Sizex
2D (width,height) size structure.
Definition: size.h:54
clan::Quadx::operator+=
Quadx< Type > & operator+=(const Vec2< Type > &point)
Quad += Point operator.
Definition: quad.h:94
clan::Quadd::Quadd
Quadd(const Rectd &rect)
Definition: quad.h:227