LCDGFX LCD display driver  1.1.5
This library is developed to control SSD1306/SSD1325/SSD1327/SSD1331/SSD1351/IL9163/PCD8554 RGB i2c/spi LED displays
point.h
Go to the documentation of this file.
1 /*
2  MIT License
3 
4  Copyright (c) 2018-2019, Alexey Dynda
5 
6  Permission is hereby granted, free of charge, to any person obtaining a copy
7  of this software and associated documentation files (the "Software"), to deal
8  in the Software without restriction, including without limitation the rights
9  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10  copies of the Software, and to permit persons to whom the Software is
11  furnished to do so, subject to the following conditions:
12 
13  The above copyright notice and this permission notice shall be included in all
14  copies or substantial portions of the Software.
15 
16  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  SOFTWARE.
23 */
28 #ifndef _NANO_POINT_H_
29 #define _NANO_POINT_H_
30 
31 #include "canvas_types.h"
32 
39 typedef struct _NanoPoint
40 {
45 
46  // _NanoPoint(lcdint_t px, lcdint_t py)
47  // {
48  // x = px;
49  // y = py;
50  // }
51 
57  void setPoint(lcdint_t px, lcdint_t py)
58  {
59  x = px;
60  y = py;
61  };
62 
67  _NanoPoint &operator>>=(const uint8_t bits)
68  {
69  x >>= bits;
70  y >>= bits;
71  return *this;
72  }
73 
78  _NanoPoint &operator<<=(const uint8_t bits)
79  {
80  x <<= bits;
81  y <<= bits;
82  return *this;
83  }
84 
90  {
91  x += p.x;
92  y += p.y;
93  return *this;
94  };
95 
101  {
102  x -= p.x;
103  y -= p.y;
104  return *this;
105  };
106 
112  {
113  return {static_cast<lcdint_t>(x - p.x), static_cast<lcdint_t>(y - p.y)};
114  };
115 
121  {
122  return {static_cast<lcdint_t>(x + p.x), static_cast<lcdint_t>(y + p.y)};
123  };
124 
129  _NanoPoint operator>>(const uint8_t bits) const
130  {
131  return {static_cast<lcdint_t>(x >> bits), static_cast<lcdint_t>(y >> bits)};
132  };
133 
138  _NanoPoint operator<<(const uint8_t bits) const
139  {
140  return {static_cast<lcdint_t>(x << bits), static_cast<lcdint_t>(y << bits)};
141  };
142 
147  _NanoPoint operator/(const int16_t d) const
148  {
149  return {static_cast<lcdint_t>(x / d), static_cast<lcdint_t>(y / d)};
150  };
151 
152 } NanoPoint;
153 
154 #ifndef DOXYGEN_SHOULD_SKIP_THIS
155 inline NanoPoint operator+(const NanoPoint &p1, const NanoPoint &p2)
156 {
157  return {(lcdint_t)(p1.x + p2.x), (lcdint_t)(p1.y + p2.y)};
158 }
159 
160 inline NanoPoint operator-(const NanoPoint &p1, const NanoPoint &p2)
161 {
162  return {(lcdint_t)(p1.x - p2.x), (lcdint_t)(p1.y - p2.y)};
163 }
164 
165 inline bool operator==(const NanoPoint &p1, const NanoPoint &p2)
166 {
167  return (p1.x == p2.x) && (p1.y == p2.y);
168 }
169 
170 inline bool operator!=(const NanoPoint &p1, const NanoPoint &p2)
171 {
172  return !(p1 == p2);
173 }
174 #endif // DOXYGEN_SHOULD_SKIP_THIS
175 
180 #endif
_NanoPoint operator-(const _NanoPoint &p)
Definition: point.h:111
struct _NanoPoint NanoPoint
void setPoint(lcdint_t px, lcdint_t py)
Definition: point.h:57
_NanoPoint operator+(const _NanoPoint &p)
Definition: point.h:120
_NanoPoint & operator<<=(const uint8_t bits)
Definition: point.h:78
int8_t lcdint_t
Definition: canvas_types.h:77
_NanoPoint operator<<(const uint8_t bits) const
Definition: point.h:138
_NanoPoint & operator>>=(const uint8_t bits)
Definition: point.h:67
lcdint_t y
Definition: point.h:44
_NanoPoint operator/(const int16_t d) const
Definition: point.h:147
_NanoPoint & operator+=(const _NanoPoint &p)
Definition: point.h:89
_NanoPoint & operator-=(const _NanoPoint &p)
Definition: point.h:100
_NanoPoint operator>>(const uint8_t bits) const
Definition: point.h:129
lcdint_t x
Definition: point.h:42