Test for STM32F4
Fork of RGB_OLED_SSD1331 by
include/Point.h@18:47cbbfc890a8, 2017-08-02 (annotated)
- Committer:
- kkado
- Date:
- Wed Aug 02 22:12:49 2017 +0000
- Revision:
- 18:47cbbfc890a8
- Parent:
- 17:1bcdc92af126
Initial commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
messi1 | 15:c49040bf0e1d | 1 | #ifndef __POINT_H_ |
messi1 | 15:c49040bf0e1d | 2 | #define __POINT_H_ |
messi1 | 15:c49040bf0e1d | 3 | |
messi1 | 15:c49040bf0e1d | 4 | template <class T> |
messi1 | 15:c49040bf0e1d | 5 | class Point |
messi1 | 15:c49040bf0e1d | 6 | { |
messi1 | 15:c49040bf0e1d | 7 | public: |
messi1 | 15:c49040bf0e1d | 8 | Point(): |
messi1 | 15:c49040bf0e1d | 9 | _x(0), |
messi1 | 15:c49040bf0e1d | 10 | _y(0) |
messi1 | 17:1bcdc92af126 | 11 | {} |
messi1 | 15:c49040bf0e1d | 12 | |
messi1 | 15:c49040bf0e1d | 13 | Point(T x, T y): |
messi1 | 15:c49040bf0e1d | 14 | _x(x), |
messi1 | 15:c49040bf0e1d | 15 | _y(y) |
messi1 | 17:1bcdc92af126 | 16 | {} |
messi1 | 15:c49040bf0e1d | 17 | |
messi1 | 17:1bcdc92af126 | 18 | T x(){return _x;} |
messi1 | 15:c49040bf0e1d | 19 | T y(){return _y;} |
messi1 | 15:c49040bf0e1d | 20 | T& rx(){return _x;} |
messi1 | 15:c49040bf0e1d | 21 | T& ry(){return _y;} |
messi1 | 15:c49040bf0e1d | 22 | void setX(T x){_x = x;} |
messi1 | 15:c49040bf0e1d | 23 | void setY(T y){_y = y;} |
messi1 | 15:c49040bf0e1d | 24 | bool isNull()const{return (_x==0 && _y==0);} |
messi1 | 17:1bcdc92af126 | 25 | |
messi1 | 15:c49040bf0e1d | 26 | Point& operator*=(T factor){_x*=factor; _y*=factor; return *this;} |
messi1 | 15:c49040bf0e1d | 27 | Point& operator+=(const Point& point){_x+=p._x; _y+=p._y; return *this;} |
messi1 | 15:c49040bf0e1d | 28 | Point& operator-=(const Point& point){_x-=p._x; _y-=p._y; return *this;} |
messi1 | 17:1bcdc92af126 | 29 | |
messi1 | 15:c49040bf0e1d | 30 | friend inline bool operator==( const Point &p1, const Point &p2 ){ return p1._x == p2._x && p1._y == p2._y; } |
messi1 | 15:c49040bf0e1d | 31 | friend inline bool operator!=( const Point &p1, const Point &p2 ){ return p1._x != p2._x || p1._y != p2._y; } |
messi1 | 15:c49040bf0e1d | 32 | friend inline const Point operator+( const Point &p1, const Point &p2 ){ return Point(p1._x+p2._x, p1._y+p2._y); } |
messi1 | 15:c49040bf0e1d | 33 | friend inline const Point operator-( const Point &p1, const Point &p2 ){ return Point(p1._x-p2._x, p1._y-p2._y); } |
messi1 | 15:c49040bf0e1d | 34 | friend inline const Point operator*( const Point &p, int factor){ return Point(p._x*factor, p._y*factor);} |
messi1 | 15:c49040bf0e1d | 35 | |
messi1 | 15:c49040bf0e1d | 36 | private: |
messi1 | 15:c49040bf0e1d | 37 | T _x; |
messi1 | 15:c49040bf0e1d | 38 | T _y; |
messi1 | 15:c49040bf0e1d | 39 | }; |
messi1 | 15:c49040bf0e1d | 40 | |
messi1 | 15:c49040bf0e1d | 41 | #endif // __POINT_H_ |