Back to index

moin  1.9.0~rc2
GridConstrainer.java
Go to the documentation of this file.
00001 /*
00002  * @(#)GridConstrainer.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.awt.*;
00009 import java.io.Serializable;
00010 
00011 import CH.ifa.draw.framework.PointConstrainer;
00012 
00020 public class GridConstrainer implements PointConstrainer, Serializable {
00021 
00022     private int fGridX;
00023     private int fGridY;
00024 
00025     public GridConstrainer(int x, int y) {
00026         fGridX = Math.max(1, x);
00027         fGridY = Math.max(1, y);
00028     }
00029 
00034     public Point constrainPoint(Point p) {
00035         p.x = ((p.x+fGridX/2) / fGridX) * fGridX;
00036         p.y = ((p.y+fGridY/2) / fGridY) * fGridY;
00037         return p;
00038     }
00039 
00043     public int getStepX() {
00044         return fGridX;
00045     }
00046 
00050     public int getStepY() {
00051         return fGridY;
00052     }
00053 }