mirror of
https://github.com/google/blockly.git
synced 2026-01-10 02:17:09 +01:00
* chore: add and configure prettier * chore: remove clang-format * chore: remove clang-format config * chore: lint additional ts files * chore: fix lint errors in blocks * chore: add prettier-ignore where needed * chore: ignore js blocks when formatting * chore: fix playground html syntax * chore: fix yaml spacing from merge * chore: convert text blocks to use arrow functions * chore: format everything with prettier * chore: fix lint unused imports in blocks
52 lines
1.2 KiB
TypeScript
52 lines
1.2 KiB
TypeScript
/**
|
|
* @license
|
|
* Copyright 2019 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
import * as goog from '../../closure/goog/goog.js';
|
|
goog.declareModuleId('Blockly.utils.math');
|
|
|
|
/**
|
|
* Converts degrees to radians.
|
|
* Copied from Closure's goog.math.toRadians.
|
|
*
|
|
* @param angleDegrees Angle in degrees.
|
|
* @returns Angle in radians.
|
|
*/
|
|
export function toRadians(angleDegrees: number): number {
|
|
return (angleDegrees * Math.PI) / 180;
|
|
}
|
|
|
|
/**
|
|
* Converts radians to degrees.
|
|
* Copied from Closure's goog.math.toDegrees.
|
|
*
|
|
* @param angleRadians Angle in radians.
|
|
* @returns Angle in degrees.
|
|
*/
|
|
export function toDegrees(angleRadians: number): number {
|
|
return (angleRadians * 180) / Math.PI;
|
|
}
|
|
|
|
/**
|
|
* Clamp the provided number between the lower bound and the upper bound.
|
|
*
|
|
* @param lowerBound The desired lower bound.
|
|
* @param number The number to clamp.
|
|
* @param upperBound The desired upper bound.
|
|
* @returns The clamped number.
|
|
*/
|
|
export function clamp(
|
|
lowerBound: number,
|
|
number: number,
|
|
upperBound: number
|
|
): number {
|
|
if (upperBound < lowerBound) {
|
|
const temp = upperBound;
|
|
upperBound = lowerBound;
|
|
lowerBound = temp;
|
|
}
|
|
return Math.max(lowerBound, Math.min(number, upperBound));
|
|
}
|