Skip to content

Commit

Permalink
Merge pull request #47 from whydoubt/fix_scaling
Browse files Browse the repository at this point in the history
Improve check for whether canvas is visible
  • Loading branch information
patriciogonzalezvivo authored Oct 29, 2022
2 parents 445df57 + 736a365 commit 694185d
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 7 deletions.
3 changes: 2 additions & 1 deletion dist/GlslCanvas.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,8 @@ function parseUniforms(uniforms) {
}

function isCanvasVisible(canvas) {
return canvas.getBoundingClientRect().top + canvas.height > 0 && canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight);
var bound = canvas.getBoundingClientRect();
return bound.top + bound.height > 0 && bound.top < (window.innerHeight || document.documentElement.clientHeight);
}

function isPowerOf2(value) {
Expand Down
3 changes: 2 additions & 1 deletion dist/GlslCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,8 @@ function parseUniforms(uniforms) {
}

function isCanvasVisible(canvas) {
return canvas.getBoundingClientRect().top + canvas.height > 0 && canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight);
var bound = canvas.getBoundingClientRect();
return bound.top + bound.height > 0 && bound.top < (window.innerHeight || document.documentElement.clientHeight);
}

function isPowerOf2(value) {
Expand Down
3 changes: 1 addition & 2 deletions dist/GlslCanvas.min.js

Large diffs are not rendered by default.

3 changes: 2 additions & 1 deletion lib/GlslCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,8 @@ function parseUniforms(uniforms) {
}

function isCanvasVisible(canvas) {
return canvas.getBoundingClientRect().top + canvas.height > 0 && canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight);
var bound = canvas.getBoundingClientRect();
return bound.top + bound.height > 0 && bound.top < (window.innerHeight || document.documentElement.clientHeight);
}

function isPowerOf2(value) {
Expand Down
5 changes: 3 additions & 2 deletions src/tools/common.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export function isCanvasVisible(canvas) {
return ((canvas.getBoundingClientRect().top + canvas.height) > 0) &&
(canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight));
let bound = canvas.getBoundingClientRect();
return ((bound.top + bound.height) > 0) &&
(bound.top < (window.innerHeight || document.documentElement.clientHeight));
}

export function isPowerOf2(value) {
Expand Down

0 comments on commit 694185d

Please sign in to comment.