CAffine2d.h
Go to the documentation of this file.
1 #ifndef i2d_CAffine2d_included
2 #define i2d_CAffine2d_included
3 
4 
5 // ACF includes
6 #include <i2d/CVector2d.h>
7 #include <i2d/CMatrix2d.h>
8 
9 
10 namespace i2d
11 {
12 
13 
17 class CAffine2d
18 {
19 public:
23  CAffine2d();
24 
28  CAffine2d(const CAffine2d& transform);
29 
33  explicit CAffine2d(const CMatrix2d& deform, const CVector2d& translation = CVector2d(0.0, 0.0));
34 
38  explicit CAffine2d(const CVector2d& translation);
39 
43  const CVector2d& GetTranslation() const;
44 
48  void SetTranslation(const CVector2d& translation);
49 
53  const CMatrix2d& GetDeformMatrix() const;
54 
58  void SetDeformMatrix(const CMatrix2d& deform);
59 
60  // internal access operations
61 
66 
71 
72  // init operations
73 
77  void Reset();
78 
82  void Reset(const CVector2d& translation);
83 
87  void Reset(const CVector2d& translation, double angle, double scale = 1.0);
88 
92  void Reset(const CVector2d& translation, double angle, const CVector2d& scale);
93 
97  CVector2d GetApply(const CVector2d& position) const;
98 
102  void GetApply(const CVector2d& position, CVector2d& result) const;
103 
108  CVector2d GetApplyToDelta(const CVector2d& delta) const;
109 
114  void GetApplyToDelta(const CVector2d& delta, CVector2d& result) const;
115 
121  CAffine2d GetApply(const CAffine2d& transform) const;
122 
128  void GetApply(const CAffine2d& transform, CAffine2d& result) const;
129 
134  void Apply(const CAffine2d& transform);
135 
140  void ApplyLeft(const CAffine2d& transform);
141 
145  CVector2d GetInvertedApply(const CVector2d& position) const;
146 
150  bool GetInvertedApply(const CVector2d& position, CVector2d& result) const;
151 
155  CAffine2d GetTranslated(const CVector2d& delta) const;
156 
160  void GetTranslated(const CVector2d& delta, CAffine2d& result) const;
161 
165  void Translate(const CVector2d& delta);
166 
170  CAffine2d GetInverted() const;
171 
175  bool GetInverted(CAffine2d& result) const;
176 
180  bool Serialize(iser::IArchive& archive);
181 
182  // operators
183  bool operator==(const CAffine2d& transform) const;
184  bool operator!=(const CAffine2d& transform) const;
185  CAffine2d& operator=(const CAffine2d& transform);
186 
187  // static methods
188  static const CAffine2d& GetIdentity();
189 
190 private:
191  CVector2d m_translation;
192  CMatrix2d m_deformMatrix;
193 
194  // static members
195  static CAffine2d s_identity;
196 };
197 
198 
199 // inline methods
200 
202 : m_translation(0.0, 0.0),
203  m_deformMatrix(CMatrix2d::GetIdentity())
204 {
205 }
206 
207 
208 inline CAffine2d::CAffine2d(const CAffine2d& transform)
209 : m_translation(transform.m_translation),
210  m_deformMatrix(transform.m_deformMatrix)
211 {
212 }
213 
214 
215 // access to members
216 
218 {
219  return m_translation;
220 }
221 
222 
223 inline void CAffine2d::SetTranslation(const CVector2d& translation)
224 {
225  m_translation = translation;
226 }
227 
228 
230 {
231  return m_deformMatrix;
232 }
233 
234 
235 inline void CAffine2d::SetDeformMatrix(const CMatrix2d& deform)
236 {
237  m_deformMatrix = deform;
238 }
239 
240 
241 // internal access operations
242 
244 {
245  return m_translation;
246 }
247 
248 
250 {
251  return m_deformMatrix;
252 }
253 
254 
255 // operations
256 
257 inline CVector2d CAffine2d::GetApply(const CVector2d& position) const
258 {
259  CVector2d result;
260  m_deformMatrix.GetMultiplied(position, result);
261 
262  return result + m_translation;
263 }
264 
265 
266 inline void CAffine2d::GetApply(const CVector2d& position, CVector2d& result) const
267 {
268  m_deformMatrix.GetMultiplied(position, result);
269  result += m_translation;
270 }
271 
272 
274 {
275  CVector2d retVal;
276 
277  m_deformMatrix.GetMultiplied(delta, retVal);
278 
279  return retVal;
280 }
281 
282 
283 inline void CAffine2d::GetApplyToDelta(const CVector2d& delta, CVector2d& result) const
284 {
285  m_deformMatrix.GetMultiplied(delta, result);
286 }
287 
288 
289 inline CAffine2d CAffine2d::GetTranslated(const CVector2d& vector) const
290 {
291  return CAffine2d(m_deformMatrix, m_translation + vector);
292 }
293 
294 
295 inline void CAffine2d::GetTranslated(const CVector2d& vector, CAffine2d& result) const
296 {
297  result.GetDeformMatrixRef() = m_deformMatrix;
298  result.GetTranslationRef() = m_translation + vector;
299 }
300 
301 
302 inline void CAffine2d::Translate(const CVector2d& vector)
303 {
304  m_translation += vector;
305 }
306 
307 
308 inline CVector2d CAffine2d::GetInvertedApply(const CVector2d& position) const
309 {
310  CVector2d result;
311 
312  GetInvertedApply(position, result);
313 
314  return result;
315 }
316 
317 
319 {
320  CAffine2d result;
321 
322  GetInverted(result);
323 
324  return result;
325 }
326 
327 
328 // operators
329 
330 inline bool CAffine2d::operator==(const CAffine2d& transform) const
331 {
332  return (m_translation == transform.m_translation) && (m_deformMatrix == transform.m_deformMatrix);
333 }
334 
335 
336 inline bool CAffine2d::operator!=(const CAffine2d& transform) const
337 {
338  return (m_translation != transform.m_translation) || (m_deformMatrix != transform.m_deformMatrix);
339 }
340 
341 
342 // static methods
343 
345 {
346  return s_identity;
347 }
348 
349 
350 } // namespace i2d
351 
352 
353 #endif // !i2d_CAffine2d_included
354 
355 
bool Serialize(iser::IArchive &archive)
Serialize transformation parameters into/from archive.
CVector2d GetMultiplied(const CVector2d &position) const
Definition: CMatrix2d.h:177
CVector2d GetApplyToDelta(const CVector2d &delta) const
Get difference vector after this transformation.
Definition: CAffine2d.h:273
CVector2d & GetTranslationRef()
Get internal reference to the translation vector.
Definition: CAffine2d.h:243
const CVector2d & GetTranslation() const
Get translation part of this affine transformation.
Definition: CAffine2d.h:217
CAffine2d GetInverted() const
Get inverted transformation.
Definition: CAffine2d.h:318
void SetTranslation(const CVector2d &translation)
Set translation part of this affine transformation.
Definition: CAffine2d.h:223
void SetDeformMatrix(const CMatrix2d &deform)
Set rotation, skew and scale part of this affine transformation.
Definition: CAffine2d.h:235
const CMatrix2d & GetDeformMatrix() const
Get rotation, skew and scale part of this affine transformation.
Definition: CAffine2d.h:229
void Apply(const CAffine2d &transform)
Combine this transformation with another transformation.
CAffine2d & operator=(const CAffine2d &transform)
CMatrix2d & GetDeformMatrixRef()
Get internal reference to the transformation matrix.
Definition: CAffine2d.h:249
bool operator==(const CAffine2d &transform) const
Definition: CAffine2d.h:330
void ApplyLeft(const CAffine2d &transform)
Combine this transformation with another transformation on the left side.
Represent input/output persistence archive.
Definition: IArchive.h:30
bool operator!=(const CAffine2d &transform) const
Definition: CAffine2d.h:336
2D matrix.
Definition: CMatrix2d.h:18
CVector2d GetInvertedApply(const CVector2d &position) const
Inverted operation to GetApply().
Definition: CAffine2d.h:308
Definition of position or mathematical vector on 2D plane.
Definition: CVector2d.h:28
CAffine2d()
Constructor, parameters will be not initialized.
Definition: CAffine2d.h:201
void Translate(const CVector2d &delta)
Combine this transformation with translation.
Definition: CAffine2d.h:302
static const CAffine2d & GetIdentity()
Definition: CAffine2d.h:344
CVector2d GetApply(const CVector2d &position) const
Calculate transformed position.
Definition: CAffine2d.h:257
This class defines an affine 2D-transformation.
Definition: CAffine2d.h:17
void Reset()
Set to identity transformation.
CAffine2d GetTranslated(const CVector2d &delta) const
Get some transformation combined with translation.
Definition: CAffine2d.h:289

© 2007-2017 Witold Gantzke and Kirill Lepskiy