 |
Gorgon Game Engine
|
Go to the documentation of this file.
11 #include <type_traits>
14 #include "../String.h"
55 while(*s==
' ' || *s==
'\t') s++;
65 x=String::To<T_>(&str[s-str.begin()]);
67 while(s!=str.end() && *s!=
',') s++;
77 y=String::To<T_>(&str[s-str.begin()]);
92 explicit operator std::string()
const {
110 return{T_(origin.X+magnitute*std::cos(angle)), T_(origin.Y+magnitute*std::sin(angle))};
132 while(s!=str.end() && (*s==
' ' || *s==
'\t')) s++;
134 if(s!=str.end() && *s==
'(') {
139 if(par==-1 && require_parenthesis) {
148 p.
X = T_(strtod(&*s, &endptr));
154 while(s!=str.end() && (*s==
' ' || *s==
'\t')) s++;
155 if(s==str.end() || *s!=
',') {
164 p.
Y=T_(strtod(&*s, &endptr));
171 while(s!=str.end() && (*s==
' ' || *s==
'\t')) s++;
172 if(s!=str.end() && *s==
')') {
181 while(s!=str.end() && (*s==
' ' || *s==
'\t')) s++;
206 return{
X+point.
X,
Y+point.
Y};
213 return{T_(
X*value), T_(
Y*value)};
218 return X*value.
X +
Y*value.
Y;
225 return{T_(
X/value), T_(
Y/value)};
266 return X*value.
Y -
Y*value.
X;
271 return X*value.
X +
Y*value.
Y;
279 return std::sqrt((xdif*xdif) + (ydif*ydif));
285 return (xdif * xdif) + (ydif * ydif);
298 return (
Float)(std::abs(
X-target.
X) + std::abs(
Y-target.
Y));
303 return (
Float)(std::abs(
X) + std::abs(
Y));
321 return (
Float)atan2(
Y-origin.
Y,
X-origin.
X);
346 return X==point.
X &&
Y==point.
Y;
360 void Move(
const T_ &x,
const T_ &y) {
384 out<<
"("<<point.
X<<
", "<<point.
Y<<
")";
396 while(in.peek()==
' ' || in.peek()==
'\t')
407 while(in.peek()!=
',' && !in.eof())
408 s.push_back((
char)in.get());
411 in.setstate(in.failbit);
416 auto x = String::To<T_>(s);
420 while(in.peek()==
' ' || in.peek()==
'\t')
423 while(in.peek()!=
')' && in.peek()!=
' ' && in.peek()!=
'\t' && in.peek()!=
'\n' && in.peek()!=
'\r' && !in.eof())
424 s.push_back(in.get());
426 if(in.bad())
return in;
429 point.
Y = String::To<T_>(s);
432 while(in.peek()==
' ' || in.peek()==
'\t')
444 template<
class T_,
class O_>
446 point.
X=T_(point.
X+x);
447 point.
Y=T_(point.
Y+y);
458 template <
class T_,
class O_>
460 point.
X = T_(point.
X*size);
461 point.
Y = T_(point.
Y*size);
465 template <
class T_,
class O1_,
class O2_>
467 point.
X = T_(point.
X*sizex);
468 point.
Y = T_(point.
Y*sizey);
473 template <
class T_,
class O_>
475 point.
X = T_((point.
X-origin.
X)*size+origin.
X);
476 point.
Y = T_((point.
Y-origin.
Y)*size+origin.
Y);
481 template <
class T_,
class O1_,
class O2_>
483 point.
X = T_((point.
X-origin.
X)*sizex+origin.
X);
484 point.
Y = T_((point.
Y-origin.
Y)*sizey+origin.
Y);
494 Float cosa=std::cos(angle), sina=std::sin(angle);
495 new_x = T_(point.
X*cosa - point.
Y*sina);
496 point.
Y = T_(point.
X*sina + point.
Y*cosa);
507 Float cosa=std::cos(angle), sina=std::sin(angle);
511 point.
X = T_(temp.
X*cosa - temp.
Y*sina);
512 point.
Y = T_(temp.
X*sina + temp.
Y*cosa);
520 template <
class T_,
class O_>
522 point.
X += T_(point.
Y*rate);
528 template <
class T_,
class O_>
530 point.
Y += T_(point.
X*rate);
536 template <
class T_,
class O_>
538 point.
X += T_((point.
Y-origin.
Y)*rate);
544 template <
class T_,
class O_>
546 point.
Y += T_((point.
X-origin.
X)*rate);
576 point.
Y = -point.
Y+origin.
Y*2;
582 point.
X = -point.
X+origin.
X*2;
606 std::floor(num.
X+
Float(0.5)),
607 std::floor(num.
Y+
Float(0.5))
basic_Point Normalize() const
Normalizes the point as a unit vector.
Definition: Point.h:307
void SkewY(basic_Bounds< T_ > &bounds, const O_ &rate)
Skews the given bounds with the given rate along Y axis.
Definition: Bounds.h:675
std::enable_if< decltype(gorgon__enum_tr_loc(T_()))::isupgradedenum, std::string >::type From(const T_ &e)
Definition: Enum.h:303
basic_Point & operator=(const basic_Point< O_ > &point)
Assignment from a different point type.
Definition: Point.h:85
basic_Point & operator-=(const basic_Point &point)
Subtracts another point from this point.
Definition: Point.h:230
Float Angle() const
Calculates the angle of the line formed from the origin to this point.
Definition: Point.h:327
Pointf Round(Pointf num)
Performs a rounding operation over a floating point point.
Definition: Point.h:604
void ReflectX(basic_Point< T_ > &point)
Reflects the given point along the X axis.
Definition: Point.h:551
basic_Point()
Default constructor, does not zero initialize point.
Definition: Point.h:38
T_ X
X coordinate.
Definition: Point.h:368
basic_Point(const std::string &str)
Conversion from string.
Definition: Point.h:48
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
basic_Point(const basic_Point< O_ > &point)
Conversion from a different point type.
Definition: Point.h:45
void VerticalMirror(basic_Point< T_ > &point)
Reflects the given point vertically.
Definition: Point.h:569
basic_Point operator/(O_ value) const
Divides this point to a scalar value.
Definition: Point.h:224
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
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
Float EuclideanSquare(const basic_Point &target) const
Calculates EuclideanSquare distance from this point to the given target.
Definition: Point.h:282
void Translate(basic_Bounds< T_ > &bounds, O_ x, O_ y)
Translation moves the given bounds by the given amount.
Definition: Bounds.h:526
Float EuclideanSquare() const
Calculates EuclideanSquare distance from this point to the given target.
Definition: Point.h:293
This error will be thrown if a parsing function encounters with an illegal token.
Definition: Exceptions.h:25
basic_Point Perpendicular() const
Calculates perpendicular vector to this point.
Definition: Point.h:312
void SkewX(basic_Bounds< T_ > &bounds, const O_ &rate)
Skews the given bounds with the given rate along X axis.
Definition: Bounds.h:658
void ReflectY(basic_Point< T_ > &point)
Reflects the given point along the Y axis.
Definition: Point.h:557
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
T_ CrossProduct(const basic_Point< T_ > &value) const
Calculates cross product of two points.
Definition: Point.h:265
This error will be thrown if a parsing function encounters with a general error.
Definition: Exceptions.h:10
T_ BaseType
Base type of the point elements.
Definition: Point.h:35
basic_Point & operator*=(O_ value)
Scales this point.
Definition: Point.h:248
Float Distance() const
Calculates Euclidean distance from this point to origin.
Definition: Point.h:288
Float Distance(const basic_Point &target) const
Calculates Euclidean distance from this point to the given target.
Definition: Point.h:276
This class represents a 2D point.
Definition: Point.h:32
T_ DotProduct(const basic_Point< T_ > &value) const
Calculates dot product of two points.
Definition: Point.h:270
basic_Point & operator/=(O_ value)
Scales this point.
Definition: Point.h:257
basic_Point & operator+=(const basic_Point &point)
Adds another point from this point.
Definition: Point.h:239
basic_Point operator+(const basic_Point &point) const
Adds another point to this one and returns the result.
Definition: Point.h:205
bool operator==(const basic_Point &point) const
Compares two points.
Definition: Point.h:350
Float ManhattanDistance(const basic_Point &target) const
Calculates Manhattan distance from this point to the given target.
Definition: Point.h:297
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
T_ Vector[2]
Allows this point to be accessed as a vector.
Definition: Point.h:375
basic_Point(const T_ &X, const T_ &Y)
Filling constructor.
Definition: Point.h:41
bool operator!=(const basic_Point &point) const
Compares two points.
Definition: Point.h:355
basic_Point operator-() const
Negates this point.
Definition: Point.h:200
static basic_Point Parse(const std::string &str, bool require_parenthesis=false)
Properly parses given string into a point.
Definition: Point.h:125
void HorizontalMirror(basic_Point< T_ > &point)
Reflects the given point horizontally.
Definition: Point.h:563
bool Compare(const basic_Point &point) const
Compares two points.
Definition: Point.h:345
basic_Point operator*(O_ value) const
Multiply this point with a scalar value.
Definition: Point.h:212
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
Float ManhattanDistance() const
Calculates Manhattan distance from this point to origin.
Definition: Point.h:302
static basic_Point FromVector(Float magnitute, Float angle, const basic_Point< O_ > &origin={0, 0})
Creates a new point from the given vector data.
Definition: Point.h:109
void Rotate(basic_Bounds< T_ > &bounds, Float angle)
Rotates the given bounds by the given angle.
Definition: Bounds.h:614
Float Slope() const
Calculates the slope of the line formed from the origin to this point.
Definition: Point.h:340