Files
blockly/core/utils/math.ts
Maribeth Bottorff 88ff901a72 chore: use prettier instead of clang-format (#7014)
* 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
2023-05-10 16:01:39 -07:00

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));
}