import { Vector2 , Vector3 } from "three" ; param screenCoordinateX param screenCoordinateY param screenSizeX param screenSizeY export function calculateNormalizedDeviceCoordinates ( screenCoordinateX , screenCoordinateY , screenSizeX , screenSizeY ) { return new Vector2 ( ( screenCoordinateX / screenSizeX ) * 2 - 1 , - ( ( screenCoordinateY / screenSizeY ) * 2 ) + 1 ) ; } param azimuth param altitude export function azimuthAltitudeToDirection ( azimuth , altitude ) { azimuth = azimuth ; altitude = altitude ; const result = new Vector3 ( ) ; const cosAltitude = Math . cos ( altitude ) ; result . setX ( Math . sin ( azimuth ) * cosAltitude ) ; result . setY ( Math . cos ( azimuth ) * cosAltitude ) ; result . setZ ( Math . sin ( altitude ) ) ; return result ; } param text param fallback export function safeParseDecimalInt ( text , fallback ) { if ( text === null || text === undefined || text === "" ) { return fallback ; } if ( ! text . match ( integerRe ) ) { return fallback ; } const result = Number . parseInt ( text , 10 ) ; if ( isNaN ( result ) ) { return fallback ; } return result ; } const integerRe = /^\d+$/ ; param canvas export function getWidthAndHeightFromCanvas ( canvas ) { return { width : safeParseDecimalInt ( canvas . style . width , canvas . clientWidth ) , height : safeParseDecimalInt ( canvas . style . height , canvas . clientHeight ) } ; }