rgeometry/data/point/
add.rs1use super::Point;
2use super::Vector;
3use array_init::array_init;
4use num_traits::NumOps;
5use std::ops::Add;
6use std::ops::AddAssign;
7use std::ops::Index;
8
9impl<'a, 'b, T, const N: usize> Add<&'a Vector<T, N>> for &'b Point<T, N>
11where
12 T: Add<Output = T> + Clone,
13{
14 type Output = Point<T, N>;
15
16 fn add(self: &'b Point<T, N>, other: &'a Vector<T, N>) -> Self::Output {
17 Point {
18 array: array_init(|i| self.array.index(i).clone() + other.0.index(i).clone()),
19 }
20 }
21}
22
23impl<T, const N: usize> Add<Vector<T, N>> for Point<T, N>
25where
26 T: Add<Output = T> + Clone,
27{
28 type Output = Point<T, N>;
29
30 fn add(self: Point<T, N>, other: Vector<T, N>) -> Self::Output {
31 self.add(&other)
32 }
33}
34
35impl<T, const N: usize> Add<&Vector<T, N>> for Point<T, N>
37where
38 T: Add<Output = T> + Clone,
39{
40 type Output = Point<T, N>;
41
42 fn add(self: Point<T, N>, other: &Vector<T, N>) -> Self::Output {
43 (&self).add(other)
44 }
45}
46
47impl<T, const N: usize> AddAssign<&Vector<T, N>> for Point<T, N>
49where
50 T: NumOps + Clone + AddAssign,
51{
52 fn add_assign(&mut self, other: &Vector<T, N>) {
53 for i in 0..N {
54 self.array[i] += other.0.index(i).clone()
55 }
56 }
57}
58
59impl<T, const N: usize> AddAssign<Vector<T, N>> for Point<T, N>
61where
62 T: NumOps + Clone + AddAssign,
63{
64 fn add_assign(&mut self, other: Vector<T, N>) {
65 self.add_assign(&other)
66 }
67}
68
69