1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.fisheyeCircular = exports.fisheye = exports.fisheyeY = exports.fisheyeX = void 0;
|
4 | function fisheyeTransform(x, focus, distortion, min, max) {
|
5 | var left = x < focus;
|
6 | var m = (left ? focus - min : max - focus) || max - min;
|
7 | var f = left ? -1 : 1;
|
8 | return (f * m * (distortion + 1)) / (distortion + m / ((x - focus) * f)) + focus;
|
9 | }
|
10 | function fisheyeUntransform(tx, focus, distortion, min, max) {
|
11 | var left = tx < focus;
|
12 | var m = (left ? focus - min : max - focus) || max - min;
|
13 | var f = left ? -1 : 1;
|
14 | return m / ((m * (distortion + 1)) / (tx - focus) - distortion * f) + focus;
|
15 | }
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | var fisheyeX = function (params, x, y, width, height) {
|
26 | var _a = params, focus = _a[0], distortion = _a[1];
|
27 | return {
|
28 | transform: function (vector) {
|
29 | var vx = vector[0], vy = vector[1];
|
30 | var fx = fisheyeTransform(vx, focus, distortion, x, x + width);
|
31 | return [fx, vy];
|
32 | },
|
33 | untransform: function (vector) {
|
34 | var fx = vector[0], vy = vector[1];
|
35 | var vx = fisheyeUntransform(fx, focus, distortion, x, x + width);
|
36 | return [vx, vy];
|
37 | },
|
38 | };
|
39 | };
|
40 | exports.fisheyeX = fisheyeX;
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 | var fisheyeY = function (params, x, y, width, height) {
|
51 | var _a = params, focus = _a[0], distortion = _a[1];
|
52 | return {
|
53 | transform: function (vector) {
|
54 | var vx = vector[0], vy = vector[1];
|
55 | var fy = fisheyeTransform(vy, focus, distortion, y, y + height);
|
56 | return [vx, fy];
|
57 | },
|
58 | untransform: function (vector) {
|
59 | var vx = vector[0], fy = vector[1];
|
60 | var vy = fisheyeUntransform(fy, focus, distortion, y, y + height);
|
61 | return [vx, vy];
|
62 | },
|
63 | };
|
64 | };
|
65 | exports.fisheyeY = fisheyeY;
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 | var fisheye = function (params, x, y, width, height) {
|
76 | var _a = params, focusX = _a[0], focusY = _a[1], distortionX = _a[2], distortionY = _a[3];
|
77 | return {
|
78 | transform: function (vector) {
|
79 | var vx = vector[0], vy = vector[1];
|
80 | var fx = fisheyeTransform(vx, focusX, distortionX, x, x + width);
|
81 | var fy = fisheyeTransform(vy, focusY, distortionY, y, y + height);
|
82 | return [fx, fy];
|
83 | },
|
84 | untransform: function (vector) {
|
85 | var fx = vector[0], fy = vector[1];
|
86 | var vx = fisheyeUntransform(fx, focusX, distortionX, x, x + width);
|
87 | var vy = fisheyeUntransform(fy, focusY, distortionY, y, y + height);
|
88 | return [vx, vy];
|
89 | },
|
90 | };
|
91 | };
|
92 | exports.fisheye = fisheye;
|
93 |
|
94 |
|
95 |
|
96 |
|
97 |
|
98 |
|
99 |
|
100 |
|
101 |
|
102 | var fisheyeCircular = function (params, x, y, width, height) {
|
103 | var _a = params, focusX = _a[0], focusY = _a[1], radius = _a[2], distortion = _a[3];
|
104 | return {
|
105 | transform: function (vector) {
|
106 | var x = vector[0], y = vector[1];
|
107 | var dx = x - focusX;
|
108 | var dy = y - focusY;
|
109 | var dd = Math.sqrt(dx * dx + dy * dy);
|
110 | if (dd > radius)
|
111 | return [x, y];
|
112 | var r = fisheyeTransform(dd, 0, distortion, 0, radius);
|
113 | var theta = Math.atan2(dy, dx);
|
114 | return [focusX + r * Math.cos(theta), focusY + r * Math.sin(theta)];
|
115 | },
|
116 | untransform: function (vector) {
|
117 | var tx = vector[0], ty = vector[1];
|
118 | var dx = tx - focusX;
|
119 | var dy = ty - focusY;
|
120 | var dd = Math.sqrt(dx * dx + dy * dy);
|
121 | if (dd > radius)
|
122 | return [tx, ty];
|
123 | var x = fisheyeUntransform(dd, 0, distortion, 0, radius);
|
124 | var theta = Math.atan2(dy, dx);
|
125 | return [focusX + x * Math.cos(theta), focusY + x * Math.sin(theta)];
|
126 | },
|
127 | };
|
128 | };
|
129 | exports.fisheyeCircular = fisheyeCircular;
|
130 |
|
\ | No newline at end of file |