2
0

collision.test.tsx 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. import { type GlobalPoint, type LocalPoint, pointFrom } from "@excalidraw/math";
  2. import { Excalidraw } from "@excalidraw/excalidraw";
  3. import { UI } from "@excalidraw/excalidraw/tests/helpers/ui";
  4. import "@excalidraw/utils/test-utils";
  5. import { render } from "@excalidraw/excalidraw/tests/test-utils";
  6. import { hitElementItself } from "../src/collision";
  7. describe("check rotated elements can be hit:", () => {
  8. beforeEach(async () => {
  9. localStorage.clear();
  10. await render(<Excalidraw handleKeyboardGlobally={true} />);
  11. });
  12. it("arrow", () => {
  13. UI.createElement("arrow", {
  14. x: 0,
  15. y: 0,
  16. width: 124,
  17. height: 302,
  18. angle: 1.8700426423973724,
  19. points: [
  20. [0, 0],
  21. [120, -198],
  22. [-4, -302],
  23. ] as LocalPoint[],
  24. });
  25. //const p = [120, -211];
  26. //const p = [0, 13];
  27. const hit = hitElementItself({
  28. point: pointFrom<GlobalPoint>(87, -68),
  29. element: window.h.elements[0],
  30. threshold: 10,
  31. elementsMap: window.h.scene.getNonDeletedElementsMap(),
  32. });
  33. expect(hit).toBe(true);
  34. });
  35. });