Mercurial > hg > digilib
comparison client/digitallibrary/jquery/dlGeometry.js @ 726:f5a0ac47bddd jquery
fixed setupZoomDrag
author | robcast |
---|---|
date | Tue, 01 Feb 2011 19:30:59 +0100 |
parents | a653d96166e9 |
children | 3a7fbdc39f6c |
comparison
equal
deleted
inserted
replaced
725:96dc93ff4d68 | 726:f5a0ac47bddd |
---|---|
46 }; | 46 }; |
47 } | 47 } |
48 that.equals = function (other) { | 48 that.equals = function (other) { |
49 return (this.x === other.x && this.y === other.y); | 49 return (this.x === other.x && this.y === other.y); |
50 }; | 50 }; |
51 // add position other to this | |
52 that.add = function (other) { | |
53 this.x += other.x; | |
54 this.y += other.y; | |
55 return this; | |
56 }; | |
51 // returns new position that is the difference between this and other | 57 // returns new position that is the difference between this and other |
52 that.delta = function (other) { | 58 that.delta = function (other) { |
53 return position(other.x - this.x, other.y - this.y); | 59 return position(other.x - this.x, other.y - this.y); |
54 }; | 60 }; |
55 // adjusts position $elem to this position | 61 // adjusts position $elem to this position |
56 that.adjustDiv = function ($elem) { | 62 that.adjustDiv = function ($elem) { |
57 $elem.offset({left : this.x, top : this.y}); | 63 $elem.offset({left : this.x, top : this.y}); |
64 }; | |
65 // returns distance of this position to pos (length if pos == null) | |
66 that.distance = function (pos) { | |
67 if (pos == null) { | |
68 pos = {x : 0, y : 0}; | |
69 } | |
70 var dx = pos.x - this.x; | |
71 var dy = pos.y - this.y; | |
72 return Math.sqrt(dx * dx + dy * dy); | |
58 }; | 73 }; |
59 that.toString = function() { | 74 that.toString = function() { |
60 return (this.x + "," + this.y); | 75 return (this.x + "," + this.y); |
61 }; | 76 }; |
62 return that; | 77 return that; |
105 that.getPt1 = that.getPosition; | 120 that.getPt1 = that.getPosition; |
106 // returns the lower right corner position of this Rectangle | 121 // returns the lower right corner position of this Rectangle |
107 that.getPt2 = function() { | 122 that.getPt2 = function() { |
108 return position(this.x + this.width, this.y + this.height); | 123 return position(this.x + this.width, this.y + this.height); |
109 }; | 124 }; |
110 // sets the upper left corner to position pos | 125 // sets the upper left corner position to pos |
111 that.setPt1 = function(pos) { | 126 that.setPosition = function(pos) { |
112 this.x = pos.x; | 127 this.x = pos.x; |
113 this.y = pos.y; | 128 this.y = pos.y; |
114 return this; | 129 return this; |
115 }; | 130 }; |
116 // adds pos to the upper left corner | 131 that.setPt1 = that.setPosition; // TODO: not really the same |
117 that.addPt1 = function(pos) { | 132 // adds pos to the position |
133 that.addPosition = function(pos) { | |
118 this.x += pos.x; | 134 this.x += pos.x; |
119 this.y += pos.y; | 135 this.y += pos.y; |
120 return this; | 136 return this; |
121 }; | 137 }; |
122 // sets the lower right corner to position pos | 138 // sets the lower right corner to position pos |