Fix build faliures due to OFPlugin checktyle fixes
[netvirt.git] / ovsdb-ui / module / src / main / resources / ovsdb / matrix.js
1 define(['app/ovsdb/lib/sylvester'], function() {
2   function Transform(a, b, c, d , e, f) {
3     if (a)
4     this.transform = $M([
5       [a, b, c],
6       [d, e, f],
7       [0, 0, 1]
8     ]);
9     else
10       this.transform = Matrix.I(3);
11   }
12
13   Transform.fromString = function(string) {
14     if(!string) {
15       return new Transform();
16     }
17     var g = document.createElementNS("http://www.w3.org/2000/svg", 'g');
18     g.setAttribute('transform', string);
19     var t = g.transform.baseVal.consolidate();
20     var m = t.matrix;
21     return new Transform(m.a, m.b, m.c, m.d, m.e, m.f);
22   }
23
24   Transform.combine = function(ma, mb) {
25     var t = new Transform();
26     t.transform = ma.transform.x(mb.transform);
27     return t;
28   }
29
30   Transform.prototype.translate = function(tx, ty) {
31     this.transform = $M([[1, 0, tx], [0, 1, ty], [0, 0, 1]]).x(this.transform);
32     return this;
33   };
34
35   Transform.prototype.rotate = function(deg) {
36     var rad = parseFloat(deg) * (Math.PI/180),
37     cos = Math.cos(rad),
38     sin = Math.sin(rad);
39
40     this.transform = $M([[cos, -sin, 0], [sin, cos, 0], [0, 0, 1]]).x(this.transform);
41     return this;
42   };
43
44   Transform.prototype.scale = function(x, y) {
45     var x = x,
46     y = y || x;
47
48     this.transform = $M([[x, 0, 0], [0, y, 0], [0, 0, 1]]).x(this.transform);
49     return this;
50   };
51
52   Transform.prototype.skew = function(x, y) {
53     var alpha = Math.tan(parseFloat(x) * (Math.PI/180)),
54      betha = Math.tan(parseFloat(y) * (Math.PI/180));
55
56     this.transform = $M([[1, alpha, 0], [betha, 1, 0], [0, 0, 1]]).x(this.transform);
57     return this;
58   };
59
60   Transform.prototype.transformPoint = function(x, y) {
61     var v = $V([x, y, 1]);
62     return this.transform.x(v);
63   };
64
65   Transform.prototype.toString = function() {
66     return this.transform.inspect();
67   }
68
69   return {
70     Matrix: Transform // Matrix function name already used by Sylvester
71   };
72 });