summaryrefslogtreecommitdiff
path: root/public/js
diff options
context:
space:
mode:
Diffstat (limited to 'public/js')
-rw-r--r--public/js/draw.js16
-rw-r--r--public/js/point.js60
2 files changed, 60 insertions, 16 deletions
diff --git a/public/js/draw.js b/public/js/draw.js
index 9116f78..b15416b 100644
--- a/public/js/draw.js
+++ b/public/js/draw.js
@@ -95,19 +95,3 @@ function Brush (b) {
$("#drawing").append(canvas);
}
-function Point(e, offset) {
- this.x = e.pageX - offset.left;
- this.y = e.pageY - offset.top;
-}
-Point.prototype.add = function(p) {
- this.x += p.x;
- this.y += p.y;
-}
-Point.prototype.subtract = function(p) {
- this.x -= p.x;
- this.y -= p.y;
-}
-Point.prototype.quantize = function(x, y) {
- this.x = Math.floor( this.x / x ) * x;
- this.y = Math.floor( this.y / y ) * y;
-}
diff --git a/public/js/point.js b/public/js/point.js
new file mode 100644
index 0000000..525392b
--- /dev/null
+++ b/public/js/point.js
@@ -0,0 +1,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;
+}
+