diff --git a/src/mightypork/gamecore/audio/SoundSystem.java b/src/mightypork/gamecore/audio/SoundSystem.java index dc361bf..88d4b79 100644 --- a/src/mightypork/gamecore/audio/SoundSystem.java +++ b/src/mightypork/gamecore/audio/SoundSystem.java @@ -62,7 +62,7 @@ public class SoundSystem extends RootBusNode implements Updateable { */ public static VectView getListener() { - return listener.view(); + return listener.getView(); } // -- instance -- diff --git a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java index eb43b55..7f5e164 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java @@ -1,7 +1,7 @@ package mightypork.gamecore.control.bus.events; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectView; @@ -80,7 +80,7 @@ public class MouseButtonEvent implements Event { */ public VectView getPos() { - return pos.view(); + return pos.getView(); } @@ -108,7 +108,7 @@ public class MouseButtonEvent implements Event { * @param rect rect region * @return was over */ - public boolean isOver(RectConstraint rect) + public boolean isOver(RectBound rect) { return rect.getRect().contains(pos); } diff --git a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java index 175b935..1c7b130 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java @@ -23,8 +23,8 @@ public class MouseMotionEvent implements Event { * @param move move vector */ public MouseMotionEvent(Vect pos, Vect move) { - this.move = move.value(); - this.pos = pos.value(); + this.move = move.getValue(); + this.pos = pos.getValue(); } diff --git a/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java b/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java index f49360b..870ae3c 100644 --- a/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java +++ b/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java @@ -52,7 +52,7 @@ public class ScreenChangeEvent implements Event { */ public VectView getScreenSize() { - return screenSize.view(); + return screenSize.getView(); } diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderable.java b/src/mightypork/gamecore/gui/components/PluggableRenderable.java index 2f6fec7..19300e4 100644 --- a/src/mightypork/gamecore/gui/components/PluggableRenderable.java +++ b/src/mightypork/gamecore/gui/components/PluggableRenderable.java @@ -2,7 +2,7 @@ package mightypork.gamecore.gui.components; import mightypork.utils.math.constraints.PluggableRect; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.rect.RectView; @@ -22,6 +22,6 @@ public interface PluggableRenderable extends Renderable, PluggableRect { @Override - void setContext(RectConstraint rect); + void setContext(RectBound rect); } diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderer.java b/src/mightypork/gamecore/gui/components/PluggableRenderer.java index bbaf463..be78b78 100644 --- a/src/mightypork/gamecore/gui/components/PluggableRenderer.java +++ b/src/mightypork/gamecore/gui/components/PluggableRenderer.java @@ -2,7 +2,7 @@ package mightypork.gamecore.gui.components; import mightypork.utils.math.constraints.ContextAdapter; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.rect.RectView; @@ -25,7 +25,7 @@ public abstract class PluggableRenderer extends ContextAdapter implements Plugga @Override - public void setContext(RectConstraint rect) + public void setContext(RectBound rect) { super.setContext(rect); } diff --git a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java index 996533c..04a4ecf 100644 --- a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java @@ -1,10 +1,10 @@ package mightypork.gamecore.gui.components.layout; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.components.PluggableRenderable; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; /** @@ -23,7 +23,7 @@ public class ColumnHolder extends ElementHolder { * @param context context * @param rows number of rows */ - public ColumnHolder(AppAccess app, RectConstraint context, int rows) { + public ColumnHolder(AppAccess app, RectBound context, int rows) { super(app, context); this.cols = rows; } @@ -52,7 +52,7 @@ public class ColumnHolder extends ElementHolder { { if (elem == null) return; - elem.setContext(cColumn(this, cols, col++)); + elem.setContext(column(this, cols, col++)); attach(elem); } diff --git a/src/mightypork/gamecore/gui/components/layout/ElementHolder.java b/src/mightypork/gamecore/gui/components/layout/ElementHolder.java index 997759f..c193f9b 100644 --- a/src/mightypork/gamecore/gui/components/layout/ElementHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/ElementHolder.java @@ -9,7 +9,7 @@ import mightypork.gamecore.control.bus.clients.BusNode; import mightypork.gamecore.gui.components.PluggableRenderable; import mightypork.gamecore.gui.components.PluggableRenderer; import mightypork.gamecore.gui.components.Renderable; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.rect.RectView; @@ -22,7 +22,7 @@ import mightypork.utils.math.rect.RectView; public abstract class ElementHolder extends BusNode implements PluggableRenderable { private final LinkedList elements = new LinkedList<>(); - private RectConstraint context; + private RectBound context; /** @@ -37,14 +37,14 @@ public abstract class ElementHolder extends BusNode implements PluggableRenderab * @param app app access * @param context boudning context */ - public ElementHolder(AppAccess app, RectConstraint context) { + public ElementHolder(AppAccess app, RectBound context) { super(app); setContext(context); } @Override - public void setContext(RectConstraint context) + public void setContext(RectBound context) { this.context = context; } diff --git a/src/mightypork/gamecore/gui/components/layout/RowHolder.java b/src/mightypork/gamecore/gui/components/layout/RowHolder.java index ff8f1a8..decd82b 100644 --- a/src/mightypork/gamecore/gui/components/layout/RowHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/RowHolder.java @@ -1,10 +1,10 @@ package mightypork.gamecore.gui.components.layout; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.components.PluggableRenderable; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; /** @@ -23,7 +23,7 @@ public class RowHolder extends ElementHolder { * @param context bounding context * @param rows number of rows */ - public RowHolder(AppAccess app, RectConstraint context, int rows) { + public RowHolder(AppAccess app, RectBound context, int rows) { super(app, context); this.rows = rows; } @@ -52,7 +52,7 @@ public class RowHolder extends ElementHolder { { if (elem == null) return; - elem.setContext(cRow(this, rows, row++)); + elem.setContext(row(this, rows, row++)); attach(elem); } diff --git a/src/mightypork/gamecore/gui/screens/Screen.java b/src/mightypork/gamecore/gui/screens/Screen.java index d1e394d..f7a8b40 100644 --- a/src/mightypork/gamecore/gui/screens/Screen.java +++ b/src/mightypork/gamecore/gui/screens/Screen.java @@ -10,7 +10,7 @@ import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.render.Render; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.rect.RectView; import mightypork.utils.math.vect.Vect; @@ -20,7 +20,7 @@ import mightypork.utils.math.vect.Vect; * * @author MightyPork */ -public abstract class Screen extends AppSubModule implements Renderable, KeyBinder, RectConstraint, ScreenChangeEvent.Listener { +public abstract class Screen extends AppSubModule implements Renderable, KeyBinder, RectBound, ScreenChangeEvent.Listener { private final KeyBindingPool keybindings = new KeyBindingPool(); @@ -66,7 +66,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind active = true; needSetupViewport = true; - onSizeChanged(getRect().getSize()); + onSizeChanged(getRect().size()); onScreenEnter(); // enable events diff --git a/src/mightypork/gamecore/gui/screens/ScreenLayer.java b/src/mightypork/gamecore/gui/screens/ScreenLayer.java index 59cb573..3d1d06a 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenLayer.java +++ b/src/mightypork/gamecore/gui/screens/ScreenLayer.java @@ -7,7 +7,7 @@ import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyStroke; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.rect.RectView; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectView; @@ -18,7 +18,7 @@ import mightypork.utils.math.vect.VectView; * * @author MightyPork */ -public abstract class ScreenLayer extends AppSubModule implements Comparable, Renderable, RectConstraint, KeyBinder { +public abstract class ScreenLayer extends AppSubModule implements Comparable, Renderable, RectBound, KeyBinder { private final Screen screen; diff --git a/src/mightypork/gamecore/input/InputSystem.java b/src/mightypork/gamecore/input/InputSystem.java index 09d4865..785117b 100644 --- a/src/mightypork/gamecore/input/InputSystem.java +++ b/src/mightypork/gamecore/input/InputSystem.java @@ -155,7 +155,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder { move.mul(1, -1, 1); if (button != -1 || wheeld != 0) { - getEventBus().send(new MouseButtonEvent(pos.value(), button, down, wheeld)); + getEventBus().send(new MouseButtonEvent(pos.getValue(), button, down, wheeld)); } moveSum.add(move); diff --git a/src/mightypork/gamecore/render/DisplaySystem.java b/src/mightypork/gamecore/render/DisplaySystem.java index 2b4e1e7..d017bc2 100644 --- a/src/mightypork/gamecore/render/DisplaySystem.java +++ b/src/mightypork/gamecore/render/DisplaySystem.java @@ -10,7 +10,7 @@ import mightypork.gamecore.control.AppModule; import mightypork.gamecore.control.bus.events.ScreenChangeEvent; import mightypork.gamecore.control.timing.FpsMeter; import mightypork.utils.logging.Log; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.rect.RectVal; import mightypork.utils.math.rect.RectView; import mightypork.utils.math.vect.VectView; @@ -26,7 +26,7 @@ import org.lwjgl.opengl.DisplayMode; * * @author MightyPork */ -public class DisplaySystem extends AppModule implements RectConstraint { +public class DisplaySystem extends AppModule implements RectBound { private DisplayMode windowDisplayMode; private int targetFps; diff --git a/src/mightypork/gamecore/render/Render.java b/src/mightypork/gamecore/render/Render.java index 4f46879..70e8c70 100644 --- a/src/mightypork/gamecore/render/Render.java +++ b/src/mightypork/gamecore/render/Render.java @@ -213,7 +213,7 @@ public class Render { */ public static void rotate(double angle, Vect axis) { - final Vect vec = axis.view().norm(1); + final Vect vec = axis.getView().norm(1); glRotated(angle, vec.x(), vec.y(), vec.z()); } @@ -351,10 +351,10 @@ public class Render { */ public static void quad(Rect quad) { - final double x1 = quad.xMin(); - final double y1 = quad.yMin(); - final double x2 = quad.xMax(); - final double y2 = quad.yMax(); + final double x1 = quad.getLeft(); + final double y1 = quad.top(); + final double x2 = quad.right(); + final double y2 = quad.bottom(); // draw with color unbindTexture(); @@ -391,15 +391,15 @@ public class Render { */ public static void quadUV_nobound(Rect quad, Rect uvs) { - final double x1 = quad.xMin(); - final double y1 = quad.yMin(); - final double x2 = quad.xMax(); - final double y2 = quad.yMax(); + final double x1 = quad.getLeft(); + final double y1 = quad.top(); + final double x2 = quad.right(); + final double y2 = quad.bottom(); - final double tx1 = uvs.xMin(); - final double ty1 = uvs.yMin(); - final double tx2 = uvs.xMax(); - final double ty2 = uvs.yMax(); + final double tx1 = uvs.getLeft(); + final double ty1 = uvs.top(); + final double tx2 = uvs.right(); + final double ty2 = uvs.bottom(); // quad with texture glTexCoord2d(tx1, ty2); @@ -437,10 +437,10 @@ public class Render { */ public static void quadColor(Rect quad, RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax) { - final double x1 = quad.xMin(); - final double y1 = quad.yMin(); - final double x2 = quad.xMax(); - final double y2 = quad.yMax(); + final double x1 = quad.getLeft(); + final double y1 = quad.top(); + final double x2 = quad.right(); + final double y2 = quad.bottom(); // draw with color unbindTexture(); diff --git a/src/mightypork/gamecore/render/fonts/FontRenderer.java b/src/mightypork/gamecore/render/fonts/FontRenderer.java index 24734fd..70b1900 100644 --- a/src/mightypork/gamecore/render/fonts/FontRenderer.java +++ b/src/mightypork/gamecore/render/fonts/FontRenderer.java @@ -110,7 +110,7 @@ public class FontRenderer { { Render.pushMatrix(); - Render.translate(pos.value().round()); + Render.translate(pos.getValue().round()); Render.scaleXY(getScale(height)); font.draw(text, color); @@ -148,20 +148,20 @@ public class FontRenderer { switch (align) { case LEFT: - start = bounds.getTopLeft(); + start = bounds.topLeft(); break; case CENTER: - start = bounds.getTopCenter(); + start = bounds.topCenter(); break; case RIGHT: default: - start = bounds.getTopRight(); + start = bounds.topRight(); break; } - draw(text, start, bounds.getHeight(), align, color); + draw(text, start, bounds.height(), align, color); } @@ -193,7 +193,7 @@ public class FontRenderer { final double w = getWidth(text, height); - final VectMutable start = pos.mutable(); + final VectMutable start = VectMutable.make(pos); switch (align) { case LEFT: diff --git a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java index 3969123..05f0a33 100644 --- a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java +++ b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java @@ -24,7 +24,6 @@ import mightypork.gamecore.render.textures.FilterMode; import mightypork.utils.logging.Log; import mightypork.utils.math.color.RGB; import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; import org.lwjgl.BufferUtils; import org.lwjgl.util.glu.GLU; diff --git a/src/mightypork/rogue/screens/LayerFps.java b/src/mightypork/rogue/screens/LayerFps.java index 4e70c41..0778452 100644 --- a/src/mightypork/rogue/screens/LayerFps.java +++ b/src/mightypork/rogue/screens/LayerFps.java @@ -1,7 +1,7 @@ package mightypork.rogue.screens; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.screens.Screen; @@ -12,7 +12,7 @@ import mightypork.gamecore.render.fonts.FontRenderer.Align; import mightypork.gamecore.render.fonts.GLFont; import mightypork.rogue.Res; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.vect.Vect; import mightypork.utils.string.StringProvider; @@ -39,7 +39,7 @@ public class LayerFps extends ScreenLayer { final GLFont font = Res.getFont("default"); - final RectConstraint constraint = cBox(cAdd(cTopRight(this), -8, 8), 0, 32); + final RectBound constraint = box(add(topRight(this), -8, 8), 0, 32); tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, new StringProvider() { diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java index 2b0858f..e4ba448 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java @@ -1,7 +1,7 @@ package mightypork.rogue.screens.test_bouncyboxes; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import java.util.Random; @@ -11,31 +11,31 @@ import mightypork.gamecore.render.Render; import mightypork.utils.math.animation.AnimDouble; import mightypork.utils.math.animation.Easing; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.constraints.NumberConstraint; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.NumberBound; +import mightypork.utils.math.constraints.RectBound; public class BouncyBox extends PluggableRenderer implements Updateable { private final Random rand = new Random(); - private final RectConstraint box; + private final RectBound box; private final AnimDouble pos = new AnimDouble(0, Easing.BOUNCE_OUT); public BouncyBox() { // create box - final NumberConstraint side = cHeight(this); - RectConstraint abox = cBox(this, side, side); + final NumberBound side = height(this); + RectBound abox = box(this, side, side); // move - final NumberConstraint move_length = cSub(cWidth(this), side); - final NumberConstraint offset = cMul(move_length, pos); - abox = cMove(abox, offset, 0); + final NumberBound move_length = sub(width(this), side); + final NumberBound offset = mul(move_length, pos); + abox = move(abox, offset, 0); // add padding - abox = cShrink(abox, cPerc(side, 10)); + abox = shrink(abox, perc(side, 10)); box = abox; } diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java index 2cc7b14..49cd253 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java @@ -1,7 +1,7 @@ package mightypork.rogue.screens.test_bouncyboxes; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import java.util.ArrayList; import java.util.List; @@ -15,7 +15,7 @@ import mightypork.gamecore.input.Keys; import mightypork.gamecore.render.fonts.FontRenderer.Align; import mightypork.rogue.Res; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.vect.VectVal; @@ -47,7 +47,7 @@ public class LayerBouncyBoxes extends ScreenLayer { }); // shrink screen rect by 8% on all sides - final RectConstraint holder_rect = cShrink(this, cPerc(cWidth(this), 4)); + final RectBound holder_rect = shrink(this, perc(width(this), 4)); addChildClient(layout = new RowHolder(screen, holder_rect, 11)); diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java index 032a96d..3591374 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java @@ -1,7 +1,7 @@ package mightypork.rogue.screens.test_cat_sound; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import java.util.Random; @@ -19,6 +19,7 @@ import mightypork.rogue.Res; import mightypork.utils.math.animation.AnimDouble; import mightypork.utils.math.animation.Easing; import mightypork.utils.math.color.RGB; +import mightypork.utils.math.constraints.Bounds; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectMutableAnim; @@ -45,7 +46,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt cat = new ImagePainter(Res.getTxQuad("test.kitten")); - cat.setContext(cCenterTo(cBox(size, size), pos)); + cat.setContext(centerTo(box(size, size), pos)); tp = new TextPainter(Res.getFont("default")); tp.setAlign(Align.CENTER); @@ -53,10 +54,10 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt tp.setText("Meow!"); tp.setShadow(RGB.dark(0.8), VectVal.make(2, 2)); - tp.setContext(cCenterTo(cBox(64, 64), cMousePos)); + tp.setContext(centerTo(box(64, 64), cMousePos)); qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED); - qp.setContext(cExpand(cBottomLeft(cat), 0, 0, 50, 50)); + qp.setContext(expand(bottomLeft(cat), 0, 0, 50, 50)); /* * Register keys diff --git a/src/mightypork/rogue/screens/test_font/ScreenTestFont.java b/src/mightypork/rogue/screens/test_font/ScreenTestFont.java index 7b97a38..0900838 100644 --- a/src/mightypork/rogue/screens/test_font/ScreenTestFont.java +++ b/src/mightypork/rogue/screens/test_font/ScreenTestFont.java @@ -1,15 +1,15 @@ package mightypork.rogue.screens.test_font; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.render.fonts.FontRenderer.Align; import mightypork.rogue.Res; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.constraints.NumberConstraint; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.NumberBound; +import mightypork.utils.math.constraints.RectBound; public class ScreenTestFont extends Screen { @@ -23,9 +23,9 @@ public class ScreenTestFont extends Screen { tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN); tp.setText("Hello World!"); - final NumberConstraint fontHeight = cMul(getDisplay().getSize().yc(), 0.1); + final NumberBound fontHeight = mul(getDisplay().getSize().yc(), 0.1); - final RectConstraint strbox = cCenterTo(cBox(fontHeight), this); + final RectBound strbox = centerTo(box(fontHeight), this); tp.setContext(strbox); } diff --git a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java index 0a9852b..51b7ca4 100644 --- a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java +++ b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java @@ -1,13 +1,13 @@ package mightypork.rogue.screens.test_render; -import static mightypork.utils.math.constraints.Constraints.*; +import static mightypork.utils.math.constraints.Bounds.*; import mightypork.gamecore.control.timing.Poller; import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.ScreenLayer; import mightypork.gamecore.render.Render; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.vect.Vect; @@ -15,15 +15,15 @@ public class LayerTestGradient extends ScreenLayer { private final Poller p = new Poller(); - private final RectConstraint pos1; - private final RectConstraint pos2; + private final RectBound pos1; + private final RectBound pos2; public LayerTestGradient(Screen screen) { super(screen); - pos1 = cCached(p, cGrowDown(cTopEdge(this), 64)); - pos2 = cCached(p, cShrinkTop(cGrowRight(cLeftEdge(this), 64), 64)); + pos1 = cached(p, growDown(edgeTop(this), 64)); + pos2 = cached(p, shrinkTop(growRight(edgeLeft(this), 64), 64)); } diff --git a/src/mightypork/test/TestConstr.java b/src/mightypork/test/TestConstr.java index e7492e4..f89c1f3 100644 --- a/src/mightypork/test/TestConstr.java +++ b/src/mightypork/test/TestConstr.java @@ -1,12 +1,13 @@ package mightypork.test; +import static mightypork.utils.math.constraints.Bounds.*; + import java.util.Locale; import mightypork.utils.math.rect.RectVal; import mightypork.utils.math.rect.RectView; import mightypork.utils.math.vect.VectVal; -import static mightypork.utils.math.constraints.Constraints.*; public class TestConstr { @@ -16,12 +17,11 @@ public class TestConstr { Locale.setDefault(Locale.ENGLISH); final RectView rect = RectVal.make(0, 0, 10, 10); - final VectVal point = VectVal.make(50,50); + final VectVal point = VectVal.make(50, 50); System.out.println(rect); System.out.println(point); - System.out.println(cCenterTo(rect, point).getRect()); - + System.out.println(centerTo(rect, point).getRect()); // final RectValue rm = RectValue.make(0, 0, 100, 100); // System.out.println(rm); diff --git a/src/mightypork/utils/math/animation/AnimDouble.java b/src/mightypork/utils/math/animation/AnimDouble.java index 1ce264a..dec2dc9 100644 --- a/src/mightypork/utils/math/animation/AnimDouble.java +++ b/src/mightypork/utils/math/animation/AnimDouble.java @@ -4,7 +4,7 @@ package mightypork.utils.math.animation; import mightypork.gamecore.control.timing.Pauseable; import mightypork.gamecore.control.timing.Updateable; import mightypork.utils.math.Calc; -import mightypork.utils.math.constraints.NumberConstraint; +import mightypork.utils.math.constraints.NumberBound; /** @@ -12,7 +12,7 @@ import mightypork.utils.math.constraints.NumberConstraint; * * @author MightyPork */ -public class AnimDouble implements Updateable, Pauseable, NumberConstraint { +public class AnimDouble implements Updateable, Pauseable, NumberBound { /** target double */ protected double to = 0; diff --git a/src/mightypork/utils/math/constraints/Bounds.java b/src/mightypork/utils/math/constraints/Bounds.java new file mode 100644 index 0000000..f4a3717 --- /dev/null +++ b/src/mightypork/utils/math/constraints/Bounds.java @@ -0,0 +1,919 @@ +package mightypork.utils.math.constraints; + + +import mightypork.gamecore.control.timing.Poller; +import mightypork.utils.math.rect.RectVal; +import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectAdapter; +import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; + + +/** + * Constraint factory.
+ * Import statically for best experience. + * + * @author MightyPork + */ +public class Bounds { + + public static RectCache cached(final Poller poller, final RectBound rc) + { + return new RectCache(poller, rc); + } + + + /** + * Convert {@link Number} to {@link NumberBound} if needed + * + * @param o unknown numeric value + * @return converted + */ + private static NumberBound toNumberBound(final Object o) + { + if (o instanceof NumberBound) return (NumberBound) o; + + if (o instanceof Number) return new NumberBound() { + + @Override + public double getValue() + { + return ((Number) o).doubleValue(); + } + }; + + throw new IllegalArgumentException("Invalid numeric type."); + } + + + /** + * Convert {@link Number} or {@link NumberBound} to double (current value) + * + * @param o unknown numeric value + * @return double value + */ + private static double eval(final Object o) + { + return toNumberBound(o).getValue(); + } + + + public static NumberBound min(final Object a, final Object b) + { + return new NumberBound() { + + @Override + public double getValue() + { + return Math.min(eval(a), eval(b)); + } + }; + } + + + public static NumberBound max(final Object a, final Object b) + { + return new NumberBound() { + + @Override + public double getValue() + { + return Math.max(eval(a), eval(b)); + } + }; + } + + + public static NumberBound abs(final NumberBound a) + { + return new NumberBound() { + + @Override + public double getValue() + { + return Math.abs(a.getValue()); + } + }; + } + + + public static NumberBound half(final NumberBound a) + { + return new NumberBound() { + + @Override + public double getValue() + { + return a.getValue() / 2; + } + }; + } + + + public static NumberBound round(final NumberBound a) + { + return new NumberBound() { + + @Override + public double getValue() + { + return Math.round(a.getValue()); + } + }; + } + + + public static RectBound round(final RectBound r) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().round(); + } + }; + } + + + public static NumberBound ceil(final NumberBound a) + { + return new NumberBound() { + + @Override + public double getValue() + { + return Math.ceil(a.getValue()); + } + }; + } + + + public static NumberBound floor(final NumberBound a) + { + return new NumberBound() { + + @Override + public double getValue() + { + return Math.floor(a.getValue()); + } + }; + } + + + public static NumberBound neg(final NumberBound a) + { + return new NumberBound() { + + @Override + public double getValue() + { + return -a.getValue(); + } + }; + } + + + public static NumberBound add(final Object a, final Object b) + { + return new NumberBound() { + + @Override + public double getValue() + { + return eval(a) + eval(b); + } + }; + } + + + public static NumberBound sub(final Object a, final Object b) + { + return new NumberBound() { + + @Override + public double getValue() + { + return eval(a) - eval(b); + } + }; + } + + + public static NumberBound mul(final Object a, final Object b) + { + return new NumberBound() { + + @Override + public double getValue() + { + return eval(a) * eval(b); + } + }; + } + + + public static NumberBound half(final Object a) + { + return mul(a, 0.5); + } + + + public static NumberBound div(final Object a, final Object b) + { + return new NumberBound() { + + @Override + public double getValue() + { + return eval(a) / eval(b); + } + }; + } + + + public static NumberBound perc(final Object whole, final Object percent) + { + return new NumberBound() { + + @Override + public double getValue() + { + return eval(whole) * (eval(percent) / 100); + } + }; + } + + + public static RectBound row(final RectBound r, final int rows, final int index) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final double height = r.getRect().height(); + final double perRow = height / rows; + + final Vect origin = r.getRect().origin().add(0, perRow * index); + final Vect size = r.getRect().size().setY(perRow); + + return RectVal.make(origin, size); + } + }; + } + + + public static RectBound column(final RectBound r, final int columns, final int index) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final double width = r.getRect().width(); + final double perCol = width / columns; + + final Vect origin = r.getRect().origin().add(perCol * index, 0); + final Vect size = r.getRect().size().setX(perCol); + + return RectVal.make(origin, size); + } + }; + } + + + public static RectBound tile(final RectBound r, final int rows, final int cols, final int left, final int top) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final double height = r.getRect().height(); + final double width = r.getRect().height(); + final double perRow = height / rows; + final double perCol = width / cols; + + final Vect origin = r.getRect().origin().add(perCol * left, perRow * (rows - top - 1)); + + return RectVal.make(origin, perCol, perRow); + } + }; + } + + + public static RectBound shrink(RectBound r, Object shrink) + { + return shrink(r, shrink, shrink, shrink, shrink); + } + + + public static RectBound shrink(RectBound context, Object horiz, Object vert) + { + return shrink(context, horiz, vert, horiz, vert); + } + + + public static RectBound shrink(final RectBound r, final Object left, final Object top, final Object right, final Object bottom) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(eval(left), eval(top), eval(right), eval(bottom)); + } + }; + } + + + public static RectBound shrinkTop(final RectBound r, final Object shrink) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(0, eval(shrink), 0, 0); + } + }; + } + + + public static RectBound shrinkBottom(final RectBound r, final Object shrink) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(0, 0, 0, eval(shrink)); + } + }; + } + + + public static RectBound shrinkLeft(final RectBound r, final Object shrink) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(eval(shrink), 0, 0, 0); + } + }; + } + + + public static RectBound shrinkRight(final RectBound r, final Object shrink) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(0, 0, eval(shrink), 0); + } + }; + } + + + public static RectBound grow(RectBound r, Object grow) + { + return grow(r, grow, grow, grow, grow); + } + + + public static RectBound grow(RectBound r, Object horiz, Object vert) + { + return grow(r, horiz, vert, horiz, vert); + } + + + public static RectBound grow(final RectBound r, final Object left, final Object right, final Object top, final Object bottom) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().grow(eval(left), eval(right), eval(top), eval(bottom)); + } + }; + } + + + public static RectBound growUp(final RectBound r, final Object grow) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().grow(0, eval(grow), 0, 0); + } + }; + } + + + public static RectBound growDown(final RectBound r, final Object grow) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().grow(0, 0, 0, eval(grow)); + } + }; + } + + + public static RectBound growLeft(final RectBound r, final Object grow) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().grow(eval(grow), 0, 0, 0); + } + }; + } + + + public static RectBound growRight(final RectBound r, final Object grow) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().grow(0, 0, eval(grow), 0); + } + }; + } + + + public static RectBound box(final Object side) + { + return box(side, side); + } + + + public static RectBound box(final Vect origin, final Object width, final Object height) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return RectVal.make(origin, eval(width), eval(height)); + } + }; + } + + + public static RectBound box(final Object width, final Object height) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return RectVal.make(0, 0, eval(width), eval(height)); + } + }; + } + + + public static RectBound box(final RectBound r, final Object width, final Object height) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final Vect origin = r.getRect().origin(); + + return RectVal.make(origin.x(), origin.y(), eval(width), eval(height)); + } + }; + } + + + public static RectBound box(final RectBound r, final Object x, final Object y, final Object width, final Object height) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final Vect origin = r.getRect().origin(); + + return RectVal.make(origin.x() + eval(x), origin.y() + eval(y), eval(width), eval(height)); + } + }; + } + + + public static RectBound centerTo(final RectBound r, final RectBound centerTo) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final VectView size = r.getRect().size(); + final VectView center = centerTo.getRect().center(); + + return RectVal.make(center.sub(size.half()), size); + } + }; + } + + + public static RectBound centerTo(final RectBound r, final Vect centerTo) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final VectView size = r.getRect().size(); + + return RectVal.make(centerTo.getValue().sub(size.half()), size); + } + }; + } + + + public static RectBound centerTo(final RectBound r, final Object x, final Object y) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final VectView size = r.getRect().size(); + final VectView v = VectVal.make(eval(x), eval(y)); + + return RectVal.make(v.sub(size.half()), size); + } + }; + } + + + public static RectBound move(final RectBound r, final Vect move) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().move(move); + } + }; + } + + + public static RectBound move(final RectBound r, final Object x, final Object y) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().move(eval(x), eval(y)); + } + }; + } + + + /** + * Make a rect around coord + * + * @param c coord + * @param allSides size to grow on all sides + * @return rect constraint + */ + public static RectBound expand(final Vect c, final Object allSides) + { + return expand(c, allSides, allSides, allSides, allSides); + } + + + /** + * Make a rect around coord + * + * @param c coord + * @param horizontal horisontal grow (left, right) + * @param vertical vertical grow (top, bottom) + * @return rect constraint + */ + public static RectBound expand(final Vect c, final Object horizontal, final Object vertical) + { + return expand(c, horizontal, vertical, horizontal, vertical); + } + + + /** + * Make a rect around coord, growing by given amounts + * + * @param c coord + * @param top + * @param right + * @param bottom + * @param left + * @return rect constraint + */ + public static RectBound expand(final Vect c, final Object top, final Object right, final Object bottom, final Object left) + { + return new RectBound() { + + @Override + public RectView getRect() + { + final double t = eval(top); + final double r = eval(right); + final double b = eval(bottom); + final double l = eval(left); + + return RectVal.make(c.x() - l, c.y() - t, l + r, t + b); + } + }; + } + + + public static RectBound edgeLeft(final RectBound r) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(0, 0, r.getRect().width(), 0); + } + }; + } + + + public static RectBound edgeTop(final RectBound r) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(0, 0, 0, r.getRect().height()); + } + }; + } + + + public static RectBound edgeRight(final RectBound r) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(r.getRect().width(), 0, 0, 0); + } + }; + } + + + public static RectBound edgeBottom(final RectBound r) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return r.getRect().shrink(0, r.getRect().height(), 0, 0); + } + }; + } + + + public static VectView neg(final Vect c) + { + return mul(c, -1); + } + + + public static VectView half(final Vect c) + { + return mul(c, 0.5); + } + + + public static VectView add(final Vect c1, final Vect c2) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return c1.getValue().add(c2); + } + }; + } + + + public static VectView add(final Vect c, final Object x, final Object y) + { + return add(c, x, y, 0); + } + + + public static VectView add(final Vect c, final Object x, final Object y, final Object z) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return c.getValue().add(eval(x), eval(y), eval(z)); + } + }; + } + + + public static VectView sub(final Vect c1, final Vect c2) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return c1.getValue().sub(c2); + } + }; + } + + + public static VectView sub(final Vect c, final Object x, final Object y) + { + return sub(c, x, y, 0); + } + + + public static VectView sub(final Vect c, final Object x, final Object y, final Object z) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return c.getValue().sub(eval(x), eval(y), eval(z)); + } + + }; + } + + + public static VectView mul(final Vect c, final Object mul) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return c.getValue().mul(eval(mul)); + } + + }; + } + + + public static VectView norm(final Vect c, final Object norm) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return c.getValue().norm(eval(norm)); + } + + }; + } + + + public static VectView origin(final RectBound r) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return r.getRect().origin(); + } + }; + } + + + public static VectView size(final RectBound r) + { + return new VectAdapter() { + + @Override + public VectView getSource() + { + return r.getRect().size(); + } + }; + } + + + public static NumberBound height(final RectBound r) + { + return size(r).yc(); + } + + + public static NumberBound width(final RectBound r) + { + return size(r).xc(); + } + + + public static VectView center(final RectBound r) + { + return add(origin(r), half(size(r))); + } + + + public static VectView topLeft(final RectBound r) + { + return origin(r); + } + + + public static VectView topRight(final RectBound r) + { + return add(origin(r), width(r), 0); + } + + + public static VectView bottomLeft(final RectBound r) + { + return add(origin(r), 0, width(r)); + } + + + public static VectView bottomRight(final RectBound r) + { + return add(origin(r), size(r)); + } + + + public static VectView topCenter(final RectBound r) + { + return add(origin(r), half(width(r)), 0); + } + + + public static VectView bottomCenter(final RectBound r) + { + return add(origin(r), half(width(r)), width(r)); + } + + + public static VectView centerLeft(final RectBound r) + { + return add(origin(r), 0, half(width(r))); + } + + + public static VectView centerRight(final RectBound r) + { + return add(origin(r), width(r), half(width(r))); + } + + + /** + * Zero-sized RectView at given coord + * + * @param c coord + * @return rect + */ + public static RectBound zeroRect(final Vect c) + { + return new RectBound() { + + @Override + public RectView getRect() + { + return RectVal.make(c.x(), c.y(), 0, 0); + } + }; + } + +} diff --git a/src/mightypork/utils/math/constraints/Constraints.java b/src/mightypork/utils/math/constraints/Constraints.java deleted file mode 100644 index 95d586e..0000000 --- a/src/mightypork/utils/math/constraints/Constraints.java +++ /dev/null @@ -1,952 +0,0 @@ -package mightypork.utils.math.constraints; - - -import mightypork.gamecore.control.timing.Poller; -import mightypork.utils.math.rect.RectVal; -import mightypork.utils.math.rect.RectView; -import mightypork.utils.math.vect.VectAdapter; -import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; - - -/** - * Constraint factory.
- * Import statically for best experience. - * - * @author MightyPork - */ -public class Constraints { - - public static RectCache cCached(final Poller poller, final RectConstraint rc) - { - return new RectCache(poller, rc); - } - - - /** - * Convert {@link Number} to {@link NumberConstraint} if needed - * - * @param o unknown numeric value - * @return converted - */ - private static NumberConstraint toConstraint(final Object o) - { - if (o instanceof NumberConstraint) return (NumberConstraint) o; - - if (o instanceof Number) return new NumberConstraint() { - - @Override - public double getValue() - { - return ((Number) o).doubleValue(); - } - }; - - throw new IllegalArgumentException("Invalid numeric type."); - } - - - /** - * Convert {@link Number} or {@link NumberConstraint} to double (current - * value) - * - * @param o unknown numeric value - * @return double value - */ - private static double toDouble(final Object o) - { - return toConstraint(o).getValue(); - } - - - public static NumberConstraint cMin(final Object a, final Object b) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return Math.min(toDouble(a), toDouble(b)); - } - }; - } - - - public static NumberConstraint cMax(final Object a, final Object b) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return Math.max(toDouble(a), toDouble(b)); - } - }; - } - - - public static NumberConstraint cAbs(final NumberConstraint a) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return Math.abs(a.getValue()); - } - }; - } - - - public static NumberConstraint cHalf(final NumberConstraint a) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return a.getValue() / 2; - } - }; - } - - - public static NumberConstraint cRound(final NumberConstraint a) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return Math.round(a.getValue()); - } - }; - } - - - public static RectConstraint cRound(final RectConstraint r) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().round(); - } - }; - } - - - public static NumberConstraint cCeil(final NumberConstraint a) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return Math.ceil(a.getValue()); - } - }; - } - - - public static NumberConstraint cFloor(final NumberConstraint a) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return Math.floor(a.getValue()); - } - }; - } - - - public static NumberConstraint cNeg(final NumberConstraint a) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return -a.getValue(); - } - }; - } - - - public static NumberConstraint cAdd(final Object a, final Object b) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return toDouble(a) + toDouble(b); - } - }; - } - - - public static NumberConstraint cSub(final Object a, final Object b) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return toDouble(a) - toDouble(b); - } - }; - } - - - public static NumberConstraint cMul(final Object a, final Object b) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return toDouble(a) * toDouble(b); - } - }; - } - - - public static NumberConstraint cHalf(final Object a) - { - return cMul(a, 0.5); - } - - - public static NumberConstraint cDiv(final Object a, final Object b) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return toDouble(a) / toDouble(b); - } - }; - } - - - public static NumberConstraint cPerc(final Object whole, final Object percent) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return toDouble(whole) * (toDouble(percent) / 100); - } - }; - } - - - public static RectConstraint cRow(final RectConstraint r, final int rows, final int index) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final double height = r.getRect().getHeight(); - final double perRow = height / rows; - - final Vect origin = r.getRect().getOrigin().add(0, perRow * index); - final Vect size = r.getRect().getSize().setY(perRow); - - return RectVal.make(origin, size); - } - }; - } - - - public static RectConstraint cColumn(final RectConstraint r, final int columns, final int index) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final double width = r.getRect().getWidth(); - final double perCol = width / columns; - - final Vect origin = r.getRect().getOrigin().add(perCol * index, 0); - final Vect size = r.getRect().getSize().setX(perCol); - - return RectVal.make(origin, size); - } - }; - } - - - public static RectConstraint cTile(final RectConstraint r, final int rows, final int cols, final int left, final int top) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final double height = r.getRect().getHeight(); - final double width = r.getRect().getHeight(); - final double perRow = height / rows; - final double perCol = width / cols; - - final Vect origin = r.getRect().getOrigin().add(perCol * left, perRow * (rows - top - 1)); - - return RectVal.make(origin, perCol, perRow); - } - }; - } - - - public static RectConstraint cShrink(RectConstraint r, Object shrink) - { - final NumberConstraint n = toConstraint(shrink); - return cShrink(r, n, n, n, n); - } - - - public static RectConstraint cShrink(RectConstraint context, Object horiz, Object vert) - { - return cShrink(context, horiz, vert, horiz, vert); - } - - - public static RectConstraint cShrink(final RectConstraint r, final Object left, final Object top, final Object right, final Object bottom) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(toDouble(left), toDouble(top), toDouble(right), toDouble(bottom)); - } - }; - } - - - public static RectConstraint cShrinkTop(final RectConstraint r, final Object shrink) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(0, toDouble(shrink), 0, 0); - } - }; - } - - - public static RectConstraint cShrinkBottom(final RectConstraint r, final Object shrink) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(0, 0, 0, toDouble(shrink)); - } - }; - } - - - public static RectConstraint cShrinkLeft(final RectConstraint r, final Object shrink) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(toDouble(shrink), 0, 0, 0); - } - }; - } - - - public static RectConstraint cShrinkRight(final RectConstraint r, final Object shrink) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(0, 0, toDouble(shrink), 0); - } - }; - } - - - public static RectConstraint cGrow(RectConstraint r, Object grow) - { - final NumberConstraint n = toConstraint(grow); - return cGrow(r, n, n, n, n); - } - - - public static RectConstraint cGrow(RectConstraint r, Object horiz, Object vert) - { - return cGrow(r, horiz, vert, horiz, vert); - } - - - public static RectConstraint cGrow(final RectConstraint r, final Object left, final Object right, final Object top, final Object bottom) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().grow(toDouble(left), toDouble(right), toDouble(top), toDouble(bottom)); - } - }; - } - - - public static RectConstraint cGrowUp(final RectConstraint r, final Object grow) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().grow(0, toDouble(grow), 0, 0); - } - }; - } - - - public static RectConstraint cGrowDown(final RectConstraint r, final Object grow) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().grow(0, 0, 0, toDouble(grow)); - } - }; - } - - - public static RectConstraint cGrowLeft(final RectConstraint r, final Object grow) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().grow(toDouble(grow), 0, 0, 0); - } - }; - } - - - public static RectConstraint cGrowRight(final RectConstraint r, final Object grow) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().grow(0, 0, toDouble(grow), 0); - } - }; - } - - - public static RectConstraint cBox(final Object side) - { - return cBox(side, side); - } - - - public static RectConstraint cBox(final VectConstraint origin, final Object width, final Object height) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return RectVal.make(origin.getVec(), toDouble(width), toDouble(height)); - } - }; - } - - - public static RectConstraint cBox(final Object width, final Object height) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return RectVal.make(0, 0, toDouble(width), toDouble(height)); - } - }; - } - - - public static RectConstraint cBox(final RectConstraint r, final Object width, final Object height) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final Vect origin = r.getRect().getOrigin(); - - return RectVal.make(origin.x(), origin.y(), toDouble(width), toDouble(height)); - } - }; - } - - - public static RectConstraint cBox(final RectConstraint r, final Object x, final Object y, final Object width, final Object height) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final Vect origin = r.getRect().getOrigin(); - - return RectVal.make(origin.x() + toDouble(x), origin.y() + toDouble(y), toDouble(width), toDouble(height)); - } - }; - } - - - public static RectConstraint cCenterTo(final RectConstraint r, final RectConstraint centerTo) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final VectView size = r.getRect().getSize(); - final VectView center = centerTo.getRect().getCenter(); - - return RectVal.make(center.sub(size.half()), size); - } - }; - } - - - public static RectConstraint cCenterTo(final RectConstraint r, final VectConstraint centerTo) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final VectView size = r.getRect().getSize(); - - return RectVal.make(centerTo.getVec().sub(size.half()), size); - } - }; - } - - - public static RectConstraint cCenterTo(final RectConstraint r, final Object x, final Object y) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final VectView size = r.getRect().getSize(); - final VectView v = VectVal.make(toDouble(x), toDouble(y)); - - return RectVal.make(v.sub(size.half()), size); - } - }; - } - - - public static RectConstraint cMove(final RectConstraint r, final VectConstraint move) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().move(move.getVec()); - } - }; - } - - - public static RectConstraint cMove(final RectConstraint r, final Object x, final Object y) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().move(toDouble(x), toDouble(y)); - } - }; - } - - - /** - * Make a rect around coord - * - * @param c coord - * @param allSides size to grow on all sides - * @return rect constraint - */ - public static RectConstraint cExpand(final VectConstraint c, final Object allSides) - { - return cExpand(c, allSides, allSides, allSides, allSides); - } - - - /** - * Make a rect around coord - * - * @param c coord - * @param horizontal horisontal grow (left, right) - * @param vertical vertical grow (top, bottom) - * @return rect constraint - */ - public static RectConstraint cExpand(final VectConstraint c, final Object horizontal, final Object vertical) - { - return cExpand(c, horizontal, vertical, horizontal, vertical); - } - - - /** - * Make a rect around coord, growing by given amounts - * - * @param c coord - * @param top - * @param right - * @param bottom - * @param left - * @return rect constraint - */ - public static RectConstraint cExpand(final VectConstraint c, final Object top, final Object right, final Object bottom, final Object left) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final double t = toDouble(top); - final double r = toDouble(right); - final double b = toDouble(bottom); - final double l = toDouble(left); - - final double x = c.getVec().x(); - final double y = c.getVec().y(); - - return RectVal.make(x - l, y - t, l + r, t + b); - } - }; - } - - - public static RectConstraint cLeftEdge(final RectConstraint r) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(0, 0, r.getRect().getWidth(), 0); - } - }; - } - - - public static RectConstraint cTopEdge(final RectConstraint r) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(0, 0, 0, r.getRect().getHeight()); - } - }; - } - - - public static RectConstraint cRightEdge(final RectConstraint r) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(r.getRect().getWidth(), 0, 0, 0); - } - }; - } - - - public static RectConstraint cBottomEdge(final RectConstraint r) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - return r.getRect().shrink(0, r.getRect().getHeight(), 0, 0); - } - }; - } - - - public static NumberConstraint cX(final VectConstraint c) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return c.getVec().x(); - } - }; - } - - - public static NumberConstraint cY(final VectConstraint c) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return c.getVec().y(); - } - }; - } - - - public static NumberConstraint cZ(final VectConstraint c) - { - return new NumberConstraint() { - - @Override - public double getValue() - { - return c.getVec().z(); - } - }; - } - - - public static VectConstraint cNeg(final VectConstraint c) - { - return cMul(c, -1); - } - - - public static VectConstraint cHalf(final VectConstraint c) - { - return cMul(c, 0.5); - } - - - public static VectConstraint cAdd(final VectConstraint c1, final VectConstraint c2) - { - return new VectAdapter() { - - @Override - public VectView getSource() - { - return c1.getVec().add(c2.getVec()); - } - }; - } - - - public static VectConstraint cAdd(final VectConstraint c, final Object x, final Object y) - { - return cAdd(c, x, y, 0); - } - - - public static VectConstraint cAdd(final VectConstraint c, final Object x, final Object y, final Object z) - { - return new VectAdapter() { - - @Override - public VectView getSource() - { - return c.getVec().add(toDouble(x), toDouble(y), toDouble(z)); - } - }; - } - - - public static VectConstraint cSub(final VectConstraint c1, final VectConstraint c2) - { - return new VectAdapter() { - - @Override - public VectView getSource() - { - return c1.getVec().sub(c2.getVec()); - } - }; - } - - - public static VectConstraint cSub(final VectConstraint c, final Object x, final Object y) - { - return cSub(c, x, y, 0); - } - - - public static VectConstraint cSub(final VectConstraint c, final Object x, final Object y, final Object z) - { - return new VectAdapter() { - - @Override - public VectView getSource() - { - return c.getVec().sub(toDouble(x), toDouble(y), toDouble(z)); - } - - }; - } - - - public static VectConstraint cMul(final VectConstraint c, final Object mul) - { - return new VectAdapter() { - - @Override - public VectView getSource() - { - return c.getVec().mul(toDouble(mul)); - } - - }; - } - - - public static VectConstraint cOrigin(final RectConstraint r) - { - return new VectAdapter() { - - @Override - public VectView getSource() - { - return r.getRect().getOrigin(); - } - }; - } - - - public static VectConstraint cSize(final RectConstraint r) - { - return new VectAdapter() { - - @Override - public VectView getSource() - { - return r.getRect().getSize(); - } - }; - } - - - public static NumberConstraint cHeight(final RectConstraint r) - { - return cY(cSize(r)); - } - - - public static NumberConstraint cWidth(final RectConstraint r) - { - return cX(cSize(r)); - } - - - public static VectConstraint cCenter(final RectConstraint r) - { - return cAdd(cOrigin(r), cHalf(cSize(r))); - } - - - public static VectConstraint cTopLeft(final RectConstraint r) - { - return cOrigin(r); - } - - - public static VectConstraint cTopRight(final RectConstraint r) - { - return cAdd(cOrigin(r), cWidth(r), 0); - } - - - public static VectConstraint cBottomLeft(final RectConstraint r) - { - return cAdd(cOrigin(r), 0, cWidth(r)); - } - - - public static VectConstraint cBottomRight(final RectConstraint r) - { - return cAdd(cOrigin(r), cSize(r)); - } - - - public static VectConstraint cTopCenter(final RectConstraint r) - { - return cAdd(cOrigin(r), cHalf(cWidth(r)), 0); - } - - - public static VectConstraint cBottomCenter(final RectConstraint r) - { - return cAdd(cOrigin(r), cHalf(cWidth(r)), cWidth(r)); - } - - - public static VectConstraint cCenterLeft(final RectConstraint r) - { - return cAdd(cOrigin(r), 0, cHalf(cWidth(r))); - } - - - public static VectConstraint cCenterRight(final RectConstraint r) - { - return cAdd(cOrigin(r), cWidth(r), cHalf(cWidth(r))); - } - - - /** - * Zero-sized RectView at given coord - * - * @param c coord - * @return rect - */ - public static RectConstraint cZeroRect(final VectConstraint c) - { - return new RectConstraint() { - - @Override - public RectView getRect() - { - final Vect v = c.getVec(); - - return RectVal.make(v.x(), v.y(), 0, 0); - } - }; - } - -} diff --git a/src/mightypork/utils/math/constraints/ContextAdapter.java b/src/mightypork/utils/math/constraints/ContextAdapter.java index 03f3646..5e73d3a 100644 --- a/src/mightypork/utils/math/constraints/ContextAdapter.java +++ b/src/mightypork/utils/math/constraints/ContextAdapter.java @@ -11,11 +11,11 @@ import mightypork.utils.math.rect.RectView; */ public abstract class ContextAdapter implements PluggableRect { - private RectConstraint backing = null; + private RectBound backing = null; @Override - public void setContext(RectConstraint rect) + public void setContext(RectBound rect) { this.backing = rect; } diff --git a/src/mightypork/utils/math/constraints/NumberBound.java b/src/mightypork/utils/math/constraints/NumberBound.java new file mode 100644 index 0000000..277686b --- /dev/null +++ b/src/mightypork/utils/math/constraints/NumberBound.java @@ -0,0 +1,20 @@ +package mightypork.utils.math.constraints; + + +/** + * Numeric constraint + * + * @author MightyPork + */ +public interface NumberBound { + + public static final NumberBound ZERO = new NumberConst(0); + public static final NumberBound ONE = new NumberConst(1); + + + /** + * @return current value + */ + double getValue(); + +} diff --git a/src/mightypork/utils/math/constraints/FixedNumberConstraint.java b/src/mightypork/utils/math/constraints/NumberConst.java similarity index 57% rename from src/mightypork/utils/math/constraints/FixedNumberConstraint.java rename to src/mightypork/utils/math/constraints/NumberConst.java index 339ac1c..de8df6d 100644 --- a/src/mightypork/utils/math/constraints/FixedNumberConstraint.java +++ b/src/mightypork/utils/math/constraints/NumberConst.java @@ -2,16 +2,16 @@ package mightypork.utils.math.constraints; /** - * Constant number {@link NumberConstraint} + * Constant number {@link NumberBound} * * @author MightyPork */ -public class FixedNumberConstraint implements NumberConstraint { +public class NumberConst implements NumberBound { private final double value; - public FixedNumberConstraint(double value) { + public NumberConst(double value) { this.value = value; } diff --git a/src/mightypork/utils/math/constraints/NumberConstraint.java b/src/mightypork/utils/math/constraints/NumberConstraint.java deleted file mode 100644 index c39dc2b..0000000 --- a/src/mightypork/utils/math/constraints/NumberConstraint.java +++ /dev/null @@ -1,20 +0,0 @@ -package mightypork.utils.math.constraints; - - -/** - * Numeric constraint - * - * @author MightyPork - */ -public interface NumberConstraint { - - public static final NumberConstraint ZERO = new FixedNumberConstraint(0); - public static final NumberConstraint ONE = new FixedNumberConstraint(1); - - - /** - * @return current value - */ - double getValue(); - -} diff --git a/src/mightypork/utils/math/constraints/PluggableRect.java b/src/mightypork/utils/math/constraints/PluggableRect.java index 9f98c06..1581ed3 100644 --- a/src/mightypork/utils/math/constraints/PluggableRect.java +++ b/src/mightypork/utils/math/constraints/PluggableRect.java @@ -9,12 +9,12 @@ import mightypork.utils.math.rect.RectView; * * @author MightyPork */ -public interface PluggableRect extends RectConstraint { +public interface PluggableRect extends RectBound { /** * @param rect context to set */ - abstract void setContext(RectConstraint rect); + abstract void setContext(RectBound rect); @Override diff --git a/src/mightypork/utils/math/constraints/RectConstraint.java b/src/mightypork/utils/math/constraints/RectBound.java similarity index 86% rename from src/mightypork/utils/math/constraints/RectConstraint.java rename to src/mightypork/utils/math/constraints/RectBound.java index d7be01f..8865441 100644 --- a/src/mightypork/utils/math/constraints/RectConstraint.java +++ b/src/mightypork/utils/math/constraints/RectBound.java @@ -9,7 +9,7 @@ import mightypork.utils.math.rect.RectView; * * @author MightyPork */ -public interface RectConstraint { +public interface RectBound { /** * @return rect region diff --git a/src/mightypork/utils/math/constraints/RectCache.java b/src/mightypork/utils/math/constraints/RectCache.java index 9885fad..7e9ec3c 100644 --- a/src/mightypork/utils/math/constraints/RectCache.java +++ b/src/mightypork/utils/math/constraints/RectCache.java @@ -8,22 +8,22 @@ import mightypork.utils.math.rect.RectView; /** - * {@link RectConstraint} cache, used for caching computed Rect from a complex - * {@link RectConstraint}.
+ * {@link RectBound} cache, used for caching computed Rect from a complex + * {@link RectBound}.
* Calculates only when polled. * * @author MightyPork */ -public class RectCache implements RectConstraint, Pollable { +public class RectCache implements RectBound, Pollable { - private final RectConstraint observed; + private final RectBound observed; private final RectMutable cached = RectMutable.zero(); /** * @param observed cached constraint */ - public RectCache(RectConstraint observed) { + public RectCache(RectBound observed) { this.observed = observed; poll(); } @@ -35,7 +35,7 @@ public class RectCache implements RectConstraint, Pollable { * @param poller poller to join * @param rc observed constraint */ - public RectCache(Poller poller, RectConstraint rc) { + public RectCache(Poller poller, RectBound rc) { this(rc); poller.add(this); } @@ -44,7 +44,7 @@ public class RectCache implements RectConstraint, Pollable { @Override public RectView getRect() { - return cached.view(); + return cached.getView(); } diff --git a/src/mightypork/utils/math/constraints/VectConstraint.java b/src/mightypork/utils/math/constraints/VectConstraint.java deleted file mode 100644 index fe3015c..0000000 --- a/src/mightypork/utils/math/constraints/VectConstraint.java +++ /dev/null @@ -1,18 +0,0 @@ -package mightypork.utils.math.constraints; - - -import mightypork.utils.math.vect.VectVal; - - -/** - * Vector constraint. - * - * @author MightyPork - */ -public interface VectConstraint { - - /** - * @return the constraint vec - */ - VectVal getVec(); -} diff --git a/src/mightypork/utils/math/rect/AbstractRect.java b/src/mightypork/utils/math/rect/AbstractRect.java index 39d7317..2a1fc34 100644 --- a/src/mightypork/utils/math/rect/AbstractRect.java +++ b/src/mightypork/utils/math/rect/AbstractRect.java @@ -1,11 +1,8 @@ package mightypork.utils.math.rect; -import static mightypork.utils.math.constraints.Constraints.*; -import mightypork.utils.math.constraints.VectConstraint; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; /** @@ -16,149 +13,122 @@ import mightypork.utils.math.vect.VectView; public abstract class AbstractRect implements Rect { private RectProxy proxy; - private VectConstraint tl; - private VectConstraint tc; - private VectConstraint tr; - private VectConstraint cl; - private VectConstraint c; - private VectConstraint cr; - private VectConstraint bl; - private VectConstraint bc; - private VectConstraint br; @Override public final RectView getRect() { - return this.view(); + return this.getView(); } @Override - public final VectVal getTopLeft() + public final VectVal topLeft() { - // lazy init - if (tl == null) tl = cTopLeft(this); - return tl.getVec(); + return origin(); } @Override - public final VectVal getTopCenter() + public final VectVal topCenter() { - // lazy init - if (tc == null) tc = cTopCenter(this); - return tc.getVec(); + return origin().add(size().x() / 2, 0); } @Override - public final VectVal getTopRight() + public final VectVal topRight() { - // lazy init - if (tr == null) tr = cTopRight(this); - return tr.getVec(); + return origin().add(size().x(), 0); } @Override - public final VectVal getCenterLeft() + public final VectVal centerLeft() { - // lazy init - if (cl == null) cl = cCenterLeft(this); - return cl.getVec(); + return origin().add(0, size().y() / 2); } @Override - public final VectVal getCenter() + public final VectVal center() { - // lazy init - if (c == null) c = cCenter(this); - return c.getVec(); + return origin().add(size().half()); } @Override - public final VectVal getCenterRight() + public final VectVal centerRight() { - // lazy init - if (cr == null) cr = cCenterRight(this); - return cr.getVec(); + return origin().add(size().x(), size().y() / 2); } @Override - public final VectVal getBottomLeft() + public final VectVal bottomLeft() { - // lazy init - if (bl == null) bl = cBottomLeft(this); - return bl.getVec(); + return origin().add(0, size().y()); } @Override - public final VectVal getBottomCenter() + public final VectVal bottomCenter() { - // lazy init - if (bc == null) bc = cBottomCenter(this); - return bc.getVec(); + return origin().add(size().x() / 2, size().y()); } @Override - public final VectVal getBottomRight() + public final VectVal bottomRight() { - // lazy init - if (br == null) br = cBottomRight(this); - return br.getVec(); + return origin().add(size().x(), size().y()); } @Override - public final double getWidth() + public final double width() { - return getSize().x(); + return size().x(); } @Override - public final double getHeight() + public final double height() { - return getSize().y(); + return size().y(); } @Override - public final double xMin() + public final double getLeft() { - return getOrigin().x(); + return origin().x(); } @Override - public final double xMax() + public final double right() { - return getOrigin().x() + getSize().x(); + return origin().x() + size().x(); } @Override - public final double yMin() + public final double top() { - return getOrigin().y(); + return origin().y(); } @Override - public final double yMax() + public final double bottom() { - return getOrigin().y() + getSize().y(); + return origin().y() + size().y(); } @Override - public RectProxy view() + public RectProxy getView() { if (proxy == null) proxy = new RectProxy(this); @@ -167,16 +137,9 @@ public abstract class AbstractRect implements Rect { @Override - public RectMutable mutable() + public RectVal getValue() { - return RectMutable.make(this); - } - - - @Override - public RectVal value() - { - return RectVal.make(getOrigin(), getSize()); + return RectVal.make(origin(), size()); } @@ -186,10 +149,10 @@ public abstract class AbstractRect implements Rect { final double x = point.x(); final double y = point.y(); - final double x1 = getOrigin().x(); - final double y1 = getOrigin().y(); - final double x2 = x1 + getSize().x(); - final double y2 = y1 + getSize().y(); + final double x1 = origin().x(); + final double y1 = origin().y(); + final double x2 = x1 + size().x(); + final double y2 = y1 + size().y(); return x >= x1 && y >= y1 && x <= x2 && y <= y2; } @@ -198,7 +161,7 @@ public abstract class AbstractRect implements Rect { @Override public String toString() { - return String.format("Rect { %s - %s }", getTopLeft(), getBottomRight()); + return String.format("Rect { %s - %s }", topLeft(), bottomRight()); } } diff --git a/src/mightypork/utils/math/rect/Rect.java b/src/mightypork/utils/math/rect/Rect.java index dcc13a2..5847c20 100644 --- a/src/mightypork/utils/math/rect/Rect.java +++ b/src/mightypork/utils/math/rect/Rect.java @@ -1,10 +1,9 @@ package mightypork.utils.math.rect; -import mightypork.utils.math.constraints.RectConstraint; +import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; /** @@ -12,26 +11,18 @@ import mightypork.utils.math.vect.VectView; * * @author MightyPork */ -public interface Rect extends RectConstraint { +public interface Rect extends RectBound { RectVal ONE = new RectVal(0, 0, 1, 1); RectVal ZERO = new RectVal(0, 0, 0, 0); - /** - * Get a writable copy - * - * @return writable copy - */ - RectMutable mutable(); - - /** * Get a copy of current value * * @return copy */ - RectVal value(); + RectVal getValue(); /** @@ -39,61 +30,61 @@ public interface Rect extends RectConstraint { * * @return proxy */ - RectProxy view(); + RectProxy getView(); /** * @return origin */ - VectVal getOrigin(); + VectVal origin(); - VectVal getSize(); + VectVal size(); - double getWidth(); + double width(); - double getHeight(); + double height(); - VectVal getTopLeft(); + VectVal topLeft(); - VectVal getTopCenter(); + VectVal topCenter(); - VectVal getTopRight(); + VectVal topRight(); - VectVal getCenterLeft(); + VectVal centerLeft(); - VectVal getCenter(); + VectVal center(); - VectVal getCenterRight(); + VectVal centerRight(); - VectVal getBottomLeft(); + VectVal bottomLeft(); - VectVal getBottomCenter(); + VectVal bottomCenter(); - VectVal getBottomRight(); + VectVal bottomRight(); - double xMin(); + double getLeft(); - double xMax(); + double right(); - double yMin(); + double top(); - double yMax(); + double bottom(); /** diff --git a/src/mightypork/utils/math/rect/RectMutable.java b/src/mightypork/utils/math/rect/RectMutable.java index 40cb8d6..4715c75 100644 --- a/src/mightypork/utils/math/rect/RectMutable.java +++ b/src/mightypork/utils/math/rect/RectMutable.java @@ -96,7 +96,7 @@ public abstract class RectMutable extends RectMath { */ public static RectMutable make(Rect other) { - return make(other.getOrigin(), other.getSize()); + return make(other.origin(), other.size()); } @@ -121,7 +121,7 @@ public abstract class RectMutable extends RectMath { */ public RectMutable setTo(Rect rect) { - return setTo(rect.getOrigin(), rect.getSize()); + return setTo(rect.origin(), rect.size()); } diff --git a/src/mightypork/utils/math/rect/RectMutableImpl.java b/src/mightypork/utils/math/rect/RectMutableImpl.java index 55a30f1..796ccd6 100644 --- a/src/mightypork/utils/math/rect/RectMutableImpl.java +++ b/src/mightypork/utils/math/rect/RectMutableImpl.java @@ -92,16 +92,16 @@ class RectMutableImpl extends RectMutable { @Override - public VectVal getOrigin() + public VectVal origin() { - return pos.value(); + return pos.getValue(); } @Override - public VectVal getSize() + public VectVal size() { - return size.value(); + return size.getValue(); } diff --git a/src/mightypork/utils/math/rect/RectProxy.java b/src/mightypork/utils/math/rect/RectProxy.java index 4b38b2a..7221cdc 100644 --- a/src/mightypork/utils/math/rect/RectProxy.java +++ b/src/mightypork/utils/math/rect/RectProxy.java @@ -2,7 +2,6 @@ package mightypork.utils.math.rect; import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; /** @@ -21,16 +20,16 @@ public class RectProxy extends RectView { @Override - public VectVal getOrigin() + public VectVal origin() { - return observed.getOrigin(); + return observed.origin(); } @Override - public VectVal getSize() + public VectVal size() { - return observed.getSize(); + return observed.size(); } } diff --git a/src/mightypork/utils/math/rect/RectVal.java b/src/mightypork/utils/math/rect/RectVal.java index 9d2eb40..2c6f68d 100644 --- a/src/mightypork/utils/math/rect/RectVal.java +++ b/src/mightypork/utils/math/rect/RectVal.java @@ -3,7 +3,6 @@ package mightypork.utils.math.rect; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; public class RectVal extends RectView { @@ -115,21 +114,21 @@ public class RectVal extends RectView { @Override - public RectVal value() + public RectVal getValue() { return this; // nothing can change. } @Override - public VectVal getOrigin() + public VectVal origin() { return pos; } @Override - public VectVal getSize() + public VectVal size() { return size; } diff --git a/src/mightypork/utils/math/rect/RectView.java b/src/mightypork/utils/math/rect/RectView.java index 7e08044..99a62c8 100644 --- a/src/mightypork/utils/math/rect/RectView.java +++ b/src/mightypork/utils/math/rect/RectView.java @@ -1,8 +1,6 @@ package mightypork.utils.math.rect; - - /** * Immutable rect * @@ -16,35 +14,37 @@ public abstract class RectView extends RectMath { * @param observed observed rect * @return view */ - public static RectView make(Rect observed) { - return observed.view(); + public static RectView make(Rect observed) + { + return observed.getView(); } + @Override public RectVal move(double x, double y) { - return RectVal.make(getOrigin().add(x, y), getSize()); + return RectVal.make(origin().add(x, y), size()); } @Override public RectVal shrink(double left, double right, double top, double bottom) { - return RectVal.make(getOrigin().add(left, top), getSize().sub(left + right, top + bottom)); + return RectVal.make(origin().add(left, top), size().sub(left + right, top + bottom)); } @Override public RectVal grow(double left, double right, double top, double bottom) { - return RectVal.make(getOrigin().sub(left, top), getSize().add(left + right, top + bottom)); + return RectVal.make(origin().sub(left, top), size().add(left + right, top + bottom)); } @Override public RectVal round() { - return RectVal.make(getOrigin().round(), getSize().round()); + return RectVal.make(origin().round(), size().round()); } } diff --git a/src/mightypork/utils/math/vect/AbstractVect.java b/src/mightypork/utils/math/vect/AbstractVect.java index 0619e9e..2356a06 100644 --- a/src/mightypork/utils/math/vect/AbstractVect.java +++ b/src/mightypork/utils/math/vect/AbstractVect.java @@ -1,22 +1,15 @@ package mightypork.utils.math.vect; -import mightypork.utils.math.constraints.NumberConstraint; +import mightypork.utils.math.constraints.NumberBound; public abstract class AbstractVect implements Vect { private VectView proxy; - private NumberConstraint xc; - private NumberConstraint yc; - private NumberConstraint zc; - - - @Override - public final VectVal getVec() - { - return value(); - } + private NumberBound xc; + private NumberBound yc; + private NumberBound zc; @Override @@ -53,9 +46,9 @@ public abstract class AbstractVect implements Vect { @Override - public final NumberConstraint xc() + public final NumberBound xc() { - if (xc == null) xc = new NumberConstraint() { + if (xc == null) xc = new NumberBound() { @Override public double getValue() @@ -69,9 +62,9 @@ public abstract class AbstractVect implements Vect { @Override - public final NumberConstraint yc() + public final NumberBound yc() { - if (yc == null) yc = new NumberConstraint() { + if (yc == null) yc = new NumberBound() { @Override public double getValue() @@ -85,9 +78,9 @@ public abstract class AbstractVect implements Vect { @Override - public final NumberConstraint zc() + public final NumberBound zc() { - if (zc == null) zc = new NumberConstraint() { + if (zc == null) zc = new NumberBound() { @Override public double getValue() @@ -116,7 +109,7 @@ public abstract class AbstractVect implements Vect { @Override - public VectVal value() + public VectVal getValue() { return new VectVal(this); } @@ -171,20 +164,12 @@ public abstract class AbstractVect implements Vect { @Override - public VectMutable mutable() - { - return VectMutable.make(this); - } - - - @Override - public VectView view() + public VectView getView() { if (proxy == null) proxy = new VectProxy(this); return proxy; } - @Override diff --git a/src/mightypork/utils/math/vect/NumConstrVect.java b/src/mightypork/utils/math/vect/NumConstrVect.java index dcf3454..fbb3c5f 100644 --- a/src/mightypork/utils/math/vect/NumConstrVect.java +++ b/src/mightypork/utils/math/vect/NumConstrVect.java @@ -1,33 +1,33 @@ package mightypork.utils.math.vect; -import mightypork.utils.math.constraints.NumberConstraint; +import mightypork.utils.math.constraints.NumberBound; /** - * Coord view composed of given {@link NumberConstraint}s, using their current + * Coord view composed of given {@link NumberBound}s, using their current * values. * * @author MightyPork */ class NumConstrVect extends VectView { - private final NumberConstraint constrX; - private final NumberConstraint constrY; - private final NumberConstraint constrZ; + private final NumberBound constrX; + private final NumberBound constrY; + private final NumberBound constrZ; - public NumConstrVect(NumberConstraint x, NumberConstraint y, NumberConstraint z) { + public NumConstrVect(NumberBound x, NumberBound y, NumberBound z) { this.constrX = x; this.constrY = y; this.constrZ = z; } - public NumConstrVect(NumberConstraint x, NumberConstraint y) { + public NumConstrVect(NumberBound x, NumberBound y) { this.constrX = x; this.constrY = y; - this.constrZ = NumberConstraint.ZERO; + this.constrZ = NumberBound.ZERO; } diff --git a/src/mightypork/utils/math/vect/Vect.java b/src/mightypork/utils/math/vect/Vect.java index 203492e..5075196 100644 --- a/src/mightypork/utils/math/vect/Vect.java +++ b/src/mightypork/utils/math/vect/Vect.java @@ -1,8 +1,7 @@ package mightypork.utils.math.vect; -import mightypork.utils.math.constraints.NumberConstraint; -import mightypork.utils.math.constraints.VectConstraint; +import mightypork.utils.math.constraints.NumberBound; /** @@ -10,7 +9,7 @@ import mightypork.utils.math.constraints.VectConstraint; * * @author MightyPork */ -public interface Vect extends VectConstraint { +public interface Vect { public static final VectVal ZERO = new VectVal(0, 0, 0); public static final VectVal ONE = new VectVal(0, 0, 0); @@ -55,19 +54,19 @@ public interface Vect extends VectConstraint { /** * @return X constraint */ - NumberConstraint xc(); + NumberBound xc(); /** * @return Y constraint */ - NumberConstraint yc(); + NumberBound yc(); /** * @return Z constraint */ - NumberConstraint zc(); + NumberBound zc(); /** @@ -134,7 +133,7 @@ public interface Vect extends VectConstraint { * * @return a immutable copy */ - VectVal value(); + VectVal getValue(); /** @@ -142,13 +141,5 @@ public interface Vect extends VectConstraint { * * @return immutable view */ - VectView view(); - - - /** - * Get a mutable copy of current values. - * - * @return mutable copy - */ - VectMutable mutable(); + VectView getView(); } diff --git a/src/mightypork/utils/math/vect/VectAdapter.java b/src/mightypork/utils/math/vect/VectAdapter.java index 0595e31..a3709e0 100644 --- a/src/mightypork/utils/math/vect/VectAdapter.java +++ b/src/mightypork/utils/math/vect/VectAdapter.java @@ -7,7 +7,7 @@ public abstract class VectAdapter extends VectView { * @return the proxied coord */ protected abstract Vect getSource(); - + @Override public double x() diff --git a/src/mightypork/utils/math/vect/VectMutableAnim.java b/src/mightypork/utils/math/vect/VectMutableAnim.java index fb3dc14..8d5eb64 100644 --- a/src/mightypork/utils/math/vect/VectMutableAnim.java +++ b/src/mightypork/utils/math/vect/VectMutableAnim.java @@ -86,7 +86,7 @@ public class VectMutableAnim extends VectMutable implements Pauseable, Updateabl public VectMutableAnim add(Vect offset, double speed) { - animate(view().add(offset), speed); + animate(getView().add(offset), speed); return this; } diff --git a/src/mightypork/utils/math/vect/VectVal.java b/src/mightypork/utils/math/vect/VectVal.java index 34d28d1..07485f6 100644 --- a/src/mightypork/utils/math/vect/VectVal.java +++ b/src/mightypork/utils/math/vect/VectVal.java @@ -18,7 +18,7 @@ public final class VectVal extends VectView { */ public static VectVal make(Vect value) { - return value.value(); + return value.getValue(); } @@ -89,7 +89,7 @@ public final class VectVal extends VectView { */ @Override @Deprecated - public VectVal value() + public VectVal getValue() { return this; // it's constant already } diff --git a/src/mightypork/utils/math/vect/VectView.java b/src/mightypork/utils/math/vect/VectView.java index b4e6f9e..8d200a6 100644 --- a/src/mightypork/utils/math/vect/VectView.java +++ b/src/mightypork/utils/math/vect/VectView.java @@ -2,7 +2,7 @@ package mightypork.utils.math.vect; import mightypork.gamecore.control.interf.DefaultImpl; -import mightypork.utils.math.constraints.NumberConstraint; +import mightypork.utils.math.constraints.NumberBound; /** @@ -11,7 +11,7 @@ import mightypork.utils.math.constraints.NumberConstraint; * @author MightyPork */ public abstract class VectView extends VectMath { // returns constant value on edit - + /** * Make a proxy view at a vector. * @@ -20,7 +20,7 @@ public abstract class VectView extends VectMath { // returns constant v */ public static VectView make(Vect observed) { - return observed.view(); + return observed.getView(); } @@ -31,7 +31,7 @@ public abstract class VectView extends VectMath { // returns constant v * @param yc Y value * @return view at the values */ - public static VectView make(NumberConstraint xc, NumberConstraint yc) + public static VectView make(NumberBound xc, NumberBound yc) { return new NumConstrVect(xc, yc); } @@ -45,7 +45,7 @@ public abstract class VectView extends VectMath { // returns constant v * @param zc Z value * @return view at the values */ - public static VectView make(NumberConstraint xc, NumberConstraint yc, NumberConstraint zc) + public static VectView make(NumberBound xc, NumberBound yc, NumberBound zc) { return new NumConstrVect(xc, yc, zc); } @@ -63,7 +63,7 @@ public abstract class VectView extends VectMath { // returns constant v */ @Override @Deprecated - public VectView view() + public VectView getView() { return this; // already not mutable } @@ -75,5 +75,5 @@ public abstract class VectView extends VectMath { // returns constant v { return 0; // implemented for ease with 2D anonymous subtypes } - + } diff --git a/src/mightypork/utils/objects/Convert.java b/src/mightypork/utils/objects/Convert.java index ced0cd7..c33a216 100644 --- a/src/mightypork/utils/objects/Convert.java +++ b/src/mightypork/utils/objects/Convert.java @@ -154,8 +154,8 @@ public class Convert { public static VectVal toVect(Object o, Vect def) { try { - if (o == null) return def.value(); - if (o instanceof Vect) return ((Vect) o).value(); + if (o == null) return def.getValue(); + if (o instanceof Vect) return ((Vect) o).getValue(); if (o instanceof String) { String s = ((String) o).trim().toUpperCase(); @@ -183,7 +183,7 @@ public class Convert { // ignore } - return def.value(); + return def.getValue(); }