-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
/
label_texttemplate.js
75 lines (60 loc) · 1.83 KB
/
label_texttemplate.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
73
74
75
'use strict';
// Wrapper functions to handle paper-referenced shapes, which have no axis
function d2l(v, axis) {
return axis ? axis.d2l(v) : v;
}
function l2d(v, axis) {
return axis ? axis.l2d(v) : v;
}
function x0Fn(shape) { return shape.x0; }
function x1Fn(shape) { return shape.x1; }
function y0Fn(shape) { return shape.y0; }
function y1Fn(shape) { return shape.y1; }
function x0shiftFn(shape) { return shape.x0shift || 0; }
function x1shiftFn(shape) { return shape.x1shift || 0; }
function y0shiftFn(shape) { return shape.y0shift || 0; }
function y1shiftFn(shape) { return shape.y1shift || 0; }
function dxFn(shape, xa) {
return d2l(shape.x1, xa) + x1shiftFn(shape) - d2l(shape.x0, xa) - x0shiftFn(shape);
}
function dyFn(shape, xa, ya) {
return d2l(shape.y1, ya) + y1shiftFn(shape) - d2l(shape.y0, ya) - y0shiftFn(shape);
}
function widthFn(shape, xa) {
return Math.abs(dxFn(shape, xa));
}
function heightFn(shape, xa, ya) {
return Math.abs(dyFn(shape, xa, ya));
}
function lengthFn(shape, xa, ya) {
return (shape.type !== 'line') ? undefined :
Math.sqrt(
Math.pow(dxFn(shape, xa), 2) +
Math.pow(dyFn(shape, xa, ya), 2)
);
}
function xcenterFn(shape, xa) {
return l2d((d2l(shape.x1, xa) + x1shiftFn(shape) + d2l(shape.x0, xa) + x0shiftFn(shape)) / 2, xa);
}
function ycenterFn(shape, xa, ya) {
return l2d((d2l(shape.y1, ya) + y1shiftFn(shape) + d2l(shape.y0, ya) + y0shiftFn(shape)) / 2, ya);
}
function slopeFn(shape, xa, ya) {
return (shape.type !== 'line') ? undefined : (
dyFn(shape, xa, ya) / dxFn(shape, xa)
);
}
module.exports = {
x0: x0Fn,
x1: x1Fn,
y0: y0Fn,
y1: y1Fn,
slope: slopeFn,
dx: dxFn,
dy: dyFn,
width: widthFn,
height: heightFn,
length: lengthFn,
xcenter: xcenterFn,
ycenter: ycenterFn,
};