Merge pull request #16096 from bungeman/fix_trig_functions

Correct PostScript trigonometric operators
This commit is contained in:
calixteman 2023-03-11 14:32:23 +01:00 committed by GitHub
commit b2a86350fc
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 37 additions and 11 deletions

View File

@ -628,8 +628,13 @@ class PostScriptEvaluator {
}
break;
case "atan":
b = stack.pop();
a = stack.pop();
stack.push(Math.atan(a));
a = (Math.atan2(a, b) / Math.PI) * 180;
if (a < 0) {
a += 360;
}
stack.push(a);
break;
case "bitshift":
b = stack.pop();
@ -650,7 +655,7 @@ class PostScriptEvaluator {
break;
case "cos":
a = stack.pop();
stack.push(Math.cos(a));
stack.push(Math.cos(((a % 360) / 180) * Math.PI));
break;
case "cvi":
a = stack.pop() | 0;
@ -774,7 +779,7 @@ class PostScriptEvaluator {
break;
case "sin":
a = stack.pop();
stack.push(Math.sin(a));
stack.push(Math.sin(((a % 360) / 180) * Math.PI));
break;
case "sqrt":
a = stack.pop();

View File

@ -273,6 +273,7 @@
!issue13316_reduced.pdf
!issue15977_reduced.pdf
!issue4575.pdf
!colorspace_atan.pdf
!bug1011159.pdf
!issue5734.pdf
!issue4875.pdf
@ -294,6 +295,7 @@
!find_all.pdf
!helloworld-bad.pdf
!zerowidthline.pdf
!colorspace_cos.pdf
!issue13242.pdf
!js-colors.pdf
!annotation-line-without-appearance-empty-Rect.pdf
@ -423,6 +425,7 @@
!issue5475.pdf
!issue10519_reduced.pdf
!annotation-border-styles.pdf
!colorspace_sin.pdf
!IdentityToUnicodeMap_charCodeOf.pdf
!PDFJS-9279-reduced.pdf
!issue5481.pdf

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -840,6 +840,12 @@
"link": false,
"type": "eq"
},
{ "id": "colorspace_sin",
"file": "pdfs/colorspace_sin.pdf",
"md5": "4e341c346f4f37cd94b82c532badb8fd",
"rounds": 1,
"type": "eq"
},
{ "id": "issue215",
"file": "pdfs/issue215.pdf",
"md5": "31f3dc60ecf008987d970edfd2b1df61",
@ -2420,6 +2426,12 @@
"rounds": 1,
"type": "eq"
},
{ "id": "colorspace_cos",
"file": "pdfs/colorspace_cos.pdf",
"md5": "d3703784c2558f33e03b91dccb745b6c",
"rounds": 1,
"type": "eq"
},
{ "id": "issue6692",
"file": "pdfs/issue6692.pdf",
"md5": "ba078e0ddd59cda4b6c51ea10599f49a",
@ -3837,6 +3849,12 @@
"rounds": 1,
"type": "eq"
},
{ "id": "colorspace_atan",
"file": "pdfs/colorspace_atan.pdf",
"md5": "ec310d65a1849a39ae57d0d16b17261d",
"rounds": 1,
"type": "eq"
},
{
"id": "bug1199237",
"file": "pdfs/bug1199237.pdf",

View File

@ -138,9 +138,9 @@ describe("function", function () {
const expectedStack = [254 & 1];
expect(stack).toEqual(expectedStack);
});
it("calculates the inverse tangent of a number", function () {
const stack = evaluate("{ 90 atan }");
const expectedStack = [Math.atan(90)];
it("the angle in degrees (0-360) whose tangent is num/den.", function () {
const stack = evaluate("{ 1 -1 atan }");
const expectedStack = [135];
expect(stack).toEqual(expectedStack);
});
it("handles bitshifting ", function () {
@ -158,9 +158,9 @@ describe("function", function () {
const expectedStack = [99, 98, 99, 98];
expect(stack).toEqual(expectedStack);
});
it("calculates the cosine of a number", function () {
const stack = evaluate("{ 90 cos }");
const expectedStack = [Math.cos(90)];
it("calculates the cosine of an angle in degrees", function () {
const stack = evaluate("{ 180 cos }");
const expectedStack = [-1];
expect(stack).toEqual(expectedStack);
});
it("converts to int", function () {
@ -358,9 +358,9 @@ describe("function", function () {
const expectedStack = [10];
expect(stack).toEqual(expectedStack);
});
it("calculates the sine of a number", function () {
it("calculates the sine of an angle in degrees", function () {
const stack = evaluate("{ 90 sin }");
const expectedStack = [Math.sin(90)];
const expectedStack = [1];
expect(stack).toEqual(expectedStack);
});
it("calculates a square root (integer)", function () {