15832144755
2022-01-06 7b4c8991dca9cf2a809a95e239d144697d3afb56
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { HermiteSpline } from "../../Source/Cesium.js";
import { Spline } from "../../Source/Cesium.js";
 
describe("Core/Spline", function () {
  it("contructor throws", function () {
    expect(function () {
      return new Spline();
    }).toThrowDeveloperError();
  });
 
  it("wraps time that is out-of-bounds", function () {
    var spline = HermiteSpline.createNaturalCubic({
      points: [Cartesian3.ZERO, Cartesian3.UNIT_X, Cartesian3.UNIT_Y],
      times: [0.0, 1.0, 2.0],
    });
 
    expect(spline.wrapTime(-0.5)).toEqual(1.5);
    expect(spline.wrapTime(2.5)).toEqual(0.5);
  });
 
  it("clamps time that is out-of-bounds", function () {
    var spline = HermiteSpline.createNaturalCubic({
      points: [Cartesian3.ZERO, Cartesian3.UNIT_X, Cartesian3.UNIT_Y],
      times: [0.0, 1.0, 2.0],
    });
 
    expect(spline.clampTime(-0.5)).toEqual(0.0);
    expect(spline.clampTime(2.5)).toEqual(2.0);
  });
 
  it("wrapTime throws without a time", function () {
    var spline = HermiteSpline.createNaturalCubic({
      points: [Cartesian3.ZERO, Cartesian3.UNIT_X, Cartesian3.UNIT_Y],
      times: [0.0, 1.0, 2.0],
    });
 
    expect(function () {
      spline.wrapTime();
    }).toThrowDeveloperError();
  });
 
  it("clampTime throws without a time", function () {
    var spline = HermiteSpline.createNaturalCubic({
      points: [Cartesian3.ZERO, Cartesian3.UNIT_X, Cartesian3.UNIT_Y],
      times: [0.0, 1.0, 2.0],
    });
 
    expect(function () {
      spline.clampTime();
    }).toThrowDeveloperError();
  });
 
  it("findTimeInterval throws without a time", function () {
    var spline = HermiteSpline.createNaturalCubic({
      points: [Cartesian3.ZERO, Cartesian3.UNIT_X, Cartesian3.UNIT_Y],
      times: [0.0, 1.0, 2.0],
    });
 
    expect(function () {
      spline.findTimeInterval();
    }).toThrowDeveloperError();
  });
 
  it("findTimeInterval throws when time is out of range", function () {
    var spline = HermiteSpline.createNaturalCubic({
      points: [Cartesian3.ZERO, Cartesian3.UNIT_X, Cartesian3.UNIT_Y],
      times: [0.0, 1.0, 2.0],
    });
 
    expect(function () {
      spline.findTimeInterval(4.0);
    }).toThrowDeveloperError();
  });
 
  it("findTimeInterval", function () {
    var spline = HermiteSpline.createNaturalCubic({
      points: [
        Cartesian3.ZERO,
        Cartesian3.UNIT_X,
        Cartesian3.UNIT_Y,
        Cartesian3.UNIT_Z,
      ],
      times: [0.0, 1.0, 2.0, 4.0],
    });
    var times = spline.times;
 
    expect(spline.findTimeInterval(times[0])).toEqual(0);
 
    // jump forward
    expect(spline.findTimeInterval(times[1])).toEqual(1);
 
    // jump backward
    expect(spline.findTimeInterval(times[0], 1)).toEqual(0);
 
    // jump far forward
    expect(spline.findTimeInterval(times[times.length - 2], 0)).toEqual(
      times.length - 2
    );
 
    // jump far back
    expect(spline.findTimeInterval(times[0], times.length - 1)).toEqual(0);
  });
});