Thunderbots Project
Loading...
Searching...
No Matches
point.h
1#pragma once
2
3#include <cmath>
4#include <iostream>
5#include <vector>
6
7#include "software/geom/angle.h"
8#include "software/geom/vector.h"
9
14{
15 public:
19 explicit Point();
20
27 Point(double x, double y);
28
34 Point(const Point &p);
35
41 explicit Point(const Vector &v);
42
48 double x() const;
49
55 double y() const;
56
63 void set(double x, double y);
64
70 void setX(double x);
71
77 void setY(double y);
78
84 double distanceFromOrigin() const;
85
91 Vector toVector() const;
92
101 Point rotate(const Angle &rot) const;
102
110 Point &operator=(const Point &other);
111
112 private:
117 double x_;
118
123 double y_;
124};
125
134Point operator+(const Point &p, const Vector &v) __attribute__((warn_unused_result));
135
144Point operator+(const Vector &v, const Point &p) __attribute__((warn_unused_result));
145
154Point operator-(const Point &p, const Vector &v) __attribute__((warn_unused_result));
155
164Point &operator-=(Point &p, const Vector &v);
165
174Point &operator+=(Point &p, const Vector &v);
175
183Point operator-(const Point &p) __attribute__((warn_unused_result));
184
193Vector operator-(const Point &p, const Point &q) __attribute__((warn_unused_result));
194
203std::ostream &operator<<(std::ostream &os, const Point &p);
204
213bool operator==(const Point &p, const Point &q);
214
223bool operator!=(const Point &p, const Point &q);
224
225// We need to define a hash function so that the Point class can be used in unordered STL
226// containers
227// like unordered_set and unordered_map
228// https://prateekvjoshi.com/2014/06/05/using-hash-function-in-c-for-user-defined-classes/
229namespace std
230{
231 template <>
232 struct hash<Point> final
233 {
234 size_t operator()(const Point &p) const
235 {
236 hash<double> h;
237 return h(p.x()) * 17 + h(p.y());
238 }
239 };
240} // namespace std
Definition angle.h:15
Definition point.h:14
Point rotate(const Angle &rot) const
Definition point.cpp:47
void setY(double y)
Definition point.cpp:32
Vector toVector() const
Definition point.cpp:42
double distanceFromOrigin() const
Definition point.cpp:37
double x() const
Definition point.cpp:11
Point & operator=(const Point &other)
Definition point.cpp:52
void setX(double x)
Definition point.cpp:27
double y() const
Definition point.cpp:16
Point()
Definition point.cpp:3
void set(double x, double y)
Definition point.cpp:21
Definition vector.h:12