mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 01:02:08 +10:00
26 lines
573 B
Java
26 lines
573 B
Java
package org.diylc.presenter;
|
|
|
|
import java.awt.Point;
|
|
|
|
import org.diylc.core.measures.Size;
|
|
|
|
public class CalcUtils {
|
|
|
|
/**
|
|
* Rounds the number to the closest grid line.
|
|
*
|
|
* @param x
|
|
* @return
|
|
*/
|
|
public static int roundToGrid(int x, Size gridSpacing) {
|
|
int grid = gridSpacing.convertToPixels();
|
|
return (Math.round(1f * x / grid) * grid);
|
|
}
|
|
|
|
public static void snapPointToGrid(Point point, Size gridSpacing) {
|
|
int x = roundToGrid(point.x, gridSpacing);
|
|
int y = roundToGrid(point.y, gridSpacing);
|
|
point.setLocation(x, y);
|
|
}
|
|
}
|