annotate client/digitallibrary/jquery/dlGeometry.js @ 747:fd4842f0afc7 jquery

smoother birdZoom indicator movement; fixed bug in jQuery.offset()
author hertzhaft
date Sat, 05 Feb 2011 13:53:45 +0100
parents ee620bcf4ab0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
1 /* digilib geometry classes
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
2 * should be integrated into jquery.digilib.js
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
3 */
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
4
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
5 var dlGeometry = function() {
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
6 /*
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
7 * Size class
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
8 */
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
9 var size = function(w, h) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
10 var that;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
11 if (typeof w === "object") {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
12 // assume its size
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
13 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
14 width : w.width,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
15 height : w.height
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
16 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
17 } else {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
18 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
19 width : parseFloat(w),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
20 height : parseFloat(h)
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
21 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
22 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
23 that.equals = function(other) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
24 return (this.width === other.width && this.height === other.height);
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
25 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
26 that.toString = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
27 return (this.width + "x" + this.height);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
28 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
29 return that;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
30 };
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
31
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
32 /*
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
33 * Position class
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
34 */
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
35 var position = function(x, y) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
36 var that;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
37 if (typeof x === "object") {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
38 if (x instanceof jQuery) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
39 // jQuery object
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
40 var pos = x.offset();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
41 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
42 x : pos.left,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
43 y : pos.top
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
44 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
45 } else {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
46 if (x.x != null) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
47 // position object
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
48 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
49 x : x.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
50 y : x.y
654
b3c05e1568cf zoomarea works now
robcast
parents: 627
diff changeset
51 };
b3c05e1568cf zoomarea works now
robcast
parents: 627
diff changeset
52 }
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
53 if (x.pageX != null) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
54 // event object
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
55 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
56 x : x.pageX,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
57 y : x.pageY
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
58 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
59 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
60 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
61 } else {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
62 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
63 x : parseFloat(x),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
64 y : parseFloat(y)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
65 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
66 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
67 that.equals = function(other) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
68 return (this.x === other.x && this.y === other.y);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
69 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
70 // add position other to this
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
71 that.add = function(other) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
72 this.x += other.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
73 this.y += other.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
74 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
75 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
76 // returns negative position
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
77 that.neg = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
78 return position({
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
79 x : -this.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
80 y : -this.y
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
81 });
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
82 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
83 // returns new position that is the difference between this and other
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
84 that.delta = function(other) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
85 return position({
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
86 x : other.x - this.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
87 y : other.y - this.y
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
88 });
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
89 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
90 // adjusts position $elem to this position
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
91 that.adjustDiv = function($elem) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
92 $elem.offset({
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
93 left : this.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
94 top : this.y
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
95 });
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
96 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
97 // returns distance of this position to pos (length if pos == null)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
98 that.distance = function(pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
99 if (pos == null) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
100 pos = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
101 x : 0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
102 y : 0
654
b3c05e1568cf zoomarea works now
robcast
parents: 627
diff changeset
103 };
b3c05e1568cf zoomarea works now
robcast
parents: 627
diff changeset
104 }
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
105 var dx = pos.x - this.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
106 var dy = pos.y - this.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
107 return Math.sqrt(dx * dx + dy * dy);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
108 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
109 that.toString = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
110 return (this.x + "," + this.y);
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
111 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
112 return that;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
113 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
114 /*
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
115 * Rectangle class
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
116 */
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
117 var rectangle = function(x, y, w, h) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
118 var that = {};
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
119 if (typeof x === "object") {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
120 if (x instanceof jQuery) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
121 // jQuery object
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
122 var pos = x.offset();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
123 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
124 x : pos.left,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
125 y : pos.top,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
126 width : x.width(),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
127 height : x.height()
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
128 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
129 } else if (y == null) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
130 // assume x is rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
131 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
132 x : x.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
133 y : x.y,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
134 width : x.width,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
135 height : x.height
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
136 };
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
137 } else {
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
138 // assume x and y are Position
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
139 that = {
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
140 x : Math.min(x.x, y.x),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
141 y : Math.min(x.y, y.y),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
142 width : Math.abs(y.x - x.x),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
143 height : Math.abs(y.y - x.y)
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
144 };
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
145 }
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
146 } else {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
147 that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
148 x : parseFloat(x),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
149 y : parseFloat(y),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
150 width : parseFloat(w),
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
151 height : parseFloat(h)
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
152 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
153 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
154 // returns a copy of this Rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
155 that.copy = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
156 return rectangle(this);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
157 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
158 // returns the position of this Rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
159 that.getPosition = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
160 return position(this);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
161 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
162 // returns the size of this Rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
163 that.getSize = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
164 return size(this);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
165 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
166 // returns the upper left corner position
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
167 that.getPt1 = that.getPosition;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
168 // returns the lower right corner position of this Rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
169 that.getPt2 = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
170 return position({
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
171 x : this.x + this.width,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
172 y : this.y + this.height
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
173 });
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
174 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
175 // sets the upper left corner position to pos
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
176 that.setPosition = function(pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
177 this.x = pos.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
178 this.y = pos.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
179 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
180 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
181 that.setPt1 = that.setPosition; // TODO: not really the same
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
182 // adds pos to the position
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
183 that.addPosition = function(pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
184 this.x += pos.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
185 this.y += pos.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
186 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
187 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
188 // sets the lower right corner to position pos
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
189 that.setPt2 = function(pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
190 this.width = pos.x - this.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
191 this.height = pos.y - this.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
192 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
193 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
194 // returns the center position of this Rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
195 that.getCenter = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
196 return position({
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
197 x : this.x + this.width / 2,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
198 y : this.y + this.height / 2
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
199 });
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
200 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
201 // moves this Rectangle's center to position pos
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
202 that.setCenter = function(pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
203 this.x = pos.x - this.width / 2;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
204 this.y = pos.y - this.height / 2;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
205 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
206 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
207 that.equals = function(other) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
208 // equal props
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
209 var eq = (this.x === other.x && this.y === other.y && this.width === other.width);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
210 return eq;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
211 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
212 // returns the area of this Rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
213 that.getArea = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
214 return (this.width * this.height);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
215 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
216 // eliminates negative width and height
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
217 that.normalize = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
218 var p = this.getPt2();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
219 this.x = Math.min(this.x, p.x);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
220 this.y = Math.min(this.y, p.y);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
221 this.width = Math.abs(this.width);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
222 this.height = Math.abs(this.height);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
223 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
224 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
225 // returns if Position "pos" lies inside of this rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
226 that.containsPosition = function(pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
227 var ct = ((pos.x >= this.x) && (pos.y >= this.y)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
228 && (pos.x <= this.x + this.width) && (pos.y <= this.y
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
229 + this.height));
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
230 return ct;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
231 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
232 // returns if rectangle "rect" is contained in this rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
233 that.containsRect = function(rect) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
234 return (this.containsPosition(rect.getPt1()) && this
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
235 .containsPosition(rect.getPt2()));
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
236 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
237 // changes this rectangle's x/y values so it stays inside of rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
238 // rect
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
239 // keeping the proportions
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
240 that.stayInside = function(rect) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
241 if (this.x < rect.x) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
242 this.x = rect.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
243 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
244 if (this.y < rect.y) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
245 this.y = rect.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
246 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
247 if (this.x + this.width > rect.x + rect.width) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
248 this.x = rect.x + rect.width - this.width;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
249 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
250 if (this.y + this.height > rect.y + rect.height) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
251 this.y = rect.y + rect.height - this.height;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
252 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
253 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
254 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
255 // clips this rectangle so it stays inside of rectangle rect
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
256 that.clipTo = function(rect) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
257 var p1 = rect.getPt1();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
258 var p2 = rect.getPt2();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
259 var this2 = this.getPt2();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
260 this.setPosition(position(Math.max(this.x, p1.x), Math.max(this.y, p1.y)));
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
261 this.setPt2(position(Math.min(this2.x, p2.x), Math.min(this2.y, p2.y)));
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
262 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
263 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
264 // returns the intersection of the given Rectangle and this one
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
265 that.intersect = function(rect) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
266 // FIX ME: not really, it should return null if there is no overlap
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
267 var sec = rect.copy();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
268 if (sec.x < this.x) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
269 sec.width = sec.width - (this.x - sec.x);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
270 sec.x = this.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
271 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
272 if (sec.y < this.y) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
273 sec.height = sec.height - (this.y - sec.y);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
274 sec.y = this.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
275 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
276 if (sec.x + sec.width > this.x + this.width) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
277 sec.width = (this.x + this.width) - sec.x;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
278 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
279 if (sec.y + sec.height > this.y + this.height) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
280 sec.height = (this.y + this.height) - sec.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
281 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
282 return sec;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
283 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
284 // returns a Rectangle that fits into this one (by moving first)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
285 that.fit = function(rect) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
286 var sec = rect.copy();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
287 sec.x = Math.max(sec.x, this.x);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
288 sec.y = Math.max(sec.y, this.x);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
289 if (sec.x + sec.width > this.x + this.width) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
290 sec.x = this.x + this.width - sec.width;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
291 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
292 if (sec.y + sec.height > this.y + this.height) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
293 sec.y = this.y + this.height - sec.height;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
294 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
295 return sec.intersect(this);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
296 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
297 // adjusts position and size of $elem to this rectangle
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
298 that.adjustDiv = function($elem) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
299 $elem.offset({
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
300 left : this.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
301 top : this.y
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
302 });
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
303 $elem.width(this.width).height(this.height);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
304 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
305 // returns size and position in css-compatible format
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
306 that.getAsCss = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
307 return {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
308 left : this.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
309 top : this.y,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
310 width : this.width,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
311 height : this.height
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
312 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
313 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
314 that.toString = function() {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
315 return this.width + "x" + this.height + "@" + this.x + "," + this.y;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
316 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
317 return that;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
318 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
319
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
320 /*
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
321 * Transform class
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
322 *
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
323 * defines a class of affine transformations
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
324 */
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
325 var transform = function(spec) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
326 var that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
327 m00 : 1.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
328 m01 : 0.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
329 m02 : 0.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
330 m10 : 0.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
331 m11 : 1.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
332 m12 : 0.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
333 m20 : 0.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
334 m21 : 0.0,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
335 m22 : 1.0
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
336 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
337 if (spec) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
338 jQuery.extend(that, spec);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
339 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
340 ;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
341 that.concat = function(trafA) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
342 // add Transform trafA to this Transform (i.e. this = trafC = trafA
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
343 // * this)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
344 var trafC = {};
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
345 for ( var i = 0; i < 3; i++) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
346 for ( var j = 0; j < 3; j++) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
347 var c = 0.0;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
348 for ( var k = 0; k < 3; k++) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
349 c += trafA["m" + i + k] * this["m" + k + j];
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
350 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
351 trafC["m" + i + j] = c;
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
352 }
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
353 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
354 jQuery.extend(this, trafC);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
355 return this;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
356 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
357 that.transform = function(rect) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
358 // returns transformed Rectangle or Position with this Transform
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
359 // applied
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
360 var x = this.m00 * rect.x + this.m01 * rect.y + this.m02;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
361 var y = this.m10 * rect.x + this.m11 * rect.y + this.m12;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
362 var pt = position(x, y);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
363 if (rect.width) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
364 // transform the other corner point
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
365 var pt2 = this.transform(rect.getPt2());
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
366 return rectangle(pt, pt2);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
367 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
368 return pt;
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
369 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
370 that.invtransform = function(rect) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
371 // returns transformed Rectangle or Position with the inverse of
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
372 // this Transform applied
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
373 var det = this.m00 * this.m11 - this.m01 * this.m10;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
374 var x = (this.m11 * rect.x - this.m01 * rect.y - this.m11
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
375 * this.m02 + this.m01 * this.m12)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
376 / det;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
377 var y = (-this.m10 * rect.x + this.m00 * rect.y + this.m10
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
378 * this.m02 - this.m00 * this.m12)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
379 / det;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
380 var pt = position(x, y);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
381 if (rect.width) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
382 // transform the other corner point
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
383 var pt2 = this.invtransform(rect.getPt2());
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
384 return rectangle(pt, pt2);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
385 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
386 return pt;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
387 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
388 that.toString = function(pretty) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
389 var s = '[';
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
390 if (pretty)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
391 s += '\n';
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
392 for ( var i = 0; i < 3; ++i) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
393 s += '[';
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
394 for ( var j = 0; j < 3; ++j) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
395 if (j)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
396 s += ',';
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
397 s += this['m' + i + j];
664
d5a5ee4cbf04 work on getting transformation to work with rotation (currently still doesn't)
robcast
parents: 656
diff changeset
398 }
d5a5ee4cbf04 work on getting transformation to work with rotation (currently still doesn't)
robcast
parents: 656
diff changeset
399 s += ']';
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
400 if (pretty)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
401 s += '\n';
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
402 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
403 s += ']';
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
404 if (pretty)
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
405 s += '\n';
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
406 return s;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
407 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
408 // add class methods to instance
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
409 that.getRotation = transform.getRotation;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
410 that.getRotationAround = transform.getRotationAround;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
411 that.getTranslation = transform.getTranslation;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
412 that.getMirror = transform.getMirror;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
413 that.getScale = transform.getScale;
655
72acc47f1831 first try at birdview indicator
hertzhaft
parents: 627
diff changeset
414
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
415 return that;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
416 };
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
417
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
418 transform.getRotation = function(angle) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
419 // returns a Transform that is a rotation by angle degrees around [0,0]
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
420 if (angle !== 0) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
421 var t = Math.PI * parseFloat(angle) / 180.0;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
422 var cost = Math.cos(t);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
423 var sint = Math.sin(t);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
424 var traf = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
425 m00 : cost,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
426 m01 : -sint,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
427 m10 : sint,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
428 m11 : cost
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
429 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
430 return transform(traf);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
431 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
432 return transform();
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
433 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
434
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
435 transform.getRotationAround = function(angle, pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
436 // returns a Transform that is a rotation by angle degrees around pos
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
437 var traf = transform.getTranslation(pos.neg());
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
438 traf.concat(transform.getRotation(angle));
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
439 traf.concat(transform.getTranslation(pos));
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
440 return traf;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
441 };
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
442
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
443 transform.getTranslation = function(pos) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
444 // returns a Transform that is a translation by [pos.x, pos,y]
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
445 var traf = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
446 m02 : pos.x,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
447 m12 : pos.y
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
448 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
449 return transform(traf);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
450 };
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
451
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
452 transform.getMirror = function(type) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
453 // returns a Transform that is a mirror about the axis type
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
454 if (type === 'x') {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
455 var traf = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
456 m00 : 1,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
457 m11 : -1
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
458 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
459 } else {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
460 var traf = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
461 m00 : -1,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
462 m11 : 1
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
463 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
464 }
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
465 return transform(traf);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
466 };
675
ca37fb4b1e72 transformation with mirror works now too!
robcast
parents: 672
diff changeset
467
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
468 transform.getScale = function(size) {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
469 // returns a Transform that is a scale by [size.width, size.height]
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
470 var traf = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
471 m00 : size.width,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
472 m11 : size.height
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
473 };
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
474 return transform(traf);
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
475 };
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
476
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
477 // export functions
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
478 var that = {
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
479 size : size,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
480 position : position,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
481 rectangle : rectangle,
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
482 transform : transform
606
8204615dad77 geometry classes as extra file
robcast
parents:
diff changeset
483 };
741
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
484
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
485 return that;
ee620bcf4ab0 image-drag now with full background image :-)
robcast
parents: 738
diff changeset
486 };