blob: 525392b1ab5f8444ca5bc052a7eb915ccfeff347 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
function Point(e, offset) {
if (typeof e == "number" && typeof offset == "number") {
this.x = e;
this.y = offset;
}
else if (! e) {
this.x = 0;
this.y = 0;
}
else if ('x' in e && 'y' in e) {
this.x = e.x;
this.y = e.y;
}
else if ('pageX' in e && 'pageX' in e) {
this.x = e.pageX;
this.y = e.pageY;
}
if (typeof offset == "object") {
this.subtract({
x: offset.left,
y: offset.top
});
}
}
Point.prototype.add = function(p) {
this.x += p.x;
this.y += p.y;
return this;
}
Point.prototype.subtract = function(p) {
this.x -= p.x;
this.y -= p.y;
return this;
}
Point.prototype.quantize = function(x, y) {
this.x = Math.floor( this.x / x ) * x;
this.y = Math.floor( this.y / y ) * y;
return this;
}
Point.prototype.scale = function(x, y) {
this.x *= x;
this.y *= y;
return this;
}
Point.prototype.floor = function(){
this.x = Math.floor(this.x);
this.y = Math.floor(this.y);
return this;
}
Point.prototype.ceil = function(){
this.x = Math.ceil(this.x);
this.y = Math.ceil(this.y);
return this;
}
Point.prototype.round = function(){
this.x = Math.round(this.x);
this.y = Math.round(this.y);
return this;
}
|