ACF $AcfVersion:0$
CIndex2d.h
Go to the documentation of this file.
1// SPDX-License-Identifier: LGPL-2.1-or-later OR GPL-2.0-or-later OR GPL-3.0-or-later OR LicenseRef-ACF-Commercial
2#pragma once
3
4
5// Qt includes
6#include <QtCore/QPoint>
7#include <QtCore/QSize>
8
9// ACF includes
10#include <istd/TIndex.h>
11
12
13namespace istd
14{
15
16
20class CIndex2d: public TIndex<2>
21{
22public:
24
25 CIndex2d();
26 CIndex2d(int x, int y);
27 CIndex2d(const TIndex<2>& index);
28 CIndex2d(const QPoint& point);
29 CIndex2d(const QSize& size);
30
31 int GetX() const;
32 void SetX(int value);
33 int GetY() const;
34 void SetY(int value);
35
36 bool operator<(const CIndex2d& index) const;
37 bool operator>(const CIndex2d& index) const;
38 bool operator<=(const CIndex2d& index) const;
39 bool operator>=(const CIndex2d& index) const;
40
44 operator QSize() const;
45
49 operator QPoint() const;
50
54 operator QPointF() const;
55
59 CIndex2d& operator=(const TIndex<2>& index);
60};
61
62
63// inline methods
64
66{
67}
68
69
70inline CIndex2d::CIndex2d(int x, int y)
71{
72 SetAt(0, x);
73 SetAt(1, y);
74}
75
76
77inline CIndex2d::CIndex2d(const TIndex<2>& index)
78: BaseClass(index)
79{
80}
81
82inline CIndex2d::CIndex2d(const QPoint& point)
83{
84 SetAt(0, point.x());
85 SetAt(1, point.y());
86}
87
88
89inline CIndex2d::CIndex2d(const QSize& size)
90{
91 SetAt(0, size.width());
92 SetAt(1, size.height());
93}
94
95
96inline int CIndex2d::GetX() const
97{
98 return GetAt(0);
99}
100
101
102inline void CIndex2d::SetX(int value)
103{
104 SetAt(0, value);
105}
106
107
108inline int CIndex2d::GetY() const
109{
110 return GetAt(1);
111}
112
113
114inline void CIndex2d::SetY(int value)
115{
116 SetAt(1, value);
117}
118
119
120inline bool CIndex2d::operator<(const CIndex2d& index) const
121{
122 if (GetY() < index.GetY()){
123 return true;
124 }
125 else if (GetY() > index.GetY()){
126 return false;
127 }
128 else if (GetX() < index.GetX()){
129 return true;
130 }
131
132 return false;
133}
134
135
136inline bool CIndex2d::operator>(const CIndex2d& index) const
137{
138 return (!operator<(index) && !operator==(index));
139}
140
141
142inline bool CIndex2d::operator<=(const CIndex2d& index) const
143{
144 return (operator<(index) || operator==(index));
145}
146
147
148inline bool CIndex2d::operator>=(const CIndex2d& index) const
149{
150 return (!operator<(index) || operator==(index));
151}
152
153
155{
157
158 return *this;
159}
160
161
162inline CIndex2d::operator QSize() const
163{
164 return QSize(GetX(), GetY());
165}
166
167
168inline CIndex2d::operator QPoint() const
169{
170 return QPoint(GetX(), GetY());
171}
172
173
174inline CIndex2d::operator QPointF() const
175{
176 return QPointF(GetX(), GetY());
177}
178
179
180} // namespace istd
181
182
183
184
Index implementation for addressing elements in 2D-space.
Definition CIndex2d.h:21
bool operator>=(const CIndex2d &index) const
Definition CIndex2d.h:148
CIndex2d & operator=(const TIndex< 2 > &index)
Assign value from a general defined 2D-index.
Definition CIndex2d.h:154
int GetX() const
Definition CIndex2d.h:96
bool operator<=(const CIndex2d &index) const
Definition CIndex2d.h:142
bool operator>(const CIndex2d &index) const
Definition CIndex2d.h:136
void SetY(int value)
Definition CIndex2d.h:114
int GetY() const
Definition CIndex2d.h:108
void SetX(int value)
Definition CIndex2d.h:102
TIndex< 2 > BaseClass
Definition CIndex2d.h:23
bool operator<(const CIndex2d &index) const
Definition CIndex2d.h:120
Multidimensional index used to addressing fixed-size array.
Definition TIndex.h:18
void SetAt(int index, int value)
Set element at specified index.
Definition TIndex.h:279
int GetAt(int index) const
Get element stored at specified index.
Definition TIndex.h:269
TIndex & operator=(const TIndex &index)=default
Standard library.
Definition IComponent.h:17