File: GembloQTransform.cpp

package info (click to toggle)
pentobi 29.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 3,892 kB
  • sloc: cpp: 25,719; javascript: 875; xml: 40; makefile: 13; sh: 6
file content (138 lines) | stat: -rw-r--r-- 3,174 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
//-----------------------------------------------------------------------------
/** @file libpentobi_base/GembloQTransform.cpp
    @author Markus Enzenberger
    @copyright GNU General Public License version 3 or later */
//-----------------------------------------------------------------------------

#include "GembloQTransform.h"

#include "libboardgame_base/MathUtil.h"

namespace libpentobi_base {

using libboardgame_base::mod;

//-----------------------------------------------------------------------------

namespace
{

/** Divide integer by 2 and round down. */
int div2(int a)
{
    return a < 0 ? (a - 1) / 2 : a / 2;
}

} // namespace

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQIdentity::get_transformed(CoordPoint p) const
{
    return p;
}

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQRot90::get_transformed(CoordPoint p) const
{
    auto y = div2(p.x);
    auto x = -2 * p.y;
    switch (mod(p.x, 4))
    {
    case 0:
    case 3:
        x -= static_cast<int>(p.y % 2 != 0);
        break;
    case 1:
    case 2:
        x -= static_cast<int>(p.y % 2 == 0);
        break;
    }
    return {x, y};
}

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQRot180::get_transformed(CoordPoint p) const
{
    return {-p.x, -p.y};
}

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQRot270::get_transformed(CoordPoint p) const
{
    auto y = -div2(p.x);
    auto x = 2 * p.y;
    switch (mod(p.x, 4))
    {
    case 0:
    case 3:
        x += static_cast<int>(p.y % 2 != 0);
        break;
    case 1:
    case 2:
        x += static_cast<int>(p.y % 2 == 0);
        break;
    }
    return {x, y};
}

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQRefl::get_transformed(CoordPoint p) const
{
    return {-p.x, p.y};
}

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQRot90Refl::get_transformed(CoordPoint p) const
{
    auto y = -div2(p.x);
    auto x = -2 * p.y;
    switch (mod(p.x, 4))
    {
    case 0:
    case 3:
        x -= static_cast<int>(p.y % 2 != 0);
        break;
    case 1:
    case 2:
        x -= static_cast<int>(p.y % 2 == 0);
        break;
    }
    return {x, y};
}

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQRot180Refl::get_transformed(CoordPoint p) const
{
    return {p.x, -p.y};
}

//-----------------------------------------------------------------------------

CoordPoint TransfGembloQRot270Refl::get_transformed(CoordPoint p) const
{
    auto y = div2(p.x);
    auto x = 2 * p.y;
    switch (mod(p.x, 4))
    {
    case 0:
    case 3:
        x += static_cast<int>(p.y % 2 != 0);
        break;
    case 1:
    case 2:
        x += static_cast<int>(p.y % 2 == 0);
        break;
    }
    return {x, y};
}

//-----------------------------------------------------------------------------

} // namespace libpentobi_base