Skip to content

Commit cd11b75

Browse files
authored
Merge pull request #10 from diffusionstudio/konstantin/fix/remove-degrees-keyframe-option
removed degrees from Keyframe object and unit tests
2 parents 219a606 + 9d0c7ef commit cd11b75

File tree

5 files changed

+6
-42
lines changed

5 files changed

+6
-42
lines changed

src/clips/mixins/visual.decorator.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ describe('The visualize decorator', () => {
555555
expect(clip.view.angle).toBe(93);
556556
expect(angleSpy).toHaveBeenCalledOnce();
557557

558-
clip.rotation = new Keyframe([0, 60], [0, 180], { type: 'degrees' })
558+
clip.rotation = new Keyframe([0, 60], [0, 180])
559559

560560
clip.update(new Timestamp(1000));
561561
expect(clip.view.angle).toBe(90);

src/clips/mixins/visual.deserializers.spec.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ describe('Deserializer1D', () => {
1717
});
1818

1919
it('should desialize Keyframes', () => {
20-
const keyframe = new Keyframe([30, 60], [30, 80], { extrapolate: 'extend', type: 'degrees' });
20+
const keyframe = new Keyframe([30, 60], [30, 80], { extrapolate: 'extend' });
2121
const data = JSON.parse(JSON.stringify(keyframe));
2222

2323
const rot = Deserializer1D.fromJSON(data);
@@ -31,7 +31,7 @@ describe('Deserializer1D', () => {
3131
expect(rot.output[1]).toBe(80);
3232

3333
expect(rot.options.extrapolate).toBe('extend');
34-
expect(rot.options.type).toBe('degrees');
34+
expect(rot.options.type).toBe('number');
3535
});
3636

3737
it('should not desialize functions', () => {
@@ -64,7 +64,7 @@ describe('Deserializer2D', () => {
6464

6565
it('should desialize nested Keyframes', () => {
6666
const keyframes = {
67-
x: new Keyframe([30, 60], [30, 80], { extrapolate: 'extend', type: 'degrees' }),
67+
x: new Keyframe([30, 60], [30, 80], { extrapolate: 'extend' }),
6868
y: new Keyframe([90, 120], ['#000000', '#FFFFFF'], { type: 'color' })
6969
};
7070
const data = JSON.parse(JSON.stringify(keyframes));
@@ -80,7 +80,7 @@ describe('Deserializer2D', () => {
8080
expect(pos.x.output[1]).toBe(80);
8181

8282
expect(pos.x.options.extrapolate).toBe('extend');
83-
expect(pos.x.options.type).toBe('degrees');
83+
expect(pos.x.options.type).toBe('number');
8484

8585
expect(pos.y).toBeInstanceOf(Keyframe);
8686

src/models/keyframe.spec.ts

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -61,37 +61,6 @@ describe('Keyframe', () => {
6161
expect(keyframe1.value(f(18))).toBe('#000000');
6262
});
6363

64-
it('should interpolate degree values correctly', () => {
65-
const keyframe0 = new Keyframe([0, 12], [0, 360 * 2], { type: "degrees" });
66-
expect(keyframe0.value(f(-3))).toBe(0);
67-
expect(keyframe0.value(f(0))).toBe(0);
68-
expect(keyframe0.value(f(3))).toBe(180);
69-
expect(keyframe0.value(f(6))).toBe(0);
70-
expect(keyframe0.value(f(9))).toBe(180);
71-
expect(keyframe0.value(f(12))).toBe(0);
72-
expect(keyframe0.value(f(15))).toBe(0);
73-
74-
const keyframe1 = new Keyframe([6, 12, 18], [180, 360, 360 * 2], { type: "degrees" });
75-
expect(keyframe1.value(f(0))).toBe(180);
76-
expect(keyframe1.value(f(6))).toBe(180);
77-
expect(keyframe1.value(f(9))).toBe(270);
78-
expect(keyframe1.value(f(12))).toBe(0);
79-
expect(keyframe1.value(f(15))).toBe(180);
80-
expect(keyframe1.value(f(18))).toBe(0);
81-
expect(keyframe1.value(f(21))).toBe(0);
82-
});
83-
84-
it('should interpolate degree values correctly with extend', () => {
85-
const keyframe = new Keyframe([0, 12], [0, 360 * 2], { extrapolate: "extend", type: "degrees" });
86-
expect(keyframe.value(f(-3))).toBe(-180);
87-
expect(keyframe.value(f(0))).toBe(0);
88-
expect(keyframe.value(f(3))).toBe(180);
89-
expect(keyframe.value(f(6))).toBe(0);
90-
expect(keyframe.value(f(9))).toBe(180);
91-
expect(keyframe.value(f(12))).toBe(0);
92-
expect(keyframe.value(f(15))).toBe(180);
93-
});
94-
9564
it('should not clamp values when extrapolate is set to "extend"', () => {
9665
const keyframe = new Keyframe([0, 12], [0, 100], { extrapolate: "extend" });
9766
expect(keyframe.value(f(-6))).toBe(-50);

src/models/keyframe.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,6 @@ export class Keyframe<T extends number | string> implements Omit<Serializer, 'id
100100
const easedT = utils.easingFunctions[this.options.easing](t);
101101

102102
if (typeof outputStart === 'number' && typeof outputEnd === 'number') {
103-
if (this.options.type === "degrees") {
104-
const totalDegrees = outputEnd - outputStart;
105-
return (outputStart + totalDegrees * easedT) % 360 as T;
106-
}
107103
return utils.lerp(outputStart, outputEnd, easedT) as T;
108104
}
109105
if (typeof outputStart === 'string' && typeof outputEnd === 'string') {

src/models/keyframe.types.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,9 @@ export type KeyframeOptions = {
2525
* Specifies the type of output values.
2626
* - "number": Output values are numbers.
2727
* - "color": Output values are colors in hex format.
28-
* - "degrees": Output values are angles in degrees.
2928
* @default "number"
3029
*/
31-
type?: "number" | "color" | "degrees";
30+
type?: "number" | "color";
3231

3332
/**
3433
* An optional easing function to apply to the interpolation.

0 commit comments

Comments
 (0)