comparison client/digitallibrary/jquery/jquery.digilib.geometry.js @ 847:c662bf335881 jquery

fixed a bug in geom.intersect
author hertzhaft
date Sun, 06 Mar 2011 12:58:09 +0100
parents b484631f37c1
children 971b7122930f
comparison
equal deleted inserted replaced
846:dad6a171bc52 847:c662bf335881
260 this.setPt2(position(Math.min(this2.x, p2.x), Math.min(this2.y, p2.y))); 260 this.setPt2(position(Math.min(this2.x, p2.x), Math.min(this2.y, p2.y)));
261 return this; 261 return this;
262 }; 262 };
263 // returns the intersection of rectangle "rect" and this one 263 // returns the intersection of rectangle "rect" and this one
264 that.intersect = function(rect) { 264 that.intersect = function(rect) {
265 var res = rect.clipTo(this); 265 var r = rect.copy();
266 if (res.width < 0 || res.height < 0) res = null; 266 var result = r.clipTo(this);
267 return res; 267 if (result.width < 0 || result.height < 0) result = null;
268 return result;
268 }; 269 };
269 270
270 // returns a copy of rectangle "rect" that fits into this one 271 // returns a copy of rectangle "rect" that fits into this one
271 // (moving it first) 272 // (moving it first)
272 that.fit = function(rect) { 273 that.fit = function(rect) {
273 var sec = rect.copy(); 274 var r = rect.copy();
274 sec.x = Math.max(sec.x, this.x); 275 r.x = Math.max(r.x, this.x);
275 sec.y = Math.max(sec.y, this.x); 276 r.y = Math.max(r.y, this.x);
276 if (sec.x + sec.width > this.x + this.width) { 277 if (r.x + r.width > this.x + this.width) {
277 sec.x = this.x + this.width - sec.width; 278 r.x = this.x + this.width - r.width;
278 } 279 }
279 if (sec.y + sec.height > this.y + this.height) { 280 if (r.y + r.height > this.y + this.height) {
280 sec.y = this.y + this.height - sec.height; 281 r.y = this.y + this.height - r.height;
281 } 282 }
282 return sec.intersect(this); 283 return r.intersect(this);
283 }; 284 };
284 // adjusts position and size of jQuery element "$elem" to this rectangle 285 // adjusts position and size of jQuery element "$elem" to this rectangle
285 that.adjustDiv = function($elem) { 286 that.adjustDiv = function($elem) {
286 $elem.offset({ 287 $elem.offset({
287 left : this.x, 288 left : this.x,