-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadjacency.rkt
35 lines (31 loc) · 1.09 KB
/
adjacency.rkt
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
#lang typed/racket
(require "flvector3.rkt"
"quaternion.rkt"
"discrete-algebra.rkt")
(provide closest-tile
adjacent-tiles)
(define closest-tile
(λ ([tile-center : (-> Integer FlVector)]
[tile-rotation : (-> Integer quaternion)])
(λ ([tile-range : (Listof Integer)]
[v : FlVector])
(argmin (λ ([n : Integer])
(flvector3-distance-squared
(quaternion-vector-product (tile-rotation n) v)
(tile-center n)))
tile-range))))
(define adjacent-tiles
(λ ([tile-range : (Listof Integer)]
[tile-normal : (-> Integer (Vectorof Integer))]
[tile-position : (-> Integer (Vectorof Integer))])
(λ ([n : Integer])
(let ([neighbours?
(λ ([k : Integer])
(>= (if (equal? (tile-normal k)
(tile-normal n))
1
0)
(discrete-vector-distance
(tile-position k)
(tile-position n))))])
(filter neighbours? tile-range)))))