diff --git a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java index 9a9bfa6..c953ec6 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java @@ -4,7 +4,6 @@ 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.VectView; /** diff --git a/src/mightypork/gamecore/gui/components/AbstractComponent.java b/src/mightypork/gamecore/gui/components/AbstractComponent.java index de63853..7707faa 100644 --- a/src/mightypork/gamecore/gui/components/AbstractComponent.java +++ b/src/mightypork/gamecore/gui/components/AbstractComponent.java @@ -3,26 +3,27 @@ package mightypork.gamecore.gui.components; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppSubModule; -import mightypork.gamecore.control.bus.BusAccess; -import mightypork.gamecore.control.bus.clients.BusNode; import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.rect.RectView; public abstract class AbstractComponent extends AppSubModule implements PluggableRenderable { - private RectBound context; - + private RectBound context; + + public AbstractComponent(AppAccess app) { super(app); } - + + @Override public void setContext(RectBound context) { this.context = context; } - + + @Override public RectView getRect() { diff --git a/src/mightypork/gamecore/gui/components/layout/AbstractLayout.java b/src/mightypork/gamecore/gui/components/layout/AbstractLayout.java index cfd1f25..cf5db55 100644 --- a/src/mightypork/gamecore/gui/components/layout/AbstractLayout.java +++ b/src/mightypork/gamecore/gui/components/layout/AbstractLayout.java @@ -20,7 +20,7 @@ import mightypork.utils.math.constraints.RectBound; */ public abstract class AbstractLayout extends AbstractComponent { - final LinkedList elements = new LinkedList<>(); + final LinkedList elements = new LinkedList<>(); /** diff --git a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java index 8d23294..3ba8ce2 100644 --- a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java @@ -1,7 +1,6 @@ package mightypork.gamecore.gui.components.layout; -import static mightypork.utils.math.constraints.ConstraintFactory.*; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.components.PluggableRenderable; import mightypork.utils.math.constraints.RectBound; diff --git a/src/mightypork/gamecore/gui/components/layout/RowHolder.java b/src/mightypork/gamecore/gui/components/layout/RowHolder.java index 7000ed2..1f38ee9 100644 --- a/src/mightypork/gamecore/gui/components/layout/RowHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/RowHolder.java @@ -1,7 +1,6 @@ package mightypork.gamecore.gui.components.layout; -import static mightypork.utils.math.constraints.ConstraintFactory.*; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.components.PluggableRenderable; import mightypork.utils.math.constraints.RectBound; diff --git a/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java b/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java index 1a1179e..ef735e2 100644 --- a/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/AbstractPainter.java @@ -3,8 +3,8 @@ package mightypork.gamecore.gui.components.painters; import mightypork.gamecore.gui.components.PluggableRenderable; import mightypork.gamecore.gui.components.Renderable; -import mightypork.utils.math.constraints.RectBoundAdapter; import mightypork.utils.math.constraints.RectBound; +import mightypork.utils.math.constraints.RectBoundAdapter; import mightypork.utils.math.rect.RectView; diff --git a/src/mightypork/gamecore/gui/components/painters/QuadPainter.java b/src/mightypork/gamecore/gui/components/painters/QuadPainter.java index 8aee05a..34070ac 100644 --- a/src/mightypork/gamecore/gui/components/painters/QuadPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/QuadPainter.java @@ -54,14 +54,14 @@ public class QuadPainter extends AbstractPainter { Render.quadColor(getRect(), colorHMinVMin, colorHMaxVMin, colorHMaxVMax, colorHMinVMax); } - + @FactoryMethod public static QuadPainter gradH(RGB colorLeft, RGB colorRight) { return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft); } - + @FactoryMethod public static QuadPainter gradV(RGB colorTop, RGB colorBottom) { diff --git a/src/mightypork/gamecore/render/Render.java b/src/mightypork/gamecore/render/Render.java index d500430..57dd6d4 100644 --- a/src/mightypork/gamecore/render/Render.java +++ b/src/mightypork/gamecore/render/Render.java @@ -352,7 +352,7 @@ public class Render { */ public static void quad(Rect quad) { - RectView rv = quad.view(); + final RectView rv = quad.view(); final double x1 = rv.left().value(); final double y1 = rv.top().value(); diff --git a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java index 05f0a33..9f262e5 100644 --- a/src/mightypork/gamecore/render/fonts/impl/CachedFont.java +++ b/src/mightypork/gamecore/render/fonts/impl/CachedFont.java @@ -294,7 +294,8 @@ public class CachedFont implements GLFont { byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI); } else { - byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); + byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()) + .put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); } byteBuffer.flip(); @@ -411,7 +412,8 @@ public class CachedFont implements GLFont { chtx = chars.get(charCurrent); if (chtx != null) { - drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + chtx.height); + drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + + chtx.height); totalwidth += chtx.width; } } diff --git a/src/mightypork/rogue/screens/LayerFps.java b/src/mightypork/rogue/screens/LayerFps.java index f1ef473..cef0e55 100644 --- a/src/mightypork/rogue/screens/LayerFps.java +++ b/src/mightypork/rogue/screens/LayerFps.java @@ -1,7 +1,6 @@ package mightypork.rogue.screens; -import static mightypork.utils.math.constraints.ConstraintFactory.*; import mightypork.gamecore.gui.Action; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.screens.Screen; diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java index 3603a0c..15669ee 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java @@ -1,8 +1,6 @@ package mightypork.rogue.screens.test_bouncyboxes; -import static mightypork.utils.math.constraints.ConstraintFactory.*; - import java.util.Random; import mightypork.gamecore.control.timing.Updateable; diff --git a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java index 100faae..717b8ab 100644 --- a/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java +++ b/src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java @@ -1,8 +1,6 @@ package mightypork.rogue.screens.test_bouncyboxes; -import static mightypork.utils.math.constraints.ConstraintFactory.*; - import java.util.ArrayList; import java.util.List; diff --git a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java index 8d91a68..1045961 100644 --- a/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java +++ b/src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java @@ -1,8 +1,6 @@ package mightypork.rogue.screens.test_cat_sound; -import static mightypork.utils.math.constraints.ConstraintFactory.*; - import java.util.Random; import mightypork.gamecore.control.bus.events.MouseButtonEvent; diff --git a/src/mightypork/rogue/screens/test_font/ScreenTestFont.java b/src/mightypork/rogue/screens/test_font/ScreenTestFont.java index ee3514e..a6f6d39 100644 --- a/src/mightypork/rogue/screens/test_font/ScreenTestFont.java +++ b/src/mightypork/rogue/screens/test_font/ScreenTestFont.java @@ -1,7 +1,6 @@ package mightypork.rogue.screens.test_font; -import static mightypork.utils.math.constraints.ConstraintFactory.*; import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.gui.components.painters.TextPainter; import mightypork.gamecore.gui.screens.Screen; diff --git a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java index 4969d5d..fa68d93 100644 --- a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java +++ b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java @@ -1,7 +1,6 @@ package mightypork.rogue.screens.test_render; -import static mightypork.utils.math.constraints.ConstraintFactory.*; import mightypork.gamecore.control.timing.Poller; import mightypork.gamecore.gui.screens.Screen; import mightypork.gamecore.gui.screens.ScreenLayer; diff --git a/src/mightypork/test/TestConstr.java b/src/mightypork/test/TestConstr.java index 6fbe357..13e5dcf 100644 --- a/src/mightypork/test/TestConstr.java +++ b/src/mightypork/test/TestConstr.java @@ -1,10 +1,16 @@ package mightypork.test; + import java.util.Locale; +import mightypork.utils.math.num.NumMutable; +import mightypork.utils.math.rect.Rect; import mightypork.utils.math.rect.RectVal; import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; public class TestConstr { @@ -13,13 +19,81 @@ public class TestConstr { { Locale.setDefault(Locale.ENGLISH); - final RectVal rect = RectVal.make(0, 0, 10, 10); - final VectVal point = VectVal.make(50, 50); + int cnt = -1; + + { + final RectVal rect = RectVal.make(0, 0, 10, 10); + final VectVal point = VectVal.make(50, 50); + System.out.println("Test " + ++cnt + ": rect = " + rect); + System.out.println("Test " + cnt + ": point = " + point); + System.out.println("Test " + cnt + ": centered rect = " + rect.view().centerTo(point)); + } + + { + final RectVal rect = RectVal.make(0, 0, 10, 10); + final RectView v = rect.view().view(); + System.out.println("\nTest " + ++cnt + ": " + (v == rect.view())); + } + + { + final RectVal rect = RectVal.make(0, 0, 10, 10); + final RectView v = rect.view().view().view().view().view().view(); + System.out.println("\nTest " + ++cnt + ": " + (v == rect.view())); + } + + { + final Vect a = VectVal.make(3, 3); + final VectVal v = a.copy().copy().copy(); + System.out.println("\nTest " + ++cnt + ": " + (v == a.copy())); + } + + { + final Vect a = VectVal.make(3, 3); + final VectVal v = a.copy().copy().copy(); + System.out.println("\nTest " + ++cnt + ": " + (v == a.copy())); + } - System.out.println(rect); - System.out.println(point); - System.out.println(rect.view().centerTo(point)); + { + final VectMutable a = VectMutable.make(10, 10); + final VectView view = a.view().mul(10).half().sub(1, 1); + System.out.println("\nTest " + ++cnt + ": " + (view.equals(VectVal.make(49, 49)))); + a.add(10, 0); + System.out.println("Test " + cnt + ": " + (view.equals(VectVal.make(99, 49)))); + a.setTo(900, 999); + System.out.println(view); + } + { + final NumMutable side = NumMutable.make(100); + final VectMutable center = VectMutable.make(0, 0); + + final Rect box = side.view().box().centerTo(center); + + System.out.println(box); + + side.setTo(10); + + System.out.println(box); + + center.setTo(900, -50); + + System.out.println(box); + + } + { + final NumMutable a = NumMutable.make(100); + + a.setTo(a.mul(50).add(10).div(2)); + + System.out.println(a); + Rect r; + System.out.println(r = a.box()); + + a.reset(); + + System.out.println(r); + + } } } diff --git a/src/mightypork/test/TestCoords.java b/src/mightypork/test/TestCoords.java index aac38f1..ac33837 100644 --- a/src/mightypork/test/TestCoords.java +++ b/src/mightypork/test/TestCoords.java @@ -3,8 +3,6 @@ package mightypork.test; import java.util.Locale; -import mightypork.utils.math.constraints.NumBound; -import mightypork.utils.math.num.Num; import mightypork.utils.math.num.NumView; import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectView; @@ -17,28 +15,28 @@ public class TestCoords { Locale.setDefault(Locale.ENGLISH); // test - VectMutable var = VectMutable.make(1, 2, 3); + final VectMutable var = VectMutable.make(1, 2, 3); - VectView cubicRoot = var.view().mul(var).mul(var); - VectView half = var.view().half(); + final VectView cubicRoot = var.mul(var).mul(var); + final VectView half = var.half(); System.out.println("x, x^3, x/5"); System.out.println(var); System.out.println(cubicRoot); System.out.println(half); - var.mul(10); + var.setTo(var.mul(10)); System.out.println("x = x*10; x, x^3, x/5"); System.out.println(var); System.out.println(cubicRoot); System.out.println(half); - NumView y = var.view().yn(); - System.out.println("y: "+y.value()); + final NumView y = var.yn(); + System.out.println("y: " + y.value()); + + var.setTo(var.add(100, 100)); - var.add(100,100); - System.out.println("x = x*100; x.y(), x, x^3, x/5"); System.out.println(y.value()); System.out.println(var); diff --git a/src/mightypork/utils/annotations/FactoryMethod.java b/src/mightypork/utils/annotations/FactoryMethod.java index af81ec9..7869603 100644 --- a/src/mightypork/utils/annotations/FactoryMethod.java +++ b/src/mightypork/utils/annotations/FactoryMethod.java @@ -1,11 +1,13 @@ package mightypork.utils.annotations; + import java.lang.annotation.Documented; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; + /** * Marks a static factory method * diff --git a/src/mightypork/utils/config/PropertyManager.java b/src/mightypork/utils/config/PropertyManager.java index 47223b9..b199381 100644 --- a/src/mightypork/utils/config/PropertyManager.java +++ b/src/mightypork/utils/config/PropertyManager.java @@ -12,7 +12,6 @@ import java.util.TreeMap; import mightypork.utils.math.Range; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; import mightypork.utils.objects.Convert; diff --git a/src/mightypork/utils/math/animation/AnimDouble.java b/src/mightypork/utils/math/animation/AnimDouble.java index 37d0b54..c193ba8 100644 --- a/src/mightypork/utils/math/animation/AnimDouble.java +++ b/src/mightypork/utils/math/animation/AnimDouble.java @@ -4,9 +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.NumBound; import mightypork.utils.math.num.NumMutable; -import mightypork.utils.math.num.NumVal; /** @@ -135,8 +133,8 @@ public class AnimDouble extends NumMutable implements Updateable, Pauseable { { return defaultDuration; } - - + + /** * @param defaultDuration default animation duration (seconds) */ @@ -144,8 +142,8 @@ public class AnimDouble extends NumMutable implements Updateable, Pauseable { { this.defaultDuration = defaultDuration; } - - + + /** * Get value at delta time * @@ -202,12 +200,11 @@ public class AnimDouble extends NumMutable implements Updateable, Pauseable { * @param value */ @Override - public AnimDouble setTo(double value) + public void setTo(double value) { from = to = value; elapsedTime = 0; duration = defaultDuration; - return this; } diff --git a/src/mightypork/utils/math/animation/Easing.java b/src/mightypork/utils/math/animation/Easing.java index 4f6ea54..386f4bb 100644 --- a/src/mightypork/utils/math/animation/Easing.java +++ b/src/mightypork/utils/math/animation/Easing.java @@ -1,5 +1,6 @@ package mightypork.utils.math.animation; + import mightypork.utils.annotations.FactoryMethod; diff --git a/src/mightypork/utils/math/constraints/NumBound.java b/src/mightypork/utils/math/constraints/NumBound.java index 0ca18ec..a7338db 100644 --- a/src/mightypork/utils/math/constraints/NumBound.java +++ b/src/mightypork/utils/math/constraints/NumBound.java @@ -1,8 +1,7 @@ package mightypork.utils.math.constraints; + import mightypork.utils.math.num.Num; -import mightypork.utils.math.num.NumVal; -import mightypork.utils.math.num.NumView; /** @@ -10,7 +9,7 @@ import mightypork.utils.math.num.NumView; * * @author MightyPork */ -public interface NumBound { +public interface NumBound { /** * @return current value diff --git a/src/mightypork/utils/math/constraints/RectBoundAdapter.java b/src/mightypork/utils/math/constraints/RectBoundAdapter.java index 61eb549..3c32b2a 100644 --- a/src/mightypork/utils/math/constraints/RectBoundAdapter.java +++ b/src/mightypork/utils/math/constraints/RectBoundAdapter.java @@ -11,8 +11,7 @@ import mightypork.utils.math.rect.RectAdapter; * @author MightyPork */ public abstract class RectBoundAdapter extends RectAdapter implements PluggableRectBound { - - + private RectBound backing = null; @@ -22,10 +21,11 @@ public abstract class RectBoundAdapter extends RectAdapter implements PluggableR this.backing = rect; } + @Override - public Rect getSource() { + public Rect getSource() + { return backing.getRect(); } - } diff --git a/src/mightypork/utils/math/constraints/RectCache.java b/src/mightypork/utils/math/constraints/RectCache.java index 79435a3..ed01d13 100644 --- a/src/mightypork/utils/math/constraints/RectCache.java +++ b/src/mightypork/utils/math/constraints/RectCache.java @@ -44,7 +44,7 @@ public class RectCache implements RectBound, Pollable { @Override public RectView getRect() { - return cached.view(); + return cached; } diff --git a/src/mightypork/utils/math/constraints/VectBound.java b/src/mightypork/utils/math/constraints/VectBound.java index 239773a..d677388 100644 --- a/src/mightypork/utils/math/constraints/VectBound.java +++ b/src/mightypork/utils/math/constraints/VectBound.java @@ -1,7 +1,6 @@ package mightypork.utils.math.constraints; -import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectView; diff --git a/src/mightypork/utils/math/num/AbstractNum.java b/src/mightypork/utils/math/num/AbstractNum.java index fc09e83..edd237b 100644 --- a/src/mightypork/utils/math/num/AbstractNum.java +++ b/src/mightypork/utils/math/num/AbstractNum.java @@ -1,23 +1,37 @@ package mightypork.utils.math.num; -public abstract class AbstractNum implements Num { +abstract class AbstractNum implements Num { + + private NumView proxy; + @Override - public Num getNum() { + public Num getNum() + { return this; } + @Override public NumView view() { - return new NumProxy(this); + if (proxy == null) proxy = new NumProxy(this); + + return proxy; } + @Override public NumVal copy() { return new NumVal(this); } + @Override + public String toString() + { + return String.format("#{%.1f}",value()); + } + } diff --git a/src/mightypork/utils/math/num/NumAdapter.java b/src/mightypork/utils/math/num/NumAdapter.java index 1a260f7..5a4a8d2 100644 --- a/src/mightypork/utils/math/num/NumAdapter.java +++ b/src/mightypork/utils/math/num/NumAdapter.java @@ -4,7 +4,8 @@ package mightypork.utils.math.num; public abstract class NumAdapter extends NumView { protected abstract Num getSource(); - + + @Override public double value() { diff --git a/src/mightypork/utils/math/num/NumMath.java b/src/mightypork/utils/math/num/NumMath.java index f6eb108..a42de7e 100644 --- a/src/mightypork/utils/math/num/NumMath.java +++ b/src/mightypork/utils/math/num/NumMath.java @@ -1,6 +1,9 @@ package mightypork.utils.math.num; +import mightypork.utils.math.rect.Rect; + + /** * Math operations for numbers * @@ -36,7 +39,7 @@ interface NumMath> extends Num { N pow(Num other); - N average(Num other); + N average(Num other); N add(double addend); @@ -154,4 +157,12 @@ interface NumMath> extends Num { boolean isZero(); + + + /** + * Make a square rect with this side, positioned at 0,0 + * + * @return new rect + */ + Rect box(); } diff --git a/src/mightypork/utils/math/num/NumMathBase.java b/src/mightypork/utils/math/num/NumMathBase.java index dd0e64a..daa39c6 100644 --- a/src/mightypork/utils/math/num/NumMathBase.java +++ b/src/mightypork/utils/math/num/NumMathBase.java @@ -1,9 +1,10 @@ package mightypork.utils.math.num; + import mightypork.utils.math.constraints.NumBound; -public abstract class NumMathBase> extends AbstractNum implements NumMath { +abstract class NumMathBase> extends AbstractNum implements NumMath { /** * Convert to double, turning null into zero. @@ -19,6 +20,7 @@ public abstract class NumMathBase> extends AbstractNum impl /** * Convert {@link NumBound} to {@link Num}, turning null to Num.ZERO. + * * @param a numeric bound * @return num */ @@ -144,7 +146,7 @@ public abstract class NumMathBase> extends AbstractNum impl if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof NumMathBase)) return false; - NumMathBase other = (NumMathBase) obj; + final NumMathBase other = (NumMathBase) obj; return eq(other); } diff --git a/src/mightypork/utils/math/num/NumMathDynamic.java b/src/mightypork/utils/math/num/NumMathDynamic.java index 7f28b42..0447991 100644 --- a/src/mightypork/utils/math/num/NumMathDynamic.java +++ b/src/mightypork/utils/math/num/NumMathDynamic.java @@ -1,8 +1,11 @@ package mightypork.utils.math.num; -public abstract class NumMathDynamic extends NumMathBase{ +import mightypork.utils.math.rect.RectView; + +abstract class NumMathDynamic extends NumMathBase { + private NumView ceil; private NumView floor; private NumView sgn; @@ -19,13 +22,15 @@ public abstract class NumMathDynamic extends NumMathBase{ private NumView square; private NumView neg; private NumView abs; - + + @Override public NumView add(final double addend) { return new NumView() { - private Num t = NumMathDynamic.this; + private final Num t = NumMathDynamic.this; + @Override public double value() @@ -34,19 +39,22 @@ public abstract class NumMathDynamic extends NumMathBase{ } }; } - + + @Override public NumView sub(final double subtrahend) { return add(-subtrahend); } - + + @Override public NumView mul(final double factor) { return new NumView() { - private Num t = NumMathDynamic.this; + private final Num t = NumMathDynamic.this; + @Override public double value() @@ -55,43 +63,49 @@ public abstract class NumMathDynamic extends NumMathBase{ } }; } - + + @Override public NumView div(final double factor) { - return mul(1/factor); + return mul(1 / factor); } - + + @Override public NumView perc(final double percent) { - return mul(percent/100); + return mul(percent / 100); } - + + @Override public NumView neg() { - if(neg==null) neg = new NumView() { + if (neg == null) neg = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { - return -1*t.value(); + return -1 * t.value(); } }; return neg; } - + + @Override public NumView abs() { - if(abs==null) abs = new NumView() { + if (abs == null) abs = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -101,7 +115,8 @@ public abstract class NumMathDynamic extends NumMathBase{ return abs; } - + + @Override public NumView max(final double other) { @@ -109,6 +124,7 @@ public abstract class NumMathDynamic extends NumMathBase{ final Num t = NumMathDynamic.this; + @Override public double value() { @@ -116,7 +132,8 @@ public abstract class NumMathDynamic extends NumMathBase{ } }; } - + + @Override public NumView min(final double other) { @@ -124,6 +141,7 @@ public abstract class NumMathDynamic extends NumMathBase{ final Num t = NumMathDynamic.this; + @Override public double value() { @@ -131,7 +149,8 @@ public abstract class NumMathDynamic extends NumMathBase{ } }; } - + + @Override public NumView pow(final double other) { @@ -139,6 +158,7 @@ public abstract class NumMathDynamic extends NumMathBase{ final Num t = NumMathDynamic.this; + @Override public double value() { @@ -146,50 +166,56 @@ public abstract class NumMathDynamic extends NumMathBase{ } }; } - + + @Override public NumView square() { - if(square==null) square = new NumView() { + if (square == null) square = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { final double v = t.value(); - return v*v; + return v * v; } }; return square; } - + + @Override public NumView cube() { - if(cube==null) cube = new NumView() { + if (cube == null) cube = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { final double v = t.value(); - return v*v*v; + return v * v * v; } }; return cube; } - + + @Override public NumView sqrt() { - if(sqrt==null) sqrt = new NumView() { + if (sqrt == null) sqrt = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -199,14 +225,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return sqrt; } - + + @Override public NumView cbrt() { - if(cbrt==null) cbrt = new NumView() { + if (cbrt == null) cbrt = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -216,14 +244,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return cbrt; } - + + @Override public NumView sin() { - if(sin==null) sin = new NumView() { + if (sin == null) sin = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -233,14 +263,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return sin; } - + + @Override public NumView cos() { - if(cos==null) cos = new NumView() { + if (cos == null) cos = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -250,14 +282,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return cos; } - + + @Override public NumView tan() { - if(tan==null) tan = new NumView() { + if (tan == null) tan = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -267,14 +301,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return tan; } - + + @Override public NumView asin() { - if(asin==null) asin = new NumView() { + if (asin == null) asin = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -284,14 +320,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return asin; } - + + @Override public NumView acos() { - if(acos==null) acos = new NumView() { + if (acos == null) acos = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -301,14 +339,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return acos; } - + + @Override public NumView atan() { - if(atan==null) atan = new NumView() { + if (atan == null) atan = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -318,14 +358,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return atan; } - + + @Override public NumView round() { - if(round==null) round = new NumView() { + if (round == null) round = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -335,14 +377,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return round; } - + + @Override public NumView floor() { - if(floor==null) floor = new NumView() { + if (floor == null) floor = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -352,14 +396,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return floor; } - + + @Override public NumView ceil() { - if(ceil==null) ceil = new NumView() { + if (ceil == null) ceil = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -369,14 +415,16 @@ public abstract class NumMathDynamic extends NumMathBase{ return ceil; } - + + @Override public NumView signum() { - if(sgn==null) sgn = new NumView() { + if (sgn == null) sgn = new NumView() { final Num t = NumMathDynamic.this; + @Override public double value() { @@ -386,7 +434,8 @@ public abstract class NumMathDynamic extends NumMathBase{ return sgn; } - + + @Override public NumView average(final double other) { @@ -399,7 +448,6 @@ public abstract class NumMathDynamic extends NumMathBase{ { return mul(0.5); } - @Override @@ -555,4 +603,11 @@ public abstract class NumMathDynamic extends NumMathBase{ } }; } + + + @Override + public RectView box() + { + return RectView.make(this, this); + } } diff --git a/src/mightypork/utils/math/num/NumMathStatic.java b/src/mightypork/utils/math/num/NumMathStatic.java index 8bd9c41..c91df97 100644 --- a/src/mightypork/utils/math/num/NumMathStatic.java +++ b/src/mightypork/utils/math/num/NumMathStatic.java @@ -1,7 +1,10 @@ package mightypork.utils.math.num; -public abstract class NumMathStatic> extends NumMathBase { +import mightypork.utils.math.rect.RectVal; + + +abstract class NumMathStatic> extends NumMathBase { protected abstract N result(double a); @@ -253,6 +256,13 @@ public abstract class NumMathStatic> extends NumMathB } + @Override + public RectVal box() + { + return RectVal.make(this, this); + } + + @Override public String toString() { diff --git a/src/mightypork/utils/math/num/NumMutable.java b/src/mightypork/utils/math/num/NumMutable.java index 5dea2b2..ed29d21 100644 --- a/src/mightypork/utils/math/num/NumMutable.java +++ b/src/mightypork/utils/math/num/NumMutable.java @@ -10,7 +10,7 @@ import mightypork.utils.math.constraints.NumBound; * * @author MightyPork */ -public abstract class NumMutable extends NumMathStatic { +public abstract class NumMutable extends NumView { /** * Make a new mutable number initialized as zero (0) @@ -36,7 +36,6 @@ public abstract class NumMutable extends NumMathStatic { } - /** * Make as copy of another * @@ -49,6 +48,7 @@ public abstract class NumMutable extends NumMathStatic { return new NumMutableImpl(value); } + /** * Make as copy of another * @@ -61,6 +61,7 @@ public abstract class NumMutable extends NumMathStatic { return new NumMutableImpl(eval(copied)); } + /** * Make as copy of another * @@ -74,31 +75,31 @@ public abstract class NumMutable extends NumMathStatic { } - @Override - protected NumMutable result(double a) - { - return setTo(a); - } - - /** * Assign a value * * @param value new value - * @return this */ - public NumMutable set(Num value) - { - return setTo(eval(value)); - } + public abstract void setTo(double value); /** * Assign a value * * @param value new value - * @return this */ - public abstract NumMutable setTo(double value); + public void setTo(Num value) + { + setTo(eval(value)); + } + + + /** + * Set to zero + */ + public void reset() + { + setTo(0); + } } diff --git a/src/mightypork/utils/math/num/NumMutableImpl.java b/src/mightypork/utils/math/num/NumMutableImpl.java index e6742e7..c3e2f47 100644 --- a/src/mightypork/utils/math/num/NumMutableImpl.java +++ b/src/mightypork/utils/math/num/NumMutableImpl.java @@ -29,10 +29,9 @@ class NumMutableImpl extends NumMutable { @Override - public NumMutable setTo(double value) + public void setTo(double value) { this.value = value; - return this; } } diff --git a/src/mightypork/utils/math/num/NumProxy.java b/src/mightypork/utils/math/num/NumProxy.java index 131d431..b3cf607 100644 --- a/src/mightypork/utils/math/num/NumProxy.java +++ b/src/mightypork/utils/math/num/NumProxy.java @@ -1,7 +1,7 @@ package mightypork.utils.math.num; -public class NumProxy extends NumAdapter { +class NumProxy extends NumAdapter { private final Num observed; @@ -10,6 +10,7 @@ public class NumProxy extends NumAdapter { this.observed = observed; } + @Override protected Num getSource() { diff --git a/src/mightypork/utils/math/num/NumVal.java b/src/mightypork/utils/math/num/NumVal.java index 274b7bc..50e30f2 100644 --- a/src/mightypork/utils/math/num/NumVal.java +++ b/src/mightypork/utils/math/num/NumVal.java @@ -17,6 +17,7 @@ public class NumVal extends NumMathStatic { @SuppressWarnings("hiding") public static final NumVal ONE = NumVal.make(1); + /** * Make a new constant * @@ -58,12 +59,12 @@ public class NumVal extends NumMathStatic { private final double value; - public NumVal(Num copied) { + NumVal(Num copied) { this.value = copied.value(); } - public NumVal(double value) { + NumVal(double value) { this.value = value; } diff --git a/src/mightypork/utils/math/rect/AbstractRect.java b/src/mightypork/utils/math/rect/AbstractRect.java index 678a996..aa40455 100644 --- a/src/mightypork/utils/math/rect/AbstractRect.java +++ b/src/mightypork/utils/math/rect/AbstractRect.java @@ -6,9 +6,9 @@ package mightypork.utils.math.rect; * * @author MightyPork */ -public abstract class AbstractRect implements Rect { +abstract class AbstractRect implements Rect { - private RectProxy proxy; + private RectProxy proxy; @Override @@ -39,10 +39,7 @@ public abstract class AbstractRect implements Rect { @Override public String toString() { - return String.format( - "Rect { %s - %s }", - origin(), - origin().view().add(size())); + return String.format("Rect { %s - %s }", origin(), origin().copy().add(size())); } } diff --git a/src/mightypork/utils/math/rect/RectAdapter.java b/src/mightypork/utils/math/rect/RectAdapter.java index e9ed2ac..537515c 100644 --- a/src/mightypork/utils/math/rect/RectAdapter.java +++ b/src/mightypork/utils/math/rect/RectAdapter.java @@ -14,7 +14,7 @@ import mightypork.utils.math.vect.VectView; */ public abstract class RectAdapter extends RectView { - private VectAdapter originAdapter = new VectAdapter() { + private final VectAdapter originAdapter = new VectAdapter() { @Override protected Vect getSource() @@ -23,7 +23,7 @@ public abstract class RectAdapter extends RectView { } }; - private VectAdapter sizeAdapter = new VectAdapter() { + private final VectAdapter sizeAdapter = new VectAdapter() { @Override protected Vect getSource() diff --git a/src/mightypork/utils/math/rect/RectMath.java b/src/mightypork/utils/math/rect/RectMath.java index 744f64c..2e5a0f2 100644 --- a/src/mightypork/utils/math/rect/RectMath.java +++ b/src/mightypork/utils/math/rect/RectMath.java @@ -1,97 +1,11 @@ package mightypork.utils.math.rect; -import mightypork.utils.math.num.Num; -import mightypork.utils.math.num.NumView; import mightypork.utils.math.vect.Vect; -import mightypork.utils.math.vect.VectAdapter; -import mightypork.utils.math.vect.VectView; abstract class RectMath extends AbstractRect { - protected NumView p_x; - protected NumView p_y; - protected NumView p_width; - protected NumView p_height; - - protected NumView p_left; - protected NumView p_top; - protected NumView p_right; - protected NumView p_bottom; - - protected VectView p_tl; - protected VectView p_tc; - protected VectView p_tr; - - protected VectView p_cl; - protected VectView p_cc; - protected VectView p_cr; - - protected VectView p_bl; - protected VectView p_bc; - protected VectView p_br; - - protected VectView p_origin; - protected VectView p_size; - - - public RectMath() { - - p_origin = new VectAdapter() { - - @Override - protected Vect getSource() - { - return RectMath.this.origin(); - } - }; - - p_size = new VectAdapter() { - - @Override - protected Vect getSource() - { - return RectMath.this.size(); - } - }; - - // setup proxies - - // origin, size disassembled - p_width = p_size.xn(); - p_height = p_size.yn(); - p_x = p_origin.xn(); - p_y = p_origin.yn(); - - // coordinates - p_top = p_y; - p_left = p_x; - p_right = p_left.add(p_width); - p_bottom = p_top.add(p_height); - - // corners - // -- top line -- - Num width_half = p_width.half(); - Num ya = Num.ZERO; - p_tl = p_origin; - p_tc = p_origin.add(width_half, ya); - p_tr = p_origin.add(p_width, ya); - - // --center line-- - ya = p_height.half(); - p_cl = p_origin.add(Num.ZERO, ya); - p_cc = p_origin.add(width_half, ya); - p_cr = p_origin.add(p_width, ya); - - // -- bottom line -- - ya = p_height; - p_bl = p_origin.add(Num.ZERO, ya); - p_bc = p_origin.add(width_half, ya); - p_br = p_origin.add(p_width, ya); - } - - /** * Add vector to origin * @@ -221,4 +135,5 @@ abstract class RectMath extends AbstractRect { return x >= x1 && y >= y1 && x <= x2 && y <= y2; } + } diff --git a/src/mightypork/utils/math/rect/RectMathDynamic.java b/src/mightypork/utils/math/rect/RectMathDynamic.java index b8687b0..102f496 100644 --- a/src/mightypork/utils/math/rect/RectMathDynamic.java +++ b/src/mightypork/utils/math/rect/RectMathDynamic.java @@ -2,12 +2,11 @@ package mightypork.utils.math.rect; import mightypork.utils.math.num.Num; -import mightypork.utils.math.num.NumView; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectView; -public abstract class RectMathDynamic extends RectMath { +abstract class RectMathDynamic extends RectMath { @Override public abstract VectView origin(); @@ -22,20 +21,20 @@ public abstract class RectMathDynamic extends RectMath { { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size; + return t.size(); } @Override public VectView origin() { - return t.p_origin.add(move); + return t.origin().add(move); } }; @@ -43,48 +42,48 @@ public abstract class RectMathDynamic extends RectMath { @Override - public RectView move(final double xd, final double yd) + public RectView move(final double x, final double y) { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size; + return t.size(); } @Override public VectView origin() { - return t.p_origin.add(xd, yd); + return t.origin().add(x, y); } }; } - public RectView move(final Num xd, final Num yd) + public RectView move(final Num x, final Num y) { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size; + return t.size(); } @Override public VectView origin() { - return t.p_origin.add(xd, yd); + return t.origin().add(x, y); } }; @@ -92,24 +91,24 @@ public abstract class RectMathDynamic extends RectMath { @Override - public RectView shrink(final double leftd, final double rightd, final double topd, final double bottomd) + public RectView shrink(final double left, final double right, final double top, final double bottom) { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size.sub(leftd + rightd, topd + bottomd); + return t.size().sub(left + right, top + bottom); } @Override public VectView origin() { - return t.p_origin.add(leftd, topd); + return t.origin().add(left, top); } }; @@ -117,73 +116,73 @@ public abstract class RectMathDynamic extends RectMath { @Override - public RectView grow(final double leftd, final double rightd, final double topd, final double bottomd) + public RectView grow(final double left, final double right, final double top, final double bottom) { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size.add(leftd + rightd, topd + bottomd); + return t.size().add(left + right, top + bottom); } @Override public VectView origin() { - return t.p_origin.sub(leftd, topd); + return t.origin().sub(left, top); } }; } - public RectView shrink(final Num leftd, final Num rightd, final Num topd, final Num bottomd) + public RectView shrink(final Num left, final Num right, final Num top, final Num bottom) { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size.sub(leftd.view().add(rightd), topd.view().add(bottomd)); + return t.size().sub(left.view().add(right), top.view().add(bottom)); } @Override public VectView origin() { - return t.p_origin.add(leftd, topd); + return t.origin().add(left, top); } }; } - public RectView grow(final Num leftd, final Num rightd, final Num topd, final Num bottomd) + public RectView grow(final Num left, final Num right, final Num top, final Num bottom) { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size.add(leftd.view().add(rightd), topd.view().add(bottomd)); + return t.size().add(left.view().add(right), top.view().add(bottom)); } @Override public VectView origin() { - return t.p_origin.sub(leftd, topd); + return t.origin().sub(left, top); } }; @@ -196,20 +195,20 @@ public abstract class RectMathDynamic extends RectMath { return new RectView() { - private RectMathDynamic t = RectMathDynamic.this; + private final RectMathDynamic t = RectMathDynamic.this; @Override public VectView size() { - return t.p_size.round(); + return t.size().round(); } @Override public VectView origin() { - return t.p_origin.round(); + return t.origin().round(); } }; @@ -217,121 +216,121 @@ public abstract class RectMathDynamic extends RectMath { @Override - public NumView x() + public Num x() { - return p_x; + return origin().xn(); } @Override - public NumView y() + public Num y() { - return p_y; + return origin().yn(); } @Override - public NumView width() + public Num width() { - return p_width; + return size().xn(); } @Override - public NumView height() + public Num height() { - return p_height; + return size().yn(); } @Override - public NumView left() + public Num left() { - return p_left; + return origin().yn(); } @Override - public NumView right() + public Num right() { - return p_right; + return origin().xn().add(size().xn()); } @Override - public NumView top() + public Num top() { - return p_top; + return origin().yn(); } @Override - public NumView bottom() + public Num bottom() { - return p_bottom; + return origin().yn().add(size().yn()); } @Override public VectView topLeft() { - return p_tl; + return origin(); } @Override public VectView topCenter() { - return p_tc; + return origin().add(size().xn().half(), Num.ZERO); } @Override public VectView topRight() { - return p_tr; + return origin().add(size().xn(), Num.ZERO); } @Override public VectView centerLeft() { - return p_cl; + return origin().add(Num.ZERO, size().yn().half()); } @Override public VectView center() { - return p_cc; + return origin().add(size().half()); } @Override public VectView centerRight() { - return p_cr; + return origin().add(size().xn(), size().yn().half()); } @Override public VectView bottomLeft() { - return p_bl; + return origin().add(Num.ZERO, size().yn()); } @Override public VectView bottomCenter() { - return p_bc; + return origin().add(size().xn().half(), size().yn()); } @Override public VectView bottomRight() { - return p_br; + return origin().add(size().xn(), size().yn()); } @@ -346,14 +345,14 @@ public abstract class RectMathDynamic extends RectMath { @Override public VectView size() { - return t.p_size; + return t.size(); } @Override public VectView origin() { - return point.view().sub(t.p_size.half()); + return point.view().sub(t.size().half()); } }; } diff --git a/src/mightypork/utils/math/rect/RectMathStatic.java b/src/mightypork/utils/math/rect/RectMathStatic.java index 663d2eb..097585c 100644 --- a/src/mightypork/utils/math/rect/RectMathStatic.java +++ b/src/mightypork/utils/math/rect/RectMathStatic.java @@ -4,9 +4,10 @@ package mightypork.utils.math.rect; import mightypork.utils.math.num.NumVal; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; -public abstract class RectMathStatic> extends RectMath { +abstract class RectMathStatic> extends RectMath { @Override public abstract VectVal origin(); @@ -15,6 +16,7 @@ public abstract class RectMathStatic> extends RectMa @Override public abstract VectVal size(); + @Override public R move(Vect move) { @@ -23,36 +25,44 @@ public abstract class RectMathStatic> extends RectMa @Override - public R move(double x, double y) { - return result(p_origin.add(x,y), p_size); + public R move(double x, double y) + { + return result(origin().add(x, y), size()); } @Override - public R shrink(double left, double right, double top, double bottom) + public R shrink(double left, double right, double top, double bottom) { - return result(p_origin.add(left, top), p_size.sub(left + right, top + bottom)); + return result(origin().add(left, top), size().sub(left + right, top + bottom)); + } @Override public R grow(double left, double right, double top, double bottom) - { - return result(p_origin.sub(left, top), p_size.add(left + right, top + bottom)); + { + return result(origin().sub(left, top), size().add(left + right, top + bottom)); } @Override public R centerTo(final Vect point) - { - return result(p_origin.sub(p_size.half()), p_size); + { + final VectView s = size().view(); + final VectView o = origin().view(); + + return result(o.sub(s.half()), s); } @Override public R round() - { - return result(p_origin.round(), p_size.round()); + { + final VectView s = size().view(); + final VectView o = origin().view(); + + return result(o.round(), s.round()); } @@ -62,118 +72,118 @@ public abstract class RectMathStatic> extends RectMa @Override public NumVal x() { - return p_x.copy(); + return origin().xn(); } @Override public NumVal y() { - return p_y.copy(); + return origin().yn(); } @Override public NumVal width() { - return p_width.copy(); + return size().xn(); } @Override public NumVal height() { - return p_height.copy(); + return size().yn(); } @Override public NumVal left() { - return p_left.copy(); + return origin().xn(); } @Override public NumVal right() { - return p_right.copy(); + return origin().xn().add(size().xn()); } @Override public NumVal top() { - return p_top.copy(); + return origin().yn(); } @Override public NumVal bottom() { - return p_bottom.copy(); + return origin().yn().add(size().yn()); } @Override public VectVal topLeft() { - return p_tl.copy(); + return origin(); } @Override public VectVal topCenter() { - return p_tc.copy(); + return origin().add(size().x() / 2, 0); } @Override public VectVal topRight() { - return p_tr.copy(); + return origin().add(size().x(), 0); } @Override public VectVal centerLeft() { - return p_cl.copy(); + return origin().add(0, size().y() / 2); } @Override public VectVal center() { - return p_cc.copy(); + return origin().add(size().view().half()); } @Override public VectVal centerRight() { - return p_cr.copy(); + return origin().add(size().x(), size().y() / 2); } @Override public VectVal bottomLeft() { - return p_bl.copy(); + return origin().add(0, size().y()); } @Override public VectVal bottomCenter() { - return p_bc.copy(); + return origin().add(size().x() / 2, size().y()); } @Override public VectVal bottomRight() { - return p_br.copy(); + return origin().add(size().view()); } } diff --git a/src/mightypork/utils/math/rect/RectMutable.java b/src/mightypork/utils/math/rect/RectMutable.java index 809ff66..ec73885 100644 --- a/src/mightypork/utils/math/rect/RectMutable.java +++ b/src/mightypork/utils/math/rect/RectMutable.java @@ -11,7 +11,7 @@ import mightypork.utils.math.vect.VectVal; * * @author MightyPork */ -public abstract class RectMutable extends RectMathStatic { +public abstract class RectMutable extends RectView { /** * Create at 0,0 with zero size @@ -125,11 +125,10 @@ public abstract class RectMutable extends RectMathStatic { * Set to other rect's coordinates * * @param rect other rect - * @return this */ - public RectMutable setTo(Rect rect) + public void setTo(Rect rect) { - return setTo(rect.origin(), rect.size()); + setTo(rect.origin(), rect.size()); } @@ -139,11 +138,10 @@ public abstract class RectMutable extends RectMathStatic { * @param origin new origin * @param width new width * @param height new height - * @return this */ - public RectMutable setTo(Vect origin, double width, double height) + public void setTo(Vect origin, double width, double height) { - return setTo(origin, VectVal.make(width, height)); + setTo(origin, VectVal.make(width, height)); } @@ -154,11 +152,10 @@ public abstract class RectMutable extends RectMathStatic { * @param y origin.y * @param width new width * @param height new height - * @return this */ - public RectMutable setTo(double x, double y, double width, double height) + public void setTo(double x, double y, double width, double height) { - return setTo(VectVal.make(x, y), VectVal.make(width, height)); + setTo(VectVal.make(x, y), VectVal.make(width, height)); } @@ -167,31 +164,35 @@ public abstract class RectMutable extends RectMathStatic { * * @param origin new origin * @param size new size - * @return this */ - public RectMutable setTo(Vect origin, Vect size) + public void setTo(Vect origin, Vect size) { setOrigin(origin); setSize(size); - return this; } + /** + * Set to zero + */ + public void reset() + { + setTo(Vect.ZERO, Vect.ZERO); + } + /** * Set new origin * * @param origin new origin - * @return this */ - public abstract RectMutable setOrigin(Vect origin); + public abstract void setOrigin(Vect origin); /** * Set new size * * @param size new size - * @return this */ - public abstract RectMutable setSize(Vect size); + public abstract void setSize(Vect size); } diff --git a/src/mightypork/utils/math/rect/RectMutableImpl.java b/src/mightypork/utils/math/rect/RectMutableImpl.java index aad007e..ed36aeb 100644 --- a/src/mightypork/utils/math/rect/RectMutableImpl.java +++ b/src/mightypork/utils/math/rect/RectMutableImpl.java @@ -3,7 +3,7 @@ package mightypork.utils.math.rect; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectMutable; -import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; class RectMutableImpl extends RectMutable { @@ -22,45 +22,34 @@ class RectMutableImpl extends RectMutable { */ public RectMutableImpl(double x, double y, double width, double height) { this.pos.setTo(x, y); - this.size.setTo(width, height).abs(); + this.size.setTo(width, height); } @Override - public VectVal origin() + public VectView origin() { - return pos.copy(); + return pos; } @Override - public VectVal size() + public VectView size() { - return size.copy(); + return size; } @Override - protected RectMutable result(Vect newOrigin, Vect newSize) - { - setOrigin(newOrigin); - setSize(newSize); - return this; - } - - - @Override - public RectMutable setOrigin(Vect origin) + public void setOrigin(Vect origin) { this.pos.setTo(origin); - return this; } @Override - public RectMutable setSize(Vect size) + public void setSize(Vect size) { - this.size.setTo(size).abs(); - return this; + this.size.setTo(size); } } diff --git a/src/mightypork/utils/math/rect/RectProxy.java b/src/mightypork/utils/math/rect/RectProxy.java index ae77b45..275e437 100644 --- a/src/mightypork/utils/math/rect/RectProxy.java +++ b/src/mightypork/utils/math/rect/RectProxy.java @@ -1,5 +1,6 @@ package mightypork.utils.math.rect; + import mightypork.utils.math.vect.VectView; @@ -8,26 +9,29 @@ import mightypork.utils.math.vect.VectView; * * @author MightyPork */ -public class RectProxy extends RectView { +class RectProxy extends RectView { - private final RectView observed; + private final Rect observed; public RectProxy(Rect observed) { - this.observed = observed.view(); + + assert (!(observed instanceof RectView)); + + this.observed = observed; } @Override public VectView origin() { - return observed.p_origin; + return observed.origin().view(); } @Override public VectView size() { - return observed.p_size; + return observed.size().view(); } } diff --git a/src/mightypork/utils/math/rect/RectVal.java b/src/mightypork/utils/math/rect/RectVal.java index fbf1f0c..d19e36f 100644 --- a/src/mightypork/utils/math/rect/RectVal.java +++ b/src/mightypork/utils/math/rect/RectVal.java @@ -2,6 +2,7 @@ package mightypork.utils.math.rect; import mightypork.utils.annotations.FactoryMethod; +import mightypork.utils.math.num.Num; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; @@ -32,6 +33,20 @@ public class RectVal extends RectMathStatic { } + /** + * Create at 0,0 with given size + * + * @param width + * @param height + * @return new mutable rect + */ + @FactoryMethod + public static RectVal make(Num width, Num height) + { + return make(0, 0, width.value(), height.value()); + } + + /** * Create at 0,0 with given size * @@ -61,6 +76,21 @@ public class RectVal extends RectMathStatic { } + /** + * Create at given origin, with given size. + * + * @param origin + * @param width + * @param height + * @return new mutable rect + */ + @FactoryMethod + public static RectVal make(Vect origin, Num width, Num height) + { + return make(origin, VectVal.make(width, height)); + } + + /** * Create at 0,0 with given size. * @@ -90,6 +120,22 @@ public class RectVal extends RectMathStatic { } + /** + * Create at given origin, with given size. + * + * @param x + * @param y + * @param width + * @param height + * @return new mutable rect + */ + @FactoryMethod + public static RectVal make(Num x, Num y, Num width, Num height) + { + return new RectVal(x.value(), y.value(), width.value(), height.value()); + } + + /** * Create at given origin, with given size. * @@ -115,7 +161,7 @@ public class RectVal extends RectMathStatic { * @param width * @param height */ - public RectVal(double x, double y, double width, double height) { + RectVal(double x, double y, double width, double height) { this.pos = VectVal.make(x, y); this.size = VectVal.make(width, height); } @@ -127,7 +173,7 @@ public class RectVal extends RectMathStatic { * @param origin * @param size */ - public RectVal(Vect origin, Vect size) { + RectVal(Vect origin, Vect size) { this.pos = origin.copy(); this.size = size.copy(); } @@ -138,7 +184,7 @@ public class RectVal extends RectMathStatic { * * @param another other coord */ - public RectVal(Rect another) { + RectVal(Rect another) { this.pos = another.origin().copy(); this.size = another.size().copy(); } diff --git a/src/mightypork/utils/math/rect/RectView.java b/src/mightypork/utils/math/rect/RectView.java index 0fec77c..3e26668 100644 --- a/src/mightypork/utils/math/rect/RectView.java +++ b/src/mightypork/utils/math/rect/RectView.java @@ -2,6 +2,9 @@ package mightypork.utils.math.rect; import mightypork.utils.annotations.FactoryMethod; +import mightypork.utils.math.num.Num; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectView; /** @@ -11,12 +14,6 @@ import mightypork.utils.annotations.FactoryMethod; */ public abstract class RectView extends RectMathDynamic { - @SuppressWarnings("hiding") - public static final RectView ZERO = Rect.ZERO.view(); - @SuppressWarnings("hiding") - public static final RectView ONE = Rect.ONE.view(); - - /** * Get a proxy at given rect * @@ -30,6 +27,56 @@ public abstract class RectView extends RectMathDynamic { } + /** + * Get a rect made of numeric constraints + * + * @param width width + * @param height height + * @return view rect + */ + @FactoryMethod + public static RectView make(Num width, Num height) + { + final Vect origin = Vect.ZERO; + final Vect size = VectView.make(width, height); + + return new VectViewRect(origin, size); + } + + + /** + * Get a rect made of numeric constraints + * + * @param x x coord + * @param y y coord + * @param width width + * @param height height + * @return view rect + */ + @FactoryMethod + public static RectView make(Num x, Num y, Num width, Num height) + { + final Vect origin = VectView.make(x, y); + final Vect size = VectView.make(width, height); + + return new VectViewRect(origin, size); + } + + + /** + * Get a rect made of two vect views + * + * @param origin origin view + * @param size size view + * @return view rect + */ + @FactoryMethod + public static RectView make(final Vect origin, final Vect size) + { + return new VectViewRect(origin, size); + } + + /** * @deprecated No point in taking view of a view */ @@ -37,7 +84,6 @@ public abstract class RectView extends RectMathDynamic { @Deprecated public RectView view() { - // must NOT call RectView.make, it'd cause infinite recursion. return this; // wont change } diff --git a/src/mightypork/utils/math/rect/VectViewRect.java b/src/mightypork/utils/math/rect/VectViewRect.java new file mode 100644 index 0000000..099da1f --- /dev/null +++ b/src/mightypork/utils/math/rect/VectViewRect.java @@ -0,0 +1,38 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectView; + + +/** + * Rect made of two {@link VectView}s + * + * @author MightyPork + */ +class VectViewRect extends RectView { + + private final VectView origin; + private final VectView size; + + + public VectViewRect(Vect origin, Vect size) { + this.origin = origin.view(); + this.size = size.view(); + } + + + @Override + public VectView origin() + { + return origin; + } + + + @Override + public VectView size() + { + return size; + } + +} diff --git a/src/mightypork/utils/math/vect/AbstractVect.java b/src/mightypork/utils/math/vect/AbstractVect.java index 57f6640..fb609bc 100644 --- a/src/mightypork/utils/math/vect/AbstractVect.java +++ b/src/mightypork/utils/math/vect/AbstractVect.java @@ -1,9 +1,7 @@ package mightypork.utils.math.vect; - - -public abstract class AbstractVect implements Vect { +abstract class AbstractVect implements Vect { private VectView proxy; @@ -47,8 +45,6 @@ public abstract class AbstractVect implements Vect { @Override public VectView view() { - // must NOT call VectView.make, it'd cause infinite recursion. - if (proxy == null) proxy = new VectProxy(this); return proxy; diff --git a/src/mightypork/utils/math/vect/VectAnimated.java b/src/mightypork/utils/math/vect/VectAnimated.java index c92a8cb..68a4621 100644 --- a/src/mightypork/utils/math/vect/VectAnimated.java +++ b/src/mightypork/utils/math/vect/VectAnimated.java @@ -111,37 +111,32 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable { @Override - public VectAnimated result(double x, double y, double z) + public void setTo(double x, double y, double z) { setX(x); setY(y); setZ(z); - - return this; } @Override - public VectMutable setX(double x) + public void setX(double x) { this.x.animate(x, defaultDuration); - return this; } @Override - public VectMutable setY(double y) + public void setY(double y) { this.y.animate(y, defaultDuration); - return this; } @Override - public VectMutable setZ(double z) + public void setZ(double z) { this.z.animate(z, defaultDuration); - return this; } @@ -150,12 +145,10 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable { * * @param offset added offset * @param duration animation time (seconds) - * @return this */ - public VectAnimated add(Vect offset, double duration) + public void add(Vect offset, double duration) { - animate(view().add(offset), duration); - return this; + animate(this.add(offset), duration); } diff --git a/src/mightypork/utils/math/vect/VectMath.java b/src/mightypork/utils/math/vect/VectMath.java index 0992d68..2ee5ee0 100644 --- a/src/mightypork/utils/math/vect/VectMath.java +++ b/src/mightypork/utils/math/vect/VectMath.java @@ -252,12 +252,33 @@ abstract class VectMath extends AbstractVect { public abstract V mul(double x, double y, double z); + /** + * Multiply each component. + * + * @param d multiplier + * @return result + */ public abstract V mul(final Num d); + /** + * Multiply each component. + * + * @param x x multiplier + * @param y y multiplier + * @return result + */ public abstract V mul(final Num x, final Num y); + /** + * Multiply each component. + * + * @param x x multiplier + * @param y y multiplier + * @param z z multiplier + * @return result + */ public abstract V mul(final Num x, final Num y, final Num z); diff --git a/src/mightypork/utils/math/vect/VectMathStatic.java b/src/mightypork/utils/math/vect/VectMathStatic.java index 7039d5b..90071ac 100644 --- a/src/mightypork/utils/math/vect/VectMathStatic.java +++ b/src/mightypork/utils/math/vect/VectMathStatic.java @@ -11,7 +11,7 @@ import mightypork.utils.math.num.NumVal; * @author MightyPork * @param Return type of methods */ -public abstract class VectMathStatic> extends VectMath { +abstract class VectMathStatic> extends VectMath { @Override public NumVal xn() diff --git a/src/mightypork/utils/math/vect/VectMutable.java b/src/mightypork/utils/math/vect/VectMutable.java index 960e28a..e965dc7 100644 --- a/src/mightypork/utils/math/vect/VectMutable.java +++ b/src/mightypork/utils/math/vect/VectMutable.java @@ -9,7 +9,7 @@ import mightypork.utils.annotations.FactoryMethod; * * @author MightyPork */ -public abstract class VectMutable extends VectMathStatic { // returns itself on edit +public abstract class VectMutable extends VectView { // returns itself on edit /** * Get a variable initialized as zero (0,0,0) @@ -79,12 +79,10 @@ public abstract class VectMutable extends VectMathStatic { // retur /** * Set all to zeros. - * - * @return this */ - public VectMutable reset() + public void reset() { - return result(0, 0, 0); + setTo(0, 0, 0); } @@ -92,11 +90,10 @@ public abstract class VectMutable extends VectMathStatic { // retur * Set coordinates to match other coord. * * @param copied coord whose coordinates are used - * @return this */ - public VectMutable setTo(Vect copied) + public void setTo(Vect copied) { - return result(copied.x(), copied.y(), copied.z()); + setTo(copied.x(), copied.y(), copied.z()); } @@ -106,11 +103,11 @@ public abstract class VectMutable extends VectMathStatic { // retur * * @param x x coordinate * @param y y coordinate - * @return this */ - public VectMutable setTo(double x, double y) + public void setTo(double x, double y) { - return result(x, y, z()); + setX(x); + setY(y); } @@ -120,37 +117,30 @@ public abstract class VectMutable extends VectMathStatic { // retur * @param x x coordinate * @param y y coordinate * @param z z coordinate - * @return this */ - public VectMutable setTo(double x, double y, double z) - { - return result(x, y, z); - } + public abstract void setTo(double x, double y, double z); /** * Set X coordinate. * * @param x x coordinate - * @return this */ - public abstract VectMutable setX(double x); + public abstract void setX(double x); /** * Set Y coordinate. * * @param y y coordinate - * @return this */ - public abstract VectMutable setY(double y); + public abstract void setY(double y); /** * Set Z coordinate. * * @param z z coordinate - * @return this */ - public abstract VectMutable setZ(double z); + public abstract void setZ(double z); } diff --git a/src/mightypork/utils/math/vect/VectMutableImpl.java b/src/mightypork/utils/math/vect/VectMutableImpl.java index c7eb845..190bd58 100644 --- a/src/mightypork/utils/math/vect/VectMutableImpl.java +++ b/src/mightypork/utils/math/vect/VectMutableImpl.java @@ -47,36 +47,31 @@ class VectMutableImpl extends VectMutable { @Override - public VectMutable result(double x, double y, double z) + public void setTo(double x, double y, double z) { this.x = x; this.y = y; this.z = z; - - return this; } @Override - public VectMutable setX(double x) + public void setX(double x) { this.x = x; - return this; } @Override - public VectMutable setY(double y) + public void setY(double y) { this.y = y; - return this; } @Override - public VectMutable setZ(double z) + public void setZ(double z) { this.z = z; - return this; } } diff --git a/src/mightypork/utils/math/vect/VectProxy.java b/src/mightypork/utils/math/vect/VectProxy.java index 5cb1b3c..5197960 100644 --- a/src/mightypork/utils/math/vect/VectProxy.java +++ b/src/mightypork/utils/math/vect/VectProxy.java @@ -19,6 +19,9 @@ class VectProxy extends VectAdapter { * @param observed */ public VectProxy(Vect observed) { + + assert (!(observed instanceof VectView)); + this.observed = observed; } diff --git a/src/mightypork/utils/math/vect/VectVal.java b/src/mightypork/utils/math/vect/VectVal.java index 71ada34..5008d50 100644 --- a/src/mightypork/utils/math/vect/VectVal.java +++ b/src/mightypork/utils/math/vect/VectVal.java @@ -2,6 +2,7 @@ package mightypork.utils.math.vect; import mightypork.utils.annotations.FactoryMethod; +import mightypork.utils.math.num.Num; /** @@ -45,6 +46,20 @@ public final class VectVal extends VectMathStatic { } + /** + * Make a constant vector + * + * @param x X value + * @param y Y value + * @return new constant vec + */ + @FactoryMethod + public static VectVal make(Num x, Num y) + { + return make(x, y, Num.ZERO); + } + + /** * Make a constant vector * @@ -59,15 +74,30 @@ public final class VectVal extends VectMathStatic { return new VectVal(x, y, z); } + + /** + * Make a constant vector + * + * @param x X value + * @param y Y value + * @param z Z value + * @return new constant vector + */ + @FactoryMethod + public static VectVal make(Num x, Num y, Num z) + { + return new VectVal(x.value(), y.value(), z.value()); + } + private final double x, y, z; - public VectVal(Vect other) { + VectVal(Vect other) { this(other.x(), other.y(), other.z()); } - public VectVal(double x, double y, double z) { + VectVal(double x, double y, double z) { this.x = x; this.y = y; this.z = z; diff --git a/src/mightypork/utils/math/vect/VectView.java b/src/mightypork/utils/math/vect/VectView.java index 86d0ec0..ce94f95 100644 --- a/src/mightypork/utils/math/vect/VectView.java +++ b/src/mightypork/utils/math/vect/VectView.java @@ -15,12 +15,6 @@ import mightypork.utils.math.num.Num; */ public abstract class VectView extends VectMathDynamic { // returns constant value on edit - @SuppressWarnings("hiding") - public static final VectView ZERO = new VectVal(0, 0, 0).view(); - @SuppressWarnings("hiding") - public static final VectView ONE = new VectVal(1, 1, 1).view(); - - /** * Make a proxy view at a vector. * @@ -78,7 +72,7 @@ public abstract class VectView extends VectMathDynamic { // returns constant val @Deprecated public VectView view() { - return super.view(); + return this; } } diff --git a/src/mightypork/utils/objects/Convert.java b/src/mightypork/utils/objects/Convert.java index a6d172a..9d2f6a4 100644 --- a/src/mightypork/utils/objects/Convert.java +++ b/src/mightypork/utils/objects/Convert.java @@ -6,7 +6,6 @@ import mightypork.utils.math.Calc; import mightypork.utils.math.Range; import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; -import mightypork.utils.math.vect.VectView; /**