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.

52 lines
1.6 KiB

  1. import { assert, expect } from 'chai';
  2. import Intersection from '../src/05/intersection';
  3. import Ray from '../src/05/ray';
  4. import Vector from "../src/05/vector";
  5. import Matrix from '../src/07/matrix';
  6. import { GroupNode, SphereNode } from '../src/08/nodes';
  7. import { Translation, Rotation, Scaling, MatrixTransformation, Transformation } from "../src/08/transformation";
  8. describe('GroupNode', () => {
  9. it('can be correctly initialized with a Transformation', () => {
  10. let t: Transformation = new MatrixTransformation(Matrix.identity(), Matrix.identity());
  11. let g: GroupNode = new GroupNode(t);
  12. expect(g).to.be.an('object');
  13. });
  14. it('can have children', () => {
  15. let t: Transformation = new MatrixTransformation(Matrix.identity(), Matrix.identity());
  16. let g: GroupNode = new GroupNode(t);
  17. let c: GroupNode = new GroupNode(t);
  18. expect(g).to.be.an('object');
  19. expect(c).to.be.an('object');
  20. g.add(c);
  21. expect(g.children).to.be.an('Array');
  22. expect(g.children.length).to.equal(1);
  23. });
  24. });
  25. describe('SphereNode', () => {
  26. it('can be intersected in Origin', () => {
  27. let t: Transformation = new MatrixTransformation(Matrix.identity(), Matrix.identity());
  28. let s: SphereNode = new SphereNode(t, new Vector(0.0, 0.0, 0.0, 1.0));
  29. expect(s).to.be.an('object');
  30. let r: Ray = new Ray(new Vector(0.0, 0.0, 10, 1.0), new Vector(0.0, 0.0, -1.0, 0.0));
  31. let i: Intersection = s.intersect(r);
  32. assert.deepEqual(i.point.data, [
  33. 0, 0, 1, 1,
  34. ]);
  35. });
  36. });