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.

69 lines
1.9 KiB

  1. import { assert, expect } from 'chai';
  2. import { Translation, Rotation, Scaling } from "../src/08/transformation";
  3. import Vector from "../src/05/vector";
  4. describe('Translation', () => {
  5. it('can be correctly initialized with a Vector', () => {
  6. const t: Translation = new Translation(new Vector(1.0, 2.0, 3.0, 0.0));
  7. expect(t).to.be.an('object');
  8. assert.deepEqual(t.getMatrix().getVals(), [
  9. 1, 0, 0, 1,
  10. 0, 1, 0, 2,
  11. 0, 0, 1, 3,
  12. 0, 0, 0, 1
  13. ]);
  14. assert.deepEqual(t.getInverseMatrix().getVals(), [
  15. 1, 0, 0, -1,
  16. 0, 1, 0, -2,
  17. 0, 0, 1, -3,
  18. 0, 0, 0, 1
  19. ]);
  20. });
  21. });
  22. describe('Rotation', () => {
  23. it('can be correctly initialized with an axis and an angle', () => {
  24. const r: Rotation = new Rotation(new Vector(0.0, 0.0, 1.0, 0.0), Math.PI / 4);
  25. console.log(r.matrix);
  26. expect(r).to.be.an('object');
  27. assert.deepEqual(r.getMatrix().getVals(), [
  28. 0.7071067690849304, -0.7071067690849304, 0, 0,
  29. 0.7071067690849304, 0.7071067690849304, 0, 0,
  30. 0, 0, 1, 0,
  31. 0, 0, 0, 1
  32. ]);
  33. assert.deepEqual(r.getInverseMatrix().getVals(), [
  34. 0.7071067690849304, 0.7071067690849304, 0, 0,
  35. -0.7071067690849304, 0.7071067690849304, 0, 0,
  36. 0, 0, 1, 0,
  37. 0, 0, 0, 1
  38. ]);
  39. });
  40. });
  41. describe('Scaling', () => {
  42. it('can be correctly initialized with a Vector', () => {
  43. const s: Scaling = new Scaling(new Vector(1.0, 2.0, 4.0, 0.0));
  44. expect(s).to.be.an('object');
  45. assert.deepEqual(s.getMatrix().getVals(), [
  46. 1, 0, 0, 0,
  47. 0, 2, 0, 0,
  48. 0, 0, 4, 0,
  49. 0, 0, 0, 1
  50. ]);
  51. assert.deepEqual(s.getInverseMatrix().getVals(), [
  52. 1, 0, 0, 0,
  53. 0, 1/2, 0, 0,
  54. 0, 0, 1/4, 0,
  55. 0, 0, 0, 1
  56. ]);
  57. });
  58. });