|
| 1 | +/** |
| 2 | + * @file |
| 3 | + */ |
| 4 | + |
| 5 | +#ifndef MICRAS_CORE_VECTOR_HPP |
| 6 | +#define MICRAS_CORE_VECTOR_HPP |
| 7 | + |
| 8 | +namespace micras::core { |
| 9 | +/** |
| 10 | + * @brief Type to store a point in 2D space. |
| 11 | + */ |
| 12 | +struct Vector { |
| 13 | + /** |
| 14 | + * @brief Calculate the distance to another point. |
| 15 | + * |
| 16 | + * @param other The other point. |
| 17 | + * @return The distance to the other point. |
| 18 | + */ |
| 19 | + float distance(const Vector& other) const; |
| 20 | + |
| 21 | + /** |
| 22 | + * @brief Calculate the distance of the point to the origin. |
| 23 | + * |
| 24 | + * @return The distance of the point to the origin. |
| 25 | + */ |
| 26 | + float magnitude() const; |
| 27 | + |
| 28 | + /** |
| 29 | + * @brief Calculate the angle between two points. |
| 30 | + * |
| 31 | + * @param other The other point. |
| 32 | + * @return The angle between the two points. |
| 33 | + */ |
| 34 | + float angle_between(const Vector& other) const; |
| 35 | + |
| 36 | + /** |
| 37 | + * @brief Move the point towards another point by a given distance. |
| 38 | + * |
| 39 | + * @param other The point to move towards. |
| 40 | + * @param distance The distance to move. |
| 41 | + * @return The point after moving towards the other point. |
| 42 | + */ |
| 43 | + Vector move_towards(const Vector& other, float distance) const; |
| 44 | + |
| 45 | + /** |
| 46 | + * @brief Add a point to another. |
| 47 | + * |
| 48 | + * @param other The point to add. |
| 49 | + * @return The result of the addition. |
| 50 | + */ |
| 51 | + Vector operator+(const Vector& other) const; |
| 52 | + |
| 53 | + /** |
| 54 | + * @brief Subtract a point from another. |
| 55 | + * |
| 56 | + * @param other The point to subtract. |
| 57 | + * @return The result of the subtraction. |
| 58 | + */ |
| 59 | + Vector operator-(const Vector& other) const; |
| 60 | + |
| 61 | + /** |
| 62 | + * @brief Compare two points for equality. |
| 63 | + * |
| 64 | + * @param other The other point to compare. |
| 65 | + * @return True if the points are equal, false otherwise. |
| 66 | + */ |
| 67 | + bool operator==(const Vector& other) const; |
| 68 | + |
| 69 | + /** |
| 70 | + * @brief Calculate the remainder of the division of the point by a value. |
| 71 | + * |
| 72 | + * @param value The value to divide the point by. |
| 73 | + * @return The remainder of the division. |
| 74 | + */ |
| 75 | + Vector operator%(float value) const; |
| 76 | + |
| 77 | + /** |
| 78 | + * @brief The x coordinate of the point in 2D space. |
| 79 | + */ |
| 80 | + float x; |
| 81 | + |
| 82 | + /** |
| 83 | + * @brief The y coordinate of the point in 2D space. |
| 84 | + */ |
| 85 | + float y; |
| 86 | +}; |
| 87 | +} // namespace micras::core |
| 88 | + |
| 89 | +#endif // MICRAS_CORE_VECTOR_HPP |
0 commit comments