2023-06-23 09:37:25 +00:00
|
|
|
export function is_in_range (number, min, max) {
|
2023-06-23 09:00:12 +00:00
|
|
|
return number >= min && number <= max;
|
|
|
|
}
|
|
|
|
|
2023-06-23 09:37:25 +00:00
|
|
|
export function clamp (number, min, max) {
|
2023-06-23 09:00:12 +00:00
|
|
|
return number < min
|
|
|
|
? min
|
|
|
|
: number > max
|
|
|
|
? max
|
|
|
|
: number;
|
|
|
|
}
|
|
|
|
|
2023-06-23 09:37:25 +00:00
|
|
|
export function range (start, end) {
|
2023-06-23 09:00:12 +00:00
|
|
|
const result = [];
|
|
|
|
for (let n = start; n <= end; n++) {
|
|
|
|
result.push(n);
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
2023-06-23 09:37:25 +00:00
|
|
|
|
|
|
|
export function iter_2d (range_1d, callback) {
|
|
|
|
for (const y in range_1d) {
|
|
|
|
for (const x in range_1d) {
|
|
|
|
callback(x, y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|