1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.tickStep = exports.tickIncrement = void 0;
|
4 | const e10 = Math.sqrt(50);
|
5 | const e5 = Math.sqrt(10);
|
6 | const e2 = Math.sqrt(2);
|
7 | function tickIncrement(start, stop, count) {
|
8 | const step = (stop - start) / Math.max(0, count);
|
9 | const power = Math.floor(Math.log(step) / Math.LN10);
|
10 | const error = step / 10 ** power;
|
11 | if (power >= 0) {
|
12 |
|
13 | return (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1) * 10 ** power;
|
14 | }
|
15 |
|
16 | return -(10 ** -power) / (error >= e10 ? 10 : error >= e5 ? 5 : error >= e2 ? 2 : 1);
|
17 | }
|
18 | exports.tickIncrement = tickIncrement;
|
19 | function tickStep(start, stop, count) {
|
20 | const step0 = Math.abs(stop - start) / Math.max(0, count);
|
21 | let step1 = 10 ** Math.floor(Math.log(step0) / Math.LN10);
|
22 | const error = step0 / step1;
|
23 | if (error >= e10)
|
24 | step1 *= 10;
|
25 | else if (error >= e5)
|
26 | step1 *= 5;
|
27 | else if (error >= e2)
|
28 | step1 *= 2;
|
29 | return stop < start ? -step1 : step1;
|
30 | }
|
31 | exports.tickStep = tickStep;
|
32 |
|
\ | No newline at end of file |