diff --git a/src/core/function.js b/src/core/function.js index 0fca3e627..acce24feb 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -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(); diff --git a/test/pdfs/.gitignore b/test/pdfs/.gitignore index 1c6e6b325..55c567aee 100644 --- a/test/pdfs/.gitignore +++ b/test/pdfs/.gitignore @@ -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 diff --git a/test/pdfs/colorspace_atan.pdf b/test/pdfs/colorspace_atan.pdf new file mode 100644 index 000000000..897495b8f Binary files /dev/null and b/test/pdfs/colorspace_atan.pdf differ diff --git a/test/pdfs/colorspace_cos.pdf b/test/pdfs/colorspace_cos.pdf new file mode 100644 index 000000000..08cd1fb72 Binary files /dev/null and b/test/pdfs/colorspace_cos.pdf differ diff --git a/test/pdfs/colorspace_sin.pdf b/test/pdfs/colorspace_sin.pdf new file mode 100644 index 000000000..5b56008d3 Binary files /dev/null and b/test/pdfs/colorspace_sin.pdf differ diff --git a/test/test_manifest.json b/test/test_manifest.json index f3ffc1ecc..62552aabe 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -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", diff --git a/test/unit/function_spec.js b/test/unit/function_spec.js index 1791bf911..3e167054a 100644 --- a/test/unit/function_spec.js +++ b/test/unit/function_spec.js @@ -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 () {