/**
 * 吸附：将坐标或尺寸按 snapStep 取整；snapStep 为 0 不吸附
 */
export function snapValue(value, snapStep) {
  if (!snapStep || snapStep <= 0) return value;
  return Math.round(value / snapStep) * snapStep;
}
export function snapRect(x, y, width, height, snapStep) {
  if (!snapStep || snapStep <= 0) return {
    x: x,
    y: y,
    width: width,
    height: height
  };
  return {
    x: snapValue(x, snapStep),
    y: snapValue(y, snapStep),
    width: Math.max(snapStep, snapValue(width, snapStep)),
    height: Math.max(snapStep, snapValue(height, snapStep))
  };
}