Skip to content

Commit

Permalink
chore: use math.hypot (svg#1936)
Browse files Browse the repository at this point in the history
  • Loading branch information
SethFalco authored Jan 17, 2024
1 parent 59796a8 commit 174e952
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions plugins/applyTransforms.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,9 @@ export const applyTransforms = (root, params) => {
}

const scale = Number(
Math.sqrt(
matrix.data[0] * matrix.data[0] + matrix.data[1] * matrix.data[1],
).toFixed(transformPrecision),
Math.hypot(matrix.data[0], matrix.data[1]).toFixed(
transformPrecision,
),
);

if (stroke && stroke != 'none') {
Expand Down
4 changes: 2 additions & 2 deletions plugins/convertPathData.js
Original file line number Diff line number Diff line change
Expand Up @@ -1113,7 +1113,7 @@ function calculateSagitta(data) {
if (data[3] === 1) return undefined;
const [rx, ry] = data;
if (Math.abs(rx - ry) > error) return undefined;
const chord = Math.sqrt(data[5] ** 2 + data[6] ** 2);
const chord = Math.hypot(data[5], data[6]);
if (chord > rx * 2) return undefined;
return rx - Math.sqrt(rx ** 2 - 0.25 * chord ** 2);
}
Expand Down Expand Up @@ -1145,7 +1145,7 @@ function makeLonghand(item, data) {
* @type {(point1: Point, point2: Point) => number}
*/
function getDistance(point1, point2) {
return Math.sqrt((point1[0] - point2[0]) ** 2 + (point1[1] - point2[1]) ** 2);
return Math.hypot(point1[0] - point2[0], point1[1] - point2[1]);
}

/**
Expand Down

0 comments on commit 174e952

Please sign in to comment.