-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtransform.exs
More file actions
47 lines (43 loc) · 1.09 KB
/
transform.exs
File metadata and controls
47 lines (43 loc) · 1.09 KB
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
defmodule Transform do
def calculate do
origin = {3, 3}
[
{:n_nw, {-1, 2}, {2, 1}},
{:nw_w, {-1, 2}, {1, 2}},
{:w_sw, {-1, 2}, {1, 4}},
{:sw_s, {-1, 2}, {2, 5}},
{:s_se, {-1, 2}, {4, 5}},
{:se_e, {-1, 2}, {5, 4}},
{:e_ne, {-1, 2}, {5, 2}},
{:ne_n, {-1, 2}, {4, 1}}
]
|> Enum.map(fn({direction, {local_x, local_y}, {global_x, global_y}}) ->
{origin_x, origin_y} = origin
[
{1, 0, 0, -1},
{-1, 0, 0, 1},
{-1, 0, 0, -1},
{0, 1, -1, 0},
{0, -1, -1, 0},
{0, 1, 1, 0},
{0, -1, 1, 0},
{1, 0, 0, 1}
]
|> Enum.find(fn({xx, xy, yx, yy} = transformation) ->
{test_x, test_y} = {
(origin_x + (local_x * xx) + (local_y * xy)),
(origin_y + (local_x * yx) + (local_y * yy)),
}
if test_x == global_x and test_y == global_y do
IO.inspect({
direction,
transformation,
test_x,
test_y
})
end
end)
end)
end
end
Transform.calculate