From b6d0b028c3cfb0ad06513182f9e9aa595c8b050c Mon Sep 17 00:00:00 2001 From: Peter Barker Date: Wed, 18 May 2016 20:23:39 +1000 Subject: [PATCH] AP_Math: add operator[] to Vector2 --- libraries/AP_Math/vector2.h | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libraries/AP_Math/vector2.h b/libraries/AP_Math/vector2.h index 398e260430..171c0e3b5d 100644 --- a/libraries/AP_Math/vector2.h +++ b/libraries/AP_Math/vector2.h @@ -107,6 +107,14 @@ struct Vector2 // check if all elements are zero bool is_zero(void) const { return (fabsf(x) < FLT_EPSILON) && (fabsf(y) < FLT_EPSILON); } + const T & operator[](uint8_t i) const { + const T *_v = &x; +#if MATH_CHECK_INDEXES + assert(i >= 0 && i < 2); +#endif + return _v[i]; + } + // zero the vector void zero() {