Skip to content

Commit ad5a27d

Browse files
authored
Refactor screenToWorld for better argument handling
1 parent 6eb1302 commit ad5a27d

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

src/core/environment.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,16 +1314,18 @@ function environment(p5, fn, lifecycles){
13141314
*
13151315
*/
13161316
fn.screenToWorld = function(screenPosition) {
1317-
let origDimension = screenPosition._origDimension;
13181317

1319-
const screenToWorldArgs = arguments.length;
1318+
let origDimension = (typeof screenPosition === 'number')
1319+
? arguments.length
1320+
: screenPosition._origDimension;
1321+
13201322
if (typeof screenPosition === 'number') {
13211323
// We got passed numbers, convert to vector
13221324
screenPosition = this.createVector(...arguments);
13231325
}
13241326

13251327
const matrix = this._renderer.getWorldToScreenMatrix();
1326-
if (origDimension === 2 || screenToWorldArgs === 2) {
1328+
if (origDimension === 2) {
13271329
// Calculate a sensible Z value for the current camera projection that
13281330
// will result in 0 once converted to world coordinates
13291331
let z = matrix.mat4[14] / matrix.mat4[15];

0 commit comments

Comments
 (0)