Source/Gorgon/Geometry/Size.h

Wed, 07 Oct 2020 20:33:51 +0300

author
cemkalyoncu
date
Wed, 07 Oct 2020 20:33:51 +0300
branch
4.x-dev
changeset 1461
6bbecfcb304e
parent 1459
f1d6091311ff
child 1687
dc9150a2185d
permissions
-rw-r--r--

#192 Size parsing bug

764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
1 /// @file Size.h contains the Size class
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
2
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
3 #pragma once
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
4
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
5 #include <iostream>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
6 #include <ostream>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
7 #include <string>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
8 #include <iomanip>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
9 #include <limits>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
10 #include <sstream>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
11
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
12 #include "../Types.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
13 #include "Point.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
14 #include "../String.h"
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
15
894
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
16 #include <ctype.h>
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
17
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
18 namespace Gorgon { namespace Geometry {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
19
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
20 /// This class represents a 2D geometric size. Although negative size is meaningless,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
21 /// this class allows all operations over negative sizes.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
22 template<class T_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
23 class basic_Size {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
24 public:
1210
f8b6a2ed380c * Added PointList and Line geometry objects with various degrees of completeness
cemkalyoncu
parents: 1137
diff changeset
25 ///Base type of the size elements.
f8b6a2ed380c * Added PointList and Line geometry objects with various degrees of completeness
cemkalyoncu
parents: 1137
diff changeset
26 typedef T_ BaseType;
f8b6a2ed380c * Added PointList and Line geometry objects with various degrees of completeness
cemkalyoncu
parents: 1137
diff changeset
27
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
28 /// Default constructor. This constructor does **not** zero initialize
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
29 /// the object.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
30 basic_Size() { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
31
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
32 /// Filling constructor. This variant assigns the given value to both dimensions,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
33 /// effectively creating a square.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
34 explicit basic_Size(const T_ &s) : Width(s), Height(s) { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
35
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
36 /// Filling constructor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
37 basic_Size(const T_ &w, const T_ &h) : Width(w), Height(h) { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
38
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
39 /// Converting constructor. Converts a different typed size object to this
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
40 /// type.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
41 template <class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
42 basic_Size(const basic_Size<O_> &size) : Width((T_)size.Width), Height((T_)size.Height) { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
43
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
44 /// Converts a point to size object. The size a point represents is the size of the
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
45 /// rectangle that starts from origin to the given point.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
46 explicit basic_Size(const basic_Point<T_> &point) : Width((T_)point.X), Height((T_)point.Y) { }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
47
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
48 /// Conversion from string
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
49 explicit basic_Size(const std::string &str) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
50 auto s=str.begin();
1461
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
51
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
52 if(s == str.end())
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
53 Width = Height = 0;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
54
1461
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
55 while(s != str.end() && (*s==' ' || *s=='\t')) s++;
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
56
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
57 if(s == str.end())
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
58 Width = Height = 0;
1459
f1d6091311ff * Size parsing fix
cemkalyoncu
parents: 1249
diff changeset
59
f1d6091311ff * Size parsing fix
cemkalyoncu
parents: 1249
diff changeset
60 auto pos = str.find_first_of('x', s-str.begin());
f1d6091311ff * Size parsing fix
cemkalyoncu
parents: 1249
diff changeset
61 if(pos != str.npos)
f1d6091311ff * Size parsing fix
cemkalyoncu
parents: 1249
diff changeset
62 Width=String::To<T_>(str.substr(s-str.begin(), pos-(s-str.begin())));
f1d6091311ff * Size parsing fix
cemkalyoncu
parents: 1249
diff changeset
63 else
f1d6091311ff * Size parsing fix
cemkalyoncu
parents: 1249
diff changeset
64 Width=String::To<T_>(&str[s-str.begin()]);
f1d6091311ff * Size parsing fix
cemkalyoncu
parents: 1249
diff changeset
65
1249
b9a720d08147 * Basic widget container design is finalized
cemkalyoncu
parents: 1210
diff changeset
66 while(s!=str.end() && *s!='x' && *s!=',') s++;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
67
1461
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
68 if(s != str.end()) {
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
69 if(*s=='x' || *s==',') s++;
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
70
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
71 Height = String::To<T_>(&str[s-str.begin()]);
6bbecfcb304e #192 Size parsing bug
cemkalyoncu
parents: 1459
diff changeset
72 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
73 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
74
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
75
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
76 /// Converts this object to string.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
77 explicit operator std::string() const {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
78 std::string ret;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
79 ret += String::From(Width);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
80 ret.push_back('x');
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
81 ret += String::From(Height);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
82
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
83 return ret;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
84 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
85
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
86
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
87 /// Properly parses given string into a size. Throws errors if the
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
88 /// size is not well formed. Works only on types that can be parsed using
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
89 /// strtod. Following error codes are reported by this parse function:
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
90 ///
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
91 /// * *IllegalTokenError* **121001**: Illegal token while reading Width
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
92 /// * *IllegalTokenError* **121002**: Illegal token while looking for width/height separator
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
93 /// * *IllegalTokenError* **121003**: Illegal token while reading Height
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
94 /// * *IllegalTokenError* **121004**: Illegal token(s) at the end
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
95 static basic_Size Parse(const std::string &str) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
96 basic_Size sz;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
97
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
98 auto s=str.begin();
894
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
99
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
100 if(s==str.end()) {
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
101 throw String::IllegalTokenError(s-str.begin(), 121002, "Unexpected end of input");
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
102 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
103
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
104 while(*s==' ' || *s=='\t') s++;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
105
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
106 char *endptr;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
107 sz.Width = T_(strtod(&*s, &endptr));
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
108 if(endptr==&*s) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
109 throw String::IllegalTokenError(0, 120001);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
110 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
111 s+=endptr-&*s;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
112
894
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
113 while(s!=str.end() && isspace(*s)) s++;
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
114 if(s==str.end()) {
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
115 throw String::IllegalTokenError(s-str.begin(), 121002, "Unexpected end of input");
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
116 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
117 if(*s!='x') {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
118 throw String::IllegalTokenError(s-str.begin(), 121002, std::string("Illegal token: ")+*s);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
119 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
120 s++;
894
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
121
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
122 if(s==str.end()) {
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
123 throw String::IllegalTokenError(s-str.begin(), 121002, "Unexpected end of input");
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
124 }
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
125
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
126 sz.Height=T_(strtod(&*s, &endptr));
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
127 if(endptr==&*s) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
128 throw String::IllegalTokenError(s-str.begin(), 121003);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
129 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
130 s+=endptr-&*s;
894
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
131
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
132 if(s==str.end()) return sz;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
133
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
134 //eat white space + a single )
894
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
135 while(s!=str.end() && isspace(*s)) s++;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
136
894
03d76e8fa8db * PNG Unit tests
cemkalyoncu
parents: 801
diff changeset
137 if(s!=str.end()) {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
138 throw String::IllegalTokenError(s-str.begin(), 121004, std::string("Illegal token: ")+*s);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
139 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
140
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
141 return sz;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
142 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
143
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
144 /// Converting assignment operator.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
145 template <class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
146 basic_Size &operator =(const basic_Size<O_> &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
147 Width=size.Width;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
148 Height=size.Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
149
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
150 return *this;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
151 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
152
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
153 /// Converting assignment operator. The size a point represents is the size of the
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
154 /// rectangle that starts from origin to the given point.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
155 template <class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
156 basic_Size &operator =(const basic_Point<O_> &point) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
157 Width=point.X;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
158 Height=point.Y;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
159
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
160 return *this;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
161 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
162
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
163 /// Compares two size objects
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
164 bool operator ==(const basic_Size &size) const {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
165 return Width==size.Width && Height==size.Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
166 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
167
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
168 /// Compares two size objects
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
169 bool operator !=(const basic_Size &size) const {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
170 return Width!=size.Width || Height!=size.Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
171 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
172
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
173 /// Adds two size objects
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
174 template<class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
175 basic_Size operator +(const basic_Size<O_> &size) const {
918
6c22e08ca5d7 * Images can now be drawn using float numbers
cemkalyoncu
parents: 894
diff changeset
176 return basic_Size(size.Width+Width, size.Height+Height);
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
177 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
178
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
179 /// Subtracts two size objects
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
180 template<class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
181 basic_Size operator -(const basic_Size<O_> &size) const {
918
6c22e08ca5d7 * Images can now be drawn using float numbers
cemkalyoncu
parents: 894
diff changeset
182 return basic_Size(Width-size.Width, Height-size.Height);
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
183 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
184
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
185 /// Negation operator
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
186 basic_Size operator -() const {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
187 return{-Width, -Height};
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
188 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
189
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
190 /// Adds the given size object to this size
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
191 template<class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
192 basic_Size &operator +=(const basic_Size<O_> &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
193 Width=size.Width +Width;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
194 Height=size.Height+Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
195
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
196 return *this;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
197 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
198
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
199 /// Subtracts the given size object from this size
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
200 template<class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
201 basic_Size &operator -=(const basic_Size<O_> &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
202 Width=Width-size.Width;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
203 Height=Height-size.Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
204
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
205 return *this;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
206 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
207
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
208 /// Multiplies this size object with the given factor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
209 template<class _S>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
210 basic_Size operator *=(_S size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
211 Width =T_(size *Width);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
212 Height=T_(size*Height);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
213
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
214 return *this;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
215 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
216
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
217 /// Divides this size object to the given factor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
218 template<class _S>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
219 basic_Size operator /=(_S size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
220 Width =T_(Width/size);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
221 Height=T_(Height/size);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
222
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
223 return *this;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
224 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
225
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
226 /// Converts this size object to a point. Conversion is performed
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
227 /// in a manner that the resultant point is the far corner of a
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
228 /// rectangle that is placed at origin and the size of this object.
801
9a81178877d7 * Data can now hold other gorgon objects
cemkalyoncu
parents: 794
diff changeset
229 explicit operator basic_Point<T_>() const {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
230 return{Width, Height};
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
231 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
232
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
233 /// Returns the number of fully encompassed cells. For instance,
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
234 /// a 3.2x2.2 size object has 6 cells.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
235 T_ Cells() const {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
236 return T_(std::floor(Width)*std::floor(Height));
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
237 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
238
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
239 /// Returns the exact area of the rectangle has the size of this object
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
240 T_ Area() const {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
241 return Width*Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
242 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
243
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
244 /// Returns whether the size is valid, i.e. both dimensions are positive.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
245 bool IsValid() const {
1137
89d936a8d764 * Conversion of FreeType to bitmap font
cemkalyoncu
parents: 1024
diff changeset
246 return Width>=0 && Height>=0;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
247 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
248
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
249 /// Returns the maximum representable size. This function requires T_ to be
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
250 /// standard arithmetic type
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
251 static basic_Size Max() {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
252 static_assert(std::numeric_limits<T_>::is_specialized, "Max function can only be used with "
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
253 "arithmetic types that have numeric_limits specialized");
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
254 return {std::numeric_limits<T_>::max(), std::numeric_limits<T_>::max()};
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
255 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
256
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
257 /// Width of this size object
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
258 T_ Width;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
259
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
260 /// Height of this size object
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
261 T_ Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
262 };
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
263
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
264 /// Multiplies a size with a scalar, effectively resizing it.
1024
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
265 template<class T_>
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
266 basic_Size<T_> operator *(const basic_Size<T_> &size, double factor) {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
267 return{T_(size.Width*factor), T_(size.Height*factor)};
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
268 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
269
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
270 /// Multiplies a size with a scalar, effectively resizing it.
1024
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
271 template<class T_>
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
272 basic_Size<T_> operator *(double factor, const basic_Size<T_> &size) {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
273 return operator*(size, factor);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
274 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
275
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
276 /// Divides a size with a scalar, effectively resizing it.
1024
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
277 template<class T_>
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
278 basic_Size<T_> operator /(const basic_Size<T_> &size, double factor) {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
279 return{T_(size.Width/factor), T_(size.Height/factor)};
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
280 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
281
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
282 /// Divides a size with a scalar, effectively resizing it.
1024
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
283 template<class T_>
e37fb3e74127 * DnD bug in Win32 which uses moved out window is fixed
cemkalyoncu
parents: 1009
diff changeset
284 basic_Size<T_> operator /(double factor, const basic_Size<T_> &size) {
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
285 return operator/(size, factor);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
286 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
287
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
288 /// Writes the given size object to the stream. Width and Height components of
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
289 /// size objects are separated by an x
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
290 template<class T_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
291 static std::ostream &operator <<(std::ostream &out, const basic_Size<T_> &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
292 out<<size.Width<<"x"<<size.Height;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
293
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
294 return out;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
295 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
296
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
297 /// Reads a size object from a stream. Width and Height components should be
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
298 /// separated by an x.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
299 template <class T_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
300 std::istream &operator >> (std::istream &in, basic_Size<T_> &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
301 while(in.peek()==' ' || in.peek()=='\t')
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
302 in.ignore(1);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
303
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
304 std::string s;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
305
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
306 while(in.peek()!='x' && !in.eof())
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
307 s.append(1, (char)in.get());
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
308
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
309 if(in.eof()) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
310 in.setstate(in.failbit);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
311 return in;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
312 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
313 in.ignore(1);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
314
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
315 auto w=String::To<T_>(s);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
316
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
317 s="";
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
318
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
319 while(in.peek()==' ' || in.peek()=='\t')
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
320 in.ignore(1);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
321
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
322 while(in.peek()!=' ' && in.peek()!='\t' && in.peek()!='\n' && in.peek()!='\r' && !in.eof())
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
323 s.append(1, in.get());
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
324
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
325 size.Width=w;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
326 size.Height=String::To<T_>(s);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
327
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
328 return in;
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
329 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
330
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
331 /// Allows multiplication of point with a size object
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
332 template<class T_, class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
333 auto operator *(const basic_Point<T_> &l, const basic_Size<O_> &r) -> basic_Point<decltype(l.X*r.Width)> {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
334 return{l.X*r.Width, l.Y*r.Height};
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
335 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
336
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
337 /// Allows division of point with a size object
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
338 template<class T_, class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
339 auto operator /(const basic_Point<T_> &l, const basic_Size<O_> &r) -> basic_Point<decltype(l.X*r.Width)> {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
340 return{l.X/r.Width, l.Y/r.Height};
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
341 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
342
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
343 /// Scales the given point by the given factor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
344 template <class T_, class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
345 void Scale(basic_Point<T_> &point, const basic_Size<O_> &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
346 point.X = T_(point.X*size.Width);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
347 point.Y = T_(point.Y*size.Height);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
348 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
349
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
350 /// Scales the given size by the given factor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
351 template <class T_, class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
352 void Scale(basic_Size<T_> &l, const O_ &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
353 l.Width = T_(l.Width*size);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
354 l.Height = T_(l.Height*size);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
355 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
356
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
357 /// Scales the given size by the given factors for x and y coordinates.
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
358 template <class T_, class O1_, class O2_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
359 void Scale(basic_Size<T_> &l, const O1_ &sizex, const O2_ &sizey) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
360 l.Width = T_(l.Width*sizex);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
361 l.Height = T_(l.Height*sizey);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
362 }
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
363
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
364 /// Scales the given l by the given factor
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
365 template <class T_, class O_>
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
366 void Scale(basic_Size<T_> &l, const basic_Size<O_> &size) {
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
367 l.Width = T_(l.Width*size.Width);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
368 l.Height = T_(l.Height*size.Height);
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
369 }
993
98fd46db44bb * MaskedObject for masked lines and rectangles
cemkalyoncu
parents: 918
diff changeset
370
1009
881536fc9c5e * Stacked/Scalable/Tinted object resources
cemkalyoncu
parents: 993
diff changeset
371 /// Returns the maximum size that can fit into both size objects
993
98fd46db44bb * MaskedObject for masked lines and rectangles
cemkalyoncu
parents: 918
diff changeset
372 template <class T_>
98fd46db44bb * MaskedObject for masked lines and rectangles
cemkalyoncu
parents: 918
diff changeset
373 basic_Size<T_> Union(const basic_Size<T_> &l, const basic_Size<T_> &r) {
98fd46db44bb * MaskedObject for masked lines and rectangles
cemkalyoncu
parents: 918
diff changeset
374 return {std::min(l.Width, r.Width), std::min(l.Height, r.Height)};
98fd46db44bb * MaskedObject for masked lines and rectangles
cemkalyoncu
parents: 918
diff changeset
375 }
1009
881536fc9c5e * Stacked/Scalable/Tinted object resources
cemkalyoncu
parents: 993
diff changeset
376
881536fc9c5e * Stacked/Scalable/Tinted object resources
cemkalyoncu
parents: 993
diff changeset
377 /// Returns the minimum required size that can hold both size objects
881536fc9c5e * Stacked/Scalable/Tinted object resources
cemkalyoncu
parents: 993
diff changeset
378 template <class T_>
881536fc9c5e * Stacked/Scalable/Tinted object resources
cemkalyoncu
parents: 993
diff changeset
379 basic_Size<T_> Combine(const basic_Size<T_> &l, const basic_Size<T_> &r) {
881536fc9c5e * Stacked/Scalable/Tinted object resources
cemkalyoncu
parents: 993
diff changeset
380 return {std::max(l.Width, r.Width), std::max(l.Height, r.Height)};
881536fc9c5e * Stacked/Scalable/Tinted object resources
cemkalyoncu
parents: 993
diff changeset
381 }
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
382
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
383
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
384 /// @see basic_Size
794
ec7895c817e6 * Initial design for Data resource
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
385 using Size = basic_Size<int>;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
386
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
387 /// @see basic_Size
794
ec7895c817e6 * Initial design for Data resource
cemkalyoncu <cemkalyoncu@gmail.com>
parents: 764
diff changeset
388 using Sizef = basic_Size<Float>;
764
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
389
7c71952bd75b Gorgon code base has been moved to Source/Gorgon
cengizkandemir
parents:
diff changeset
390 } }

mercurial