yzt
2023-05-26 de4278af2fd46705a40bac58ec01122db6b7f3d7
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { Particle } from "../../Source/Cesium.js";
import { SphereEmitter } from "../../Source/Cesium.js";
 
describe("Scene/SphereEmitter", function () {
  var emitter;
 
  it("default constructor", function () {
    emitter = new SphereEmitter();
    expect(emitter.radius).toEqual(1.0);
  });
 
  it("constructor", function () {
    emitter = new SphereEmitter(5.0);
    expect(emitter.radius).toEqual(5.0);
  });
 
  it("constructor throws with invalid radius", function () {
    expect(function () {
      emitter = new SphereEmitter(0.0);
    }).toThrowDeveloperError();
    expect(function () {
      emitter = new SphereEmitter(-1.0);
    }).toThrowDeveloperError();
  });
 
  it("radius setter", function () {
    emitter = new SphereEmitter();
    emitter.radius = 5.0;
    expect(emitter.radius).toEqual(5.0);
  });
 
  it("radius setter throws with invalid value", function () {
    emitter = new SphereEmitter();
    expect(function () {
      emitter.radius = undefined;
    }).toThrowDeveloperError();
    expect(function () {
      emitter.radius = 0.0;
    }).toThrowDeveloperError();
    expect(function () {
      emitter.radius = -1.0;
    }).toThrowDeveloperError();
  });
 
  it("emits", function () {
    emitter = new SphereEmitter(5.0);
    var particle = new Particle();
 
    for (var i = 0; i < 1000; ++i) {
      emitter.emit(particle);
      expect(Cartesian3.magnitude(particle.position)).toBeLessThanOrEqualTo(
        emitter.radius
      );
      expect(particle.velocity).toEqual(
        Cartesian3.normalize(particle.position, new Cartesian3())
      );
    }
  });
});