You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.9 KiB

  1. import Ray from "../src/05/ray";
  2. import Camera from "../src/05/camera";
  3. import { assert, expect } from 'chai';
  4. describe('Ray', () => {
  5. it('can be initialized with two numbers and a camera', () => {
  6. const r: Ray = Ray.makeRay(0, 0, new Camera(128, 128, 45));
  7. expect(r).to.be.an('object');
  8. });
  9. it('the origin of the ray is initialized correctly', () => {
  10. const r: Ray = Ray.makeRay(0, 0, new Camera(128, 128, 45));
  11. expect(r).to.be.an('object');
  12. expect(r.origin.x).to.equal(0);
  13. expect(r.origin.y).to.equal(0);
  14. expect(r.origin.z).to.equal(0);
  15. expect(r.origin.w).to.equal(1);
  16. });
  17. it('the direction is normalized', () => {
  18. const r: Ray = Ray.makeRay(64, 64, new Camera(129, 129, 45));
  19. expect(r).to.be.an('object');
  20. expect(r.direction.length).to.equal(1);
  21. });
  22. it('the direction is initialized correctly', () => {
  23. const r: Ray = Ray.makeRay(64, 64, new Camera(129, 129, 45));
  24. expect(r).to.be.an('object');
  25. expect(r.direction.x).to.be.closeTo(0, 0.01);
  26. expect(r.direction.y).to.be.closeTo(0, 0.01);
  27. expect(r.direction.z).to.be.closeTo(-1, 0.01);
  28. expect(r.direction.w).to.be.closeTo(0, 0.01);
  29. const r2: Ray = Ray.makeRay(0, 0, new Camera(129, 129, 45));
  30. expect(r2).to.be.an('object');
  31. expect(r2.direction.x).to.be.closeTo(-0.435, 0.01);
  32. expect(r2.direction.y).to.be.closeTo(0.435, 0.01);
  33. expect(r2.direction.z).to.be.closeTo(-0.787, 0.01);
  34. expect(r2.direction.w).to.be.closeTo(0, 0.01);
  35. const r3: Ray = Ray.makeRay(10, 7, new Camera(64, 64, 90));
  36. expect(r3).to.be.an('object');
  37. expect(r3.direction.x).to.be.closeTo(-0.564, 0.01);
  38. expect(r3.direction.y).to.be.closeTo(0.642, 0.01);
  39. expect(r3.direction.z).to.be.closeTo(-0.518, 0.01);
  40. expect(r3.direction.w).to.equal(0);
  41. });
  42. });