# ShapeFactory.java :  » Scripting » flywheel » com » panopset » centralen » grid » Java Open Source

 Java Open Source » Scripting » flywheel
 flywheel » com » panopset » centralen » grid » ShapeFactory.java ``````package com.panopset.centralen.grid; import static java.lang.Math.abs; import static java.lang.Math.min; import java.awt.Point; import java.awt.Rectangle; /** * Shape factory. * * @author Karl Dinwiddie * */ public final class ShapeFactory { /** * Create rectangle from points. Order does not matter. * * @param a * Point a. * @param b * Point b. * @return Rectangle. */ public static Rectangle createRectangleFromPoints(final Point a, final Point b) { Rectangle r = new Rectangle(); setRectangleFromPoints(r, a, b); return r; } /** * Set rectangle from points. * * @param r * Rectangle to set dimensions of. * @param a * Point a. * @param b * Point b. */ public static void setRectangleFromPoints(final Rectangle r, final Point a, final Point b) { setRectangleFromInts(r, a.x, a.y, b.x, b.y); } /** * Set rectangle from integers. * @param r * Rectangle to set dimensions of. * @param x0 Point 0 x coordinate. * @param y0 Point 0 y coordinate. * @param x1 Point 1 x coordinate. * @param y1 Point 1 y coordinate. */ public static void setRectangleFromInts(final Rectangle r, final int x0, final int y0, final int x1, final int y1) { r.x = min(x0, x1); r.y = min(y0, y1); r.width = abs(x1 - x0); r.height = abs(y1 - y0); } /** * Private constructor. */ private ShapeFactory() { // nothing to do here. } } ``````