Remove treeview-1.3 since it is unused.
[openemr.git] / interface / static / literallycanvas-0-4-13 / js / core / math.js
blobbf6c0ab7dda8d238162208b67e075afb6509ca7a
1 var Point, _slope, math, normals, unit, util;
3 Point = require('./shapes').Point;
5 util = require('./util');
7 math = {};
9 math.toPoly = function(line) {
10   var i, index, len, n, point, polyLeft, polyRight;
11   polyLeft = [];
12   polyRight = [];
13   index = 0;
14   for (i = 0, len = line.length; i < len; i++) {
15     point = line[i];
16     n = normals(point, _slope(line, index));
17     polyLeft = polyLeft.concat([n[0]]);
18     polyRight = [n[1]].concat(polyRight);
19     index += 1;
20   }
21   return polyLeft.concat(polyRight);
24 _slope = function(line, index) {
25   var point;
26   if (line.length < 3) {
27     point = {
28       x: 0,
29       y: 0
30     };
31   }
32   if (index === 0) {
33     point = _slope(line, index + 1);
34   } else if (index === line.length - 1) {
35     point = _slope(line, index - 1);
36   } else {
37     point = math.diff(line[index - 1], line[index + 1]);
38   }
39   return point;
42 math.diff = function(a, b) {
43   return {
44     x: b.x - a.x,
45     y: b.y - a.y
46   };
49 unit = function(vector) {
50   var length;
51   length = math.len(vector);
52   return {
53     x: vector.x / length,
54     y: vector.y / length
55   };
58 normals = function(p, slope) {
59   slope = unit(slope);
60   slope.x = slope.x * p.size / 2;
61   slope.y = slope.y * p.size / 2;
62   return [
63     {
64       x: p.x - slope.y,
65       y: p.y + slope.x,
66       color: p.color
67     }, {
68       x: p.x + slope.y,
69       y: p.y - slope.x,
70       color: p.color
71     }
72   ];
75 math.len = function(vector) {
76   return Math.sqrt(Math.pow(vector.x, 2) + Math.pow(vector.y, 2));
79 math.scalePositionScalar = function(val, viewportSize, oldScale, newScale) {
80   var newSize, oldSize;
81   oldSize = viewportSize * oldScale;
82   newSize = viewportSize * newScale;
83   return val + (oldSize - newSize) / 2;
86 module.exports = math;