Skip to content

Commit

Permalink
AP_Math: allow write to indexed vector2
Browse files Browse the repository at this point in the history
  • Loading branch information
tridge committed Nov 21, 2017
1 parent 0646815 commit ca3364c
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion libraries/AP_Math/vector2.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,23 @@ struct Vector2
// check if all elements are zero
bool is_zero(void) const { return (fabsf(x) < FLT_EPSILON) && (fabsf(y) < FLT_EPSILON); }

// allow a vector2 to be used as an array, 0 indexed
T & operator[](uint8_t i) {
T *_v = &x;
#if MATH_CHECK_INDEXES
assert(i >= 0 && i < 2);
#endif
return _v[i];
}

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()
{
Expand Down

0 comments on commit ca3364c

Please sign in to comment.