-
Notifications
You must be signed in to change notification settings - Fork 0
/
se1.ts
52 lines (43 loc) · 866 Bytes
/
se1.ts
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
export type SE1 = {
scale: number,
translate: number,
}
export function apply(a: SE1, x: number): number {
return a.scale * x + a.translate;
}
export function compose(a: SE1, b: SE1): SE1 {
return {
scale: a.scale * b.scale,
translate: a.scale * b.translate + a.translate,
}
}
export function composen(...xforms: SE1[]): SE1 {
return xforms.reduce(compose);
}
export function inverse(a: SE1): SE1 {
return {
scale: 1 / a.scale,
translate: -a.translate / a.scale,
}
}
export function ident(): SE1 {
return {
scale: 1,
translate: 0,
}
}
export function translate(p: number): SE1 {
return {
scale: 1,
translate: p,
}
}
export function scale(p: number): SE1 {
return {
scale: p,
translate: 0,
}
}
export function mkSE1(scale: number, translate: number): SE1 {
return { scale, translate };
}