• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

jumpinjackie / mapguide-react-layout / 15160437878

21 May 2025 11:00AM UTC coverage: 21.631% (-42.6%) from 64.24%
15160437878

Pull #1552

github

web-flow
Merge 8b7153d9e into 236e2ea07
Pull Request #1552: Feature/package updates 2505

839 of 1165 branches covered (72.02%)

11 of 151 new or added lines in 25 files covered. (7.28%)

1332 existing lines in 50 files now uncovered.

4794 of 22163 relevant lines covered (21.63%)

6.89 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

87.14
/src/utils/number.ts
1
const SHIM_EPSILON = Math.pow(2, -52);
1✔
2

3
function epsilon(): number {
6✔
4
    const num: any = Number;
6✔
5
    return num.EPSILON || SHIM_EPSILON;
6!
6
}
6✔
7

8
/**
9
 * Restricts the given number to the given range
10
 * 
11
 * @export
12
 * @param {number} val 
13
 * @param {number} lower 
14
 * @param {number} upper 
15
 */
16
export function restrictToRange(val: number, lower: number, upper: number) {
1✔
17
    return Math.min(Math.max(val, lower), upper);
2✔
18
}
2✔
19

20
/**
21
 * Indicates if the given numbers are equal
22
 *
23
 * @export
24
 * @param {number} a
25
 * @param {number} b
26
 * @returns {boolean}
27
 */
28
export function areNumbersEqual(a: number, b: number): boolean {
1✔
29
    return Math.abs(a - b) < epsilon();
6✔
30
}
6✔
31

32
/**
33
 * Indicates if the given scale is within the specified range
34
 *
35
 * @export
36
 * @param {number} scale
37
 * @param {number} minScale
38
 * @param {number} maxScale
39
 * @returns {boolean}
40
 */
41
export function scaleRangeBetween(scale: number, minScale: number, maxScale: number): boolean {
1✔
42
    //Note the '<'. This is the same range check used in MapGuide Server
43
    return scale >= minScale && scale < maxScale;
5✔
44
}
5✔
45

46
/**
47
 * Gets the closest scale index for the given scale and scale array pair
48
 *
49
 * @export
50
 * @param {[number, number]} scales
51
 * @param {number} scale
52
 * @returns {number}
53
 */
54
export function getClosestScaleIndex(scales: [number, number], scale: number): number {
1✔
55
    const d1 = Math.abs(scales[0] - scale);
11✔
56
    const d2 = Math.abs(scales[1] - scale);
11✔
57
    if (d1 < d2)
11✔
58
        return 0;
11✔
59
    else
60
        return 1;
7✔
61
}
11✔
62

63
/**
64
 * Gets the applicable finite scale index for the given scale and finite scale array
65
 *
66
 * @export
67
 * @param {number[]} finiteScaleList
68
 * @param {number} scale
69
 * @returns {number}
70
 */
71
export function getFiniteScaleIndexForScale(finiteScaleList: number[], scale: number): number {
1✔
72
    for (let i = 0; i < finiteScaleList.length; i++) {
11✔
73
        if (scale >= finiteScaleList[i]) { //Found the lower bound
52✔
74
            if ((i + 1) < finiteScaleList.length) { //There is a possible upper bound
51✔
75
                if (scale <= finiteScaleList[i+1]) { //It is the upper bound
50✔
76
                    const test: [number, number] = [finiteScaleList[i], finiteScaleList[i+1]];
9✔
77
                    //Snap to the scale with lowest difference
78
                    const testIndex = getClosestScaleIndex(test, scale);
9✔
79
                    if (testIndex == 0) {
9✔
80
                        return i;
3✔
81
                    } else {
9✔
82
                        return i+1;
6✔
83
                    }
6✔
84
                }
9✔
85
            } else { //There is no upper bound (we're at the end), snap to it
51✔
86
                return i;
1✔
87
            }
1✔
88
        } else if (scale <= finiteScaleList[i]) {
52✔
89
            if (i > 0) {
1!
90
                const test: [number, number] = [finiteScaleList[i-1], finiteScaleList[i]];
×
91
                const testIndex = getClosestScaleIndex(test, scale);
×
92
                if (testIndex == 0) {
×
93
                    return i-1;
×
UNCOV
94
                } else {
×
95
                    return i;
×
UNCOV
96
                }
×
97
            } else {
1✔
98
                return i;
1✔
99
            }
1✔
100
        }
1✔
101
    }
52!
102
    return 0;
×
UNCOV
103
}
×
104

105
/**
106
 * Converts the given angle in degrees to radians
107
 * @param deg The angle in degrees
108
 */
109
export function deg2rad(deg: number): number {
1✔
110
    return deg * (Math.PI / 180);
1✔
111
}
1✔
112

113
/**
114
 * Converts the given angle in radians to degrees
115
 * @param radians 
116
 * @since 0.13
117
 */
118
export function rad2deg(radians: number) {
1✔
119
    return radians * (180 / Math.PI);
1✔
120
}
1✔
121

122
/**
123
 * Computes the sum of the given array
124
 * 
125
 * @since 0.11
126
 * @export
127
 * @template T 
128
 * @param {T[]} array 
129
 * @param {(item: T) => number} numSelector 
130
 * @returns {number} 
131
 */
132
export function sum<T>(array: T[], numSelector: (item: T) => number): number {
1✔
133
    let total = 0;
1✔
134
    for (const item of array) {
1✔
135
        total += numSelector(item);
3✔
136
    }
3✔
137
    return total;
1✔
138
}
1✔
139

140
/**
141
 * Rounds the given number to the specified number of decimals
142
 * 
143
 * @since 0.11
144
 * @export
145
 * @param {number} num 
146
 * @param {number} [decimals=2] 
147
 * @returns {number} 
148
 */
149
export function roundTo(num: number, decimals: number = 2): number {
1✔
150
    const a = Math.pow(10, decimals);
3✔
151
    return Math.round(num * a) / a;
3✔
152
}
3✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc