Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ad1992 committed May 16, 2024
1 parent e7e9f65 commit 0fdc632
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
13 changes: 9 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,10 +113,16 @@ export const computeEdgePositions = (
})
.filter((point, index, array) => {
// Always include the last point
if (index === array.length - 1) {
if (index === 0 || index === array.length - 1) {
return true;
}

// Exclude the points which are the same as the previous point
if (point.x === array[index - 1].x && point.y === array[index - 1].y) {
return false;
}

// The below check is exclusively for second last point
if (
index === array.length - 2 &&
(array[index - 1].x === point.x || array[index - 1].y === point.y)
Expand All @@ -135,9 +141,8 @@ export const computeEdgePositions = (
return distance > 20;
}

// Always include the start point, or if the current point is not the same as the previous point
const prevPoint = array[index - 1];
return index === 0 || point.x !== prevPoint.x || point.y !== prevPoint.y;
// Always include if the current point is not the same as the previous point
return point.x !== array[index - 1].x || point.y !== array[index - 1].y;
})
.map((p) => {
// Offset the point by the provided offset
Expand Down
8 changes: 4 additions & 4 deletions tests/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe("Test Utils", () => {
]);
});

it("should include the second last point if the distance to the last point is greater than 50 and second last point is straight line", () => {
it("should include the second last point if the distance to the last point is greater than 20 and second last point is straight line", () => {
const commands = ["M29.383,38.5", "L29.383,83.2", "L90.383,83.2"];
pathElement.setAttribute("d", commands.join(""));

Expand All @@ -84,15 +84,15 @@ describe("Test Utils", () => {
]);
});

it("should exclude the second last point if the distance to the last point is less than 50 and second last point is straight line", () => {
const commands = ["M29.383,38.5", "L29.383,83.2", "L59.383,83.2"];
it("should exclude the second last point if the distance to the last point is less than 20 and second last point is straight line", () => {
const commands = ["M29.383,38.5", "L29.383,83.2", "L33.383,83.2"];
pathElement.setAttribute("d", commands.join(""));

const result = computeEdgePositions(pathElement);

expect(result.reflectionPoints).toEqual([
{ x: 29.383, y: 38.5 },
{ x: 59.383, y: 83.2 },
{ x: 33.383, y: 83.2 },
]);
});

Expand Down

0 comments on commit 0fdc632

Please sign in to comment.