SSD1306 OLED display driver 1.8.2 This library is developed to control SSD1306/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, 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 */
29 #ifndef _NANO_POINT_H_
30 #define _NANO_POINT_H_
31
32 #include "ssd1306_hal/io.h"
33
40 typedef struct _NanoPoint
41 {
43 lcdint_t x;
45 lcdint_t y;
46
47 // _NanoPoint(lcdint_t px, lcdint_t py)
48 // {
49 // x = px;
50 // y = py;
51 // }
52
58 void setPoint(lcdint_t px, lcdint_t py) { x=px; y=py; };
59
64 _NanoPoint& operator>>=(const uint8_t bits)
65 {
66 x >>= bits;
67 y >>= bits;
68 return *this;
69 }
70
75 _NanoPoint& operator<<=(const uint8_t bits)
76 {
77 x <<= bits;
78 y <<= bits;
79 return *this;
80 }
81
86 _NanoPoint& operator+=(const _NanoPoint &p)
87 {
88 x += p.x;
89 y += p.y;
90 return *this;
91 };
92
97 _NanoPoint& operator-=(const _NanoPoint &p)
98 {
99 x -= p.x;
100 y -= p.y;
101 return *this;
102 };
103
108 _NanoPoint operator-(const _NanoPoint &p)
109 {
110 return { static_cast<lcdint_t>(x - p.x),
111 static_cast<lcdint_t>(y - p.y) };
112 };
113
118 _NanoPoint operator+(const _NanoPoint &p)
119 {
120 return { static_cast<lcdint_t>(x + p.x),
121 static_cast<lcdint_t>(y + p.y) };
122 };
123
128 _NanoPoint operator>>(const uint8_t bits) const
129 {
130 return { static_cast<lcdint_t>(x >> bits),
131 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),
141 static_cast<lcdint_t>(y << bits) };
142 };
143
148 _NanoPoint operator/(const int16_t d) const
149 {
150 return { static_cast<lcdint_t>(x / d),
151 static_cast<lcdint_t>(y / d) };
152 };
153
154 } NanoPoint;
155
156 #ifndef DOXYGEN_SHOULD_SKIP_THIS
157 inline NanoPoint operator+(const NanoPoint& p1, const NanoPoint& p2)
158 {
159 return { (lcdint_t)(p1.x + p2.x), (lcdint_t)(p1.y + p2.y) };
160 }
161
162 inline NanoPoint operator-(const NanoPoint& p1, const NanoPoint& p2)
163 {
164 return { (lcdint_t)(p1.x - p2.x), (lcdint_t)(p1.y - p2.y) };
165 }
166
167 inline bool operator==(const NanoPoint& p1, const NanoPoint& p2)
168 {
169 return (p1.x == p2.x) && (p1.y == p2.y);
170 }
171
172 inline bool operator!=(const NanoPoint& p1, const NanoPoint& p2)
173 {
174 return !(p1 == p2);
175 }
176 #endif // DOXYGEN_SHOULD_SKIP_THIS
177
182 #endif
183
_NanoPoint::operator-
_NanoPoint operator-(const _NanoPoint &p)
Definition: point.h:108
_NanoPoint
Definition: point.h:40
_NanoPoint::setPoint
void setPoint(lcdint_t px, lcdint_t py)
Definition: point.h:58
NanoPoint
struct _NanoPoint NanoPoint
_NanoPoint::operator+
_NanoPoint operator+(const _NanoPoint &p)
Definition: point.h:118
lcdint_t
int lcdint_t
Definition: io.h:63
_NanoPoint::operator<<=
_NanoPoint & operator<<=(const uint8_t bits)
Definition: point.h:75
_NanoPoint::operator<<
_NanoPoint operator<<(const uint8_t bits) const
Definition: point.h:138
io.h
_NanoPoint::operator>>=
_NanoPoint & operator>>=(const uint8_t bits)
Definition: point.h:64
_NanoPoint::y
lcdint_t y
Definition: point.h:45
_NanoPoint::operator/
_NanoPoint operator/(const int16_t d) const
Definition: point.h:148
_NanoPoint::operator+=
_NanoPoint & operator+=(const _NanoPoint &p)
Definition: point.h:86
_NanoPoint::operator-=
_NanoPoint & operator-=(const _NanoPoint &p)
Definition: point.h:97
_NanoPoint::operator>>
_NanoPoint operator>>(const uint8_t bits) const
Definition: point.h:128
_NanoPoint::x
lcdint_t x
Definition: point.h:43