-
Notifications
You must be signed in to change notification settings - Fork 1
/
Navigation.cs
100 lines (95 loc) · 2.92 KB
/
Navigation.cs
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
using System;
namespace coil{
public static class Navigation{
public static (int,int) Add((int,int) start, Dir dir){
var x = start.Item1;
var y = start.Item2;
switch (dir){
case Dir.Up:
return (x,y-1);
case Dir.Right:
return (x+1,y);
case Dir.Down:
return (x,y+1);
case Dir.Left:
return (x-1,y);
default:
throw new Exception("x");
}
}
public static Dir Rot(Dir dir){
switch (dir){
case Dir.Up:
return Dir.Right;
case Dir.Right:
return Dir.Down;
case Dir.Down:
return Dir.Left;
case Dir.Left:
return Dir.Up;
default:
throw new Exception("x");
}
}
public static Dir ARot(Dir dir){
switch (dir){
case Dir.Up:
return Dir.Left;
case Dir.Right:
return Dir.Up;
case Dir.Down:
return Dir.Right;
case Dir.Left:
return Dir.Down;
default:
throw new Exception("x");
}
}
public static (int,int) Add((int,int) start, Dir dir, int n, bool allowZero = false){
if (allowZero)
{
if (n < 0)
{
throw new Exception("Invalid n");
}
}
else
{
if (n < 1)
{
throw new Exception("Invalid n");
}
}
var x = start.Item1;
var y = start.Item2;
switch (dir){
case Dir.Up:
return (x,y-n);
case Dir.Right:
return (x+n,y);
case Dir.Down:
return (x,y+n);
case Dir.Left:
return (x-n,y);
default:
throw new Exception("x");
}
}
public static (int,int) GetEnd(Seg seg){
var x = seg.Start.Item1;
var y = seg.Start.Item2;
switch (seg.Dir){
case Dir.Up:
return (x, y-seg.Len);
case Dir.Right:
return (x+seg.Len, y);
case Dir.Down:
return (x, y+seg.Len);
case Dir.Left:
return (x-seg.Len, y);
default:
throw new Exception("Bad seg dir.");
}
}
}
}