var x=Math.min(this.start.x, this.end.x); var y=Math.min(this.start.y, this.end.y); var w=Math.max(this.start.x, this.end.x); var h=Math.max(this.start.y, this.end.y); this.start={ x:x, y:y }; this.end={ x:w, y:h }; this.textPosition={ x:this.end.x-this.textOffset, y:this.end.y-this.textOffset };