Calculate safe position that prevents clipping at screen edges
Takes a desired position and element bounds, then ensures the element stays within screen bounds by clamping to safe area.
Desired 3D position [x, y, z]
Size of the element
Screen size and safe area insets
Safe position with clipping prevention
const safePos = calculateSafePosition( [100, 50, 0], { width: 200, height: 100, margin: 10 }, { width: 1920, height: 1080 });// Returns: { x: 100, y: 50, wasClamped: false } Copy
const safePos = calculateSafePosition( [100, 50, 0], { width: 200, height: 100, margin: 10 }, { width: 1920, height: 1080 });// Returns: { x: 100, y: 50, wasClamped: false }
안전위치계산
Calculate safe position that prevents clipping at screen edges
Takes a desired position and element bounds, then ensures the element stays within screen bounds by clamping to safe area.