5#ifndef INCLUDE_FIFECHAN_POINT_HPP_
6#define INCLUDE_FIFECHAN_POINT_HPP_
14#include "fifechan/math.hpp"
33 std::array<int, 2> val;
45 explicit Point(
int _x = 0,
int _y = 0) : val{_x, _y} { }
50 Point(
Point const & rhs) : val{rhs.val[0], rhs.val[1]} { }
84 return Point(x + p.x, y + p.y);
92 return Point(x - p.x, y - p.y);
120 return Point(x * i, y * i);
128 return Point(x / i, y / i);
136 return x == p.x && y == p.y;
144 return x != p.x || y != p.y;
152 double const sq = (
static_cast<double>(x) * x) + (
static_cast<double>(y) * y);
161 float const len =
length();
164 float const invLength = 1.0F / len;
165 x =
static_cast<int>(x * invLength);
166 y =
static_cast<int>(y * invLength);
178 double const theta =
static_cast<double>(angle) *
Mathd::pi() / 180.0;
183 static_cast<int>(std::round((c * x) - (s * y))),
static_cast<int>(std::round((s * x) + (c * y))));
191 double const theta = angle *
Mathd::pi() / 180.0;
196 double const nx =
static_cast<double>(x);
197 double const ny =
static_cast<double>(y);
199 x =
static_cast<int>((costheta * nx) - (sintheta * ny));
200 y =
static_cast<int>((sintheta * nx) + (costheta * ny));
212 double const nx =
static_cast<double>(x - origin.x);
213 double const ny =
static_cast<double>(y - origin.y);
216 double const theta =
static_cast<double>(angle) *
Mathd::pi() / 180.0;
223 double const rx = (costheta * nx) - (sintheta * ny);
224 double const ry = (sintheta * nx) + (costheta * ny);
227 x =
static_cast<int>(std::round(origin.x + rx));
228 y =
static_cast<int>(std::round(origin.y + ry));
248 assert(ind > -1 && ind < 2);
259 return os <<
"(" << p.x <<
":" << p.y <<
")";
263 using PointVector = std::vector<Point>;
static num_type zeroTolerance()
static float Sqrt(float _val)
static double Cos(double _val)
static double Sin(double _val)
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.