Skip to content

Commit

Permalink
Merge pull request #209 from VisActor/fix/max-radius-error
Browse files Browse the repository at this point in the history
Fix/max radius error
  • Loading branch information
xile611 authored Oct 28, 2024
2 parents 809dce6 + d7dc174 commit 46a61c3
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"changes": [
{
"comment": "fix: fix error of calculate max radius for specified angles and center\n\n",
"type": "none",
"packageName": "@visactor/vutils"
}
],
"packageName": "@visactor/vutils",
"email": "[email protected]"
}
5 changes: 4 additions & 1 deletion packages/vutils/__tests__/angle.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@ describe('angle utils', () => {
).toBeCloseTo(150);
expect(
calculateMaxRadius({ width: 400, height: 500 }, { x: 200, y: 350 }, -0.8 * Math.PI, 0.1 * Math.PI)
).toBeCloseTo(157.71933363574007);
).toBeCloseTo(200);
expect(
calculateMaxRadius({ width: 400, height: 500 }, { x: 200, y: 550 }, -1.1 * Math.PI, 0.1 * Math.PI)
).toBeCloseTo(161.8033988749892);
});

it('computeQuadrant', () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/vutils/src/angle.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,15 @@ export function calculateMaxRadius(
radiusList.push(x);
} else {
if (sin > 0) {
radiusList.push(Math.abs((height - y) / cos));
radiusList.push(Math.abs((height - y) / sin));
} else {
radiusList.push(Math.abs(y / cos));
radiusList.push(Math.abs(y / sin));
}

if (cos > 0) {
radiusList.push(Math.abs((width - x) / sin));
radiusList.push(Math.abs((width - x) / cos));
} else {
radiusList.push(Math.abs(x / sin));
radiusList.push(Math.abs(x / cos));
}
}
});
Expand Down

0 comments on commit 46a61c3

Please sign in to comment.