quad.h Source File - ClanLib SDK
Description: quad.h Source File

quad.h
1/*
2** ClanLib SDK
3** Copyright (c) 1997-2020 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#pragma once
31
32#include "rect.h"
33#include "size.h"
34#include "point.h"
35#include "origin.h"
36
37namespace clan
38{
41
46 template<typename Type>
47 class Quadx
48 {
49 public:
51 Quadx() : p(), q(), r(), s() {}
52
59 Quadx(const Vec2<Type> &new_p, const Vec2<Type> &new_q, const Vec2<Type> &new_r, const Vec2<Type> &new_s)
60 : p(new_p), q(new_q), r(new_r), s(new_s) {}
61
73 Quadx(const Rectx<Type> &rect) : p(rect.left, rect.top), q(rect.right, rect.top),
74 r(rect.right, rect.bottom), s(rect.left, rect.bottom) {}
75
79 Quadx(const Quadx<Type> &quad) : p(quad.p), q(quad.q), r(quad.r), s(quad.s) {}
80
82 Quadx<Type> &operator+=(const Quadx<Type> &quad)
83 {
84 p += quad.p; q += quad.q; r += quad.r; s += quad.s; return *this;
85 }
86
88 Quadx<Type> &operator-=(const Quadx<Type> &quad)
89 {
90 p -= quad.p; q -= quad.q; r -= quad.r; s -= quad.s; return *this;
91 }
92
94 Quadx<Type> &operator+=(const Vec2<Type> &point)
95 {
96 p += point; q += point; r += point; s += point; return *this;
97 }
98
100 Quadx<Type> &operator-=(const Vec2<Type> &point)
101 {
102 p -= point; q -= point; r -= point; s -= point; return *this;
103 }
104
106 Quadx<Type> operator+(const Quadx<Type> &quad) const
107 {
108 return Quadx(p + quad.p, q + quad.q, r + quad.r, s + quad.s);
109 }
110
112 Quadx<Type> operator-(const Quadx<Type> &quad) const
113 {
114 return Quadx(p - quad.p, q - quad.q, r - quad.r, s - quad.s);
115 }
116
118 Quadx<Type> operator+(const Vec2<Type> &point) const
119 {
120 return Quadx(p + point, q + point, r + point, s + point);
121 }
122
124 Quadx<Type> operator-(const Vec2<Type> &point) const
125 {
126 return Quadx(p - point, q - point, r - point, s - point);
127 }
128
130 bool operator==(const Quadx<Type> &quad) const
131 {
132 return (p == quad.p && q == quad.q && r == quad.r && s == quad.s);
133 }
134
136 bool operator!=(const Quadx<Type> &quad) const
137 {
138 return (p != quad.p || q != quad.q || r != quad.r || s != quad.s);
139 }
140
142 Vec2<Type> p;
143
145 Vec2<Type> q;
146
148 Vec2<Type> r;
149
151 Vec2<Type> s;
152
154 Type get_width() const;
155
157 Type get_height() const;
158
160 Sizex<Type> get_size() const { return Sizex<Type>(get_width(), get_height()); }
161
163 Rect get_bounds() const;
164
171 Quadx<Type> &rotate(const Vec2<Type> &hotspot, const Angle &angle);
172
179 Quadx<Type> &scale(float sx, float sy);
180
188 Quadx<Type> &scale(const Vec2<Type> &hotspot, float sx, float sy);
189
191 Vec2<Type> center() const;
192
199 Quadx<Type> &apply_alignment(Origin origin, Type x, Type y);
200
202 bool is_inside(const Vec2<Type> &point) const;
203 };
204
206 class Quad : public Quadx<int>
207 {
208 public:
209 Quad() : Quadx<int>() {}
210 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) {}
211 Quad(const Rect &rect) : Quadx<int>(rect) {}
212 Quad(const Quadx<int> &quad) : Quadx<int>(quad) {}
213 };
214
216 class Quadf : public Quadx<float>
217 {
218 public:
219 Quadf() : Quadx<float>() {}
220 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) {}
221 Quadf(const Rectf &rect) : Quadx<float>(rect) {}
222 Quadf(const Quadx<float> &quad) : Quadx<float>(quad) {}
223 };
224
226 class Quadd : public Quadx<double>
227 {
228 public:
229 Quadd() : Quadx<double>() {}
230 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) {}
231 Quadd(const Rectd &rect) : Quadx<double>(rect) {}
232 Quadd(const Quadx<double> &quad) : Quadx<double>(quad) {}
233 };
234
236}
clan::Angle
Angle class.
Definition angle.h:60
clan::Quad
2D quad structure - Integer
Definition quad.h:207
clan::Quad::Quad
Quad()
Definition quad.h:209
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:210
clan::Quad::Quad
Quad(const Rect &rect)
Definition quad.h:211
clan::Quad::Quad
Quad(const Quadx< int > &quad)
Definition quad.h:212
clan::Quadd
2D quad structure - Double
Definition quad.h:227
clan::Quadd::Quadd
Quadd()
Definition quad.h:229
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:230
clan::Quadd::Quadd
Quadd(const Rectd &rect)
Definition quad.h:231
clan::Quadd::Quadd
Quadd(const Quadx< double > &quad)
Definition quad.h:232
clan::Quadf
2D quad structure - Float
Definition quad.h:217
clan::Quadf::Quadf
Quadf(const Rectf &rect)
Definition quad.h:221
clan::Quadf::Quadf
Quadf(const Quadx< float > &quad)
Definition quad.h:222
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:220
clan::Quadf::Quadf
Quadf()
Definition quad.h:219
clan::Quadx
2D quad structure.
Definition quad.h:48
clan::Quadx::q
Vec2< Type > q
Second Point.
Definition quad.h:145
clan::Quadx::scale
Quadx< Type > & scale(float sx, float sy)
Scale the Quad.
clan::Quadx::operator+=
Quadx< Type > & operator+=(const Vec2< Type > &point)
Quad += Point operator.
Definition quad.h:94
clan::Quadx::operator-
Quadx< Type > operator-(const Vec2< Type > &point) const
Quad - Point operator.
Definition quad.h:124
clan::Quadx::Quadx
Quadx(const Quadx< Type > &quad)
Constructs a quad.
Definition quad.h:79
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:59
clan::Quadx::get_size
Sizex< Type > get_size() const
Returns the size of the rectangle.
Definition quad.h:160
clan::Quadx::operator==
bool operator==(const Quadx< Type > &quad) const
Quad == Quad operator.
Definition quad.h:130
clan::Quadx::rotate
Quadx< Type > & rotate(const Vec2< Type > &hotspot, const Angle &angle)
Rotates the Quad.
clan::Quadx::Quadx
Quadx(const Rectx< Type > &rect)
Constructs a quad.
Definition quad.h:73
clan::Quadx::operator!=
bool operator!=(const Quadx< Type > &quad) const
Quad != Quad operator.
Definition quad.h:136
clan::Quadx::operator+
Quadx< Type > operator+(const Vec2< Type > &point) const
Quad + Point operator.
Definition quad.h:118
clan::Quadx::scale
Quadx< Type > & scale(const Vec2< Type > &hotspot, float sx, float sy)
Scale the Quad.
clan::Quadx::s
Vec2< Type > s
Fourth Point.
Definition quad.h:151
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:51
clan::Quadx::center
Vec2< Type > center() const
Returns the center point of the quad.
clan::Quadx::operator-
Quadx< Type > operator-(const Quadx< Type > &quad) const
Quad - Quad operator.
Definition quad.h:112
clan::Quadx::get_bounds
Rect get_bounds() const
Returns the bounding box of the quad as a Rect.
clan::Quadx::get_height
Type get_height() const
Returns the height of the quad.
clan::Quadx::r
Vec2< Type > r
Third Point.
Definition quad.h:148
clan::Quadx::is_inside
bool is_inside(const Vec2< Type > &point) const
Check if a point is inside or outside the quad.
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::p
Vec2< Type > p
First Point.
Definition quad.h:142
clan::Quadx::operator-=
Quadx< Type > & operator-=(const Quadx< Type > &quad)
Quad -= Quad operator.
Definition quad.h:88
clan::Quadx::get_width
Type get_width() const
Returns the width of the quad.
clan::Quadx::operator+=
Quadx< Type > & operator+=(const Quadx< Type > &quad)
Quad += Quad operator.
Definition quad.h:82
clan::Quadx::operator-=
Quadx< Type > & operator-=(const Vec2< Type > &point)
Quad -= Point operator.
Definition quad.h:100
clan::Rect
2D (left,top,right,bottom) rectangle structure - Integer
Definition rect.h:489
clan::Rectd
2D (left,top,right,bottom) rectangle structure - Double
Definition rect.h:518
clan::Rectf
2D (left,top,right,bottom) rectangle structure - Float
Definition rect.h:503
clan::Rectx
2D (left,top,right,bottom) rectangle structure.
Definition rect.h:51
clan::Sizex
2D (width,height) size structure.
Definition vec4.h:61
clan::Vec2
2D vector
Definition vec4.h:43
clan::Origin
Origin
Alignment origins.
Definition origin.h:39
clan::Handedness::right
@ right
clan::Handedness::left
@ left
clan::FillMode::point
@ point
clan
Definition clanapp.h:36
clan::StyleValueType::angle
@ angle
value is a color
clan::Key::y
@ y
clan::Key::x
@ x