ASPiK SDK
cpoint.h
1 // This file is part of VSTGUI. It is subject to the license terms
2 // in the LICENSE file found in the top-level directory of this
3 // distribution and at http://github.com/steinbergmedia/vstgui/LICENSE
4 
5 #ifndef __cpoint__
6 #define __cpoint__
7 
8 #include "vstguibase.h"
9 #include <cmath>
10 
11 namespace VSTGUI {
12 struct CRect;
13 
14 //-----------------------------------------------------------------------------
16 //-----------------------------------------------------------------------------
17 struct CPoint
18 {
19  CPoint () = default;
20  CPoint (CCoord x, CCoord y) : x (x), y (y) {}
21  CPoint& operator () (CCoord _x, CCoord _y) { x = _x; y = _y; return *this; }
22 
23  bool operator!= (const CPoint &other) const { return (x != other.x || y != other.y); }
24  bool operator== (const CPoint &other) const { return (x == other.x && y == other.y); }
25 
26  CPoint& operator+= (const CPoint& other) { x += other.x; y += other.y; return *this; }
27  CPoint& operator-= (const CPoint& other) { x -= other.x; y -= other.y; return *this; }
28  CPoint operator+ (const CPoint& other) const { return CPoint (x + other.x, y + other.y); }
29  CPoint operator- (const CPoint& other) const { return CPoint (x - other.x, y - other.y); }
30  CPoint operator- () const { return CPoint (-x, -y); }
31 
32  CPoint& offset (const CCoord c) { *this += CPoint (c, c); return *this; }
33  CPoint& offset (const CCoord _x, const CCoord _y) { *this += CPoint (_x, _y); return *this; }
34  CPoint& offset (const CPoint& other) { *this += other; return *this; }
35  CPoint& offsetInverse (const CPoint& other) { *this -= other; return *this; }
36 
37  inline CPoint& makeIntegral ();
38 
39  CCoord x {0.};
40  CCoord y {0.};
41 };
42 
43 //-----------------------------------------------------------------------------
44 inline CPoint& CPoint::makeIntegral ()
45 {
46  x = std::floor (x + 0.5);
47  y = std::floor (y + 0.5);
48  return *this;
49 }
50 
51 
52 } // namespace
53 
54 #endif
Definition: customcontrols.cpp:8
Point structure.
Definition: cpoint.h:17