forked from darkreader/darkreader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmath.ts
More file actions
22 lines (20 loc) · 705 Bytes
/
Copy pathmath.ts
File metadata and controls
22 lines (20 loc) · 705 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
export function scale(x: number, inLow: number, inHigh: number, outLow: number, outHigh: number) {
return (x - inLow) * (outHigh - outLow) / (inHigh - inLow) + outLow;
}
export function clamp(x: number, min: number, max: number) {
return Math.min(max, Math.max(min, x));
}
export function multiplyMatrices(m1: number[][], m2: number[][]) {
const result: number[][] = [];
for (let i = 0; i < m1.length; i++) {
result[i] = [];
for (let j = 0; j < m2[0].length; j++) {
let sum = 0;
for (let k = 0; k < m1[0].length; k++) {
sum += m1[i][k] * m2[k][j];
}
result[i][j] = sum;
}
}
return result;
}