LineIntersectionSpec.js 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import {
  2. getApproxIntersection
  3. } from 'lib/util/LineIntersection';
  4. describe('features/bendpoints - LineIntersection', function() {
  5. describe('#getApproxIntersection', function() {
  6. var waypoints = [
  7. { x: 0, y: 0 },
  8. { x: 50, y: 50 },
  9. { x: 100, y: 50 },
  10. { x: 100, y: 100 }
  11. ];
  12. it('should match start point', function() {
  13. var intersection = getApproxIntersection(waypoints, waypoints[0]);
  14. expect(intersection.bendpoint).to.be.true;
  15. expect(intersection.index).to.equal(0);
  16. expect(intersection.point).to.equal(waypoints[0]);
  17. });
  18. it('should fuzzy match start point', function() {
  19. var intersection = getApproxIntersection(waypoints, { x: 7, y: -7 });
  20. expect(intersection.bendpoint).to.be.true;
  21. expect(intersection.index).to.equal(0);
  22. expect(intersection.point).to.equal(waypoints[0]);
  23. });
  24. it('should not match start point', function() {
  25. var intersection = getApproxIntersection(waypoints, { x: 10, y: -10 });
  26. expect(intersection).to.be.null;
  27. });
  28. it('should fuzzy match intermediate waypoint', function() {
  29. var intersection = getApproxIntersection(waypoints, { x: 55, y: 45 });
  30. expect(intersection.bendpoint).to.be.true;
  31. expect(intersection.index).to.equal(1);
  32. });
  33. it('should fuzzy match inbetween point', function() {
  34. var intersection = getApproxIntersection(waypoints, { x: 24.5, y: 25.5 });
  35. expect(intersection.bendpoint).to.be.undefined;
  36. expect(intersection.index).to.equal(1);
  37. expect(intersection.point).to.eql({ x: 25, y: 25 });
  38. });
  39. it('should fuzzy match end point', function() {
  40. var intersection = getApproxIntersection(waypoints, { x: 105, y: 95 });
  41. expect(intersection.bendpoint).to.be.true;
  42. expect(intersection.index).to.equal(3);
  43. expect(intersection.point).to.eql(waypoints[waypoints.length - 1]);
  44. });
  45. });
  46. });