Skip to content

Commit

Permalink
Round char rotation to the closest standard angle
Browse files Browse the repository at this point in the history
  • Loading branch information
mrtcode committed Oct 2, 2023
1 parent ef32f7a commit 159a1d5
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/core/evaluator.js
Original file line number Diff line number Diff line change
Expand Up @@ -2874,6 +2874,22 @@ class PartialEvaluator {
}
textChunk.str.push(glyphUnicode);

function closestStandardAngle(degrees) {
const standardAngles = [0, 90, 180, 270];
let closestAngle = standardAngles[0];
let minDifference = Math.abs(degrees - closestAngle);

for (let i = 1; i < standardAngles.length; i++) {
const difference = Math.abs(degrees - standardAngles[i]);
if (difference < minDifference) {
minDifference = difference;
closestAngle = standardAngles[i];
}
}

return closestAngle;
}

function matrixToDegrees(matrix) {
let radians = Math.atan2(matrix[1], matrix[0]);
if (radians < 0) {
Expand All @@ -2884,6 +2900,7 @@ class PartialEvaluator {
if (degrees < 0) {
degrees += 360;
}
degrees = closestStandardAngle(degrees);
return degrees;
}

Expand Down

0 comments on commit 159a1d5

Please sign in to comment.