Space Fighter
A "shmup" game for Computer Programming C++
Loading...
Searching...
No Matches
Point.cpp
Go to the documentation of this file.
1
2/*
3 ██╗ ██╗ █████╗ ████████╗ █████╗ ███╗ ██╗ █████╗
4 ██║ ██╔╝ ██╔══██╗ ╚══██╔══╝ ██╔══██╗ ████╗ ██║ ██╔══██╗
5 █████╔╝ ███████║ ██║ ███████║ ██╔██╗ ██║ ███████║
6 ██╔═██╗ ██╔══██║ ██║ ██╔══██║ ██║╚██╗██║ ██╔══██║
7 ██║ ██╗ ██║ ██║ ██║ ██║ ██║ ██║ ╚████║ ██║ ██║
8 ╚═╝ ╚═╝ ╚═╝ ╚═╝/\ ╚═╝ ╚═╝ ╚═╝ ╚═╝ ╚═══╝ ╚═╝ ╚═╝
9 /vvvvvvvvvvvvvvvvvvv \=========================================,
10 `^^^^^^^^^^^^^^^^^^^ /---------------------------------------"
11 Katana Engine \/ © 2012 - Shuriken Studios LLC
12 http://www.shurikenstudios.com
13*/
14
15#include "KatanaEngine.h"
16
17namespace KatanaEngine
18{
19 const Point Point::Origin = Point(0, 0);
20
21
22 Point::Point(const int x, const int y)
23 {
24 X = x;
25 Y = y;
26 }
27
28 void Point::Set(const int x, const int y)
29 {
30 X = x;
31 Y = y;
32 }
33
34 void Point::Set(const Point point)
35 {
36 X = point.X;
37 Y = point.Y;
38 }
39
40 std::string Point::ToString() const
41 {
42 std::ostringstream ss;
43 ss << "{ " << X << ", " << Y << " }";
44 return ss.str();
45 }
46
48 {
49 if (this != &point)
50 {
51 X = point.X;
52 Y = point.Y;
53 }
54
55 return *this;
56 }
57
59 {
60 X += point.X;
61 Y += point.Y;
62
63 return *this;
64 }
65
67 {
68 X -= point.X;
69 Y -= point.Y;
70
71 return *this;
72 }
73
74 const Point Point::operator+(const Point &point) const
75 {
76 return Point(*this) += point;
77 }
78
79 const Point Point::operator-(const Point &point) const
80 {
81 return Point(*this) -= point;
82 }
83
84 bool Point::operator== (const Point &point) const
85 {
86 return ((X == point.X) && (Y == point.Y));
87 }
88
89 bool Point::operator!= (const Point &point) const
90 {
91 return !((X == point.X) && (Y == point.Y));
92 }
93
95 {
96 return Vector2(X, Y);
97 }
98}
Defines a point in 2D space.
Definition Point.h:23
bool operator==(const Point &point) const
Determines if two points are equal.
Definition Point.cpp:84
Point & operator-=(const Point &point)
Subtracts a point.
Definition Point.cpp:66
void Set(const int x, const int y)
Sets the components of the point.
Definition Point.cpp:28
const Vector2 ToVector2() const
Converts the point into a vector.
Definition Point.cpp:94
Point(const int x=0, const int y=0)
Instantiates a new point object.
Definition Point.cpp:22
const Point operator-(const Point &point) const
Subtracts a point from another.
Definition Point.cpp:79
int X
The x-coordinate of the point.
Definition Point.h:100
bool operator!=(const Point &point) const
Determines if two points are not equal.
Definition Point.cpp:89
int Y
The y-coordinate of the point.
Definition Point.h:101
Point & operator=(const Point &point)
Assigns the reference of a point.
Definition Point.cpp:47
std::string ToString() const
Gets a string representation of the point.
Definition Point.cpp:40
const Point operator+(const Point &point) const
Adds two points.
Definition Point.cpp:74
static const Point Origin
A point located at the origin.
Definition Point.h:34
Point & operator+=(const Point &point)
Adds a point.
Definition Point.cpp:58
Defines a vector with 2 components (x and y).
Definition Vector2.h:21
Katana Engine is a library of classes, interfaces, and value types that provides a foundation for dev...
Definition Animation.cpp:18