KTech 1.1.0
C++ 2D terminal game engine library
Loading...
Searching...
No Matches
point.hpp
1/*
2 KTech, Kaup's C++ 2D terminal game engine library.
3 Copyright (C) 2023-2025 Ethan Kaufman (AKA Kaup)
4
5 This file is part of KTech.
6
7 KTech is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 any later version.
11
12 KTech is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with KTech. If not, see <https://www.gnu.org/licenses/>.
19*/
20
21#pragma once
22
23#define KTECH_DEFINITION
24#include "../ktech.hpp"
25#undef KTECH_DEFINITION
26#include "upoint.hpp"
27
30{
31 int32_t x;
32 int32_t y;
33
39 constexpr Point(int32_t x = 0, int32_t y = 0)
40 : x(x), y(y) {}
41
46 constexpr Point(const UPoint& uPoint)
47 : x(uPoint.x), y(uPoint.y) {}
48
54 constexpr auto operator==(const Point& point) const -> bool
55 {
56 return (x == point.x) && (y == point.y);
57 }
58
64 constexpr auto operator+(const Point& point) const -> Point
65 {
66 return {x + point.x, y + point.y};
67 }
68
74 constexpr auto operator-(const Point& point) const -> Point
75 {
76 return {x - point.x, y - point.y};
77 }
78
84 constexpr auto operator+=(const Point& point) -> Point&
85 {
86 x += point.x;
87 y += point.y;
88 return *this;
89 }
90
96 constexpr auto operator-=(const Point& point) -> Point&
97 {
98 x -= point.x;
99 y -= point.y;
100 return *this;
101 }
102};
2D vector, mostly used to store positions and directions.
Definition point.hpp:30
int32_t y
Y axis (+ down, - up).
Definition point.hpp:32
constexpr auto operator+=(const Point &point) -> Point &
Add a Point to this Point.
Definition point.hpp:84
constexpr auto operator==(const Point &point) const -> bool
Compare 2 Points.
Definition point.hpp:54
constexpr auto operator-=(const Point &point) -> Point &
Subtract a Point from this Point.
Definition point.hpp:96
int32_t x
X axis (+ right, - left).
Definition point.hpp:31
constexpr Point(int32_t x=0, int32_t y=0)
Construct a Point.
Definition point.hpp:39
constexpr auto operator-(const Point &point) const -> Point
Subtract Point from another.
Definition point.hpp:74
constexpr Point(const UPoint &uPoint)
Construct a Point from a UPoint.
Definition point.hpp:46
constexpr auto operator+(const Point &point) const -> Point
Add 2 Points together.
Definition point.hpp:64
Unsigned 2D vector, mostly used to store sizes and 2D indexes.
Definition upoint.hpp:29