forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpoint.h
More file actions
125 lines (96 loc) · 2.25 KB
/
point.h
File metadata and controls
125 lines (96 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
// Aseprite Gfx Library
// Copyright (C) 2001-2016 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef GFX_POINT_H_INCLUDED
#define GFX_POINT_H_INCLUDED
#pragma once
namespace gfx {
template<typename T>
class SizeT;
// A 2D coordinate in the screen.
template<typename T>
class PointT
{
public:
T x, y;
PointT() : x(0), y(0) {
}
PointT(const T& x, const T& y) : x(x), y(y) {
}
PointT(const PointT& point) : x(point.x), y(point.y) {
}
template<typename T2>
explicit PointT(const PointT<T2>& point) : x(static_cast<T>(point.x)),
y(static_cast<T>(point.y)) {
}
explicit PointT(const SizeT<T>& size) : x(size.w), y(size.h) {
}
const PointT& operator=(const PointT& pt) {
x = pt.x;
y = pt.y;
return *this;
}
const PointT& operator+=(const PointT& pt) {
x += pt.x;
y += pt.y;
return *this;
}
const PointT& operator-=(const PointT& pt) {
x -= pt.x;
y -= pt.y;
return *this;
}
const PointT& operator+=(const T& value) {
x += value;
y += value;
return *this;
}
const PointT& operator-=(const T& value) {
x -= value;
y -= value;
return *this;
}
const PointT& operator*=(const T& value) {
x *= value;
y *= value;
return *this;
}
const PointT& operator/=(const T& value) {
x /= value;
y /= value;
return *this;
}
PointT operator+(const PointT& pt) const {
return PointT(x+pt.x, y+pt.y);
}
PointT operator-(const PointT& pt) const {
return PointT(x-pt.x, y-pt.y);
}
PointT operator+(const T& value) const {
return PointT(x+value, y+value);
}
PointT operator-(const T& value) const {
return PointT(x-value, y-value);
}
PointT operator*(const T& value) const {
return PointT(x*value, y*value);
}
PointT operator/(const T& value) const {
return PointT(x/value, y/value);
}
PointT operator-() const {
return PointT(-x, -y);
}
bool operator==(const PointT& pt) const {
return x == pt.x && y == pt.y;
}
bool operator!=(const PointT& pt) const {
return x != pt.x || y != pt.y;
}
};
typedef PointT<int> Point;
typedef PointT<double> PointF;
} // namespace gfx
#endif