mirror of
https://github.com/spacebarchat/server.git
synced 2026-10-23 00:03:05 +00:00
rid of Math.clamp
This commit is contained in:
1 parent
1613ba82ae
commit
5a3965ab22
4 files changed
+2
-53
No files matched your search
@@ -1,19 +0,0 @@
|
||||
import moduleAlias from "module-alias";
|
||||
moduleAlias();
|
||||
import './Math';
|
||||
import { describe, it } from 'node:test';
|
||||
import assert from 'node:assert/strict';
|
||||
|
||||
describe("Math extensions", () => {
|
||||
|
||||
it("clamp", async () => {
|
||||
assert.strictEqual(Math.clamp(5, 1, 10), 5);
|
||||
assert.strictEqual(Math.clamp(0, 1, 10), 1);
|
||||
assert.strictEqual(Math.clamp(15, 1, 10), 10);
|
||||
assert.strictEqual(Math.clamp(-5, -10, -1), -5);
|
||||
assert.strictEqual(Math.clamp(-15, -10, -1), -10);
|
||||
assert.strictEqual(Math.clamp(-0.5, -1, 0), -0.5);
|
||||
assert.strictEqual(Math.clamp(1.5, 1, 2), 1.5);
|
||||
});
|
||||
|
||||
});
|
||||
@@ -1,31 +0,0 @@
|
||||
/*
|
||||
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
|
||||
Copyright (C) 2025 Spacebar and Spacebar Contributors
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published
|
||||
by the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
declare global {
|
||||
interface Math {
|
||||
clamp(value: number, min: number, max: number): number;
|
||||
}
|
||||
}
|
||||
|
||||
export function mathClamp(value: number, min: number, max: number): number {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
// register extensions
|
||||
if (!Math.clamp)
|
||||
Math.clamp = mathClamp;
|
||||
@@ -1,4 +1,3 @@
|
||||
export * from "./Array";
|
||||
export * from "./Math";
|
||||
export * from "./Url";
|
||||
export * from "./String";
|
||||
Reference in new issue
Block a user