HarmonyOSBaseLibs/src/main/ets/utils/AlgorithmHelper.ets
徐勤民 9c6141f7fa refactor(utils): 为工具类添加私有构造函数
- 在多个工具类中添加私有构造函数,防止实例化
-这种设计模式确保了工具类的静态方法和属性的正确使用
- 受影响的主要类包括:
  - AlgorithmHelper
  - AppStorageHelper
  - LogHelper
  - PreferencesHelper
  - SZYXLocalStorageHelper
  - SZYXLocalStorageKeys
  - TimeHelper
  - ToolsHelper  - ToolsHelperForTS - ValidatorHelper
  - WindowHelper
  - XWebHelper
2024-10-31 12:28:44 +08:00

20 行
386 B
Plaintext

/**
* 计算相关工具类
*/
export class AlgorithmHelper {
private constructor() {
}
/**
* 计算两点间距离
* @param x1
* @param y1
* @param x2
* @param y2
* @returns
*/
static calculateDistance(x1: number, y1: number, x2: number, y2: number): number {
const dx = x2 - x1;
const dy = y2 - y1;
return Math.sqrt(dx * dx + dy * dy);
}
}