-
Notifications
You must be signed in to change notification settings - Fork 1
/
geometry.js
72 lines (62 loc) · 1.26 KB
/
geometry.js
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
61
62
63
64
65
66
67
68
69
70
71
72
var Geometry = function (args) {
if ( !(this instanceof Geometry) ) {
return new Geometry(args)
}
}
Geometry.prototype.rect = function(x, y, width, height, rx, ry) {
return new Element({
x: x,
y: y,
width: width,
height: height,
rx: rx,
ry: ry
})
}
Geometry.prototype.line = function(x1, y1, x2, y2) {
return new Element({
x1: x1,
y1: y1,
x2: x2,
y2: y2
})
}
Geometry.prototype.circle = function(x, y, r) {
return new Element({
cx: x,
cy: y,
r: r
})
}
var Element = function(args) {
if ( !(this instanceof Element) ) {
return new Element(args)
}
if (args) {
var keys = Object.keys(args)
keys.forEach(function(key){
this[key] = args[key]
}, this)
}
}
Element.prototype.attr = function(args) {
if (typeof args === 'object') {
var keys = Object.keys(args)
keys.forEach(function(key){
this[key] = args[key]
}, this)
return this
} else if (typeof args === 'string'){
return this[args]
}
}
Element.prototype.drag = function(onmove, onstart, onend, mcontext, scontext, econtext) {
this.onmove = onmove
return this
}
Element.prototype.click = function(func) {
this.onclick = func
return this
}
exports.Element = Element
exports.Geometry = Geometry