diff --git a/test/unit/core/environment.js b/test/unit/core/environment.js index 96cb7ff387..af9ea4ffa3 100644 --- a/test/unit/core/environment.js +++ b/test/unit/core/environment.js @@ -236,4 +236,41 @@ suite('Environment', function() { assert.isNumber(myp5.displayDensity(), pd); }); }); + + suite('2D context test', function() { + beforeEach(function() { + myp5.createCanvas(100, 100); + }); + + test('worldToScreen for 2D context', function() { + let worldPos = myp5.createVector(50, 50); + let screenPos = myp5.worldToScreen(worldPos); + assert.closeTo(screenPos.x, 50, 0.1); + assert.closeTo(screenPos.y, 50, 0.1); + }); + + }); + + suite('3D context test', function() { + beforeEach(function() { + myp5.createCanvas(100, 100, myp5.WEBGL); + }); + + test('worldToScreen for 3D context', function() { + let worldPos = myp5.createVector(0, 0, 0); + let screenPos = myp5.worldToScreen(worldPos); + assert.isTrue(screenPos.x >= 0 && screenPos.x <= 100); + assert.isTrue(screenPos.y >= 0 && screenPos.y <= 100); + }); + + test('worldToScreen with rotation', function() { + myp5.push(); + myp5.rotateY(myp5.PI / 2); + let worldPos = myp5.createVector(50, 0, 0); + let screenPos = myp5.worldToScreen(worldPos); + myp5.pop(); + assert.isTrue(screenPos.x >= 0 && screenPos.x <= 100); + assert.isTrue(screenPos.y >= 0 && screenPos.y <= 100); + }); + }); });