Mercurial > hg > digilib
changeset 1243:e69b80f99a00
interactive creation of vector lines and rectangles.
author | robcast |
---|---|
date | Wed, 15 Jan 2014 22:30:46 +0100 |
parents | b5ceeeae3582 |
children | 8cb0faad875a |
files | webapp/src/main/webapp/jquery/jquery.digilib.geometry.js |
diffstat | 1 files changed, 12 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Wed Jan 15 19:19:49 2014 +0100 +++ b/webapp/src/main/webapp/jquery/jquery.digilib.geometry.js Wed Jan 15 22:30:46 2014 +0100 @@ -136,6 +136,16 @@ top : this.y }); }; + // adjust this position so that is is inside rect + that.clipTo = function (rect) { + var p1 = rect.getPt1(); + var p2 = rect.getPt2(); + this.x = Math.max(this.x, p1.x); + this.y = Math.max(this.y, p1.y); + this.x = Math.min(this.x, p2.x); + this.y = Math.min(this.y, p2.y); + return this; + }; // returns distance of this position to pos (length if pos == null) that.distance = function(pos) { if (pos == null) { @@ -435,7 +445,7 @@ var x = this.m00 * rect.x + this.m01 * rect.y + this.m02; var y = this.m10 * rect.x + this.m11 * rect.y + this.m12; var pt = position(x, y); - if (rect.width) { + if (rect.width != null) { // transform the other corner point var pt2 = this.transform(rect.getPt2()); return rectangle(pt, pt2); @@ -453,7 +463,7 @@ * this.m02 - this.m00 * this.m12) / det; var pt = position(x, y); - if (rect.width) { + if (rect.width != null) { // transform the other corner point var pt2 = this.invtransform(rect.getPt2()); return rectangle(pt, pt2);