UNPKG

awv3

Version:
92 lines (91 loc) 3.2 kB
import { Vector3 } from 'three'; import { calculateIntersection, roundVector, calculateInCenter, round } from '../../plugins/csys/calculations'; it('calculate intersection', function () { var p11 = new Vector3(0.246, 1.397, -6.35); var p12 = new Vector3(3.186, 18.066, -6.35); var p21 = new Vector3(4.358, 19.05, -6.35); var p22 = new Vector3(21.284, 19.05, -6.35); var intersection = calculateIntersection(p11, p12, p21, p22); intersection = roundVector(intersection); expect(intersection).toMatchObject({ x: 3.36, y: 19.05, z: -6.35 }); }); it('detect skew lines inside calculate intersection', function () { var p11 = new Vector3(4.358, 19.05, -6.35); var p12 = new Vector3(21.284, 19.05, -6.35); var p21 = new Vector3(3.186, 18.066, 0); var p22 = new Vector3(0.246, 1.397, 0); var intersection = calculateIntersection(p11, p12, p21, p22); expect(intersection).toBeUndefined(); }); it('detect paralle lines inside calculate intersection', function () { var p11 = new Vector3(3.186, 18.066, 0); var p12 = new Vector3(3.186, 18.066, -6.35); var p21 = new Vector3(3.593, 18.771, 0); var p22 = new Vector3(3.593, 18.771, -6.35); var intersection = calculateIntersection(p11, p12, p21, p22); expect(intersection).toBeUndefined(); }); it('calculate incenter', function () { var pa1 = new Vector3(0.246, 1.397, -6.35); var pa2 = new Vector3(3.186, 18.066, -6.35); var pb1 = new Vector3(3.186, 18.066, 0); var pb2 = new Vector3(0.246, 1.397, 0); var pc1 = new Vector3(3.186, 18.066, 0); var pc2 = new Vector3(3.186, 18.066, -6.35); // rotate lines in all different orders, two of them are parallel var incenter = calculateInCenter(pa1, pa2, pb1, pb2, pc1, pc2); incenter = roundVector(incenter); expect(incenter).toMatchObject({ x: 2.635, y: 14.939, z: -3.175 }); incenter = calculateInCenter(pa1, pa2, pc1, pc2, pb1, pb2); incenter = roundVector(incenter); expect(incenter).toMatchObject({ x: 2.635, y: 14.939, z: -3.175 }); incenter = calculateInCenter(pb1, pb2, pa1, pa2, pc1, pc2); incenter = roundVector(incenter); expect(incenter).toMatchObject({ x: 2.635, y: 14.939, z: -3.175 }); incenter = calculateInCenter(pb1, pb2, pc1, pc2, pa1, pa2); incenter = roundVector(incenter); expect(incenter).toMatchObject({ x: 2.635, y: 14.939, z: -3.175 }); incenter = calculateInCenter(pc1, pc2, pa1, pa2, pb1, pb2); incenter = roundVector(incenter); expect(incenter).toMatchObject({ x: 2.635, y: 14.939, z: -3.175 }); incenter = calculateInCenter(pc1, pc2, pb1, pb2, pa1, pa2); incenter = roundVector(incenter); expect(incenter).toMatchObject({ x: 2.635, y: 14.939, z: -3.175 }); }); it('detect non-planar lines inside calculate incenter', function () { var pa1 = new Vector3(3.186, 18.066, 0); var pa2 = new Vector3(0.246, 1.397, 0); var pb1 = new Vector3(4.358, 19.05, -6.35); var pb2 = new Vector3(21.284, 19.05, -6.35); var pc1 = new Vector3(3.186, 18.066, 0); var pc2 = new Vector3(3.186, 18.066, -6.35); var incenter = calculateInCenter(pa1, pa2, pb1, pb2, pc1, pc2); expect(incenter).toBeUndefined(); });