-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbone.rkt
75 lines (58 loc) · 2.27 KB
/
bone.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
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
#lang racket
;TODO: should unit test this file (specifically the operations)
(provide (all-defined-out))
(require "structs/point.rkt"
"structs/rect.rkt"
"structs/polygon.rkt"
"structs/polygon-tree.rkt"
"string.rkt"
racket/gui/base)
(define bone%
(class object%
(init points)
(init-field
[connections '()] ;connections are only required for when the name of child bones is required (e.g. printing bones, converting to JSON). It is a list of child bones. TODO: we should rename to be more descriptive
[name ""]
[polygon-tree #f])
(super-new)
(set! polygon-tree
(points->root-polygon-tree (vector->list points)))
(define/public (add-connection! bone
point-on-parent
point-on-child
angle)
(set! connections (append connections (list bone)))
(polygon-tree-add-child!
polygon-tree
(get-field polygon-tree bone)
point-on-parent
point-on-child
angle))
(define/public (point-at-index index)
(list-ref (polygon-tree-polygon polygon-tree) index))
(define/public (operation-on-index! op point index)
(set-polygon-tree-polygon! polygon-tree
(list-set
(polygon-tree-polygon polygon-tree)
index
(op
(list-ref (polygon-tree-polygon polygon-tree) index)
point))))
(define/public (operation-on-range! op point start end)
(for ([i (in-range start (+ end 1))])
(operation-on-index! op point i)))
(define/public (operation-on-dimension-of-index! op dimension val index)
(set-polygon-tree-polygon! polygon-tree
(list-set
(polygon-tree-polygon polygon-tree)
index
(operation-on-point-dimension op dimension
(list-ref (polygon-tree-polygon polygon-tree) index)
val))))
(define/public (operation-on-dimension-of-range! op dimension val start end)
(for ([i (in-range start (+ end 1))])
(operation-on-dimension-of-index! op dimension val i)
))
(define/public (scale! x y z)
(scale-root-only-of-polygon-tree! polygon-tree x y z))
))