Déplacer l'objet à l'intérieur de la toile limite de

Je suis en train de la limite de l'objet en mouvement à l'intérieur de la toile, mais je suis certaine difficulté à déplacer l'objet avec la limite de la zone sur le côté gauche et en haut et quand je l'échelle de l'objet de grande taille cette fois je ne suis pas en mesure à la limite de l'objet en mouvement sur la gauche et de la partie supérieure de la toile

canvas.observe("object:moving", function(e){
      var obj = e.target;
         //if object is too big ignore
        if(obj.currentHeight > obj.canvas.height || obj.currentWidth > obj.canvas.width){
            return;
        }

        var halfw = obj.currentWidth/2;
        var halfh = obj.currentHeight/2;
        var bounds = {tl: {x: halfw, y:halfh},
            br: {x: obj.canvas.width-halfw, y: obj.canvas.height-halfh}
        };

        //top-left  corner
        if(obj.top < bounds.tl.y || obj.left < bounds.tl.x){
            obj.top = Math.max(obj.top, bounds.tl.y);
            obj.left = Math.max(obj.left, bounds.tl.x )
        }


        //bot-right corner
        if(obj.top > bounds.br.y || obj.left > bounds.br.x){
            obj.top = Math.min(obj.top, bounds.br.y);
            obj.left = Math.min(obj.left, bounds.br.x)
        }
});