5#ifndef INCLUDE_FIFECHAN_POINT_HPP_
6#define INCLUDE_FIFECHAN_POINT_HPP_
16#include "fifechan/platform.hpp"
19#include "fifechan/math.hpp"
38 std::array<int, 2> val;
53 explicit Point(
int _x = 0,
int _y = 0) : x(_x), y(_y)
111 return Point(x + p.x, y + p.y);
122 return Point(x - p.x, y - p.y);
159 return Point(x * i, y * i);
170 return Point(x / i, y / i);
181 return x == p.x && y == p.y;
192 return x != p.x || y != p.y;
200 double const sq = (
static_cast<double>(x) * x) + (
static_cast<double>(y) * y);
209 float const len =
length();
212 float const invLength = 1.0F / len;
214 x =
static_cast<int>(x * invLength);
215 y =
static_cast<int>(y * invLength);
230 double const theta =
static_cast<double>(angle) *
Mathd::pi() / 180.0;
236 static_cast<int>(std::round((c * x) - (s * y))),
static_cast<int>(std::round((s * x) + (c * y))));
246 double const theta = angle *
Mathd::pi() / 180.0;
251 double const nx =
static_cast<double>(x);
252 double const ny =
static_cast<double>(y);
254 x =
static_cast<int>((costheta * nx) - (sintheta * ny));
255 y =
static_cast<int>((sintheta * nx) + (costheta * ny));
270 double const nx =
static_cast<double>(x - origin.x);
271 double const ny =
static_cast<double>(y - origin.y);
274 double const theta =
static_cast<double>(angle) *
Mathd::pi() / 180.0;
281 double const rx = (costheta * nx) - (sintheta * ny);
282 double const ry = (sintheta * nx) + (costheta * ny);
285 x =
static_cast<int>(std::round(origin.x + rx));
286 y =
static_cast<int>(std::round(origin.y + ry));
309 assert(ind > -1 && ind < 2);
310 return val.at(
static_cast<size_t>(ind));
324 return os <<
"(" << p.x <<
":" << p.y <<
")";
static num_type zeroTolerance()
static float Sqrt(float _val)
static double Cos(double _val)
static double Sin(double _val)
Represents a 2D coordinate (X, Y).
Point & operator+=(Point const &p)
Vector inplace addition.
void rotate(Point const &origin, int angle)
Rotates the point around a given origin by angle degrees.
bool operator!=(Point const &p) const
Equality comparision.
int & operator[](int ind)
Index accessor for the point components.
int length() const
Return length.
Point(Point const &rhs)
Copy Constructor.
Point operator-(Point const &p) const
Vector subtraction.
void normalize()
Normalizes the point.
Point & operator=(Point const &rhs)
Copy assignment.
Point & operator=(Point &&rhs) noexcept
Move assignment.
Point(Point &&rhs) noexcept
Move Constructor.
void rotate(double angle)
Rotates the point around the origin by angle degrees.
friend std::ostream & operator<<(std::ostream &os, Point const &p)
Stream output operator for debug/logging.
Point & operator-=(Point const &p)
Vector inplace subtraction.
Point operator*(int const &i) const
Scalar multiplication with an integer value.
Point(int _x=0, int _y=0)
Constructor.
bool operator==(Point const &p) const
Equality comparision.
Point rotated(int angle) const
Rotates the point around the origin by angle degrees.
Point operator+(Point const &p) const
Vector addition.
Point operator/(int const &i) const
Scalar division with an integer value.
void set(int _x, int _y)
Sets the x and y coordinate of the 2D point.
Used replacement tokens by configure_file():
std::vector< Point > PointVector
A list of points.