|
2 | 2 |
|
3 | 3 | #include "units/Angle.hpp"
|
4 | 4 |
|
5 |
| -namespace units { |
6 | 5 | /**
|
7 | 6 | * @class Vector2D
|
8 | 7 | *
|
@@ -43,8 +42,8 @@ template <isQuantity T> class Vector2D {
|
43 | 42 | */
|
44 | 43 | constexpr static Vector2D fromPolar(Angle t, T m) {
|
45 | 44 | m = abs(m);
|
46 |
| - t = constrainAngle360(t); |
47 |
| - return Vector2D<T>(m * cos(t), m * sin(t)); |
| 45 | + t = units::constrainAngle360(t); |
| 46 | + return Vector2D<T>(m * units::cos(t), m * units::sin(t)); |
48 | 47 | }
|
49 | 48 |
|
50 | 49 | /**
|
@@ -277,9 +276,30 @@ constexpr Vector2D<Q3> operator*(Q1 lhs, const Vector2D<Q2>& rhs) {
|
277 | 276 | */
|
278 | 277 | template <isQuantity Q> constexpr Vector2D<Q> operator*(double lhs, const Vector2D<Q>& rhs) { return rhs * lhs; }
|
279 | 278 |
|
| 279 | +namespace std { |
| 280 | +template <typename T> struct formatter<Vector2D<T>> : formatter<T> { |
| 281 | + // Optionally parse format specifiers for T |
| 282 | + constexpr auto parse(auto& ctx) { return formatter<T>::parse(ctx); } |
| 283 | + |
| 284 | + auto format(const Vector2D<T>& vector, format_context& ctx) const { |
| 285 | + auto it = ctx.out(); |
| 286 | + it = format_to(it, "("); |
| 287 | + |
| 288 | + // Format vector.x using the base formatter<T> |
| 289 | + it = static_cast<const formatter<T>*>(this)->format(vector.x, ctx); |
| 290 | + it = format_to(it, ", "); |
| 291 | + |
| 292 | + // Format vector.y using the base formatter<T> |
| 293 | + it = static_cast<const formatter<T>*>(this)->format(vector.y, ctx); |
| 294 | + it = format_to(it, ")"); |
| 295 | + |
| 296 | + return it; |
| 297 | + } |
| 298 | +}; |
| 299 | +} // namespace std |
| 300 | + |
280 | 301 | // define some common vector types
|
281 | 302 | typedef Vector2D<Length> V2Position;
|
282 | 303 | typedef Vector2D<LinearVelocity> V2Velocity;
|
283 | 304 | typedef Vector2D<LinearAcceleration> V2Acceleration;
|
284 | 305 | typedef Vector2D<Force> V2Force;
|
285 |
| -} // namespace units |
|
0 commit comments