-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTransform.cpp
69 lines (66 loc) · 1.27 KB
/
Transform.cpp
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
//
// Created by yuanyu on 2018.01.30.
//
#include "Transform.h"
void transform_xy(int& x, int& y, int width, int height, int mode)
{
int val_x;
int val_y;
switch (mode)
{
case 2:
{
val_x = height - 1 - y;
val_y = width - 1 - x;
break;
}
case 3:
{
val_y = width - 1 - x;
val_x = y;
break;
}
case 4:
{
val_x = width - 1 - x;
val_y = y;
break;
}
case 5:
{
val_x = width - 1 - x;
val_y = height - 1 - y;
break;
}
case 6:
{
val_x = y;
val_y = x;
break;
}
case 7:
{
val_x = height - 1 - y;
val_y = x;
break;
}
case 8:
{
val_y = height - 1 - y;
val_x = x;
break;
}
default:
val_x = x;
val_y = y;
}
x = val_x;
y = val_y;
}
int transform_p(int p, int width, int height, int mode)
{
auto new_x = p % width;
auto new_y = p / width;
transform_xy(new_x, new_y, width, height, mode);
return new_x + new_y * width;
}