RIT VEXU Core API
Loading...
Searching...
No Matches
point2d.h
1#pragma once
2
3#include <Eigen/Dense>
4#include "cevalm.hpp"
5
7class Point2d {
8 private:
9 int x_, y_;
10
11 public:
13 constexpr Point2d() : x_(0), y_(0) {}
14
20 constexpr Point2d(int x, int y) : x_(x), y_(y) {}
21
26 constexpr Point2d(Eigen::Vector2i vector)
27 : x_(vector(0)), y_(vector(1)) {}
28
30 constexpr int x() const { return x_; }
31
33 constexpr void set_x(int val) { x_ = val; }
34
36 constexpr int y() const { return y_; }
37
39 constexpr void set_y(int val) { y_ = val; }
40
42 constexpr Eigen::Vector2i as_vector() const { return Eigen::Vector2i(x_, y_); }
43
50 constexpr Eigen::Vector2d as_vector(Eigen::Vector2d X, Eigen::Vector2d Y) const {
51 return Eigen::Vector2d(
52 x_ * X(0) + y_ * Y(0),
53 x_ * X(1) + y_ * Y(1)
54 );
55 }
56
58 constexpr int manhattan_distance(Point2d other) const {
59 return cevalm::abs(x_ - other.x_) + cevalm::abs(y_ - other.y_);
60 }
61
63 constexpr int manhattan_norm() const { return cevalm::abs(x_) + cevalm::abs(y_); }
64
66 constexpr double distance(Point2d other) const { return cevalm::hypot(x_ - other.x_, y_ - other.y_); }
67
69 constexpr double norm() const { return cevalm::hypot(x_, y_); }
70
79 constexpr Point2d inverse() const { return Point2d{-x_, -y_};; }
80
89 constexpr int dot(Point2d other) const { return (x_ * other.x_) + (y_ * other.y_); }
90
100 constexpr Point2d operator+(Point2d other) const { return Point2d{x_ + other.x_, y_ + other.y_}; }
101
103 constexpr Point2d& operator+=(Point2d other) { return *this = *this + other; }
104
114 constexpr Point2d operator-(Point2d other) const { return Point2d{x_ - other.x_, y_ - other.y_}; }
115
117 constexpr Point2d& operator-=(Point2d other) { return *this = *this - other; }
118
127 constexpr Point2d operator-() const { return inverse(); }
128
138 constexpr Point2d operator*(int scalar) const { return Point2d{x_ * scalar, y_ * scalar}; }
139
141 friend constexpr Point2d operator*(int scalar, Point2d point) { return point * scalar; }
142
151 constexpr int operator*(Point2d other) const { return dot(other); }
152
154 constexpr Point2d& operator*=(int scalar) { return *this = *this * scalar; }
155
161 constexpr bool operator==(Point2d other) const { return x_ == other.x_ && y_ == other.y_; }
162};
constexpr void set_x(int val)
Sets the x coordinate.
Definition point2d.h:33
constexpr int manhattan_norm() const
Calculates the manhattan distance away from the origin.
Definition point2d.h:63
constexpr Point2d operator-(Point2d other) const
Definition point2d.h:114
constexpr bool operator==(Point2d other) const
Definition point2d.h:161
constexpr Point2d operator*(int scalar) const
Definition point2d.h:138
constexpr Eigen::Vector2i as_vector() const
Gets the point as an Eigen::Vector2i.
Definition point2d.h:42
constexpr Point2d inverse() const
Definition point2d.h:79
constexpr Point2d & operator+=(Point2d other)
Adds another point to this point.
Definition point2d.h:103
constexpr void set_y(int val)
Sets the y coordinate.
Definition point2d.h:39
constexpr Eigen::Vector2d as_vector(Eigen::Vector2d X, Eigen::Vector2d Y) const
Definition point2d.h:50
constexpr Point2d operator-() const
Definition point2d.h:127
constexpr double norm() const
Calculates the distance (as a continuous number) away from the origin.
Definition point2d.h:69
constexpr int operator*(Point2d other) const
Definition point2d.h:151
constexpr Point2d(Eigen::Vector2i vector)
Definition point2d.h:26
constexpr Point2d operator+(Point2d other) const
Definition point2d.h:100
constexpr int x() const
Gets the X coordinate of the point.
Definition point2d.h:30
constexpr Point2d(int x, int y)
Definition point2d.h:20
constexpr int y() const
Gets the Y coordinate of the point.
Definition point2d.h:36
constexpr Point2d()
Default constructor for Point2d creating a lattice point at the origin.
Definition point2d.h:13
constexpr Point2d & operator-=(Point2d other)
Subtracts another point from this point.
Definition point2d.h:117
constexpr Point2d & operator*=(int scalar)
Multiplies this point by a scalar.
Definition point2d.h:154
constexpr int manhattan_distance(Point2d other) const
Calculates the manhattan distance between two points.
Definition point2d.h:58
constexpr int dot(Point2d other) const
Definition point2d.h:89
friend constexpr Point2d operator*(int scalar, Point2d point)
Scales the point.
Definition point2d.h:141
constexpr double distance(Point2d other) const
Calculates the distance (as a continuous number) between two points.
Definition point2d.h:66