forked from yeemachine/kalidokit
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcalcLegs.test.ts
148 lines (109 loc) · 5.27 KB
/
calcLegs.test.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const cloneDeep = require("lodash.clonedeep")
import { calcLegs } from "../src/PoseSolver/calcLegs"
import poseWorldLandmarks from "./poseWorlLandmarks"
import { Results } from "../src/Types"
import { offsets } from "../src/PoseSolver/calcLegs"
let worldLandmarks: Results
const PI = Math.PI
describe("should resolve the correct upper leg rotation for", () => {
beforeEach(() => {
worldLandmarks = cloneDeep(poseWorldLandmarks)
})
test("upper left leg, 90 degree forward, up", () => {
worldLandmarks[23] = { x: -0.2, y: 0, z: 0 }
worldLandmarks[24] = { x: 0, y: 0, z: 0 }
worldLandmarks[26] = { x: 0, y: 0, z: -0.4 }
const result = calcLegs(worldLandmarks)
expect(result.UpperLeg.l.x).toBeCloseTo(PI / 2)
expect(result.Unscaled.UpperLeg.l.x).toBeCloseTo(0.5)
expect(result.UpperLeg.l.z).toBeCloseTo((0 - offsets.upperLeg.z))
expect(result.Unscaled.UpperLeg.l.z).toBeCloseTo(0)
})
test("upper left leg, straight down", () => {
worldLandmarks[23] = { x: -0.2, y: 0, z: 0 }
worldLandmarks[24] = { x: 0, y: 0, z: 0 }
worldLandmarks[26] = { x: 0, y: 0.4, z: 0 }
const result = calcLegs(worldLandmarks)
expect(result.UpperLeg.l.x).toBeCloseTo(0)
expect(result.Unscaled.UpperLeg.l.z).toBeCloseTo(0)
expect(result.UpperLeg.l.z).toBeCloseTo((0 - offsets.upperLeg.z))
expect(result.Unscaled.UpperLeg.l.x).toBeCloseTo(-0)
})
test("upper left leg, 90 degree forward, up, 45 degree left", () => {
worldLandmarks[23] = { x: -0.2, y: 0, z: 0 }
worldLandmarks[24] = { x: 0, y: 0, z: 0 }
worldLandmarks[26] = { x: -0.4, y: 0, z: -0.4 }
const result = calcLegs(worldLandmarks)
expect(result.UpperLeg.l.x).toBeCloseTo(PI / 2)
expect(result.Unscaled.UpperLeg.l.x).toBeCloseTo(0.5)
expect(result.UpperLeg.l.z).toBeCloseTo((-PI / 4 - offsets.upperLeg.z))
expect(result.Unscaled.UpperLeg.l.z).toBeCloseTo(-0.25)
})
test("upper right leg, 90 degree forward, up", () => {
worldLandmarks[23] = { x: 0, y: 0, z: 0 }
worldLandmarks[24] = { x: 0.2, y: 0, z: 0 }
worldLandmarks[25] = { x: 0, y: 0, z: -0.4 }
const result = calcLegs(worldLandmarks)
expect(result.UpperLeg.r.x).toBeCloseTo(PI / 2)
expect(result.Unscaled.UpperLeg.r.x).toBeCloseTo(0.5)
expect(result.UpperLeg.r.z).toBeCloseTo(0 + offsets.upperLeg.z)
expect(result.Unscaled.UpperLeg.r.z).toBeCloseTo(0)
})
test("upper right leg, straight down", () => {
worldLandmarks[23] = { x: 0, y: 0, z: 0 }
worldLandmarks[24] = { x: 0.2, y: 0, z: 0 }
worldLandmarks[25] = { x: 0, y: 0.4, z: 0 }
const result = calcLegs(worldLandmarks)
expect(result.UpperLeg.r.x).toBeCloseTo(0)
expect(result.Unscaled.UpperLeg.r.z).toBeCloseTo(0)
expect(result.UpperLeg.r.z).toBeCloseTo((0 + offsets.upperLeg.z))
expect(result.Unscaled.UpperLeg.r.x).toBeCloseTo(0)
})
test("upper right leg, 90 degree forward, up, 45 degree left", () => {
worldLandmarks[23] = { x: 0, y: 0, z: 0 }
worldLandmarks[24] = { x: 0.2, y: 0, z: 0 }
worldLandmarks[25] = { x: 0.4, y: 0, z: -0.4 }
const result = calcLegs(worldLandmarks)
expect(result.UpperLeg.r.x).toBeCloseTo(PI / 2)
expect(result.Unscaled.UpperLeg.r.x).toBeCloseTo(0.5)
expect(result.UpperLeg.r.z).toBeCloseTo((PI / 4 + offsets.upperLeg.z))
expect(result.Unscaled.UpperLeg.r.z).toBeCloseTo(0.25)
})
})
describe("should resolve the correct lower leg rotation for", () => {
beforeEach(() => {
worldLandmarks = cloneDeep(poseWorldLandmarks)
})
test("lower left leg, 90 degree", () => {
worldLandmarks[24] = { x: 0, y: 0, z: 0 }
worldLandmarks[26] = { x: 0, y: 0, z: -0.4 }
worldLandmarks[28] = { x: 0, y: 0.4, z: -0.4 }
const result = calcLegs(worldLandmarks)
expect(result.LowerLeg.l.x).toBeCloseTo(-PI / 2)
expect(result.Unscaled.LowerLeg.l.x).toBeCloseTo(-0.5)
})
test("lower left leg, 45 degree", () => {
worldLandmarks[24] = { x: 0, y: 0, z: 0 }
worldLandmarks[26] = { x: 0, y: 0, z: -0.4 }
worldLandmarks[28] = { x: 0, y: 0.4, z: -0.8 }
const result = calcLegs(worldLandmarks)
expect(result.LowerLeg.l.x).toBeCloseTo(-PI / 4)
expect(result.Unscaled.LowerLeg.l.x).toBeCloseTo(-0.25)
})
test("lower right leg, 90 degree", () => {
worldLandmarks[23] = { x: -0.2, y: 0, z: 0 }
worldLandmarks[25] = { x: 0, y: 0, z: -0.4 }
worldLandmarks[27] = { x: 0, y: 0.4, z: -0.4 }
const result = calcLegs(worldLandmarks)
expect(result.LowerLeg.r.x).toBeCloseTo(-PI / 2)
expect(result.Unscaled.LowerLeg.r.x).toBeCloseTo(-0.5)
})
test("lower right leg, 45 degree", () => {
worldLandmarks[23] = { x: 0, y: 0, z: 0 }
worldLandmarks[25] = { x: 0, y: 0, z: -0.4 }
worldLandmarks[27] = { x: 0, y: 0.4, z: -0.8 }
const result = calcLegs(worldLandmarks)
expect(result.LowerLeg.r.x).toBeCloseTo(-PI / 4)
expect(result.Unscaled.LowerLeg.r.x).toBeCloseTo(-0.25)
})
})