Debian Codegraph @

wxcrafter/src/xy_pair.cpp

raw
1 #include "xy_pair.h"
2 #include "wxgui_helpers.h"
3
4 XYPair::XYPair(const wxString& str, int defaultx, int defaulty)
5 : m_string(str)
6 , m_x(defaultx)
7 , m_y(defaulty)
8 {
9 m_string.Trim().Trim(false);
10 if(m_string.StartsWith(wxT("("))) m_string.Remove(0, 1);
11
12 if(m_string.EndsWith(wxT(")"))) m_string.RemoveLast();
13
14 wxString strx = m_string.BeforeFirst(wxT(','));
15 wxString stry = m_string.AfterFirst(wxT(','));
16
17 strx.Trim().Trim(false);
18 stry.Trim().Trim(false);
19
20 m_x = wxCrafter::ToNumber(strx, defaultx);
21 m_y = wxCrafter::ToNumber(stry, defaulty);
22 }
23
24 XYPair::XYPair(int x, int y)
25 : m_x(x)
26 , m_y(y)
27 {
28 m_string = ToString(false);
29 }
30
31 XYPair::~XYPair() {}
32
33 wxString XYPair::ToString(bool withBraces) const
34 {
35 wxString str;
36 str << m_x << wxT(",") << m_y;
37 if(withBraces) { str.Prepend(wxT("(")).Append(wxT(")")); }
38 return str;
39 }
40
41 bool XYPair::operator>(const XYPair& xy) const
42 {
43 if(GetX() == xy.GetX()) {
44 return GetY() > xy.GetY();
45
46 } else {
47 return GetX() > xy.GetX();
48 }
49 }
50
51 bool XYPair::operator==(const XYPair& xy) const { return GetX() == xy.GetX() && GetY() == xy.GetY(); }
52
53 bool XYPair::operator!=(const XYPair& xy) const { return !(*this == xy); }