From cacaa9dcce39fd6eb5ee20ba7a20c15ae5059b5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ond=C5=99ej=20Hru=C5=A1ka?= Date: Sun, 13 Apr 2014 10:39:01 +0200 Subject: [PATCH] Minor vect/rect changes --- .../gamecore/audio/SoundSystem.java | 2 +- .../control/bus/events/MouseButtonEvent.java | 2 +- .../control/bus/events/MouseMotionEvent.java | 4 +- .../control/bus/events/ScreenChangeEvent.java | 2 +- .../gui/components/layout/ColumnHolder.java | 2 +- .../gui/components/layout/RowHolder.java | 2 +- .../gamecore/input/InputSystem.java | 2 +- src/mightypork/gamecore/render/Render.java | 10 +-- .../gamecore/render/fonts/FontRenderer.java | 2 +- src/mightypork/rogue/screens/LayerFps.java | 2 +- .../screens/test_bouncyboxes/BouncyBox.java | 23 +++-- .../test_bouncyboxes/LayerBouncyBoxes.java | 2 +- .../test_cat_sound/LayerFlyingCat.java | 12 +-- .../screens/test_font/ScreenTestFont.java | 6 +- .../test_render/LayerTestGradient.java | 2 +- src/mightypork/test/TestConstr.java | 2 +- src/mightypork/test/TestConvert.java | 24 +++++ .../utils/config/PropertyManager.java | 2 +- src/mightypork/utils/math/Range.java | 7 +- .../utils/math/animation/AnimDouble.java | 4 +- .../{Bounds.java => ConstraintFactory.java} | 84 ++++++++--------- .../{NumberBound.java => NumBound.java} | 6 +- .../utils/math/constraints/NumberConst.java | 4 +- .../utils/math/constraints/RectCache.java | 2 +- .../utils/math/constraints/VectBound.java | 18 ++++ .../math/constraints/builder/Bounds.java | 19 ++++ .../utils/math/rect/AbstractRect.java | 56 +++++++----- src/mightypork/utils/math/rect/Rect.java | 90 +++++++++++++++---- .../utils/math/rect/RectMutableImpl.java | 4 +- src/mightypork/utils/math/rect/RectVal.java | 19 +++- src/mightypork/utils/math/rect/RectView.java | 2 +- .../utils/math/vect/AbstractVect.java | 81 +++++------------ .../utils/math/vect/NumConstrVect.java | 17 ++-- src/mightypork/utils/math/vect/Vect.java | 60 ++----------- ...VectMutableAnim.java => VectAnimated.java} | 69 ++++++++++++-- src/mightypork/utils/math/vect/VectMath.java | 73 +++++++++++++++ .../utils/math/vect/VectMutable.java | 60 +------------ ...ableImpl.java => VectMutableVariable.java} | 6 +- src/mightypork/utils/math/vect/VectVal.java | 15 ++-- src/mightypork/utils/math/vect/VectView.java | 19 ++-- src/mightypork/utils/objects/Convert.java | 64 ++++++++----- 41 files changed, 526 insertions(+), 356 deletions(-) create mode 100644 src/mightypork/test/TestConvert.java rename src/mightypork/utils/math/constraints/{Bounds.java => ConstraintFactory.java} (88%) rename src/mightypork/utils/math/constraints/{NumberBound.java => NumBound.java} (52%) create mode 100644 src/mightypork/utils/math/constraints/VectBound.java create mode 100644 src/mightypork/utils/math/constraints/builder/Bounds.java rename src/mightypork/utils/math/vect/{VectMutableAnim.java => VectAnimated.java} (61%) rename src/mightypork/utils/math/vect/{VectMutableImpl.java => VectMutableVariable.java} (78%) diff --git a/src/mightypork/gamecore/audio/SoundSystem.java b/src/mightypork/gamecore/audio/SoundSystem.java index 88d4b79..dc361bf 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.getView(); + return listener.view(); } // -- instance -- diff --git a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java index 7f5e164..1623f0d 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java @@ -80,7 +80,7 @@ public class MouseButtonEvent implements Event { */ public VectView getPos() { - return pos.getView(); + return pos.view(); } diff --git a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java index 1c7b130..a6a9706 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.getValue(); - this.pos = pos.getValue(); + this.move = move.copy(); + this.pos = pos.copy(); } diff --git a/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java b/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java index 870ae3c..f49360b 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.getView(); + return screenSize.view(); } diff --git a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java index 04a4ecf..d4171e3 100644 --- a/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/ColumnHolder.java @@ -1,7 +1,7 @@ package mightypork.gamecore.gui.components.layout; -import static mightypork.utils.math.constraints.Bounds.*; +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 decd82b..0daf6ef 100644 --- a/src/mightypork/gamecore/gui/components/layout/RowHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/RowHolder.java @@ -1,7 +1,7 @@ package mightypork.gamecore.gui.components.layout; -import static mightypork.utils.math.constraints.Bounds.*; +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/input/InputSystem.java b/src/mightypork/gamecore/input/InputSystem.java index 785117b..93230cf 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.getValue(), button, down, wheeld)); + getEventBus().send(new MouseButtonEvent(pos.copy(), button, down, wheeld)); } moveSum.add(move); diff --git a/src/mightypork/gamecore/render/Render.java b/src/mightypork/gamecore/render/Render.java index 70e8c70..64fea4f 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.getView().norm(1); + final Vect vec = axis.view().norm(1); glRotated(angle, vec.x(), vec.y(), vec.z()); } @@ -351,7 +351,7 @@ public class Render { */ public static void quad(Rect quad) { - final double x1 = quad.getLeft(); + final double x1 = quad.left(); final double y1 = quad.top(); final double x2 = quad.right(); final double y2 = quad.bottom(); @@ -391,12 +391,12 @@ public class Render { */ public static void quadUV_nobound(Rect quad, Rect uvs) { - final double x1 = quad.getLeft(); + final double x1 = quad.left(); final double y1 = quad.top(); final double x2 = quad.right(); final double y2 = quad.bottom(); - final double tx1 = uvs.getLeft(); + final double tx1 = uvs.left(); final double ty1 = uvs.top(); final double tx2 = uvs.right(); final double ty2 = uvs.bottom(); @@ -437,7 +437,7 @@ public class Render { */ public static void quadColor(Rect quad, RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax) { - final double x1 = quad.getLeft(); + final double x1 = quad.left(); final double y1 = quad.top(); final double x2 = quad.right(); final double y2 = quad.bottom(); diff --git a/src/mightypork/gamecore/render/fonts/FontRenderer.java b/src/mightypork/gamecore/render/fonts/FontRenderer.java index 70b1900..769b1e3 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.getValue().round()); + Render.translate(pos.copy().round()); Render.scaleXY(getScale(height)); font.draw(text, color); diff --git a/src/mightypork/rogue/screens/LayerFps.java b/src/mightypork/rogue/screens/LayerFps.java index 0778452..f1ef473 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.Bounds.*; +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 e4ba448..8632028 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.Bounds.*; +import static mightypork.utils.math.constraints.ConstraintFactory.*; import java.util.Random; @@ -11,7 +11,7 @@ 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.NumberBound; +import mightypork.utils.math.constraints.NumBound; import mightypork.utils.math.constraints.RectBound; @@ -26,15 +26,28 @@ public class BouncyBox extends PluggableRenderer implements Updateable { public BouncyBox() { // create box - final NumberBound side = height(this); + final NumBound side = height(this); RectBound abox = box(this, side, side); // move - final NumberBound move_length = sub(width(this), side); - final NumberBound offset = mul(move_length, pos); + final NumBound move_length = sub(width(this), side); + final NumBound offset = mul(move_length, pos); abox = move(abox, offset, 0); // add padding + /* + * leftEdge(this) + * .growRight(height(this)) + * .move( + * width(this) + * .sub(height(this)) + * .mul(pos), + * 0) + * .shrink( + * height(this) + * .perc(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 49cd253..100faae 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.Bounds.*; +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 3591374..8d91a68 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.Bounds.*; +import static mightypork.utils.math.constraints.ConstraintFactory.*; import java.util.Random; @@ -19,17 +19,15 @@ 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; +import mightypork.utils.math.vect.VectAnimated; import mightypork.utils.math.vect.VectVal; public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener { private final AnimDouble size = new AnimDouble(400, Easing.SINE_BOTH); - private final VectMutableAnim pos = VectMutable.makeAnim(Easing.ELASTIC_OUT); + private final VectAnimated pos = VectAnimated.make(Easing.ELASTIC_OUT); private final Random rand = new Random(); @@ -46,6 +44,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt cat = new ImagePainter(Res.getTxQuad("test.kitten")); + // Bounds.box(size,size).centerTo(pos) cat.setContext(centerTo(box(size, size), pos)); tp = new TextPainter(Res.getFont("default")); @@ -54,9 +53,12 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt tp.setText("Meow!"); tp.setShadow(RGB.dark(0.8), VectVal.make(2, 2)); + // Bounds.box(64,64).centerTo(cMousePos) tp.setContext(centerTo(box(64, 64), cMousePos)); qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED); + + // Bounds.wrap(cat).bottomLeft().expand(0,0,50,50) qp.setContext(expand(bottomLeft(cat), 0, 0, 50, 50)); /* diff --git a/src/mightypork/rogue/screens/test_font/ScreenTestFont.java b/src/mightypork/rogue/screens/test_font/ScreenTestFont.java index 0900838..de95427 100644 --- a/src/mightypork/rogue/screens/test_font/ScreenTestFont.java +++ b/src/mightypork/rogue/screens/test_font/ScreenTestFont.java @@ -1,14 +1,14 @@ package mightypork.rogue.screens.test_font; -import static mightypork.utils.math.constraints.Bounds.*; +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; import mightypork.gamecore.render.fonts.FontRenderer.Align; import mightypork.rogue.Res; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.constraints.NumberBound; +import mightypork.utils.math.constraints.NumBound; import mightypork.utils.math.constraints.RectBound; @@ -23,7 +23,7 @@ public class ScreenTestFont extends Screen { tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN); tp.setText("Hello World!"); - final NumberBound fontHeight = mul(getDisplay().getSize().yc(), 0.1); + final NumBound fontHeight = mul(getDisplay().getSize().yc(), 0.1); final RectBound strbox = centerTo(box(fontHeight), this); diff --git a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java index 51b7ca4..4969d5d 100644 --- a/src/mightypork/rogue/screens/test_render/LayerTestGradient.java +++ b/src/mightypork/rogue/screens/test_render/LayerTestGradient.java @@ -1,7 +1,7 @@ package mightypork.rogue.screens.test_render; -import static mightypork.utils.math.constraints.Bounds.*; +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 f89c1f3..b3e43ec 100644 --- a/src/mightypork/test/TestConstr.java +++ b/src/mightypork/test/TestConstr.java @@ -1,7 +1,7 @@ package mightypork.test; -import static mightypork.utils.math.constraints.Bounds.*; +import static mightypork.utils.math.constraints.ConstraintFactory.*; import java.util.Locale; diff --git a/src/mightypork/test/TestConvert.java b/src/mightypork/test/TestConvert.java new file mode 100644 index 0000000..f515bb1 --- /dev/null +++ b/src/mightypork/test/TestConvert.java @@ -0,0 +1,24 @@ +package mightypork.test; + + +import mightypork.utils.objects.Convert; + + +public class TestConvert { + + public static void main(String[] args) + { + System.out.println(Convert.toVect("(10:20:30)")); + System.out.println(Convert.toVect("30.6 ; 80")); + System.out.println(Convert.toVect("30.6")); + + System.out.println(Convert.toRange("10")); + System.out.println(Convert.toRange("10..60")); + System.out.println(Convert.toRange("10-60")); + System.out.println(Convert.toRange("10--60")); + System.out.println(Convert.toRange("-10--60")); + System.out.println(Convert.toRange("3.1;22")); + System.out.println(Convert.toRange("3.1|22")); + + } +} diff --git a/src/mightypork/utils/config/PropertyManager.java b/src/mightypork/utils/config/PropertyManager.java index 649b538..eaafe9e 100644 --- a/src/mightypork/utils/config/PropertyManager.java +++ b/src/mightypork/utils/config/PropertyManager.java @@ -364,7 +364,7 @@ public class PropertyManager { */ public VectView getCoord(String n) { - return Convert.toCoord(get(n).value); + return Convert.toVect(get(n).value); } diff --git a/src/mightypork/utils/math/Range.java b/src/mightypork/utils/math/Range.java index 2b21861..dafe06a 100644 --- a/src/mightypork/utils/math/Range.java +++ b/src/mightypork/utils/math/Range.java @@ -11,6 +11,11 @@ import java.util.Random; */ public class Range { + public static Range make(double low, double high) + { + return new Range(low, high); + } + private double min = 0; private double max = 1; @@ -132,7 +137,7 @@ public class Range { @Override public String toString() { - return String.format("( %.2f : %.2f )", min, max); + return String.format("Range(%.1f|%.1f)", min, max); } diff --git a/src/mightypork/utils/math/animation/AnimDouble.java b/src/mightypork/utils/math/animation/AnimDouble.java index dec2dc9..cbf7692 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.NumberBound; +import mightypork.utils.math.constraints.NumBound; /** @@ -12,7 +12,7 @@ import mightypork.utils.math.constraints.NumberBound; * * @author MightyPork */ -public class AnimDouble implements Updateable, Pauseable, NumberBound { +public class AnimDouble implements Updateable, Pauseable, NumBound { /** target double */ protected double to = 0; diff --git a/src/mightypork/utils/math/constraints/Bounds.java b/src/mightypork/utils/math/constraints/ConstraintFactory.java similarity index 88% rename from src/mightypork/utils/math/constraints/Bounds.java rename to src/mightypork/utils/math/constraints/ConstraintFactory.java index f4a3717..202fff2 100644 --- a/src/mightypork/utils/math/constraints/Bounds.java +++ b/src/mightypork/utils/math/constraints/ConstraintFactory.java @@ -16,7 +16,7 @@ import mightypork.utils.math.vect.VectView; * * @author MightyPork */ -public class Bounds { +public class ConstraintFactory { public static RectCache cached(final Poller poller, final RectBound rc) { @@ -25,16 +25,16 @@ public class Bounds { /** - * Convert {@link Number} to {@link NumberBound} if needed + * Convert {@link Number} to {@link NumBound} if needed * * @param o unknown numeric value * @return converted */ - private static NumberBound toNumberBound(final Object o) + private static NumBound toNumberBound(final Object o) { - if (o instanceof NumberBound) return (NumberBound) o; + if (o instanceof NumBound) return (NumBound) o; - if (o instanceof Number) return new NumberBound() { + if (o instanceof Number) return new NumBound() { @Override public double getValue() @@ -48,7 +48,7 @@ public class Bounds { /** - * Convert {@link Number} or {@link NumberBound} to double (current value) + * Convert {@link Number} or {@link NumBound} to double (current value) * * @param o unknown numeric value * @return double value @@ -59,9 +59,9 @@ public class Bounds { } - public static NumberBound min(final Object a, final Object b) + public static NumBound min(final Object a, final Object b) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -72,9 +72,9 @@ public class Bounds { } - public static NumberBound max(final Object a, final Object b) + public static NumBound max(final Object a, final Object b) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -85,9 +85,9 @@ public class Bounds { } - public static NumberBound abs(final NumberBound a) + public static NumBound abs(final NumBound a) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -98,9 +98,9 @@ public class Bounds { } - public static NumberBound half(final NumberBound a) + public static NumBound half(final NumBound a) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -111,9 +111,9 @@ public class Bounds { } - public static NumberBound round(final NumberBound a) + public static NumBound round(final NumBound a) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -137,9 +137,9 @@ public class Bounds { } - public static NumberBound ceil(final NumberBound a) + public static NumBound ceil(final NumBound a) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -150,9 +150,9 @@ public class Bounds { } - public static NumberBound floor(final NumberBound a) + public static NumBound floor(final NumBound a) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -163,9 +163,9 @@ public class Bounds { } - public static NumberBound neg(final NumberBound a) + public static NumBound neg(final NumBound a) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -176,9 +176,9 @@ public class Bounds { } - public static NumberBound add(final Object a, final Object b) + public static NumBound add(final Object a, final Object b) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -189,9 +189,9 @@ public class Bounds { } - public static NumberBound sub(final Object a, final Object b) + public static NumBound sub(final Object a, final Object b) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -202,9 +202,9 @@ public class Bounds { } - public static NumberBound mul(final Object a, final Object b) + public static NumBound mul(final Object a, final Object b) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -215,15 +215,15 @@ public class Bounds { } - public static NumberBound half(final Object a) + public static NumBound half(final Object a) { return mul(a, 0.5); } - public static NumberBound div(final Object a, final Object b) + public static NumBound div(final Object a, final Object b) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -234,9 +234,9 @@ public class Bounds { } - public static NumberBound perc(final Object whole, final Object percent) + public static NumBound perc(final Object whole, final Object percent) { - return new NumberBound() { + return new NumBound() { @Override public double getValue() @@ -546,7 +546,7 @@ public class Bounds { { final VectView size = r.getRect().size(); - return RectVal.make(centerTo.getValue().sub(size.half()), size); + return RectVal.make(centerTo.copy().sub(size.half()), size); } }; } @@ -720,7 +720,7 @@ public class Bounds { @Override public VectView getSource() { - return c1.getValue().add(c2); + return c1.copy().add(c2); } }; } @@ -739,7 +739,7 @@ public class Bounds { @Override public VectView getSource() { - return c.getValue().add(eval(x), eval(y), eval(z)); + return c.copy().add(eval(x), eval(y), eval(z)); } }; } @@ -752,7 +752,7 @@ public class Bounds { @Override public VectView getSource() { - return c1.getValue().sub(c2); + return c1.copy().sub(c2); } }; } @@ -771,7 +771,7 @@ public class Bounds { @Override public VectView getSource() { - return c.getValue().sub(eval(x), eval(y), eval(z)); + return c.copy().sub(eval(x), eval(y), eval(z)); } }; @@ -785,7 +785,7 @@ public class Bounds { @Override public VectView getSource() { - return c.getValue().mul(eval(mul)); + return c.copy().mul(eval(mul)); } }; @@ -799,7 +799,7 @@ public class Bounds { @Override public VectView getSource() { - return c.getValue().norm(eval(norm)); + return c.copy().norm(eval(norm)); } }; @@ -832,13 +832,13 @@ public class Bounds { } - public static NumberBound height(final RectBound r) + public static NumBound height(final RectBound r) { return size(r).yc(); } - public static NumberBound width(final RectBound r) + public static NumBound width(final RectBound r) { return size(r).xc(); } diff --git a/src/mightypork/utils/math/constraints/NumberBound.java b/src/mightypork/utils/math/constraints/NumBound.java similarity index 52% rename from src/mightypork/utils/math/constraints/NumberBound.java rename to src/mightypork/utils/math/constraints/NumBound.java index 277686b..46636bc 100644 --- a/src/mightypork/utils/math/constraints/NumberBound.java +++ b/src/mightypork/utils/math/constraints/NumBound.java @@ -6,10 +6,10 @@ package mightypork.utils.math.constraints; * * @author MightyPork */ -public interface NumberBound { +public interface NumBound { - public static final NumberBound ZERO = new NumberConst(0); - public static final NumberBound ONE = new NumberConst(1); + public static final NumBound ZERO = new NumberConst(0); + public static final NumBound ONE = new NumberConst(1); /** diff --git a/src/mightypork/utils/math/constraints/NumberConst.java b/src/mightypork/utils/math/constraints/NumberConst.java index de8df6d..596b94c 100644 --- a/src/mightypork/utils/math/constraints/NumberConst.java +++ b/src/mightypork/utils/math/constraints/NumberConst.java @@ -2,11 +2,11 @@ package mightypork.utils.math.constraints; /** - * Constant number {@link NumberBound} + * Constant number {@link NumBound} * * @author MightyPork */ -public class NumberConst implements NumberBound { +public class NumberConst implements NumBound { private final double value; diff --git a/src/mightypork/utils/math/constraints/RectCache.java b/src/mightypork/utils/math/constraints/RectCache.java index 7e9ec3c..79435a3 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.getView(); + return cached.view(); } diff --git a/src/mightypork/utils/math/constraints/VectBound.java b/src/mightypork/utils/math/constraints/VectBound.java new file mode 100644 index 0000000..c74c569 --- /dev/null +++ b/src/mightypork/utils/math/constraints/VectBound.java @@ -0,0 +1,18 @@ +package mightypork.utils.math.constraints; + + +import mightypork.utils.math.vect.Vect; + + +/** + * Element holding a vector, used for constraint building. + * + * @author MightyPork + */ +public interface VectBound { + + /** + * @return the current vector. + */ + public Vect getVect(); +} diff --git a/src/mightypork/utils/math/constraints/builder/Bounds.java b/src/mightypork/utils/math/constraints/builder/Bounds.java new file mode 100644 index 0000000..af75a28 --- /dev/null +++ b/src/mightypork/utils/math/constraints/builder/Bounds.java @@ -0,0 +1,19 @@ +package mightypork.utils.math.constraints.builder; + + +import mightypork.utils.math.constraints.RectBound; + + +public class Bounds { + + public static class RectBB { + + private final RectBound parent; + + + public RectBB(RectBound parent) { + this.parent = parent; + } + + } +} diff --git a/src/mightypork/utils/math/rect/AbstractRect.java b/src/mightypork/utils/math/rect/AbstractRect.java index 2a1fc34..39ee1f9 100644 --- a/src/mightypork/utils/math/rect/AbstractRect.java +++ b/src/mightypork/utils/math/rect/AbstractRect.java @@ -16,119 +16,133 @@ public abstract class AbstractRect implements Rect { @Override - public final RectView getRect() + public RectView getRect() { - return this.getView(); + return this.view(); } @Override - public final VectVal topLeft() + public VectVal topLeft() { return origin(); } @Override - public final VectVal topCenter() + public VectVal topCenter() { return origin().add(size().x() / 2, 0); } @Override - public final VectVal topRight() + public VectVal topRight() { return origin().add(size().x(), 0); } @Override - public final VectVal centerLeft() + public VectVal centerLeft() { return origin().add(0, size().y() / 2); } @Override - public final VectVal center() + public VectVal center() { return origin().add(size().half()); } @Override - public final VectVal centerRight() + public VectVal centerRight() { return origin().add(size().x(), size().y() / 2); } @Override - public final VectVal bottomLeft() + public VectVal bottomLeft() { return origin().add(0, size().y()); } @Override - public final VectVal bottomCenter() + public VectVal bottomCenter() { return origin().add(size().x() / 2, size().y()); } @Override - public final VectVal bottomRight() + public VectVal bottomRight() { return origin().add(size().x(), size().y()); } @Override - public final double width() + public double x() + { + return origin().x(); + } + + + @Override + public double y() + { + return origin().y(); + } + + + @Override + public double width() { return size().x(); } @Override - public final double height() + public double height() { return size().y(); } @Override - public final double getLeft() + public double left() { return origin().x(); } @Override - public final double right() + public double right() { return origin().x() + size().x(); } @Override - public final double top() + public double top() { return origin().y(); } @Override - public final double bottom() + public double bottom() { return origin().y() + size().y(); } @Override - public RectProxy getView() + public RectView view() { if (proxy == null) proxy = new RectProxy(this); @@ -137,14 +151,14 @@ public abstract class AbstractRect implements Rect { @Override - public RectVal getValue() + public RectVal copy() { - return RectVal.make(origin(), size()); + return new RectVal(x(), y(), width(), height()); } @Override - public final boolean contains(Vect point) + public boolean contains(Vect point) { final double x = point.x(); final double y = point.y(); diff --git a/src/mightypork/utils/math/rect/Rect.java b/src/mightypork/utils/math/rect/Rect.java index 5847c20..a769dfe 100644 --- a/src/mightypork/utils/math/rect/Rect.java +++ b/src/mightypork/utils/math/rect/Rect.java @@ -22,7 +22,7 @@ public interface Rect extends RectBound { * * @return copy */ - RectVal getValue(); + RectVal copy(); /** @@ -30,63 +30,123 @@ public interface Rect extends RectBound { * * @return proxy */ - RectProxy getView(); + RectView view(); /** - * @return origin + * @return origin (top left) */ VectVal origin(); + /** + * @return size vector + */ VectVal size(); + /** + * @return current width + */ double width(); + /** + * @return current height + */ double height(); + /** + * @return origin X + */ + double x(); + + + /** + * @return origin Y + */ + double y(); + + + /** + * @return left X (low) + */ + double left(); + + + /** + * @return right X (high) + */ + double right(); + + + /** + * @return top Y (low) + */ + double top(); + + + /** + * @return bottom Y (high) + */ + double bottom(); + + + /** + * @return top left corner position + */ VectVal topLeft(); + /** + * @return top center position + */ VectVal topCenter(); + /** + * @return top right corner position + */ VectVal topRight(); + /** + * @return left center position + */ VectVal centerLeft(); + /** + * @return center position + */ VectVal center(); + /** + * @return right center position + */ VectVal centerRight(); + /** + * @return bottom left corner position + */ VectVal bottomLeft(); + /** + * @return bottom center position + */ VectVal bottomCenter(); + /** + * @return bottom right corner position + */ VectVal bottomRight(); - double getLeft(); - - - double right(); - - - double top(); - - - double bottom(); - - /** * Check if point is inside this rectangle * diff --git a/src/mightypork/utils/math/rect/RectMutableImpl.java b/src/mightypork/utils/math/rect/RectMutableImpl.java index 796ccd6..dc332b1 100644 --- a/src/mightypork/utils/math/rect/RectMutableImpl.java +++ b/src/mightypork/utils/math/rect/RectMutableImpl.java @@ -94,14 +94,14 @@ class RectMutableImpl extends RectMutable { @Override public VectVal origin() { - return pos.getValue(); + return pos.copy(); } @Override public VectVal size() { - return size.getValue(); + return size.copy(); } diff --git a/src/mightypork/utils/math/rect/RectVal.java b/src/mightypork/utils/math/rect/RectVal.java index 2c6f68d..56b66cb 100644 --- a/src/mightypork/utils/math/rect/RectVal.java +++ b/src/mightypork/utils/math/rect/RectVal.java @@ -5,8 +5,25 @@ import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.VectVal; +/** + * Rectangle with constant bounds, that can never change. + * + * @author MightyPork + */ public class RectVal extends RectView { + /** + * Get a proxy at given rect + * + * @param observed observed rect + * @return view + */ + public static RectVal make(Rect observed) + { + return observed.copy(); + } + + /** * Create at 0,0 with zero size * @@ -114,7 +131,7 @@ public class RectVal extends RectView { @Override - public RectVal getValue() + public RectVal copy() { return this; // nothing can change. } diff --git a/src/mightypork/utils/math/rect/RectView.java b/src/mightypork/utils/math/rect/RectView.java index 99a62c8..ff3f686 100644 --- a/src/mightypork/utils/math/rect/RectView.java +++ b/src/mightypork/utils/math/rect/RectView.java @@ -16,7 +16,7 @@ public abstract class RectView extends RectMath { */ public static RectView make(Rect observed) { - return observed.getView(); + return observed.view(); } diff --git a/src/mightypork/utils/math/vect/AbstractVect.java b/src/mightypork/utils/math/vect/AbstractVect.java index 2356a06..a628c22 100644 --- a/src/mightypork/utils/math/vect/AbstractVect.java +++ b/src/mightypork/utils/math/vect/AbstractVect.java @@ -1,15 +1,15 @@ package mightypork.utils.math.vect; -import mightypork.utils.math.constraints.NumberBound; +import mightypork.utils.math.constraints.NumBound; public abstract class AbstractVect implements Vect { private VectView proxy; - private NumberBound xc; - private NumberBound yc; - private NumberBound zc; + private NumBound xc; + private NumBound yc; + private NumBound zc; @Override @@ -46,9 +46,9 @@ public abstract class AbstractVect implements Vect { @Override - public final NumberBound xc() + public final NumBound xc() { - if (xc == null) xc = new NumberBound() { + if (xc == null) xc = new NumBound() { @Override public double getValue() @@ -62,9 +62,9 @@ public abstract class AbstractVect implements Vect { @Override - public final NumberBound yc() + public final NumBound yc() { - if (yc == null) yc = new NumberBound() { + if (yc == null) yc = new NumBound() { @Override public double getValue() @@ -78,9 +78,9 @@ public abstract class AbstractVect implements Vect { @Override - public final NumberBound zc() + public final NumBound zc() { - if (zc == null) zc = new NumberBound() { + if (zc == null) zc = new NumBound() { @Override public double getValue() @@ -93,6 +93,13 @@ public abstract class AbstractVect implements Vect { } + @Override + public final Vect getVect() + { + return this; + } + + @Override public final double size() { @@ -109,62 +116,14 @@ public abstract class AbstractVect implements Vect { @Override - public VectVal getValue() + public VectVal copy() { return new VectVal(this); } @Override - public final double distTo(Vect point) - { - final double dx = x() - point.x(); - final double dy = y() - point.y(); - final double dz = z() - point.z(); - - return Math.sqrt(dx * dx + dy * dy + dz * dz); - } - - - @Override - public final VectVal midTo(Vect point) - { - final double dx = (point.x() - x()) * 0.5; - final double dy = (point.y() - y()) * 0.5; - final double dz = (point.z() - z()) * 0.5; - - return VectVal.make(dx, dy, dz); - } - - - @Override - public final VectVal vecTo(Vect point) - { - return VectVal.make(point.x() - x(), point.y() - y(), point.z() - z()); - } - - - @Override - public final VectVal cross(Vect vec) - { - //@formatter:off - return VectVal.make( - y() * vec.z() - z() * vec.y(), - z() * vec.x() - x() * vec.z(), - x() * vec.y() - y() * vec.x()); - //@formatter:on - } - - - @Override - public final double dot(Vect vec) - { - return x() * vec.x() + y() * vec.y() + z() * vec.z(); - } - - - @Override - public VectView getView() + public VectView view() { if (proxy == null) proxy = new VectProxy(this); @@ -199,6 +158,6 @@ public abstract class AbstractVect implements Vect { @Override public String toString() { - return String.format("(%.1f %.1f %.1f)", x(), y(), z()); + return String.format("(%.1f|%.1f|%.1f)", x(), y(), z()); } } diff --git a/src/mightypork/utils/math/vect/NumConstrVect.java b/src/mightypork/utils/math/vect/NumConstrVect.java index fbb3c5f..967cbe9 100644 --- a/src/mightypork/utils/math/vect/NumConstrVect.java +++ b/src/mightypork/utils/math/vect/NumConstrVect.java @@ -1,33 +1,32 @@ package mightypork.utils.math.vect; -import mightypork.utils.math.constraints.NumberBound; +import mightypork.utils.math.constraints.NumBound; /** - * Coord view composed of given {@link NumberBound}s, using their current - * values. + * Coord view composed of given {@link NumBound}s, using their current values. * * @author MightyPork */ class NumConstrVect extends VectView { - private final NumberBound constrX; - private final NumberBound constrY; - private final NumberBound constrZ; + private final NumBound constrX; + private final NumBound constrY; + private final NumBound constrZ; - public NumConstrVect(NumberBound x, NumberBound y, NumberBound z) { + public NumConstrVect(NumBound x, NumBound y, NumBound z) { this.constrX = x; this.constrY = y; this.constrZ = z; } - public NumConstrVect(NumberBound x, NumberBound y) { + public NumConstrVect(NumBound x, NumBound y) { this.constrX = x; this.constrY = y; - this.constrZ = NumberBound.ZERO; + this.constrZ = NumBound.ZERO; } diff --git a/src/mightypork/utils/math/vect/Vect.java b/src/mightypork/utils/math/vect/Vect.java index 5075196..813053b 100644 --- a/src/mightypork/utils/math/vect/Vect.java +++ b/src/mightypork/utils/math/vect/Vect.java @@ -1,7 +1,8 @@ package mightypork.utils.math.vect; -import mightypork.utils.math.constraints.NumberBound; +import mightypork.utils.math.constraints.NumBound; +import mightypork.utils.math.constraints.VectBound; /** @@ -9,7 +10,7 @@ import mightypork.utils.math.constraints.NumberBound; * * @author MightyPork */ -public interface Vect { +public interface Vect extends VectBound { public static final VectVal ZERO = new VectVal(0, 0, 0); public static final VectVal ONE = new VectVal(0, 0, 0); @@ -54,19 +55,19 @@ public interface Vect { /** * @return X constraint */ - NumberBound xc(); + NumBound xc(); /** * @return Y constraint */ - NumberBound yc(); + NumBound yc(); /** * @return Z constraint */ - NumberBound zc(); + NumBound zc(); /** @@ -83,57 +84,12 @@ public interface Vect { public boolean isZero(); - /** - * Get distance to other point - * - * @param point other point - * @return distance - */ - double distTo(Vect point); - - - /** - * Get middle of line to other point - * - * @param point other point - * @return result - */ - VectVal midTo(Vect point); - - - /** - * Create vector from this point to other point - * - * @param point second point - * @return result - */ - VectVal vecTo(Vect point); - - - /** - * Get cross product (vector multiplication) - * - * @param vec other vector - * @return result - */ - VectVal cross(Vect vec); - - - /** - * Get dot product (scalar multiplication) - * - * @param vec other vector - * @return dot product - */ - double dot(Vect vec); - - /** * Get a view at current state, not propagating further changes. * * @return a immutable copy */ - VectVal getValue(); + VectVal copy(); /** @@ -141,5 +97,5 @@ public interface Vect { * * @return immutable view */ - VectView getView(); + VectView view(); } diff --git a/src/mightypork/utils/math/vect/VectMutableAnim.java b/src/mightypork/utils/math/vect/VectAnimated.java similarity index 61% rename from src/mightypork/utils/math/vect/VectMutableAnim.java rename to src/mightypork/utils/math/vect/VectAnimated.java index 8d5eb64..f02683c 100644 --- a/src/mightypork/utils/math/vect/VectMutableAnim.java +++ b/src/mightypork/utils/math/vect/VectAnimated.java @@ -12,20 +12,73 @@ import mightypork.utils.math.animation.Easing; * * @author MightyPork */ -public class VectMutableAnim extends VectMutable implements Pauseable, Updateable { +public class VectAnimated extends VectMutable implements Pauseable, Updateable { + + /** + * Create an animated vector; This way different easing / settings can be + * specified for each coordinate. + * + * @param x x animator + * @param y y animator + * @param z z animator + * @return animated mutable vector + */ + public static VectAnimated make(AnimDouble x, AnimDouble y, AnimDouble z) + { + return new VectAnimated(x, y, z); + } + + + /** + * Create an animated vector + * + * @param start initial positioon + * @param easing animation easing + * @return animated mutable vector + */ + public static VectAnimated make(Vect start, Easing easing) + { + return new VectAnimated(start, easing); + } + + + /** + * Create an animated vector, initialized at 0,0,0 + * + * @param easing animation easing + * @return animated mutable vector + */ + public static VectAnimated make(Easing easing) + { + return new VectAnimated(Vect.ZERO, easing); + } private final AnimDouble x, y, z; private double defaultDuration = 0; - VectMutableAnim(AnimDouble x, AnimDouble y, AnimDouble z) { + /** + * Create an animated vector; This way different easing / settings can be + * specified for each coordinate. + * + * @param x x animator + * @param y y animator + * @param z z animator + */ + public VectAnimated(AnimDouble x, AnimDouble y, AnimDouble z) { this.x = x; this.y = y; this.z = z; } - VectMutableAnim(Vect start, Easing easing) { + /** + * Create an animated vector + * + * @param start initial positioon + * @param easing animation easing + */ + public VectAnimated(Vect start, Easing easing) { x = new AnimDouble(start.x(), easing); y = new AnimDouble(start.y(), easing); z = new AnimDouble(start.z(), easing); @@ -74,7 +127,7 @@ public class VectMutableAnim extends VectMutable implements Pauseable, Updateabl @Override - public VectMutableAnim result(double x, double y, double z) + public VectAnimated result(double x, double y, double z) { this.x.animate(x, defaultDuration); this.y.animate(y, defaultDuration); @@ -84,14 +137,14 @@ public class VectMutableAnim extends VectMutable implements Pauseable, Updateabl } - public VectMutableAnim add(Vect offset, double speed) + public VectAnimated add(Vect offset, double speed) { - animate(getView().add(offset), speed); + animate(view().add(offset), speed); return this; } - public VectMutableAnim animate(double x, double y, double z, double duration) + public VectAnimated animate(double x, double y, double z, double duration) { this.x.animate(x, duration); this.y.animate(y, duration); @@ -100,7 +153,7 @@ public class VectMutableAnim extends VectMutable implements Pauseable, Updateabl } - public VectMutableAnim animate(Vect target, double duration) + public VectAnimated animate(Vect target, double duration) { animate(target.x(), target.y(), target.z(), duration); return this; diff --git a/src/mightypork/utils/math/vect/VectMath.java b/src/mightypork/utils/math/vect/VectMath.java index 946bef2..8666a68 100644 --- a/src/mightypork/utils/math/vect/VectMath.java +++ b/src/mightypork/utils/math/vect/VectMath.java @@ -274,4 +274,77 @@ abstract class VectMath extends AbstractVect { return mul(k); } + + + /** + * Get distance to other point + * + * @param point other point + * @return distance + */ + public final double distTo(Vect point) + { + final double dx = x() - point.x(); + final double dy = y() - point.y(); + final double dz = z() - point.z(); + + return Math.sqrt(dx * dx + dy * dy + dz * dz); + } + + + /** + * Get middle of line to other point + * + * @param point other point + * @return result + */ + public final VectVal midTo(Vect point) + { + final double dx = (point.x() - x()) * 0.5; + final double dy = (point.y() - y()) * 0.5; + final double dz = (point.z() - z()) * 0.5; + + return VectVal.make(dx, dy, dz); + } + + + /** + * Create vector from this point to other point + * + * @param point second point + * @return result + */ + public final VectVal vectTo(Vect point) + { + return VectVal.make(point.x() - x(), point.y() - y(), point.z() - z()); + } + + + /** + * Get cross product (vector multiplication) + * + * @param vec other vector + * @return result + */ + public final VectVal cross(Vect vec) + { + //@formatter:off + return VectVal.make( + y() * vec.z() - z() * vec.y(), + z() * vec.x() - x() * vec.z(), + x() * vec.y() - y() * vec.x()); + //@formatter:on + } + + + /** + * Get dot product (scalar multiplication) + * + * @param vec other vector + * @return dot product + */ + public final double dot(Vect vec) + { + return x() * vec.x() + y() * vec.y() + z() * vec.z(); + } } diff --git a/src/mightypork/utils/math/vect/VectMutable.java b/src/mightypork/utils/math/vect/VectMutable.java index e8102d3..1ad3342 100644 --- a/src/mightypork/utils/math/vect/VectMutable.java +++ b/src/mightypork/utils/math/vect/VectMutable.java @@ -1,8 +1,6 @@ package mightypork.utils.math.vect; -import mightypork.utils.math.animation.AnimDouble; -import mightypork.utils.math.animation.Easing; /** @@ -69,66 +67,10 @@ public abstract class VectMutable extends VectMath { // returns its */ public static VectMutable make(double x, double y, double z) { - return new VectMutableImpl(x, y, z); + return new VectMutableVariable(x, y, z); } - /** - * Create an animated vector; This way different easing / settings can be - * specified for each coordinate. - * - * @param animX x animator - * @param animY y animator - * @param animZ z animator - * @return animated mutable vector - */ - public static VectMutableAnim makeAnim(AnimDouble animX, AnimDouble animY, AnimDouble animZ) - { - return new VectMutableAnim(animX, animY, animZ); - } - - - /** - * Create an animated vector - * - * @param animStart initial positioon - * @param easing animation easing - * @return animated mutable vector - */ - public static VectMutableAnim makeAnim(Vect animStart, Easing easing) - { - return new VectMutableAnim(animStart, easing); - } - - - /** - * Create an animated vector, initialized at 0,0,0 - * - * @param easing animation easing - * @return animated mutable vector - */ - public static VectMutableAnim makeAnim(Easing easing) - { - return new VectMutableAnim(Vect.ZERO, easing); - } - - - @Override - public abstract VectMutable result(double x, double y, double z); - - - @Override - public abstract double x(); - - - @Override - public abstract double y(); - - - @Override - public abstract double z(); - - public VectMutable reset() { return result(0, 0, 0); diff --git a/src/mightypork/utils/math/vect/VectMutableImpl.java b/src/mightypork/utils/math/vect/VectMutableVariable.java similarity index 78% rename from src/mightypork/utils/math/vect/VectMutableImpl.java rename to src/mightypork/utils/math/vect/VectMutableVariable.java index 12875b2..2b8927e 100644 --- a/src/mightypork/utils/math/vect/VectMutableImpl.java +++ b/src/mightypork/utils/math/vect/VectMutableVariable.java @@ -7,7 +7,7 @@ package mightypork.utils.math.vect; * * @author MightyPork */ -class VectMutableImpl extends VectMutable { +class VectMutableVariable extends VectMutable { private double x, y, z; @@ -17,7 +17,7 @@ class VectMutableImpl extends VectMutable { * @param y Y coordinate * @param z Z coordinate */ - public VectMutableImpl(double x, double y, double z) { + public VectMutableVariable(double x, double y, double z) { super(); this.x = x; this.y = y; @@ -47,7 +47,7 @@ class VectMutableImpl extends VectMutable { @Override - public VectMutableImpl result(double x, double y, double z) + public VectMutable result(double x, double y, double z) { this.x = x; this.y = y; diff --git a/src/mightypork/utils/math/vect/VectVal.java b/src/mightypork/utils/math/vect/VectVal.java index 07485f6..e7ddcdd 100644 --- a/src/mightypork/utils/math/vect/VectVal.java +++ b/src/mightypork/utils/math/vect/VectVal.java @@ -3,8 +3,7 @@ package mightypork.utils.math.vect; /** * Coordinate with immutable numeric values.
- * This coordinate is guaranteed to never change, as opposed to view, which can - * be a proxy or a synthetic vector. + * This coordinate is guaranteed to never change, as opposed to view. * * @author MightyPork */ @@ -18,7 +17,7 @@ public final class VectVal extends VectView { */ public static VectVal make(Vect value) { - return value.getValue(); + return value.copy(); } @@ -51,12 +50,12 @@ public final class VectVal extends VectView { private final double x, y, z; - protected VectVal(Vect other) { + public VectVal(Vect other) { this(other.x(), other.y(), other.z()); } - protected VectVal(double x, double y, double z) { + public VectVal(double x, double y, double z) { this.x = x; this.y = y; this.z = z; @@ -84,12 +83,8 @@ public final class VectVal extends VectView { } - /** - * @deprecated It's constant already. - */ @Override - @Deprecated - public VectVal getValue() + public VectVal copy() { 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 8d200a6..74ea8f2 100644 --- a/src/mightypork/utils/math/vect/VectView.java +++ b/src/mightypork/utils/math/vect/VectView.java @@ -2,11 +2,12 @@ package mightypork.utils.math.vect; import mightypork.gamecore.control.interf.DefaultImpl; -import mightypork.utils.math.constraints.NumberBound; +import mightypork.utils.math.constraints.NumBound; /** - * Read-only coordinate. + * Read-only coordinate, whose values cannot be changed directly. To keep + * current state, use the value() method. * * @author MightyPork */ @@ -20,7 +21,7 @@ public abstract class VectView extends VectMath { // returns constant v */ public static VectView make(Vect observed) { - return observed.getView(); + return observed.view(); } @@ -31,7 +32,7 @@ public abstract class VectView extends VectMath { // returns constant v * @param yc Y value * @return view at the values */ - public static VectView make(NumberBound xc, NumberBound yc) + public static VectView make(NumBound xc, NumBound yc) { return new NumConstrVect(xc, yc); } @@ -45,7 +46,7 @@ public abstract class VectView extends VectMath { // returns constant v * @param zc Z value * @return view at the values */ - public static VectView make(NumberBound xc, NumberBound yc, NumberBound zc) + public static VectView make(NumBound xc, NumBound yc, NumBound zc) { return new NumConstrVect(xc, yc, zc); } @@ -58,14 +59,10 @@ public abstract class VectView extends VectMath { // returns constant v } - /** - * @deprecated VecView is not mutable, making a proxy has no effect. - */ @Override - @Deprecated - public VectView getView() + public VectView view() { - return this; // already not mutable + return this; // already a view } diff --git a/src/mightypork/utils/objects/Convert.java b/src/mightypork/utils/objects/Convert.java index c33a216..d55da0f 100644 --- a/src/mightypork/utils/objects/Convert.java +++ b/src/mightypork/utils/objects/Convert.java @@ -154,16 +154,24 @@ public class Convert { public static VectVal toVect(Object o, Vect def) { try { - if (o == null) return def.getValue(); - if (o instanceof Vect) return ((Vect) o).getValue(); + if (o == null) return def.copy(); + if (o instanceof Vect) return ((Vect) o).copy(); if (o instanceof String) { - String s = ((String) o).trim().toUpperCase(); + String s = ((String) o).trim(); + + // drop whitespace + s = s.replaceAll("\\s", ""); - // colon to semicolon - s = s.replace(':', ';'); - // remove brackets if any + // drop brackets s = s.replaceAll("[\\(\\[\\{\\)\\]\\}]", ""); - final String[] parts = s.split("[;]"); + + // norm separators + s = s.replaceAll("[:;]", "|"); + + // norm floating point + s = s.replaceAll("[,]", "."); + + final String[] parts = s.split("[|]"); if (parts.length >= 2) { @@ -183,7 +191,7 @@ public class Convert { // ignore } - return def.getValue(); + return def.copy(); } @@ -203,18 +211,34 @@ public class Convert { if (o instanceof String) { String s = ((String) o).trim(); - // colon to semicolon - s = s.replace(',', ':'); - // comma to dot. - s = s.replace(';', ':'); - // dash - s = s.replaceAll("([0-9])\\s?[\\-]", "$1:"); - // remove brackets if any + // drop whitespace + s = s.replaceAll("\\s", ""); + + // drop brackets s = s.replaceAll("[\\(\\[\\{\\)\\]\\}]", ""); - final String[] parts = s.split("[:]"); - if (parts.length == 2) return new Range(Double.parseDouble(parts[0].trim()), Double.parseDouble(parts[1].trim())); - return new Range(Double.parseDouble(parts[0].trim()), Double.parseDouble(parts[0].trim())); + // norm separators + s = s.replaceAll("[:;]", "|").replace("..", "|"); + + // norm floating point + s = s.replaceAll("[,]", "."); + + // dash to pipe, if not a minus sign + s = s.replaceAll("([0-9])\\s?[\\-]", "$1|"); + + final String[] parts = s.split("[|]"); + + if (parts.length >= 1) { + + final double low = Double.parseDouble(parts[0].trim()); + + if (parts.length == 2) { + final double high = Double.parseDouble(parts[1].trim()); + return Range.make(low, high); + } + + return Range.make(low, low); + } } } catch (final NumberFormatException e) { // ignore @@ -284,12 +308,12 @@ public class Convert { /** - * Get Coord + * Get a vector of two or three coordinates * * @param o object * @return Coord */ - public static VectView toCoord(Object o) + public static VectView toVect(Object o) { return toVect(o, Vect.ZERO); }