export const fitSizeToStage = (
  width: number,
  height: number,
  stageWidth: number,
  stageHeight: number,
) => {
  if (width <= stageWidth && height <= stageHeight) {
    return { width, height };
  }
  const ratio = Math.min(stageWidth / width, stageHeight / height);
  return {
    width: Math.round(width * ratio),
    height: Math.round(height * ratio),
  };
};

export const clampPositionToStage = (
  x: number,
  y: number,
  width: number,
  height: number,
  stageWidth: number,
  stageHeight: number,
) => ({
  x: Math.max(0, Math.min(stageWidth - width, Math.round(x))),
  y: Math.max(0, Math.min(stageHeight - height, Math.round(y))),
});
