Skip to content

Instantly share code, notes, and snippets.

@zaidalyafeai
Last active July 3, 2018 17:58
Show Gist options
  • Save zaidalyafeai/7d500cf468c974a04d521dbc85824bd4 to your computer and use it in GitHub Desktop.
Save zaidalyafeai/7d500cf468c974a04d521dbc85824bd4 to your computer and use it in GitHub Desktop.
//record the current drawing coordinates
function recordCoor(event)
{
//get current mouse coordinate
var pointer = canvas.getPointer(event.e);
var posX = pointer.x;
var posY = pointer.y;
//record the point if withing the canvas and the mouse is pressed
if(posX >=0 && posY >= 0 && mousePressed)
{
coords.push(pointer)
}
}
//get the best bounding box by finding the top left and bottom right cornders
function getMinBox(){
var coorX = coords.map(function(p) {return p.x});
var coorY = coords.map(function(p) {return p.y});
//find top left corner
var min_coords = {
x : Math.min.apply(null, coorX),
y : Math.min.apply(null, coorY)
}
//find right bottom corner
var max_coords = {
x : Math.max.apply(null, coorX),
y : Math.max.apply(null, coorY)
}
return {
min : min_coords,
max : max_coords
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment