mirror of
				https://github.com/hannobraun/Fornjot
				synced 2025-10-31 04:08:17 +00:00 
			
		
		
		
	Implement Vector addition
				
					
				
			This commit is contained in:
		
							parent
							
								
									1137726ea8
								
							
						
					
					
						commit
						508e1bbff6
					
				| @ -1,5 +1,7 @@ | ||||
| use std::{cmp::Ordering, ops}; | ||||
| 
 | ||||
| use iter_fixed::IntoIteratorFixed; | ||||
| 
 | ||||
| #[derive(Clone, Copy, Debug, Eq, Ord, PartialEq, PartialOrd)] | ||||
| pub struct Point { | ||||
|     pub coords: Vector, | ||||
| @ -32,6 +34,26 @@ where | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| impl<T> ops::Add<T> for Vector | ||||
| where | ||||
|     T: Into<Vector>, | ||||
| { | ||||
|     type Output = Self; | ||||
| 
 | ||||
|     fn add(self, other: T) -> Self::Output { | ||||
|         let other = other.into(); | ||||
| 
 | ||||
|         let components = self | ||||
|             .components | ||||
|             .into_iter_fixed() | ||||
|             .zip(other.components) | ||||
|             .map(|(a, b)| a + b) | ||||
|             .collect(); | ||||
| 
 | ||||
|         Self { components } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| #[derive(Clone, Copy, Debug, PartialEq)] | ||||
| pub struct Scalar { | ||||
|     value: f64, | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user