comparison client/digitallibrary/jquery/dlGeometry.js @ 649:e328273b7ef4 jquery

first try at birdview indicator
author hertzhaft
date Fri, 21 Jan 2011 00:34:15 +0100
parents 8f76bd79648e a2aadf44a454
children b0c6cc4a0932
comparison
equal deleted inserted replaced
648:8f76bd79648e 649:e328273b7ef4
22 22
23 /* 23 /*
24 * Position class 24 * Position class
25 */ 25 */
26 var position = function (x, y) { 26 var position = function (x, y) {
27 var that = { 27 if (typeof x === "object") {
28 x : parseFloat(x), 28 if (x instanceof jQuery) {
29 y : parseFloat(y) 29 // jQuery object
30 }; 30 var pos = x.offset();
31 var that = {
32 x : pos.left,
33 y : pos.top
34 };
35 } else {
36 // event object(?)
37 var that = {
38 x : x.pageX,
39 y : x.pageY
40 };
41 }
42 } else {
43 var that = {
44 x : parseFloat(x),
45 y : parseFloat(y)
46 };
47 }
31 that.equals = function(other) { 48 that.equals = function(other) {
32 return (this.x === other.x && this.y === other.y); 49 return (this.x === other.x && this.y === other.y);
33 }; 50 };
34 that.toString = function() { 51 that.toString = function() {
35 return (this.x + "," + this.y); 52 return (this.x + "," + this.y);
40 * Rectangle class 57 * Rectangle class
41 */ 58 */
42 var rectangle = function (x, y, w, h) { 59 var rectangle = function (x, y, w, h) {
43 var that = {}; 60 var that = {};
44 if (typeof x === "object") { 61 if (typeof x === "object") {
45 // assume x and y are Position 62 if (x instanceof jQuery) {
46 that = { 63 // jQuery object
47 x : x.x, 64 var pos = x.offset();
48 y : x.y, 65 that = {
49 width : y.x - x.x, 66 x : pos.left,
50 height : y.y - x.y 67 y : pos.top,
51 }; 68 width : x.width(),
69 height : x.height()
70 };
71 } else {
72 // assume x and y are Position
73 that = {
74 x : x.x,
75 y : x.y,
76 width : y.x - x.x,
77 height : y.y - x.y
78 };
79 }
52 } else { 80 } else {
53 that = { 81 that = {
54 x : parseFloat(x), 82 x : parseFloat(x),
55 y : parseFloat(y), 83 y : parseFloat(y),
56 width : parseFloat(w), 84 width : parseFloat(w),
117 return this; 145 return this;
118 }; 146 };
119 that.containsPosition = function(pos) { 147 that.containsPosition = function(pos) {
120 // returns if Position "pos" lies inside of this rectangle 148 // returns if Position "pos" lies inside of this rectangle
121 var ct = ((pos.x >= this.x) && (pos.y >= this.y) && 149 var ct = ((pos.x >= this.x) && (pos.y >= this.y) &&
122 (pos.x <= this.x + this.width) && (pos.y <= this.y + this.width)); 150 (pos.x <= this.x + this.width) && (pos.y <= this.y + this.height));
123 return ct; 151 return ct;
124 }; 152 };
125 that.containsRect = function(rect) { 153 that.containsRect = function(rect) {
126 // returns if rectangle "rect" is contained in this rectangle 154 // returns if rectangle "rect" is contained in this rectangle
127 return (this.containsPosition(rect.getPt1()) && this.containsPosition(rect.getPt2())); 155 return (this.containsPosition(rect.getPt1()) && this.containsPosition(rect.getPt2()));