Lumitronix_Iflex_Pro_Workshop
Library to interact with the iFlexPro
NeoTopology.h
Go to the documentation of this file.
1 /*-------------------------------------------------------------------------
2 NeoTopology provides a mapping feature of a 2d cordinate to linear 1d cordinate
3 It is used to map a matrix of LumitronixIFlexs to a index on the LumitronixIFlexBus
4 
5 Written by Michael C. Miller.
6 
7 I invest time and resources providing this open source code,
8 please support me by dontating (see https://github.com/Makuna)
9 
10 -------------------------------------------------------------------------
11 This file is part of the LUMITRONIX_iFlex_Workshop library.
12 
13 LumitronixIFlexBus is free software: you can redistribute it and/or modify
14 it under the terms of the GNU Lesser General Public License as
15 published by the Free Software Foundation, either version 3 of
16 the License, or (at your option) any later version.
17 
18 LumitronixIFlexBus is distributed in the hope that it will be useful,
19 but WITHOUT ANY WARRANTY; without even the implied warranty of
20 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 GNU Lesser General Public License for more details.
22 
23 You should have received a copy of the GNU Lesser General Public
24 License along with LumitronixIFlex. If not, see
25 <http://www.gnu.org/licenses/>.
26 -------------------------------------------------------------------------*/
27 #pragma once
28 
30 {
35 };
36 
37 // NeoTopology -
38 //
39 // T_LAYOUT - the following classes and their rotated variants
40 // RowMajorLayout
41 // ColumnMajorLayout
42 // RowMajorAlternatingLayout
43 // ColumnMajorAlternatingLayout
44 //
45 template <typename T_LAYOUT> class NeoTopology
46 {
47 public:
48  NeoTopology(uint16_t width, uint16_t height) :
49  _width(width),
50  _height(height)
51  {
52 
53  }
54 
55  uint16_t Map(int16_t x, int16_t y) const
56  {
57  if (x >= static_cast<int16_t>(_width))
58  {
59  x = _width - 1;
60  }
61  else if (x < 0)
62  {
63  x = 0;
64  }
65  if (y >= static_cast<int16_t>(_height))
66  {
67  y = _height - 1;
68  }
69  else if (y < 0)
70  {
71  y = 0;
72  }
73  return T_LAYOUT::Map(_width, _height, x, y);
74  }
75 
76  uint16_t MapProbe(int16_t x, int16_t y) const
77  {
78  if (x < 0 || x >= _width || y < 0 || y >= _height)
79  {
80  return _width * _height; // count, out of bounds
81  }
82  return T_LAYOUT::Map(_width, _height, x, y);
83  }
84 
85  uint16_t getWidth() const
86  {
87  return _width;
88  }
89 
90  uint16_t getHeight() const
91  {
92  return _height;
93  }
94 
95 private:
96  const uint16_t _width;
97  const uint16_t _height;
98 };
NeoTopologyHint
Definition: NeoTopology.h:30
@ NeoTopologyHint_LastOnPanel
Definition: NeoTopology.h:33
@ NeoTopologyHint_OutOfBounds
Definition: NeoTopology.h:34
@ NeoTopologyHint_InPanel
Definition: NeoTopology.h:32
@ NeoTopologyHint_FirstOnPanel
Definition: NeoTopology.h:31
Definition: NeoTopology.h:46
uint16_t MapProbe(int16_t x, int16_t y) const
Definition: NeoTopology.h:76
uint16_t Map(int16_t x, int16_t y) const
Definition: NeoTopology.h:55
uint16_t getWidth() const
Definition: NeoTopology.h:85
uint16_t getHeight() const
Definition: NeoTopology.h:90
NeoTopology(uint16_t width, uint16_t height)
Definition: NeoTopology.h:48