@@ -8,77 +8,87 @@ namespace microcode {
8
8
* Affine transformations can be chained thru the `parent` property, in which case `worldPos` will report the composed value.
9
9
*/
10
10
export class Affine {
11
- private localPos_ : Vec2 ;
12
- private parent_ : Affine ;
13
- private dirty_ : boolean ;
14
- private worldPos_ : Vec2 ;
15
- public tag : string ;
11
+ private localPos_ : Vec2
12
+ private parent_ : Affine
13
+ private dirty_ : boolean
14
+ private worldPos_ : Vec2
15
+ public tag : string
16
16
17
17
//% blockCombine block="dirty" callInDebugger
18
18
public get dirty ( ) : boolean {
19
- return this . dirty_ || this . localPos_ . dirty || ( this . parent && this . parent . dirty ) ;
19
+ return (
20
+ this . dirty_ ||
21
+ this . localPos_ . dirty ||
22
+ ( this . parent && this . parent . dirty )
23
+ )
20
24
}
21
25
22
26
//% blockCombine block="worldPos" callInDebugger
23
27
public get worldPos ( ) {
24
- if ( this . dirty ) { this . recalc ( ) ; }
25
- return this . worldPos_ ;
28
+ if ( this . dirty ) {
29
+ this . recalc ( )
30
+ }
31
+ return this . worldPos_
26
32
}
27
33
28
34
//% blockCombine block="localPos" callInDebugger
29
- public get localPos ( ) : Vec2 { return this . localPos_ ; }
35
+ public get localPos ( ) : Vec2 {
36
+ return this . localPos_
37
+ }
30
38
public set localPos ( v : Vec2 ) {
31
- this . localPos_ . copyFrom ( v ) ;
32
- this . dirty_ = true ;
39
+ this . localPos_ . copyFrom ( v )
40
+ this . dirty_ = true
33
41
}
34
42
35
43
//% blockCombine block="parent" callInDebugger
36
- public get parent ( ) { return this . parent_ ; }
44
+ public get parent ( ) {
45
+ return this . parent_
46
+ }
37
47
public set parent ( p : Affine ) {
38
- this . parent_ = p ;
39
- this . dirty_ = true ;
48
+ this . parent_ = p
49
+ this . dirty_ = true
40
50
}
41
51
42
52
//% blockCombine block="root" callInDebugger
43
- public get root ( ) {
44
- let node = this . parent ;
53
+ public get root ( ) {
54
+ let node = this . parent
45
55
while ( node && node . parent ) {
46
- node = node . parent ;
56
+ node = node . parent
47
57
}
48
- return node ;
58
+ return node
49
59
}
50
60
51
61
constructor ( ) {
52
- this . localPos_ = new Vec2 ( ) ;
53
- this . worldPos_ = new Vec2 ( ) ;
54
- this . dirty_ = true ;
62
+ this . localPos_ = new Vec2 ( )
63
+ this . worldPos_ = new Vec2 ( )
64
+ this . dirty_ = true
55
65
}
56
66
57
67
public copyFrom ( src : Affine ) : this {
58
- this . localPos . copyFrom ( src . localPos ) ;
59
- return this ;
68
+ this . localPos . copyFrom ( src . localPos )
69
+ return this
60
70
}
61
71
62
72
public clone ( ) : Affine {
63
- const aff = new Affine ( ) ;
64
- aff . copyFrom ( this ) ;
65
- return aff ;
73
+ const aff = new Affine ( )
74
+ aff . copyFrom ( this )
75
+ return aff
66
76
}
67
77
68
78
public recalc ( force = false ) {
69
79
if ( this . dirty || force ) {
70
- this . dirty_ = false ;
80
+ this . dirty_ = false
71
81
if ( this . parent ) {
72
- const ppos = this . parent . worldPos ;
73
- Vec2 . TranslateToRef ( this . localPos_ , ppos , this . worldPos_ ) ;
82
+ const ppos = this . parent . worldPos
83
+ Vec2 . TranslateToRef ( this . localPos_ , ppos , this . worldPos_ )
74
84
} else {
75
- this . worldPos_ . copyFrom ( this . localPos ) ;
85
+ this . worldPos_ . copyFrom ( this . localPos )
76
86
}
77
87
}
78
88
}
79
89
80
90
public transformToRef ( v : Vec2 , ref : Vec2 ) : Vec2 {
81
- return Vec2 . TranslateToRef ( ref , this . worldPos , ref ) ;
91
+ return Vec2 . TranslateToRef ( ref , this . worldPos , ref )
82
92
}
83
93
}
84
- }
94
+ }
0 commit comments