 |
Gorgon Game Engine
|
Go to the documentation of this file.
14 #include "../String.h"
18 namespace Gorgon {
namespace Geometry {
55 while(s != str.end() && (*s==
' ' || *s==
'\t')) s++;
60 auto pos = str.find_first_of(
'x', s-str.begin());
62 Width=String::To<T_>(str.substr(s-str.begin(), pos-(s-str.begin())));
64 Width=String::To<T_>(&str[s-str.begin()]);
66 while(s!=str.end() && *s!=
'x' && *s!=
',') s++;
69 if(*s==
'x' || *s==
',') s++;
71 Height = String::To<T_>(&str[s-str.begin()]);
77 explicit operator std::string()
const {
104 while(*s==
' ' || *s==
'\t') s++;
107 sz.
Width = T_(strtod(&*s, &endptr));
113 while(s!=str.end() &&
isspace(*s)) s++;
126 sz.
Height=T_(strtod(&*s, &endptr));
132 if(s==str.end())
return sz;
135 while(s!=str.end() &&
isspace(*s)) s++;
252 static_assert(std::numeric_limits<T_>::is_specialized,
"Max function can only be used with "
253 "arithmetic types that have numeric_limits specialized");
254 return {std::numeric_limits<T_>::max(), std::numeric_limits<T_>::max()};
267 return{T_(size.
Width*factor), T_(size.
Height*factor)};
279 return{T_(size.
Width/factor), T_(size.
Height/factor)};
291 static std::ostream &
operator <<(std::ostream &out,
const basic_Size<T_> &size) {
292 out<<size.Width<<
"x"<<size.Height;
301 while(in.peek()==
' ' || in.peek()==
'\t')
306 while(in.peek()!=
'x' && !in.eof())
307 s.append(1, (
char)in.get());
310 in.setstate(in.failbit);
315 auto w=String::To<T_>(s);
319 while(in.peek()==
' ' || in.peek()==
'\t')
322 while(in.peek()!=
' ' && in.peek()!=
'\t' && in.peek()!=
'\n' && in.peek()!=
'\r' && !in.eof())
323 s.append(1, in.get());
326 size.
Height=String::To<T_>(s);
332 template<
class T_,
class O_>
334 return{l.
X*r.Width, l.Y*r.Height};
338 template<
class T_,
class O_>
340 return{l.
X/r.Width, l.Y/r.Height};
344 template <
class T_,
class O_>
346 point.
X = T_(point.
X*size.
Width);
351 template <
class T_,
class O_>
358 template <
class T_,
class O1_,
class O2_>
365 template <
class T_,
class O_>
bool operator!=(const basic_Size &size) const
Compares two size objects.
Definition: Size.h:169
basic_Size(const T_ &s)
Filling constructor.
Definition: Size.h:34
basic_Size operator+(const basic_Size< O_ > &size) const
Adds two size objects.
Definition: Size.h:175
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
basic_Size(const std::string &str)
Conversion from string.
Definition: Size.h:49
long GetCount() const
Returns the number of elements in the map.
Definition: Hashmap.h:375
void init_scripting()
Definition: Scripting.cpp:13
basic_Size< T_ > operator/(const basic_Size< T_ > &size, double factor)
Divides a size with a scalar, effectively resizing it.
Definition: Size.h:278
T_ X
X coordinate.
Definition: Point.h:368
bool IsValid() const
Returns whether the size is valid, i.e. both dimensions are positive.
Definition: Size.h:245
T_ Height
Height of this size object.
Definition: Size.h:261
Scripting::Library LibGeometry("Geometry", "Data types under geometry module and their member functions and operators")
void Move(const T_ &x, const T_ &y)
Moves this point to the given coordinates.
Definition: Point.h:360
Float Angle(const basic_Point &origin) const
Calculates the angle of the line formed from the given point to this point.
Definition: Point.h:320
const StaticMemberList & Members
List of static members.
Definition: Reflection.h:1148
float Float
Represents floating point data type.
Definition: Types.h:16
std::istream & operator>>(std::istream &in, basic_Bounds< T_ > &bounds)
Stream extractor for bounds.
Definition: Bounds.h:423
basic_Size & operator+=(const basic_Size< O_ > &size)
Adds the given size object to this size.
Definition: Size.h:192
void Scale(basic_Bounds< T_ > &bounds, const O_ &size)
Scales the given bounds by the given factor. Center of the bounds is used as origin.
Definition: Bounds.h:544
basic_Size operator*=(_S size)
Multiplies this size object with the given factor.
Definition: Size.h:210
This error will be thrown if a parsing function encounters with an illegal token.
Definition: Exceptions.h:25
basic_Bounds< T_ > Union(const basic_Bounds< T_ > &l, const basic_Bounds< T_ > &r)
Returns the smallest bounds that contains given bounds.
Definition: Bounds.h:488
This class makes working with operators easier.
Definition: Embedding.h:635
bool isspace(Glyph g)
Definition: Font.cpp:96
static basic_Size Max()
Returns the maximum representable size.
Definition: Size.h:251
basic_Size(const T_ &w, const T_ &h)
Filling constructor.
Definition: Size.h:37
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
This class represents a 2D geometric size.
Definition: Size.h:23
This class represents a library.
Definition: Reflection.h:1596
basic_Size & operator=(const basic_Size< O_ > &size)
Converting assignment operator.
Definition: Size.h:146
basic_Size()
Default constructor.
Definition: Size.h:30
basic_Size(const basic_Size< O_ > &size)
Converting constructor.
Definition: Size.h:42
basic_Size operator-() const
Negation operator.
Definition: Size.h:186
basic_Point< int > Point
Definition: Point.h:598
T_ Cells() const
Returns the number of fully encompassed cells.
Definition: Size.h:235
T_ BaseType
Base type of the size elements.
Definition: Size.h:26
Float Distance(const basic_Point &target) const
Calculates Euclidean distance from this point to the given target.
Definition: Point.h:276
basic_Size< T_ > Combine(const basic_Size< T_ > &l, const basic_Size< T_ > &r)
Returns the minimum required size that can hold both size objects.
Definition: Size.h:379
This class represents a 2D point.
Definition: Point.h:32
@ ConstTag
Marks a parameter or a function constant.
Definition: Reflection.h:95
This class allows a one to one mapping of a data member to a c++ data member.
Definition: Embedding.h:951
This class allows embedded types to become scripting types that are passed around as values.
Definition: Embedding.h:1300
bool operator==(const basic_Size &size) const
Compares two size objects.
Definition: Size.h:164
basic_Size< T_ > operator*(const basic_Size< T_ > &size, double factor)
Multiplies a size with a scalar, effectively resizing it.
Definition: Size.h:266
std::set< std::string, String::CaseInsensitiveLess > KeywordNames
Definition: Scripting.cpp:13
This class represents a function parameter description.
Definition: Reflection.h:137
basic_Size & operator-=(const basic_Size< O_ > &size)
Subtracts the given size object from this size.
Definition: Size.h:201
Float ManhattanDistance(const basic_Point &target) const
Calculates Manhattan distance from this point to the given target.
Definition: Point.h:297
T_ Area() const
Returns the exact area of the rectangle has the size of this object.
Definition: Size.h:240
basic_Size(const basic_Point< T_ > &point)
Converts a point to size object.
Definition: Size.h:46
T_ Y
Y coordinate.
Definition: Point.h:371
std::ostream & operator<<(std::ostream &out, const basic_Bounds< T_ > &bounds)
Allows streaming of bounds.
Definition: Bounds.h:415
virtual void AddMember(StaticMember &member)
Adds a new member to this namespace.
Definition: Reflection.h:1088
T_ Width
Width of this size object.
Definition: Size.h:258
Scripting::Function::Overload * MapFunction(F_ fn, const Type *returntype, ParameterList parameters, P_ ...tags)
Definition: Embedding.h:614
Represents a function.
Definition: Reflection.h:557
bool Compare(const basic_Point &point) const
Compares two points.
Definition: Point.h:345
basic_Size operator/=(_S size)
Divides this size object to the given factor.
Definition: Size.h:219
Float Slope(const basic_Point &point) const
Calculates the slope of the line formed from the given point to this point.
Definition: Point.h:334
static basic_Size Parse(const std::string &str)
Properly parses given string into a size.
Definition: Size.h:95