mirror of
https://github.com/firestar5683/StarPilot.git
synced 2026-11-11 15:03:44 +08:00
fab3ec9aeb
Add Galaxy web assets and client settings interfaces with their bundled vendor notices. Co-authored-by: Danny <dannyirwin31@yahoo.com> Co-authored-by: Prabhaav Pillai <prabhaav@msu.edu> Co-authored-by: dirwin31 <83434411+dirwin31@users.noreply.github.com> Co-authored-by: firestarsdog <229254897+firestarsdog@users.noreply.github.com> Co-authored-by: Dom <168790843+firestar5683@users.noreply.github.com> Co-authored-by: prabhaavp <prabhaav@msu.edu>
31 lines
1.6 KiB
JavaScript
31 lines
1.6 KiB
JavaScript
// Saved centers are pixels in the unmirrored cabin frame. Invert changes only
|
|
// the displayed crop pixels; vehicle-side selection always uses source sides.
|
|
export const FORMATS = [[1928, 1208], [1344, 760]]
|
|
|
|
export function displayPoint(center, width, invert) {
|
|
return center === null ? null : [invert ? width - center[0] : center[0], center[1]]
|
|
}
|
|
|
|
export function sourcePoint(clientX, clientY, rect, width, height, invert) {
|
|
if (!(rect?.width > 0 && rect.height > 0) || typeof invert !== "boolean" ||
|
|
!FORMATS.some(([w, h]) => w === width && h === height)) return null
|
|
const x = (clientX - rect.left) / rect.width
|
|
const y = (clientY - rect.top) / rect.height
|
|
if (!Number.isFinite(x) || !Number.isFinite(y) || x < 0 || x > 1 || y < 0 || y > 1) return null
|
|
return [Math.round((invert ? 1 - x : x) * width), Math.round(y * height)]
|
|
}
|
|
|
|
const centerValid = (center, width, height, size) => center === null ||
|
|
(Array.isArray(center) && center.length === 2 && center.every(Number.isInteger) &&
|
|
center[0] - size / 2 >= 0 && center[0] + size / 2 <= width &&
|
|
center[1] - size / 2 >= 0 && center[1] + size / 2 <= height)
|
|
|
|
export function maskDraft(width, height, cropSize, centerLeft, centerRight) {
|
|
if (!FORMATS.some(([w, h]) => w === width && h === height) ||
|
|
!Number.isInteger(cropSize) || cropSize < 20 || cropSize > Math.min(width, height) ||
|
|
(centerLeft === null && centerRight === null) ||
|
|
!centerValid(centerLeft, width, height, cropSize) ||
|
|
!centerValid(centerRight, width, height, cropSize)) return null
|
|
return { width, height, crop_size: cropSize, center_left: centerLeft, center_right: centerRight }
|
|
}
|