diff --git a/src/App.tsx b/src/App.tsx index b5c487e..845d8b5 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,6 @@ import "./App.css"; import { futurPosition, - getArea, getBoundingRect, placeWordOnOuterCircle, Word, @@ -71,7 +70,6 @@ const Wordcloud = () => { ...word, rect: newPositions[idx], })); - }); }; diff --git a/src/utils.test.ts b/src/utils.test.ts index 6069b29..d248e69 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -1,5 +1,11 @@ import { describe, expect, it } from "vitest"; -import { areCentersTooClose, Coordinate, Rectangle } from "./utils"; +import { + areCentersTooClose, + Coordinate, + getBoundingRect, + Rectangle, + getMoveDirection, +} from "./utils"; const origin: Coordinate = { x: 0, @@ -28,3 +34,39 @@ describe("areCentersTooClose", () => { expect(areCentersTooClose({ x: -2, y: -2 }, origin, 2.5, 2.5)).toBe(true); }); }); + +describe("Get move direction", () => { + it("Test with three rectangle", () => { + const rect = { id: "word-1", text: " Big word ", coef: 0.99 }; + + expect( + getMoveDirection( + [ + { + x: 4, + y: 6, + width: 4, + height: 4, + }, + { + x: 8, + y: 5, + width: 7, + height: 7, + }, + ], + { + x: 3, + y: 4, + width: 3, + height: 3, + } + ) + ).toEqual({ + x: 6, + y: 3, + width: 3, + height: 3, + }); + }); +}); diff --git a/src/utils.ts b/src/utils.ts index af3600b..a7f63a7 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -71,7 +71,7 @@ export const placeWordOnOuterCircle = (w: Rectangle) => { return newPosition; }; -const getMoveDirection = ( +export const getMoveDirection = ( pastWords: Rectangle[], currentWord: Rectangle ): Coordinate => {