diff --git a/build/concrete.js b/build/concrete.js index 763a6cb..0128c9e 100644 --- a/build/concrete.js +++ b/build/concrete.js @@ -2,11 +2,11 @@ * Concrete v3.0.2 * A lightweight Html5 Canvas framework that enables hit detection, layering, multi buffering, * pixel ratio management, exports, and image downloads - * Release Date: 11-20-2018 + * Release Date: 4-19-2019 * https://github.com/ericdrowell/concrete * Licensed under the MIT or GPL Version 2 licenses. * - * Copyright (C) 2018 Eric Rowell @ericdrowell + * Copyright (C) 2019 Eric Rowell @ericdrowell * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -502,9 +502,17 @@ Concrete.Hit.prototype = { var context = this.context, data; + x = Math.round(x); + y = Math.round(y); + + // if x or y are out of bounds return -1 + if (x < 0 || y < 0 || x > this.width || y > this.height) { + return -1; + } + // 2d if (this.contextType === '2d') { - data = context.getImageData(Math.round(x), Math.round(y), 1, 1).data; + data = context.getImageData(x, y, 1, 1).data; if (data[3] === 0) { return -1; @@ -513,7 +521,7 @@ Concrete.Hit.prototype = { // webgl else { data = new Uint8Array(4); - context.readPixels(Math.round(x*Concrete.PIXEL_RATIO), Math.round((this.height - y)*Concrete.PIXEL_RATIO), 1, 1, context.RGBA, context.UNSIGNED_BYTE, data); + context.readPixels(x*Concrete.PIXEL_RATIO, (this.height - y - 1)*Concrete.PIXEL_RATIO, 1, 1, context.RGBA, context.UNSIGNED_BYTE, data); if (data[0] === 255 && data[1] === 255 && data[2] === 255) { return -1; diff --git a/build/concrete.min.js b/build/concrete.min.js index 0505688..4058ca7 100644 --- a/build/concrete.min.js +++ b/build/concrete.min.js @@ -2,11 +2,11 @@ * Concrete v3.0.2 * A lightweight Html5 Canvas framework that enables hit detection, layering, multi buffering, * pixel ratio management, exports, and image downloads - * Release Date: 11-20-2018 + * Release Date: 4-19-2019 * https://github.com/ericdrowell/concrete * Licensed under the MIT or GPL Version 2 licenses. * - * Copyright (C) 2018 Eric Rowell @ericdrowell + * Copyright (C) 2019 Eric Rowell @ericdrowell * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal @@ -26,4 +26,4 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ -var Concrete={},idCounter=0;Concrete.PIXEL_RATIO=window&&window.navigator&&window.navigator.userAgent&&!/PhantomJS/.test(window.navigator.userAgent)?2:1,Concrete.viewports=[],Concrete.Viewport=function(t){t||(t={}),this.container=t.container,this.layers=[],this.id=idCounter++,this.scene=new Concrete.Scene,this.setSize(t.width||0,t.height||0),t.container.innerHTML="",t.container.appendChild(this.scene.canvas),Concrete.viewports.push(this)},Concrete.Viewport.prototype={add:function(t){return this.layers.push(t),t.setSize(t.width||this.width,t.height||this.height),t.viewport=this},setSize:function(t,e){return this.width=t,this.height=e,this.scene.setSize(t,e),this},getIntersection:function(t,e){var i,n,s=this.layers;for(i=s.length-1;0<=i;i--)if(0<=(n=s[i].hit.getIntersection(t,e)))return n;return-1},getIndex:function(){var t,e=Concrete.viewports,i=e.length,n=0;for(n=0;n>16,(65280&t)>>8,255&t]}},function(t){"use strict";"function"==typeof define&&define.amd?define(function(){return Concrete}):"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=Concrete),exports.Concrete=Concrete):t.Concrete=Concrete}(this); \ No newline at end of file +var Concrete={},idCounter=0;Concrete.PIXEL_RATIO=window&&window.navigator&&window.navigator.userAgent&&!/PhantomJS/.test(window.navigator.userAgent)?2:1,Concrete.viewports=[],Concrete.Viewport=function(t){t||(t={}),this.container=t.container,this.layers=[],this.id=idCounter++,this.scene=new Concrete.Scene,this.setSize(t.width||0,t.height||0),t.container.innerHTML="",t.container.appendChild(this.scene.canvas),Concrete.viewports.push(this)},Concrete.Viewport.prototype={add:function(t){return this.layers.push(t),t.setSize(t.width||this.width,t.height||this.height),t.viewport=this},setSize:function(t,e){return this.width=t,this.height=e,this.scene.setSize(t,e),this},getIntersection:function(t,e){var i,n,s=this.layers;for(i=s.length-1;0<=i;i--)if(0<=(n=s[i].hit.getIntersection(t,e)))return n;return-1},getIndex:function(){var t,e=Concrete.viewports,i=e.length,n=0;for(n=0;nthis.width||e>this.height)return-1;if("2d"===this.contextType){if(0===(i=n.getImageData(t,e,1,1).data)[3])return-1}else if(i=new Uint8Array(4),n.readPixels(t*Concrete.PIXEL_RATIO,(this.height-e-1)*Concrete.PIXEL_RATIO,1,1,n.RGBA,n.UNSIGNED_BYTE,i),255===i[0]&&255===i[1]&&255===i[2])return-1;return this.rgbToInt(i)},getColorFromIndex:function(t){var e=this.intToRGB(t);return"rgb("+e[0]+", "+e[1]+", "+e[2]+")"},rgbToInt:function(t){return(t[0]<<16)+(t[1]<<8)+t[2]},intToRGB:function(t){return[(16711680&t)>>16,(65280&t)>>8,255&t]}},function(t){"use strict";"function"==typeof define&&define.amd?define(function(){return Concrete}):"undefined"!=typeof exports?("undefined"!=typeof module&&module.exports&&(exports=module.exports=Concrete),exports.Concrete=Concrete):t.Concrete=Concrete}(this); \ No newline at end of file diff --git a/package.json b/package.json index 3607146..9a9b9d6 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "concretejs", - "version": "3.0.2", + "version": "3.0.3", "main": "build/concrete.min.js", "keywords": [ "html5", diff --git a/src/concrete.js b/src/concrete.js index 4393882..e0ecdaf 100644 --- a/src/concrete.js +++ b/src/concrete.js @@ -474,9 +474,17 @@ Concrete.Hit.prototype = { var context = this.context, data; + x = Math.round(x); + y = Math.round(y); + + // if x or y are out of bounds return -1 + if (x < 0 || y < 0 || x > this.width || y > this.height) { + return -1; + } + // 2d if (this.contextType === '2d') { - data = context.getImageData(Math.round(x), Math.round(y), 1, 1).data; + data = context.getImageData(x, y, 1, 1).data; if (data[3] === 0) { return -1; @@ -485,7 +493,7 @@ Concrete.Hit.prototype = { // webgl else { data = new Uint8Array(4); - context.readPixels(Math.round(x*Concrete.PIXEL_RATIO), Math.round((this.height - y)*Concrete.PIXEL_RATIO), 1, 1, context.RGBA, context.UNSIGNED_BYTE, data); + context.readPixels(x*Concrete.PIXEL_RATIO, (this.height - y - 1)*Concrete.PIXEL_RATIO, 1, 1, context.RGBA, context.UNSIGNED_BYTE, data); if (data[0] === 255 && data[1] === 255 && data[2] === 255) { return -1;