diff --git a/src/mightypork/gamecore/audio/SoundSystem.java b/src/mightypork/gamecore/audio/SoundSystem.java index dc361bf..479d880 100644 --- a/src/mightypork/gamecore/audio/SoundSystem.java +++ b/src/mightypork/gamecore/audio/SoundSystem.java @@ -13,8 +13,7 @@ import mightypork.gamecore.control.bus.events.ResourceLoadRequest; import mightypork.gamecore.control.timing.Updateable; import mightypork.utils.math.Calc.Buffers; import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectMutable; -import mightypork.utils.math.vect.VectView; +import mightypork.utils.math.vect.VectVar; import org.lwjgl.openal.AL; import org.lwjgl.openal.AL10; @@ -31,7 +30,7 @@ public class SoundSystem extends RootBusNode implements Updateable { private static final Vect INITIAL_LISTENER_POS = Vect.ZERO; private static final int MAX_SOURCES = 256; - private static VectMutable listener = VectMutable.zero(); + private static VectVar listener = Vect.makeVar(); private static boolean soundSystemInited = false; @@ -60,9 +59,9 @@ public class SoundSystem extends RootBusNode implements Updateable { /** * @return listener coordinate */ - public static VectView getListener() + public static Vect getListener() { - return listener.view(); + return listener; } // -- instance -- diff --git a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java index 1623f0d..6cc9493 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java @@ -3,7 +3,6 @@ package mightypork.gamecore.control.bus.events; import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectView; /** @@ -78,9 +77,9 @@ public class MouseButtonEvent implements Event { /** * @return mouse position when the event occurred */ - public VectView getPos() + public Vect getPos() { - return pos.view(); + return pos; } diff --git a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java index c953ec6..a1e230f 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java @@ -3,7 +3,7 @@ package mightypork.gamecore.control.bus.events; import mightypork.gamecore.control.bus.events.types.UnloggedEvent; import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectConst; /** @@ -14,8 +14,8 @@ import mightypork.utils.math.vect.VectVal; @UnloggedEvent public class MouseMotionEvent implements Event { - private final VectVal move; - private final VectVal pos; + private final VectConst move; + private final VectConst pos; /** @@ -23,15 +23,15 @@ public class MouseMotionEvent implements Event { * @param move move vector */ public MouseMotionEvent(Vect pos, Vect move) { - this.move = move.copy(); - this.pos = pos.copy(); + this.move = move.freeze(); + this.pos = pos.freeze(); } /** * @return movement since last {@link MouseMotionEvent} */ - public VectVal getMove() + public VectConst getMove() { return move; } @@ -40,7 +40,7 @@ public class MouseMotionEvent implements Event { /** * @return current mouse position */ - public VectVal getPos() + public VectConst getPos() { return pos; } diff --git a/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java b/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java index f49360b..c41aa36 100644 --- a/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java +++ b/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java @@ -2,7 +2,6 @@ package mightypork.gamecore.control.bus.events; import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectView; /** @@ -50,9 +49,9 @@ public class ScreenChangeEvent implements Event { /** * @return new screen size */ - public VectView getScreenSize() + public Vect getScreenSize() { - return screenSize.view(); + return screenSize; } diff --git a/src/mightypork/gamecore/gui/components/AbstractComponent.java b/src/mightypork/gamecore/gui/components/AbstractComponent.java index 7707faa..6d04520 100644 --- a/src/mightypork/gamecore/gui/components/AbstractComponent.java +++ b/src/mightypork/gamecore/gui/components/AbstractComponent.java @@ -4,7 +4,7 @@ package mightypork.gamecore.gui.components; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppSubModule; import mightypork.utils.math.constraints.RectBound; -import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.rect.Rect; public abstract class AbstractComponent extends AppSubModule implements PluggableRenderable { @@ -25,7 +25,7 @@ public abstract class AbstractComponent extends AppSubModule implements Pluggabl @Override - public RectView getRect() + public Rect getRect() { return context.getRect(); } diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderable.java b/src/mightypork/gamecore/gui/components/PluggableRenderable.java index b8fa952..e9558ac 100644 --- a/src/mightypork/gamecore/gui/components/PluggableRenderable.java +++ b/src/mightypork/gamecore/gui/components/PluggableRenderable.java @@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components; import mightypork.utils.math.constraints.PluggableRectBound; import mightypork.utils.math.constraints.RectBound; -import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.rect.Rect; /** @@ -18,7 +18,7 @@ public interface PluggableRenderable extends Renderable, PluggableRectBound { @Override - RectView getRect(); + Rect getRect(); @Override diff --git a/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java b/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java index ef735e2..83226b2 100644 --- a/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java @@ -5,7 +5,7 @@ import mightypork.gamecore.gui.components.PluggableRenderable; import mightypork.gamecore.gui.components.Renderable; import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.constraints.RectBoundAdapter; -import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.rect.Rect; /** @@ -20,7 +20,7 @@ public abstract class AbstractPainter extends RectBoundAdapter implements Plugga @Override - public RectView getRect() + public Rect getRect() { return super.getRect(); } diff --git a/src/mightypork/gamecore/gui/components/painters/TextPainter.java b/src/mightypork/gamecore/gui/components/painters/TextPainter.java index 6d29fe9..331f57d 100644 --- a/src/mightypork/gamecore/gui/components/painters/TextPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/TextPainter.java @@ -5,9 +5,9 @@ import mightypork.gamecore.render.fonts.FontRenderer; import mightypork.gamecore.render.fonts.FontRenderer.Align; import mightypork.gamecore.render.fonts.GLFont; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.rect.Rect; import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectMutable; +import mightypork.utils.math.vect.VectVar; import mightypork.utils.string.StringProvider; import mightypork.utils.string.StringProvider.StringWrapper; @@ -28,7 +28,7 @@ public class TextPainter extends AbstractPainter { private boolean shadow; private RGB shadowColor = RGB.BLACK; - private final VectMutable shadowOffset = VectMutable.make(1, 1); + private final VectVar shadowOffset = Vect.makeVar(1, 1); /** @@ -84,7 +84,7 @@ public class TextPainter extends AbstractPainter { if (text == null) return; final String str = text.getString(); - final RectView rect = getRect(); + final Rect rect = getRect(); if (shadow) { font.draw(str, rect.move(shadowOffset), align, shadowColor); diff --git a/src/mightypork/gamecore/gui/screens/Screen.java b/src/mightypork/gamecore/gui/screens/Screen.java index 54dd9c8..94f0e45 100644 --- a/src/mightypork/gamecore/gui/screens/Screen.java +++ b/src/mightypork/gamecore/gui/screens/Screen.java @@ -11,7 +11,7 @@ import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.render.Render; import mightypork.utils.annotations.DefaultImpl; import mightypork.utils.math.constraints.RectBound; -import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.rect.Rect; import mightypork.utils.math.vect.Vect; @@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind @Override - public RectView getRect() + public Rect getRect() { return getDisplay().getRect(); } @@ -169,4 +169,17 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind * @return screen identifier to be used for requests. */ public abstract String getName(); + + + protected final Rect bounds() + { + return getRect(); + } + + + protected final Vect mouse() + { + return getInput().getMousePos(); + } + } diff --git a/src/mightypork/gamecore/gui/screens/ScreenLayer.java b/src/mightypork/gamecore/gui/screens/ScreenLayer.java index 6f2ec83..9dd468b 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenLayer.java +++ b/src/mightypork/gamecore/gui/screens/ScreenLayer.java @@ -8,9 +8,8 @@ import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyStroke; import mightypork.utils.annotations.DefaultImpl; import mightypork.utils.math.constraints.RectBound; -import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.rect.Rect; import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectView; /** @@ -26,11 +25,6 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable extractZip(File file, File outputDir, StringFilter filter) throws IOException { - try(ZipFile zip = new ZipFile(file)) { + try (ZipFile zip = new ZipFile(file)) { return extractZip(zip, outputDir, filter); } } @@ -89,7 +89,7 @@ public class ZipUtils { */ public static List listZip(File zipFile) throws IOException { - try(ZipFile zip = new ZipFile(zipFile)) { + try (ZipFile zip = new ZipFile(zipFile)) { return listZip(zip); } } @@ -133,10 +133,7 @@ public class ZipUtils { { if (!destFile.getParentFile().mkdirs()) throw new IOException("Could not create output directory."); - try(InputStream in = zip.getInputStream(entry); - BufferedInputStream is = new BufferedInputStream(in); - FileOutputStream fos = new FileOutputStream(destFile); - BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) { + try (InputStream in = zip.getInputStream(entry); BufferedInputStream is = new BufferedInputStream(in); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) { FileUtils.copyStream(is, dest); } @@ -170,7 +167,7 @@ public class ZipUtils { public static boolean entryExists(File selectedFile, String string) { - try(ZipFile zf = new ZipFile(selectedFile)) { + try (ZipFile zf = new ZipFile(selectedFile)) { return zf.getEntry(string) != null; } catch (final IOException | RuntimeException e) { Log.w("Error reading zip.", e); diff --git a/src/mightypork/utils/files/ion/Ion.java b/src/mightypork/utils/files/ion/Ion.java index 3d0dbb6..26b6a9a 100644 --- a/src/mightypork/utils/files/ion/Ion.java +++ b/src/mightypork/utils/files/ion/Ion.java @@ -67,7 +67,7 @@ public class Ion { */ public static Object fromFile(File file) throws IonException { - try(InputStream in = new FileInputStream(file)) { + try (InputStream in = new FileInputStream(file)) { final Object obj = fromStream(in); return obj; @@ -113,7 +113,7 @@ public class Ion { */ public static void toFile(File path, Object obj) throws IonException { - try(OutputStream out = new FileOutputStream(path)) { + try (OutputStream out = new FileOutputStream(path)) { final String f = path.toString(); final File dir = new File(f.substring(0, f.lastIndexOf(File.separator))); diff --git a/src/mightypork/utils/math/constraints/ConstraintFactory.java b/src/mightypork/utils/math/constraints/ConstraintFactory.java index 98983be..26b9026 100644 --- a/src/mightypork/utils/math/constraints/ConstraintFactory.java +++ b/src/mightypork/utils/math/constraints/ConstraintFactory.java @@ -11,7 +11,7 @@ //import mightypork.utils.math.vect.Vect; //import mightypork.utils.math.vect.VectAdapter; //import mightypork.utils.math.vect.VectVal; -//import mightypork.utils.math.vect.VectView; +//import mightypork.utils.math.vect.Vect; // // ///** @@ -69,9 +69,9 @@ // * @param vectBound vect bound // * @return contained vect // */ -// private static VectView eval(final VectBound vectBound) +// private static Vect eval(final VectBound vectBound) // { -// return vectBound == null ? Vect.ZERO.view() : vectBound.getVect(); +// return vectBound == null ? Vect.ZERO : vectBound.getVect(); // } // // @@ -83,7 +83,7 @@ // */ // private static RectView eval(final RectBound rectBound) // { -// return rectBound == null ? Rect.ZERO.view() : rectBound.getRect(); +// return rectBound == null ? Rect.ZERO : rectBound.getRect(); // } // // @@ -670,7 +670,7 @@ // final double b = eval(bottom); // final double l = eval(left); // -// final VectView v = eval(c); +// final Vect v = eval(c); // // return RectVal.make(v.x() - l, v.y() - t, l + r, t + b); // } @@ -736,24 +736,24 @@ // } // // -// public static VectView neg(final VectBound c) +// public static Vect neg(final VectBound c) // { // return mul(c, -1); // } // // -// public static VectView half(final VectBound c) +// public static Vect half(final VectBound c) // { // return mul(c, 0.5); // } // // -// public static VectView add(final VectBound c1, final VectBound c2) +// public static Vect add(final VectBound c1, final VectBound c2) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(c1).add(eval(c2)); // } @@ -761,18 +761,18 @@ // } // // -// public static VectView add(final VectBound c, final Object x, final Object y) +// public static Vect add(final VectBound c, final Object x, final Object y) // { // return add(c, x, y, 0); // } // // -// public static VectView add(final VectBound c, final Object x, final Object y, final Object z) +// public static Vect add(final VectBound c, final Object x, final Object y, final Object z) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(c).add(eval(x), eval(y), eval(z)); // } @@ -780,12 +780,12 @@ // } // // -// public static VectView sub(final VectBound c1, final VectBound c2) +// public static Vect sub(final VectBound c1, final VectBound c2) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(c1).sub(eval(c2)); // } @@ -793,18 +793,18 @@ // } // // -// public static VectView sub(final VectBound c, final Object x, final Object y) +// public static Vect sub(final VectBound c, final Object x, final Object y) // { // return sub(c, x, y, 0); // } // // -// public static VectView sub(final VectBound c, final Object x, final Object y, final Object z) +// public static Vect sub(final VectBound c, final Object x, final Object y, final Object z) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(c).sub(eval(x), eval(y), eval(z)); // } @@ -813,12 +813,12 @@ // } // // -// public static VectView mul(final VectBound c, final Object mul) +// public static Vect mul(final VectBound c, final Object mul) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(c).mul(eval(mul)); // } @@ -827,12 +827,12 @@ // } // // -// public static VectView norm(final VectBound c, final Object norm) +// public static Vect norm(final VectBound c, final Object norm) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(c).norm(eval(norm)); // } @@ -841,12 +841,12 @@ // } // // -// public static VectView origin(final RectBound r) +// public static Vect origin(final RectBound r) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(r).origin(); // } @@ -854,12 +854,12 @@ // } // // -// public static VectView size(final RectBound r) +// public static Vect size(final RectBound r) // { // return new VectAdapter() { // // @Override -// public VectView getSource() +// public Vect getSource() // { // return eval(r).size(); // } @@ -879,55 +879,55 @@ // } // // -// public static VectView center(final RectBound r) +// public static Vect center(final RectBound r) // { // return add(origin(r), half(size(r))); // } // // -// public static VectView topLeft(final RectBound r) +// public static Vect topLeft(final RectBound r) // { // return origin(r); // } // // -// public static VectView topRight(final RectBound r) +// public static Vect topRight(final RectBound r) // { // return add(origin(r), width(r), 0); // } // // -// public static VectView bottomLeft(final RectBound r) +// public static Vect bottomLeft(final RectBound r) // { // return add(origin(r), 0, width(r)); // } // // -// public static VectView bottomRight(final RectBound r) +// public static Vect bottomRight(final RectBound r) // { // return add(origin(r), size(r)); // } // // -// public static VectView topCenter(final RectBound r) +// public static Vect topCenter(final RectBound r) // { // return add(origin(r), half(width(r)), 0); // } // // -// public static VectView bottomCenter(final RectBound r) +// public static Vect bottomCenter(final RectBound r) // { // return add(origin(r), half(width(r)), width(r)); // } // // -// public static VectView centerLeft(final RectBound r) +// public static Vect centerLeft(final RectBound r) // { // return add(origin(r), 0, half(width(r))); // } // // -// public static VectView centerRight(final RectBound r) +// public static Vect centerRight(final RectBound r) // { // return add(origin(r), width(r), half(width(r))); // } @@ -946,19 +946,19 @@ // @Override // public RectView getRect() // { -// VectView cv = eval(c); +// Vect cv = eval(c); // // return new RectView() { // // @Override -// public VectView size() +// public Vect size() // { -// return Vect.ZERO.view(); +// return Vect.ZERO; // } // // // @Override -// public VectView origin() +// public Vect origin() // { // return null; // } diff --git a/src/mightypork/utils/math/num/NumMutable.java b/src/mightypork/utils/math/num/NumMutable.java index 76d106b..56bcc69 100644 --- a/src/mightypork/utils/math/num/NumMutable.java +++ b/src/mightypork/utils/math/num/NumMutable.java @@ -21,7 +21,7 @@ public abstract class NumMutable extends Num { * * @param value new value */ - public void setTo(Num value) + public void assign(Num value) { setTo(eval(value)); } diff --git a/src/mightypork/utils/math/rect/Rect.java b/src/mightypork/utils/math/rect/Rect.java index e62d058..db86dba 100644 --- a/src/mightypork/utils/math/rect/Rect.java +++ b/src/mightypork/utils/math/rect/Rect.java @@ -30,6 +30,12 @@ public abstract class Rect implements RectBound { } + public static Rect make(Vect size) + { + return Rect.make(size.xn(), size.yn()); + } + + @FactoryMethod public static Rect make(Num x, Num y, Num width, Num height) { @@ -122,6 +128,26 @@ public abstract class Rect implements RectBound { return Rect.makeVar(Rect.ZERO); } + private Vect p_bl; + private Vect p_bc; + private Vect p_br; + // p_t == origin + private Vect p_tc; + private Vect p_tr; + + private Vect p_cl; + private Vect p_cc; + private Vect p_cr; + + private Num p_x; + private Num p_y; + private Num p_w; + private Num p_h; + private Num p_l; + private Num p_r; + private Num p_t; + private Num p_b; + /** * Get a copy of current value @@ -448,49 +474,49 @@ public abstract class Rect implements RectBound { public Num x() { - return origin().xn(); + return p_x != null ? p_x : (p_x = origin().xn()); } public Num y() { - return origin().yn(); + return p_y != null ? p_y : (p_y = origin().yn()); } public Num width() { - return size().xn(); + return p_w != null ? p_w : (p_w = size().xn()); } public Num height() { - return size().yn(); + return p_h != null ? p_h : (p_h = size().yn()); } public Num left() { - return origin().yn(); + return p_l != null ? p_l : (p_l = origin().yn()); } public Num right() { - return origin().xn().add(size().xn()); + return p_r != null ? p_r : (p_r = origin().xn().add(size().xn())); } public Num top() { - return origin().yn(); + return p_t != null ? p_t : (p_t = origin().yn()); } public Num bottom() { - return origin().yn().add(size().yn()); + return p_b != null ? p_b : (p_b = origin().yn().add(size().yn())); } @@ -502,49 +528,49 @@ public abstract class Rect implements RectBound { public Vect topCenter() { - return origin().add(size().xn().half(), Num.ZERO); + return p_tc != null ? p_tc : (p_tc = origin().add(size().xn().half(), Num.ZERO)); } public Vect topRight() { - return origin().add(size().xn(), Num.ZERO); + return p_tr != null ? p_tr : (p_tr = origin().add(size().xn(), Num.ZERO)); } public Vect centerLeft() { - return origin().add(Num.ZERO, size().yn().half()); + return p_cl != null ? p_cl : (p_cl = origin().add(Num.ZERO, size().yn().half())); } public Vect center() { - return origin().add(size().half()); + return p_cc != null ? p_cc : (p_cc = origin().add(size().half())); } public Vect centerRight() { - return origin().add(size().xn(), size().yn().half()); + return p_cr != null ? p_cr : (p_cr = origin().add(size().xn(), size().yn().half())); } public Vect bottomLeft() { - return origin().add(Num.ZERO, size().yn()); + return p_bl != null ? p_bl : (p_bl = origin().add(Num.ZERO, size().yn())); } public Vect bottomCenter() { - return origin().add(size().xn().half(), size().yn()); + return p_bc != null ? p_bc : (p_bc = origin().add(size().xn().half(), size().yn())); } public Vect bottomRight() { - return origin().add(size().xn(), size().yn()); + return p_br != null ? p_br : (p_br = origin().add(size().xn(), size().yn())); } @@ -595,4 +621,11 @@ public abstract class Rect implements RectBound { return x >= x1 && y >= y1 && x <= x2 && y <= y2; } + + + public Rect centerTo(Rect parent) + { + return centerTo(parent.center()); + } + } diff --git a/src/mightypork/utils/math/rect/RectConst.java b/src/mightypork/utils/math/rect/RectConst.java index d53ce7e..5ce4bce 100644 --- a/src/mightypork/utils/math/rect/RectConst.java +++ b/src/mightypork/utils/math/rect/RectConst.java @@ -16,6 +16,19 @@ public class RectConst extends Rect { private final VectConst pos; private final VectConst size; + // cached with lazy loading + private NumConst v_b; + private NumConst v_r; + private VectConst v_br; + private VectConst v_tc; + private VectConst v_tr; + private VectConst v_cl; + private VectConst v_c; + private VectConst v_cr; + private VectConst v_bl; + private VectConst v_bc; + private RectConst v_round; + /** * Create at given origin, with given size. @@ -89,14 +102,14 @@ public class RectConst extends Rect { @Override public RectConst move(double x, double y) { - return Rect.make(origin().add(x, y), size()).freeze(); + return Rect.make(pos.add(x, y), size); } @Override public RectConst shrink(double left, double right, double top, double bottom) { - return Rect.make(origin().add(left, top), size().sub(left + right, top + bottom)).freeze(); + return Rect.make(pos.add(left, top), size.sub(left + right, top + bottom)).freeze(); } @@ -104,136 +117,144 @@ public class RectConst extends Rect { @Override public RectConst grow(double left, double right, double top, double bottom) { - return Rect.make(origin().sub(left, top), size().add(left + right, top + bottom)).freeze(); + return Rect.make(pos.sub(left, top), size.add(left + right, top + bottom)).freeze(); } @Override public RectConst round() { - final VectConst s = size(); - final VectConst o = origin(); - - return Rect.make(o.round(), s.round()).freeze(); + if (v_round == null) v_round = Rect.make(pos.round(), size.round()); + return v_round; } @Override public NumConst x() { - return origin().xn(); + return pos.xn(); } @Override public NumConst y() { - return origin().yn(); + return pos.yn(); } @Override public NumConst width() { - return size().xn(); + return size.xn(); } @Override public NumConst height() { - return size().yn(); + return size.yn(); } @Override public NumConst left() { - return origin().xn(); + return pos.xn(); } @Override public NumConst right() { - return origin().xn().add(size().xn()); + if (v_r == null) v_r = super.right().freeze(); + return v_r; } @Override public NumConst top() { - return origin().yn(); + return pos.yn(); } @Override public NumConst bottom() { - return origin().yn().add(size().yn()); + if (v_b == null) v_b = super.bottom().freeze(); + return v_b; } @Override public VectConst topLeft() { - return origin(); + return pos; } @Override public VectConst topCenter() { - return origin().add(size().x() / 2, 0); + if (v_tc == null) v_tc = super.topCenter().freeze(); + return v_tc; } @Override public VectConst topRight() { - return origin().add(size().x(), 0); + if (v_tr == null) v_tr = super.topRight().freeze(); + return v_tr; } @Override public VectConst centerLeft() { - return origin().add(0, size().y() / 2); + if (v_cl == null) v_cl = super.centerLeft().freeze(); + return v_cl; } @Override public VectConst center() { - return origin().add(size().half()).freeze(); + if (v_c == null) v_c = super.center().freeze(); + return v_c; } @Override public VectConst centerRight() { - return origin().add(size().x(), size().y() / 2); + if (v_cr == null) v_cr = super.centerRight().freeze(); + return v_cr; } @Override public VectConst bottomLeft() { - return origin().add(0, size().y()); + if (v_bl == null) v_bl = super.bottomLeft().freeze(); + return v_bl; } @Override public VectConst bottomCenter() { - return origin().add(size().x() / 2, size().y()); + if (v_bc == null) v_bc = super.bottomCenter().freeze(); + return v_bc; } @Override public VectConst bottomRight() { - return origin().add(size()).freeze(); + if (v_br == null) v_br = super.bottomRight().freeze(); + return v_br; } } diff --git a/src/mightypork/utils/math/rect/RectVectAdapter.java b/src/mightypork/utils/math/rect/RectVectAdapter.java index 2403d65..fa8cce9 100644 --- a/src/mightypork/utils/math/rect/RectVectAdapter.java +++ b/src/mightypork/utils/math/rect/RectVectAdapter.java @@ -5,7 +5,7 @@ import mightypork.utils.math.vect.Vect; /** - * Rect made of two {@link VectView}s + * Rect made of two {@link Vect}s * * @author MightyPork */ diff --git a/src/mightypork/utils/math/vect/Vect.java b/src/mightypork/utils/math/vect/Vect.java index edfa36d..5592df7 100644 --- a/src/mightypork/utils/math/vect/Vect.java +++ b/src/mightypork/utils/math/vect/Vect.java @@ -7,6 +7,7 @@ import mightypork.utils.math.Calc; import mightypork.utils.math.constraints.VectBound; import mightypork.utils.math.num.Num; import mightypork.utils.math.num.NumConst; +import mightypork.utils.math.rect.Rect; /** @@ -1102,4 +1103,34 @@ public abstract class Vect implements VectBound { return x() == other.x() && y() == other.y() && z() == other.z(); } + + + /** + * Expand to a rect, with given growth to each side. + * + * @param left + * @param right + * @param top + * @param bottom + * @return the rect + */ + public Rect expand(int left, int right, int top, int bottom) + { + return Rect.make(this, Vect.ZERO).grow(left, right, top, bottom); + } + + + /** + * Expand to a rect, with given growth to each side. + * + * @param left + * @param right + * @param top + * @param bottom + * @return the rect + */ + public Rect expand(Num left, Num right, Num top, Num bottom) + { + return Rect.make(this, Vect.ZERO).grow(left, right, top, bottom); + } }