Skip to content

Commit

Permalink
Add missing IndexMut impl for Point
Browse files Browse the repository at this point in the history
  • Loading branch information
jdahlstrom committed Jan 12, 2025
1 parent 357a728 commit 426ef79
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions core/src/math/point.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ use core::{
array,
fmt::{Debug, Formatter},
marker::PhantomData as Pd,
ops::{Add, AddAssign, Index, Sub, SubAssign},
ops::{Add, AddAssign, Index, IndexMut, Sub, SubAssign},
};

use crate::math::{space::Real, vary::ZDiv, Affine, ApproxEq, Linear, Vector};
use super::{space::Real, vary::ZDiv, Affine, ApproxEq, Linear, Vector};

#[repr(transparent)]
pub struct Point<Repr, Space = ()>(pub Repr, Pd<Space>);
Expand Down Expand Up @@ -251,6 +251,12 @@ impl<R: Index<usize>, Sp> Index<usize> for Point<R, Sp> {
}
}

impl<R: IndexMut<usize>, Sp> IndexMut<usize> for Point<R, Sp> {
fn index_mut(&mut self, i: usize) -> &mut R::Output {
self.0.index_mut(i)
}
}

impl<R, Sp> Add<<Self as Affine>::Diff> for Point<R, Sp>
where
Self: Affine,
Expand Down Expand Up @@ -365,16 +371,22 @@ mod tests {
}
#[test]
fn point2_index() {
let p = pt2(2.0, -1.0);
let mut p = pt2(2.0, -1.0);
assert_eq!(p[0], p.x());
assert_eq!(p[1], p.y());

p[1] -= 1.0;
assert_eq!(p[1], -2.0);
}
#[test]
fn point3_index() {
let p = pt3(2.0, -1.0, 3.0);
let mut p = pt3(2.0, -1.0, 3.0);
assert_eq!(p[0], p.x());
assert_eq!(p[1], p.y());
assert_eq!(p[2], p.z());

p[2] += 1.0;
assert_eq!(p[2], 4.0);
}
#[test]
#[should_panic]
Expand Down

0 comments on commit 426ef79

Please sign in to comment.