mirror of
https://github.com/PhotonVision/photonvision
synced 2026-06-29 02:21:41 +00:00
Improve UI stability, reliability, and readability (#1104)
closes #1090 closes #1030 Also fixes various styling issues and overflow issues for mobile support
This commit is contained in:
13
photon-client/src/lib/MathUtils.ts
Normal file
13
photon-client/src/lib/MathUtils.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const mean = (values: number[]): number | undefined => {
|
||||
if (values.length === 0) return undefined;
|
||||
return values.reduce((acc, num) => acc + num, 0) / values.length;
|
||||
};
|
||||
|
||||
export const angleModulus = (valueRad: number): number => {
|
||||
while (valueRad < -Math.PI) valueRad += Math.PI * 2;
|
||||
while (valueRad > Math.PI) valueRad -= Math.PI * 2;
|
||||
return valueRad;
|
||||
};
|
||||
|
||||
export const toDeg = (val: number) => val * (180.0 / Math.PI);
|
||||
export const toRad = (val: number) => val * (Math.PI / 180.0);
|
||||
20
photon-client/src/lib/PhotonUtils.ts
Normal file
20
photon-client/src/lib/PhotonUtils.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import type { Resolution } from "@/types/SettingTypes";
|
||||
|
||||
export const resolutionsAreEqual = (a: Resolution, b: Resolution) => {
|
||||
return a.height === b.height && a.width === b.width;
|
||||
};
|
||||
|
||||
export const getResolutionString = (resolution: Resolution): string => `${resolution.width}x${resolution.height}`;
|
||||
|
||||
export const parseJsonFile = async <T extends Record<string, any>>(file: File): Promise<T> => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const fileReader = new FileReader();
|
||||
fileReader.onload = (event) => {
|
||||
const target: FileReader | null = event.target;
|
||||
if (target === null) reject();
|
||||
else resolve(JSON.parse(target.result as string) as T);
|
||||
};
|
||||
fileReader.onerror = (error) => reject(error);
|
||||
fileReader.readAsText(file);
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user