BoxEmitterSpec.js 2.27 KB
Newer Older
Manggar Mahardhika's avatar
Manggar Mahardhika committed
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
import { Cartesian3 } from "../../Source/Cesium.js";
import { BoxEmitter } from "../../Source/Cesium.js";
import { Particle } from "../../Source/Cesium.js";

describe("Scene/BoxEmitter", function () {
  var emitter;

  it("default constructor", function () {
    emitter = new BoxEmitter();
    expect(emitter.dimensions).toEqual(new Cartesian3(1.0, 1.0, 1.0));
  });

  it("constructor", function () {
    var dimensions = new Cartesian3(2.0, 3.0, 4.0);
    emitter = new BoxEmitter(dimensions);
    expect(emitter.dimensions).toEqual(dimensions);
  });

  it("constructor throws with invalid dimensions", function () {
    expect(function () {
      emitter = new BoxEmitter(new Cartesian3(-1.0, 1.0, 1.0));
    }).toThrowDeveloperError();
    expect(function () {
      emitter = new BoxEmitter(new Cartesian3(1.0, -1.0, 1.0));
    }).toThrowDeveloperError();
    expect(function () {
      emitter = new BoxEmitter(new Cartesian3(1.0, 1.0, -1.0));
    }).toThrowDeveloperError();
  });

  it("dimensions setter", function () {
    emitter = new BoxEmitter();
    var dimensions = new Cartesian3(2.0, 3.0, 4.0);
    emitter.dimensions = dimensions;
    expect(emitter.dimensions).toEqual(dimensions);
  });

  it("dimensions setter throws with invalid value", function () {
    emitter = new BoxEmitter();
    expect(function () {
      emitter.dimensions = undefined;
    }).toThrowDeveloperError();
    expect(function () {
      emitter.dimensions = new Cartesian3(-1.0, 1.0, 1.0);
    }).toThrowDeveloperError();
    expect(function () {
      emitter.dimensions = new Cartesian3(1.0, -1.0, 1.0);
    }).toThrowDeveloperError();
    expect(function () {
      emitter.dimensions = new Cartesian3(1.0, -1.0, 1.0);
    }).toThrowDeveloperError();
  });

  it("emits", function () {
    emitter = new BoxEmitter(new Cartesian3(2.0, 3.0, 4.0));
    var particle = new Particle();

    for (var i = 0; i < 1000; ++i) {
      emitter.emit(particle);
      expect(particle.position.x).toBeLessThanOrEqualTo(emitter.dimensions.x);
      expect(particle.position.y).toBeLessThanOrEqualTo(emitter.dimensions.y);
      expect(particle.position.z).toBeLessThanOrEqualTo(emitter.dimensions.z);
      expect(particle.velocity).toEqual(
        Cartesian3.normalize(particle.position, new Cartesian3())
      );
    }
  });
});