Smart Matrix
vector.hpp
Go to the documentation of this file.
1 // ==========================================================================
2 //
3 // File : vector.hpp
4 // Part of : led matrix library
5 // Copyright : mostafa@khattat.nl 2016
6 //
7 // led matrix implementation for an Arduino Due (ATSAM3X8E chip)
8 //
9 // Distributed under the Boost Software License, Version 1.0.
10 // (See accompanying file LICENSE_1_0.txt or copy at
11 // http://www.boost.org/LICENSE_1_0.txt)
12 //
13 // ==========================================================================
15 
16 #ifndef VECTOR_HPP
17 #define VECTOR_HPP
18 
20 //
23 class vector {
24 public:
25  int x;
26  int y;
27 
28  vector( int x, int y ):
29  x( x ), y( y )
30  {}
31 
32  vector( const vector & rhs ):
33  x( rhs.x ),
34  y( rhs.y )
35  {}
36 
37  vector & operator+=( const vector & rhs ){
38  x += rhs.x;
39  y += rhs.y;
40  return *this;
41  }
42 
43  vector operator+( const vector & rhs ) const {
44  vector temp = *this;
45  temp += rhs;
46  return temp;
47  }
48 
49  vector & operator-=( const vector & rhs ){
50  x -= rhs.x;
51  y -= rhs.y;
52  return *this;
53  }
54 
55  vector operator-( const vector & rhs ) const {
56  vector temp = *this;
57  temp -= rhs;
58  return temp;
59  }
60 
61  vector & operator*=( int n ){
62  x *= n;
63  y *= n;
64  return *this;
65  }
66 
67  vector operator*( int n ) const {
68  vector temp = *this;
69  temp *= n;
70  return temp;
71  }
72 };
73 
74 #endif // VECTOR_HPP
Implementation of vector class to store x and y.
Definition: vector.hpp:23