Extract Vector
This commit is contained in:
		
							parent
							
								
									7e99f4b204
								
							
						
					
					
						commit
						1f5892a1b7
					
				
					 2 changed files with 61 additions and 0 deletions
				
			
		
							
								
								
									
										37
									
								
								src/Vector.cpp
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										37
									
								
								src/Vector.cpp
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,37 @@
 | 
				
			||||||
 | 
					#include "Vector.h"
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector2::Vector2(double x, double y) : x(x), y(y) {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector2 Vector2::conjugate() {
 | 
				
			||||||
 | 
					    return {x, -y};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					Vector2 Vector2::operator*(double d) {
 | 
				
			||||||
 | 
					    return {x*d, y*d};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector2 Vector2::operator*=(double d) {
 | 
				
			||||||
 | 
					    x *= d;
 | 
				
			||||||
 | 
					    y *= d;
 | 
				
			||||||
 | 
					    return *this;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector2 Vector2::operator+(Vector2 v) {
 | 
				
			||||||
 | 
					    return {x+v.x, y+v.y};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector2 Vector2::operator+=(Vector2 v) {
 | 
				
			||||||
 | 
					    x += v.x;
 | 
				
			||||||
 | 
					    y += v.y;
 | 
				
			||||||
 | 
					    return *this;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector2 Vector2::operator-(Vector2 v) {
 | 
				
			||||||
 | 
					    return {x-v.x, y-v.y};
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					Vector2 Vector2::operator-=(Vector2 v) {
 | 
				
			||||||
 | 
					    x -= v.x;
 | 
				
			||||||
 | 
					    y -= v.y;
 | 
				
			||||||
 | 
					    return *this;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
							
								
								
									
										24
									
								
								src/Vector.h
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										24
									
								
								src/Vector.h
									
										
									
									
									
										Normal file
									
								
							| 
						 | 
					@ -0,0 +1,24 @@
 | 
				
			||||||
 | 
					#ifndef VECTOR_H
 | 
				
			||||||
 | 
					#define VECTOR_H 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					struct Vector2 {
 | 
				
			||||||
 | 
					    double x, y;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Vector2(double x = 0, double y = 0);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Vector2 conjugate();
 | 
				
			||||||
 | 
					    
 | 
				
			||||||
 | 
					    Vector2 operator*(double d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Vector2 operator*=(double d);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Vector2 operator+(Vector2 v);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Vector2 operator+=(Vector2 v);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Vector2 operator-(Vector2 v);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    Vector2 operator-=(Vector2 v);
 | 
				
			||||||
 | 
					};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#endif /* VECTOR_H */
 | 
				
			||||||
		Reference in a new issue