diff --git a/src/mightypork/gamecore/audio/DeferredAudio.java b/src/mightypork/gamecore/audio/DeferredAudio.java index 78e3893..ecb00c7 100644 --- a/src/mightypork/gamecore/audio/DeferredAudio.java +++ b/src/mightypork/gamecore/audio/DeferredAudio.java @@ -6,7 +6,7 @@ import java.io.IOException; import mightypork.gamecore.loading.DeferredResource; import mightypork.utils.files.FileUtils; import mightypork.utils.logging.LoggedName; -import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.vect.Vect; import org.newdawn.slick.openal.Audio; import org.newdawn.slick.openal.SoundStore; @@ -204,7 +204,7 @@ public class DeferredAudio extends DeferredResource { * @param pos coord * @return source id */ - public int playAsEffect(double pitch, double gain, boolean loop, Vec pos) + public int playAsEffect(double pitch, double gain, boolean loop, Vect pos) { if (!ensureLoaded()) return -1; diff --git a/src/mightypork/gamecore/audio/SoundSystem.java b/src/mightypork/gamecore/audio/SoundSystem.java index cbe42a7..dc361bf 100644 --- a/src/mightypork/gamecore/audio/SoundSystem.java +++ b/src/mightypork/gamecore/audio/SoundSystem.java @@ -12,9 +12,9 @@ import mightypork.gamecore.control.bus.clients.RootBusNode; import mightypork.gamecore.control.bus.events.ResourceLoadRequest; import mightypork.gamecore.control.timing.Updateable; import mightypork.utils.math.Calc.Buffers; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecMutable; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectMutable; +import mightypork.utils.math.vect.VectView; import org.lwjgl.openal.AL; import org.lwjgl.openal.AL10; @@ -28,10 +28,10 @@ import org.newdawn.slick.openal.SoundStore; */ public class SoundSystem extends RootBusNode implements Updateable { - private static final Vec INITIAL_LISTENER_POS = Vec.ZERO; + private static final Vect INITIAL_LISTENER_POS = Vect.ZERO; private static final int MAX_SOURCES = 256; - private static VecMutable listener = VecMutable.zero(); + private static VectMutable listener = VectMutable.zero(); private static boolean soundSystemInited = false; @@ -40,7 +40,7 @@ public class SoundSystem extends RootBusNode implements Updateable { * * @param pos */ - public static void setListener(Vec pos) + public static void setListener(Vect pos) { listener.setTo(pos); final FloatBuffer buf3 = Buffers.alloc(3); @@ -60,7 +60,7 @@ public class SoundSystem extends RootBusNode implements Updateable { /** * @return listener coordinate */ - public static VecView getListener() + public static VectView getListener() { return listener.view(); } diff --git a/src/mightypork/gamecore/audio/players/EffectPlayer.java b/src/mightypork/gamecore/audio/players/EffectPlayer.java index bbe94e5..df4cc59 100644 --- a/src/mightypork/gamecore/audio/players/EffectPlayer.java +++ b/src/mightypork/gamecore/audio/players/EffectPlayer.java @@ -3,7 +3,7 @@ package mightypork.gamecore.audio.players; import mightypork.gamecore.audio.DeferredAudio; import mightypork.gamecore.audio.Volume; -import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.vect.Vect; /** @@ -59,7 +59,7 @@ public class EffectPlayer extends BaseAudioPlayer { * @param pos play position * @return source id */ - public int play(double pitch, double gain, Vec pos) + public int play(double pitch, double gain, Vect pos) { if (!hasAudio()) return -1; diff --git a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java index a435991..eb43b55 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java @@ -2,8 +2,8 @@ package mightypork.gamecore.control.bus.events; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectView; /** @@ -19,7 +19,7 @@ public class MouseButtonEvent implements Event { private final int button; private final int wheeld; - private final Vec pos; + private final Vect pos; private final boolean down; @@ -31,7 +31,7 @@ public class MouseButtonEvent implements Event { * @param down button pressed * @param wheeld wheel change */ - public MouseButtonEvent(Vec pos, int button, boolean down, int wheeld) { + public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) { this.button = button; this.down = down; this.pos = pos; @@ -78,7 +78,7 @@ public class MouseButtonEvent implements Event { /** * @return mouse position when the event occurred */ - public VecView getPos() + public VectView getPos() { return pos.view(); } diff --git a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java index 0f5bbe7..175b935 100644 --- a/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java +++ b/src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java @@ -2,8 +2,8 @@ package mightypork.gamecore.control.bus.events; import mightypork.gamecore.control.bus.events.types.UnloggedEvent; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectView; /** @@ -14,15 +14,15 @@ import mightypork.utils.math.coord.VecView; @UnloggedEvent public class MouseMotionEvent implements Event { - private final VecView move; - private final VecView pos; + private final VectView move; + private final VectView pos; /** * @param pos end pos * @param move move vector */ - public MouseMotionEvent(Vec pos, Vec move) { + public MouseMotionEvent(Vect pos, Vect move) { this.move = move.value(); this.pos = pos.value(); } @@ -31,7 +31,7 @@ public class MouseMotionEvent implements Event { /** * @return movement since last {@link MouseMotionEvent} */ - public VecView getMove() + public VectView getMove() { return move; } @@ -40,7 +40,7 @@ public class MouseMotionEvent implements Event { /** * @return current mouse position */ - public VecView getPos() + public VectView getPos() { return pos; } diff --git a/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java b/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java index eb5dbc1..f49360b 100644 --- a/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java +++ b/src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java @@ -1,8 +1,8 @@ package mightypork.gamecore.control.bus.events; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectView; /** @@ -13,7 +13,7 @@ import mightypork.utils.math.coord.VecView; public class ScreenChangeEvent implements Event { private final boolean fullscreen; - private final Vec screenSize; + private final Vect screenSize; private final boolean fsChanged; @@ -22,7 +22,7 @@ public class ScreenChangeEvent implements Event { * @param fullscreen is now fullscreen * @param size new screen size */ - public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Vec size) { + public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) { this.fullscreen = fullscreen; this.screenSize = size; this.fsChanged = fsChanged; @@ -50,7 +50,7 @@ public class ScreenChangeEvent implements Event { /** * @return new screen size */ - public VecView getScreenSize() + public VectView getScreenSize() { return screenSize.view(); } diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderable.java b/src/mightypork/gamecore/gui/components/PluggableRenderable.java index 3495313..2f6fec7 100644 --- a/src/mightypork/gamecore/gui/components/PluggableRenderable.java +++ b/src/mightypork/gamecore/gui/components/PluggableRenderable.java @@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components; import mightypork.utils.math.constraints.PluggableRect; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; /** @@ -18,7 +18,7 @@ public interface PluggableRenderable extends Renderable, PluggableRect { @Override - RectValue getRect(); + RectView getRect(); @Override diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderer.java b/src/mightypork/gamecore/gui/components/PluggableRenderer.java index 46cd859..bbaf463 100644 --- a/src/mightypork/gamecore/gui/components/PluggableRenderer.java +++ b/src/mightypork/gamecore/gui/components/PluggableRenderer.java @@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components; import mightypork.utils.math.constraints.ContextAdapter; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; /** @@ -18,7 +18,7 @@ public abstract class PluggableRenderer extends ContextAdapter implements Plugga @Override - public RectValue getRect() + public RectView getRect() { return super.getRect(); } diff --git a/src/mightypork/gamecore/gui/components/layout/ElementHolder.java b/src/mightypork/gamecore/gui/components/layout/ElementHolder.java index 0bab0ec..997759f 100644 --- a/src/mightypork/gamecore/gui/components/layout/ElementHolder.java +++ b/src/mightypork/gamecore/gui/components/layout/ElementHolder.java @@ -10,7 +10,7 @@ import mightypork.gamecore.gui.components.PluggableRenderable; import mightypork.gamecore.gui.components.PluggableRenderer; import mightypork.gamecore.gui.components.Renderable; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; /** @@ -60,7 +60,7 @@ public abstract class ElementHolder extends BusNode implements PluggableRenderab @Override - public RectValue getRect() + public RectView getRect() { return context.getRect(); } diff --git a/src/mightypork/gamecore/gui/components/painters/TextPainter.java b/src/mightypork/gamecore/gui/components/painters/TextPainter.java index 6887cc1..d102ac2 100644 --- a/src/mightypork/gamecore/gui/components/painters/TextPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/TextPainter.java @@ -6,9 +6,9 @@ import mightypork.gamecore.render.fonts.FontRenderer; import mightypork.gamecore.render.fonts.FontRenderer.Align; import mightypork.gamecore.render.fonts.GLFont; import mightypork.utils.math.color.RGB; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecMutable; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectMutable; import mightypork.utils.string.StringProvider; import mightypork.utils.string.StringProvider.StringWrapper; @@ -29,7 +29,7 @@ public class TextPainter extends PluggableRenderer { private boolean shadow; private RGB shadowColor = RGB.BLACK; - private final VecMutable shadowOffset = VecMutable.make(1, 1); + private final VectMutable shadowOffset = VectMutable.make(1, 1); /** @@ -85,7 +85,7 @@ public class TextPainter extends PluggableRenderer { if (text == null) return; final String str = text.getString(); - final RectValue rect = getRect(); + final RectView rect = getRect(); if (shadow) { font.draw(str, rect.move(shadowOffset), align, shadowColor); @@ -94,7 +94,7 @@ public class TextPainter extends PluggableRenderer { } - public void setShadow(RGB color, Vec offset) + public void setShadow(RGB color, Vect offset) { setShadow(true); setShadowColor(color); @@ -114,7 +114,7 @@ public class TextPainter extends PluggableRenderer { } - public void setShadowOffset(Vec shadowOffset) + public void setShadowOffset(Vect shadowOffset) { this.shadowOffset.setTo(shadowOffset); } diff --git a/src/mightypork/gamecore/gui/screens/LayeredScreen.java b/src/mightypork/gamecore/gui/screens/LayeredScreen.java index ee3520b..fe5e309 100644 --- a/src/mightypork/gamecore/gui/screens/LayeredScreen.java +++ b/src/mightypork/gamecore/gui/screens/LayeredScreen.java @@ -5,7 +5,7 @@ import java.util.Collection; import java.util.TreeSet; import mightypork.gamecore.control.AppAccess; -import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.vect.Vect; /** @@ -79,7 +79,7 @@ public abstract class LayeredScreen extends Screen { @Override - protected void onSizeChanged(Vec size) + protected void onSizeChanged(Vect size) { for (final ScreenLayer layer : layers) { layer.onSizeChanged(size); diff --git a/src/mightypork/gamecore/gui/screens/Screen.java b/src/mightypork/gamecore/gui/screens/Screen.java index 37aef14..d1e394d 100644 --- a/src/mightypork/gamecore/gui/screens/Screen.java +++ b/src/mightypork/gamecore/gui/screens/Screen.java @@ -11,8 +11,8 @@ import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyStroke; import mightypork.gamecore.render.Render; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.vect.Vect; /** @@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind @Override - public RectValue getRect() + public RectView getRect() { return getDisplay().getRect(); } @@ -153,7 +153,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind * @param size screen size */ @DefaultImpl - protected void onSizeChanged(Vec size) + protected void onSizeChanged(Vect size) { // } diff --git a/src/mightypork/gamecore/gui/screens/ScreenLayer.java b/src/mightypork/gamecore/gui/screens/ScreenLayer.java index c61e6ef..59cb573 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenLayer.java +++ b/src/mightypork/gamecore/gui/screens/ScreenLayer.java @@ -8,9 +8,9 @@ import mightypork.gamecore.input.KeyBinder; import mightypork.gamecore.input.KeyBindingPool; import mightypork.gamecore.input.KeyStroke; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectView; /** @@ -27,9 +27,9 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable { + private class CoordProperty extends Property { - public CoordProperty(String key, Vec defaultValue, String comment) { + public CoordProperty(String key, Vect defaultValue, String comment) { super(key, defaultValue, comment); } @@ -132,7 +132,7 @@ public class PropertyManager { @Override public void parse(String string) { - value = Convert.toCoord(string, defaultValue); + value = Convert.toVect(string, defaultValue); } } @@ -173,8 +173,10 @@ public class PropertyManager { public void apply() { boolean needsSave = false; - if (!new File(file.getParent()).mkdirs()) { - throw new RuntimeException("Cound not create config file."); + if (!file.getParentFile().mkdirs()) { + if (!file.getParentFile().exists()) { + throw new RuntimeException("Cound not create config file."); + } } try(FileInputStream fis = new FileInputStream(file)) { @@ -360,7 +362,7 @@ public class PropertyManager { * @param n key * @return the coord found, or null */ - public VecView getCoord(String n) + public VectView getCoord(String n) { return Convert.toCoord(get(n).value); } @@ -425,7 +427,7 @@ public class PropertyManager { * @param d default value * @param comment the in-file comment */ - public void putCoord(String n, Vec d, String comment) + public void putCoord(String n, Vect d, String comment) { entries.put(n, new CoordProperty(n, d, comment)); } diff --git a/src/mightypork/utils/math/Calc.java b/src/mightypork/utils/math/Calc.java index b8199cf..3051102 100644 --- a/src/mightypork/utils/math/Calc.java +++ b/src/mightypork/utils/math/Calc.java @@ -7,7 +7,7 @@ import java.util.List; import java.util.Random; import mightypork.utils.math.animation.Easing; -import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.vect.Vect; import org.lwjgl.BufferUtils; @@ -31,7 +31,7 @@ public class Calc { * @param point point coordinate * @return distance */ - public static double linePointDist(Vec lineDirVec, Vec linePoint, Vec point) + public static double linePointDist(Vect lineDirVec, Vect linePoint, Vect point) { // line point L[lx,ly] final double lx = linePoint.x(); diff --git a/src/mightypork/utils/math/Polar.java b/src/mightypork/utils/math/Polar.java index fe33bd0..b6e16e2 100644 --- a/src/mightypork/utils/math/Polar.java +++ b/src/mightypork/utils/math/Polar.java @@ -3,8 +3,8 @@ package mightypork.utils.math; import mightypork.utils.math.Calc.Deg; import mightypork.utils.math.Calc.Rad; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectView; /** @@ -20,7 +20,7 @@ public class Polar { /** distance in units */ private double radius = 0; - private VecView coord = null; + private VectView coord = null; /** @@ -107,7 +107,7 @@ public class Polar { * @param coord coord * @return polar */ - public static Polar fromCoord(Vec coord) + public static Polar fromCoord(Vect coord) { return Polar.fromCoord(coord.x(), coord.y()); @@ -135,11 +135,11 @@ public class Polar { * * @return coord */ - public VecView toCoord() + public VectView toCoord() { // lazy init if (coord == null) { - coord = new VecView() { + coord = new VectView() { @Override public double x() diff --git a/src/mightypork/utils/math/constraints/CReverseProxy.java b/src/mightypork/utils/math/constraints/CReverseProxy.java deleted file mode 100644 index 77ca9d7..0000000 --- a/src/mightypork/utils/math/constraints/CReverseProxy.java +++ /dev/null @@ -1,36 +0,0 @@ -package mightypork.utils.math.constraints; - - -import mightypork.utils.math.coord.VecView; - - -public class CReverseProxy extends VecView { - - private final VecConstraint constraint; - - - public CReverseProxy(VecConstraint wrapped) { - this.constraint = wrapped; - } - - - @Override - public double x() - { - return constraint.getVec().x(); - } - - - @Override - public double y() - { - return constraint.getVec().y(); - } - - - @Override - public double z() - { - return constraint.getVec().z(); - } -} diff --git a/src/mightypork/utils/math/constraints/Constraints.java b/src/mightypork/utils/math/constraints/Constraints.java index e3013b7..95d586e 100644 --- a/src/mightypork/utils/math/constraints/Constraints.java +++ b/src/mightypork/utils/math/constraints/Constraints.java @@ -2,10 +2,12 @@ package mightypork.utils.math.constraints; import mightypork.gamecore.control.timing.Poller; -import mightypork.utils.math.coord.AbstractVecProxy; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectVal; +import mightypork.utils.math.rect.RectView; +import mightypork.utils.math.vect.VectAdapter; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; /** @@ -58,8 +60,6 @@ public class Constraints { } - // =================== Number constraints ==================== - public static NumberConstraint cMin(final Object a, final Object b) { return new NumberConstraint() { @@ -130,7 +130,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().round(); } @@ -253,15 +253,15 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { final double height = r.getRect().getHeight(); final double perRow = height / rows; - final Vec origin = r.getRect().getOrigin().add(0, perRow * index); - final Vec size = r.getRect().getSize().setY(perRow); + final Vect origin = r.getRect().getOrigin().add(0, perRow * index); + final Vect size = r.getRect().getSize().setY(perRow); - return RectValue.make(origin, size); + return RectVal.make(origin, size); } }; } @@ -272,15 +272,15 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { final double width = r.getRect().getWidth(); final double perCol = width / columns; - final Vec origin = r.getRect().getOrigin().add(perCol * index, 0); - final Vec size = r.getRect().getSize().setX(perCol); + final Vect origin = r.getRect().getOrigin().add(perCol * index, 0); + final Vect size = r.getRect().getSize().setX(perCol); - return RectValue.make(origin, size); + return RectVal.make(origin, size); } }; } @@ -291,23 +291,21 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { final double height = r.getRect().getHeight(); final double width = r.getRect().getHeight(); final double perRow = height / rows; final double perCol = width / cols; - final Vec origin = r.getRect().getOrigin().add(perCol * left, perRow * (rows - top - 1)); + final Vect origin = r.getRect().getOrigin().add(perCol * left, perRow * (rows - top - 1)); - return RectValue.make(origin, perCol, perRow); + return RectVal.make(origin, perCol, perRow); } }; } - /* ================= RectView manipulation ================= */ - public static RectConstraint cShrink(RectConstraint r, Object shrink) { final NumberConstraint n = toConstraint(shrink); @@ -326,7 +324,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(toDouble(left), toDouble(top), toDouble(right), toDouble(bottom)); } @@ -339,7 +337,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(0, toDouble(shrink), 0, 0); } @@ -352,7 +350,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(0, 0, 0, toDouble(shrink)); } @@ -365,7 +363,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(toDouble(shrink), 0, 0, 0); } @@ -378,7 +376,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(0, 0, toDouble(shrink), 0); } @@ -404,7 +402,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().grow(toDouble(left), toDouble(right), toDouble(top), toDouble(bottom)); } @@ -417,7 +415,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().grow(0, toDouble(grow), 0, 0); } @@ -430,7 +428,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().grow(0, 0, 0, toDouble(grow)); } @@ -443,7 +441,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().grow(toDouble(grow), 0, 0, 0); } @@ -456,7 +454,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().grow(0, 0, toDouble(grow), 0); } @@ -464,22 +462,20 @@ public class Constraints { } - /* ================= Box creation ================= */ - public static RectConstraint cBox(final Object side) { return cBox(side, side); } - public static RectConstraint cBox(final VecConstraint origin, final Object width, final Object height) + public static RectConstraint cBox(final VectConstraint origin, final Object width, final Object height) { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - return RectValue.make(origin.getVec(), toDouble(width), toDouble(height)); + return RectVal.make(origin.getVec(), toDouble(width), toDouble(height)); } }; } @@ -490,9 +486,9 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - return RectValue.make(0, 0, toDouble(width), toDouble(height)); + return RectVal.make(0, 0, toDouble(width), toDouble(height)); } }; } @@ -503,11 +499,11 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - final Vec origin = r.getRect().getOrigin(); + final Vect origin = r.getRect().getOrigin(); - return RectValue.make(origin.x(), origin.y(), toDouble(width), toDouble(height)); + return RectVal.make(origin.x(), origin.y(), toDouble(width), toDouble(height)); } }; } @@ -518,11 +514,11 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - final Vec origin = r.getRect().getOrigin(); + final Vect origin = r.getRect().getOrigin(); - return RectValue.make(origin.x() + toDouble(x), origin.y() + toDouble(y), toDouble(width), toDouble(height)); + return RectVal.make(origin.x() + toDouble(x), origin.y() + toDouble(y), toDouble(width), toDouble(height)); } }; } @@ -533,27 +529,27 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - final VecView size = r.getRect().getSize(); - final VecView center = centerTo.getRect().getCenter(); + final VectView size = r.getRect().getSize(); + final VectView center = centerTo.getRect().getCenter(); - return RectValue.make(center.sub(size.half()), size); + return RectVal.make(center.sub(size.half()), size); } }; } - public static RectConstraint cCenterTo(final RectConstraint r, final VecConstraint centerTo) + public static RectConstraint cCenterTo(final RectConstraint r, final VectConstraint centerTo) { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - final VecView size = r.getRect().getSize(); + final VectView size = r.getRect().getSize(); - return RectValue.make(centerTo.getVec().sub(size.half()), size); + return RectVal.make(centerTo.getVec().sub(size.half()), size); } }; } @@ -564,23 +560,23 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - final VecView size = r.getRect().getSize(); - final VecView v = VecView.make(toDouble(x), toDouble(y)); + final VectView size = r.getRect().getSize(); + final VectView v = VectVal.make(toDouble(x), toDouble(y)); - return RectValue.make(v.sub(size.half()), size); + return RectVal.make(v.sub(size.half()), size); } }; } - public static RectConstraint cMove(final RectConstraint r, final VecConstraint move) + public static RectConstraint cMove(final RectConstraint r, final VectConstraint move) { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().move(move.getVec()); } @@ -593,7 +589,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().move(toDouble(x), toDouble(y)); } @@ -608,7 +604,7 @@ public class Constraints { * @param allSides size to grow on all sides * @return rect constraint */ - public static RectConstraint cExpand(final VecConstraint c, final Object allSides) + public static RectConstraint cExpand(final VectConstraint c, final Object allSides) { return cExpand(c, allSides, allSides, allSides, allSides); } @@ -622,7 +618,7 @@ public class Constraints { * @param vertical vertical grow (top, bottom) * @return rect constraint */ - public static RectConstraint cExpand(final VecConstraint c, final Object horizontal, final Object vertical) + public static RectConstraint cExpand(final VectConstraint c, final Object horizontal, final Object vertical) { return cExpand(c, horizontal, vertical, horizontal, vertical); } @@ -638,12 +634,12 @@ public class Constraints { * @param left * @return rect constraint */ - public static RectConstraint cExpand(final VecConstraint c, final Object top, final Object right, final Object bottom, final Object left) + public static RectConstraint cExpand(final VectConstraint c, final Object top, final Object right, final Object bottom, final Object left) { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { final double t = toDouble(top); final double r = toDouble(right); @@ -653,20 +649,18 @@ public class Constraints { final double x = c.getVec().x(); final double y = c.getVec().y(); - return RectValue.make(x - l, y - t, l + r, t + b); + return RectVal.make(x - l, y - t, l + r, t + b); } }; } - /* ================= RectView bounds ================= */ - public static RectConstraint cLeftEdge(final RectConstraint r) { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(0, 0, r.getRect().getWidth(), 0); } @@ -679,7 +673,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(0, 0, 0, r.getRect().getHeight()); } @@ -692,7 +686,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(r.getRect().getWidth(), 0, 0, 0); } @@ -705,7 +699,7 @@ public class Constraints { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { return r.getRect().shrink(0, r.getRect().getHeight(), 0, 0); } @@ -713,7 +707,7 @@ public class Constraints { } - public static NumberConstraint cX(final VecConstraint c) + public static NumberConstraint cX(final VectConstraint c) { return new NumberConstraint() { @@ -726,7 +720,7 @@ public class Constraints { } - public static NumberConstraint cY(final VecConstraint c) + public static NumberConstraint cY(final VectConstraint c) { return new NumberConstraint() { @@ -739,7 +733,7 @@ public class Constraints { } - public static NumberConstraint cZ(final VecConstraint c) + public static NumberConstraint cZ(final VectConstraint c) { return new NumberConstraint() { @@ -752,26 +746,24 @@ public class Constraints { } - public static VecConstraint cNeg(final VecConstraint c) + public static VectConstraint cNeg(final VectConstraint c) { return cMul(c, -1); } - public static VecConstraint cHalf(final VecConstraint c) + public static VectConstraint cHalf(final VectConstraint c) { return cMul(c, 0.5); } - // --- add --- - - public static VecConstraint cAdd(final VecConstraint c1, final VecConstraint c2) + public static VectConstraint cAdd(final VectConstraint c1, final VectConstraint c2) { - return new AbstractVecProxy() { + return new VectAdapter() { @Override - public VecView getSource() + public VectView getSource() { return c1.getVec().add(c2.getVec()); } @@ -779,18 +771,18 @@ public class Constraints { } - public static VecConstraint cAdd(final VecConstraint c, final Object x, final Object y) + public static VectConstraint cAdd(final VectConstraint c, final Object x, final Object y) { return cAdd(c, x, y, 0); } - public static VecConstraint cAdd(final VecConstraint c, final Object x, final Object y, final Object z) + public static VectConstraint cAdd(final VectConstraint c, final Object x, final Object y, final Object z) { - return new AbstractVecProxy() { + return new VectAdapter() { @Override - public VecView getSource() + public VectView getSource() { return c.getVec().add(toDouble(x), toDouble(y), toDouble(z)); } @@ -798,14 +790,12 @@ public class Constraints { } - // --- sub --- - - public static VecConstraint cSub(final VecConstraint c1, final VecConstraint c2) + public static VectConstraint cSub(final VectConstraint c1, final VectConstraint c2) { - return new AbstractVecProxy() { + return new VectAdapter() { @Override - public VecView getSource() + public VectView getSource() { return c1.getVec().sub(c2.getVec()); } @@ -813,18 +803,18 @@ public class Constraints { } - public static VecConstraint cSub(final VecConstraint c, final Object x, final Object y) + public static VectConstraint cSub(final VectConstraint c, final Object x, final Object y) { return cSub(c, x, y, 0); } - public static VecConstraint cSub(final VecConstraint c, final Object x, final Object y, final Object z) + public static VectConstraint cSub(final VectConstraint c, final Object x, final Object y, final Object z) { - return new AbstractVecProxy() { + return new VectAdapter() { @Override - public VecView getSource() + public VectView getSource() { return c.getVec().sub(toDouble(x), toDouble(y), toDouble(z)); } @@ -833,14 +823,12 @@ public class Constraints { } - // --- mul --- - - public static VecConstraint cMul(final VecConstraint c, final Object mul) + public static VectConstraint cMul(final VectConstraint c, final Object mul) { - return new AbstractVecProxy() { + return new VectAdapter() { @Override - public VecView getSource() + public VectView getSource() { return c.getVec().mul(toDouble(mul)); } @@ -849,14 +837,12 @@ public class Constraints { } - // --- rects --- - - public static VecConstraint cOrigin(final RectConstraint r) + public static VectConstraint cOrigin(final RectConstraint r) { - return new AbstractVecProxy() { + return new VectAdapter() { @Override - public VecView getSource() + public VectView getSource() { return r.getRect().getOrigin(); } @@ -864,12 +850,12 @@ public class Constraints { } - public static VecConstraint cSize(final RectConstraint r) + public static VectConstraint cSize(final RectConstraint r) { - return new AbstractVecProxy() { + return new VectAdapter() { @Override - public VecView getSource() + public VectView getSource() { return r.getRect().getSize(); } @@ -889,55 +875,55 @@ public class Constraints { } - public static VecConstraint cCenter(final RectConstraint r) + public static VectConstraint cCenter(final RectConstraint r) { return cAdd(cOrigin(r), cHalf(cSize(r))); } - public static VecConstraint cTopLeft(final RectConstraint r) + public static VectConstraint cTopLeft(final RectConstraint r) { return cOrigin(r); } - public static VecConstraint cTopRight(final RectConstraint r) + public static VectConstraint cTopRight(final RectConstraint r) { return cAdd(cOrigin(r), cWidth(r), 0); } - public static VecConstraint cBottomLeft(final RectConstraint r) + public static VectConstraint cBottomLeft(final RectConstraint r) { return cAdd(cOrigin(r), 0, cWidth(r)); } - public static VecConstraint cBottomRight(final RectConstraint r) + public static VectConstraint cBottomRight(final RectConstraint r) { return cAdd(cOrigin(r), cSize(r)); } - public static VecConstraint cTopCenter(final RectConstraint r) + public static VectConstraint cTopCenter(final RectConstraint r) { return cAdd(cOrigin(r), cHalf(cWidth(r)), 0); } - public static VecConstraint cBottomCenter(final RectConstraint r) + public static VectConstraint cBottomCenter(final RectConstraint r) { return cAdd(cOrigin(r), cHalf(cWidth(r)), cWidth(r)); } - public static VecConstraint cCenterLeft(final RectConstraint r) + public static VectConstraint cCenterLeft(final RectConstraint r) { return cAdd(cOrigin(r), 0, cHalf(cWidth(r))); } - public static VecConstraint cCenterRight(final RectConstraint r) + public static VectConstraint cCenterRight(final RectConstraint r) { return cAdd(cOrigin(r), cWidth(r), cHalf(cWidth(r))); } @@ -949,30 +935,18 @@ public class Constraints { * @param c coord * @return rect */ - public static RectConstraint cZeroRect(final VecConstraint c) + public static RectConstraint cZeroRect(final VectConstraint c) { return new RectConstraint() { @Override - public RectValue getRect() + public RectView getRect() { - final Vec v = c.getVec(); + final Vect v = c.getVec(); - return RectValue.make(v.x(), v.y(), 0, 0); + return RectVal.make(v.x(), v.y(), 0, 0); } }; } - - /** - * Convert VecConstraint to VecView - * - * @param c vec constraint - * @return CReverseProxy - */ - public static VecView cVec(final VecConstraint c) - { - return new CReverseProxy(c); - } - } diff --git a/src/mightypork/utils/math/constraints/ContextAdapter.java b/src/mightypork/utils/math/constraints/ContextAdapter.java index 5c99acb..03f3646 100644 --- a/src/mightypork/utils/math/constraints/ContextAdapter.java +++ b/src/mightypork/utils/math/constraints/ContextAdapter.java @@ -1,7 +1,7 @@ package mightypork.utils.math.constraints; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; /** @@ -22,7 +22,7 @@ public abstract class ContextAdapter implements PluggableRect { @Override - public RectValue getRect() + public RectView getRect() { return backing.getRect(); } diff --git a/src/mightypork/utils/math/constraints/PluggableRect.java b/src/mightypork/utils/math/constraints/PluggableRect.java index b2cc6f5..9f98c06 100644 --- a/src/mightypork/utils/math/constraints/PluggableRect.java +++ b/src/mightypork/utils/math/constraints/PluggableRect.java @@ -1,7 +1,7 @@ package mightypork.utils.math.constraints; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; /** @@ -18,6 +18,6 @@ public interface PluggableRect extends RectConstraint { @Override - abstract RectValue getRect(); + abstract RectView getRect(); } diff --git a/src/mightypork/utils/math/constraints/RectCache.java b/src/mightypork/utils/math/constraints/RectCache.java index 9a26b0c..9885fad 100644 --- a/src/mightypork/utils/math/constraints/RectCache.java +++ b/src/mightypork/utils/math/constraints/RectCache.java @@ -4,7 +4,7 @@ package mightypork.utils.math.constraints; import mightypork.gamecore.control.timing.Pollable; import mightypork.gamecore.control.timing.Poller; import mightypork.utils.math.rect.RectMutable; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; /** @@ -42,7 +42,7 @@ public class RectCache implements RectConstraint, Pollable { @Override - public RectValue getRect() + public RectView getRect() { return cached.view(); } diff --git a/src/mightypork/utils/math/constraints/RectConstraint.java b/src/mightypork/utils/math/constraints/RectConstraint.java index 7251239..d7be01f 100644 --- a/src/mightypork/utils/math/constraints/RectConstraint.java +++ b/src/mightypork/utils/math/constraints/RectConstraint.java @@ -1,7 +1,7 @@ package mightypork.utils.math.constraints; -import mightypork.utils.math.rect.RectValue; +import mightypork.utils.math.rect.RectView; /** @@ -14,5 +14,5 @@ public interface RectConstraint { /** * @return rect region */ - RectValue getRect(); + RectView getRect(); } diff --git a/src/mightypork/utils/math/constraints/VecConstraint.java b/src/mightypork/utils/math/constraints/VecConstraint.java deleted file mode 100644 index db7450a..0000000 --- a/src/mightypork/utils/math/constraints/VecConstraint.java +++ /dev/null @@ -1,19 +0,0 @@ -package mightypork.utils.math.constraints; - - -import mightypork.utils.math.coord.VecView; - - -public interface VecConstraint { - - VecView getVec(); - - - NumberConstraint xc(); - - - NumberConstraint yc(); - - - NumberConstraint zc(); -} diff --git a/src/mightypork/utils/math/constraints/VectConstraint.java b/src/mightypork/utils/math/constraints/VectConstraint.java new file mode 100644 index 0000000..fe3015c --- /dev/null +++ b/src/mightypork/utils/math/constraints/VectConstraint.java @@ -0,0 +1,18 @@ +package mightypork.utils.math.constraints; + + +import mightypork.utils.math.vect.VectVal; + + +/** + * Vector constraint. + * + * @author MightyPork + */ +public interface VectConstraint { + + /** + * @return the constraint vec + */ + VectVal getVec(); +} diff --git a/src/mightypork/utils/math/coord/AbstractVec.java b/src/mightypork/utils/math/coord/AbstractVec.java deleted file mode 100644 index f1f2915..0000000 --- a/src/mightypork/utils/math/coord/AbstractVec.java +++ /dev/null @@ -1,188 +0,0 @@ -package mightypork.utils.math.coord; - - -import mightypork.utils.math.constraints.NumberConstraint; - - -public abstract class AbstractVec implements Vec { - - private AbstractVecProxy view; - private NumberConstraint constraintX; - private NumberConstraint constraintY; - private NumberConstraint constraintZ; - - - @Override - public VecView getVec() - { - return view(); - } - - - @Override - public abstract double x(); - - - @Override - public abstract double y(); - - - @Override - public abstract double z(); - - - @Override - public int xi() - { - return (int) Math.round(x()); - } - - - @Override - public int yi() - { - return (int) Math.round(y()); - } - - - @Override - public int zi() - { - return (int) Math.round(z()); - } - - - @Override - public NumberConstraint xc() - { - if (constraintX == null) constraintX = new NumberConstraint() { - - @Override - public double getValue() - { - return x(); - } - }; - - return constraintX; - } - - - @Override - public NumberConstraint yc() - { - if (constraintY == null) constraintY = new NumberConstraint() { - - @Override - public double getValue() - { - return y(); - } - }; - - return constraintY; - } - - - @Override - public NumberConstraint zc() - { - if (constraintZ == null) constraintZ = new NumberConstraint() { - - @Override - public double getValue() - { - return z(); - } - }; - - return constraintZ; - } - - - @Override - public double size() - { - final double x = x(), y = y(), z = z(); - return Math.sqrt(x * x + y * y + z * z); - } - - - @Override - public boolean isZero() - { - return x() == 0 && y() == 0 && z() == 0; - } - - - @Override - public VecView value() - { - return new ConstVec(this); - } - - - @Override - public double distTo(Vec 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 VecView midTo(Vec 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 VecView.make(dx, dy, dz); - } - - - @Override - public VecView vecTo(Vec point) - { - return VecView.make(point.x() - x(), point.y() - y(), point.z() - z()); - } - - - @Override - public VecView cross(Vec vec) - { - //@formatter:off - return VecView.make( - y() * vec.z() - z() * vec.y(), - z() * vec.x() - x() * vec.z(), - x() * vec.y() - y() * vec.x()); - //@formatter:on - } - - - @Override - public double dot(Vec vec) - { - return x() * vec.x() + y() * vec.y() + z() * vec.z(); - } - - - @Override - public VecMutable mutable() - { - return VecMutable.make(this); - } - - - @Override - public VecView view() - { - if (view == null) view = new VecProxy(this); - - return view; - } - -} diff --git a/src/mightypork/utils/math/coord/ConstVec.java b/src/mightypork/utils/math/coord/ConstVec.java deleted file mode 100644 index 8ff7ad4..0000000 --- a/src/mightypork/utils/math/coord/ConstVec.java +++ /dev/null @@ -1,58 +0,0 @@ -package mightypork.utils.math.coord; - - -/** - * Coordinate with immutable numeric values. - * - * @author MightyPork - */ -class ConstVec extends VecView { - - private final double x, y, z; - - - public ConstVec(Vec other) { - this(other.x(), other.y(), other.z()); - } - - - public ConstVec(double x, double y) { - this(x, y, 0); - } - - - public ConstVec(double x, double y, double z) { - this.x = x; - this.y = y; - this.z = z; - } - - - @Override - public double x() - { - return x; - } - - - @Override - public double y() - { - return y; - } - - - @Override - public double z() - { - return z; - } - - - @Override - public VecView value() - { - return this; // it's constant already - } - -} diff --git a/src/mightypork/utils/math/coord/Synths.java b/src/mightypork/utils/math/coord/Synths.java deleted file mode 100644 index a1bd3ad..0000000 --- a/src/mightypork/utils/math/coord/Synths.java +++ /dev/null @@ -1,153 +0,0 @@ -package mightypork.utils.math.coord; - - -public class Synths { - - private static abstract class HeteroSynth extends VecProxy { - - public HeteroSynth(Vec observed) { - super(observed); - } - - - @Override - protected abstract double processX(double x); - - - @Override - protected abstract double processY(double y); - - - @Override - protected abstract double processZ(double z); - } - - private static abstract class UniformSynth extends VecProxy { - - public UniformSynth(Vec observed) { - super(observed); - } - - - @Override - protected double processX(double x) - { - return super.processX(x); - } - - - @Override - protected double processY(double y) - { - return super.processY(y); - } - - - @Override - protected double processZ(double z) - { - return super.processZ(z); - } - - - protected abstract double process(double a); - } - - public static class Round extends UniformSynth { - - public Round(Vec observed) { - super(observed); - } - - - @Override - protected double process(double a) - { - return Math.round(a); - } - } - - public static class Ceil extends UniformSynth { - - public Ceil(Vec observed) { - super(observed); - } - - - @Override - protected double process(double a) - { - return Math.ceil(a); - } - } - - public static class Floor extends UniformSynth { - - public Floor(Vec observed) { - super(observed); - } - - - @Override - protected double process(double a) - { - return Math.floor(a); - } - } - - public static class Neg extends UniformSynth { - - public Neg(Vec observed) { - super(observed); - } - - - @Override - protected double process(double a) - { - return -a; - } - } - - public static class Half extends UniformSynth { - - public Half(Vec observed) { - super(observed); - } - - - @Override - protected double process(double a) - { - return a / 2; - } - } - - public static class Norm extends HeteroSynth { - - public Norm(Vec observed) { - super(observed); - } - - - @Override - protected double processX(double x) - { - return 0; - } - - - @Override - protected double processY(double y) - { - return 0; - } - - - @Override - protected double processZ(double z) - { - return 0; - } - } -} diff --git a/src/mightypork/utils/math/coord/VecView.java b/src/mightypork/utils/math/coord/VecView.java deleted file mode 100644 index 46c6202..0000000 --- a/src/mightypork/utils/math/coord/VecView.java +++ /dev/null @@ -1,177 +0,0 @@ -package mightypork.utils.math.coord; - - -import mightypork.gamecore.control.interf.DefaultImpl; -import mightypork.utils.math.constraints.NumberConstraint; - - -/** - * Read-only coordinate. - * - * @author MightyPork - */ -public abstract class VecView extends VecMath { - - /** - * Get a zero (0,0,0) constant - * - * @return new constant vec - */ - public static VecView zero() - { - return ZERO.view(); - } - - - /** - * Get a one (1,1,1) constant - * - * @return one constant - */ - public static VecView one() - { - return ONE.view(); - } - - - /** - * Make a constant vector - * - * @param x X value - * @param y Y value - * @return new constant vec - */ - public static VecView make(double x, double y) - { - return new ConstVec(x, y); - } - - - /** - * Make a constant vector - * - * @param x X value - * @param y Y value - * @param z Z value - * @return new constant vector - */ - public static VecView make(double x, double y, double z) - { - return new ConstVec(x, y, z); - } - - - /** - * Make a view at number constraints, reflecting their future changes. - * - * @param x X value - * @param y Y value - * @return view at the values - */ - public static VecView make(NumberConstraint x, NumberConstraint y) - { - return new NumConstrVec(x, y); - } - - - /** - * Make a view at number constraints, reflecting their future changes. - * - * @param x X value - * @param y Y value - * @param z Z value - * @return view at the values - */ - public static VecView make(NumberConstraint x, NumberConstraint y, NumberConstraint z) - { - return new NumConstrVec(x, y, z); - } - - // synth views - private VecView view_round; - private VecView view_floor; - private VecView view_ceil; - private VecView view_neg; - private VecView view_half; - - - @Override - public VecView result(double x, double y, double z) - { - return new ConstVec(x, y, z); - } - - - @Override - @Deprecated - public VecView view() - { - return this; // already not mutable - } - - - @Override - public abstract double x(); - - - @Override - public abstract double y(); - - - @Override - @DefaultImpl - public double z() - { - return 0; // implemented for ease with 2D anonymous subtypes - } - - - @Override - public VecView round() - { - // lazy init - if (view_round == null) view_round = new Synths.Round(this); - - return view_round; - } - - - @Override - public VecView floor() - { - // lazy init - if (view_floor == null) view_floor = new Synths.Floor(this); - - return view_floor; - } - - - @Override - public VecView ceil() - { - // lazy init - if (view_ceil == null) view_ceil = new Synths.Ceil(this); - - return view_ceil; - } - - - @Override - public VecView half() - { - // lazy init - if (view_half == null) view_half = new Synths.Half(this); - - return view_half; - } - - - @Override - public VecView neg() - { - // lazy init - if (view_neg == null) view_neg = new Synths.Neg(this); - - return view_neg; - } -} diff --git a/src/mightypork/utils/math/rect/AbstractRect.java b/src/mightypork/utils/math/rect/AbstractRect.java index b507bf0..39d7317 100644 --- a/src/mightypork/utils/math/rect/AbstractRect.java +++ b/src/mightypork/utils/math/rect/AbstractRect.java @@ -2,9 +2,10 @@ package mightypork.utils.math.rect; import static mightypork.utils.math.constraints.Constraints.*; -import mightypork.utils.math.constraints.VecConstraint; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.constraints.VectConstraint; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; /** @@ -14,26 +15,27 @@ import mightypork.utils.math.coord.VecView; */ public abstract class AbstractRect implements Rect { - private VecConstraint tl; - private VecConstraint tc; - private VecConstraint tr; - private VecConstraint cl; - private VecConstraint c; - private VecConstraint cr; - private VecConstraint bl; - private VecConstraint bc; - private VecConstraint br; + private RectProxy proxy; + private VectConstraint tl; + private VectConstraint tc; + private VectConstraint tr; + private VectConstraint cl; + private VectConstraint c; + private VectConstraint cr; + private VectConstraint bl; + private VectConstraint bc; + private VectConstraint br; @Override - public final RectValue getRect() + public final RectView getRect() { return this.view(); } @Override - public final VecView getTopLeft() + public final VectVal getTopLeft() { // lazy init if (tl == null) tl = cTopLeft(this); @@ -42,7 +44,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getTopCenter() + public final VectVal getTopCenter() { // lazy init if (tc == null) tc = cTopCenter(this); @@ -51,7 +53,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getTopRight() + public final VectVal getTopRight() { // lazy init if (tr == null) tr = cTopRight(this); @@ -60,7 +62,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getCenterLeft() + public final VectVal getCenterLeft() { // lazy init if (cl == null) cl = cCenterLeft(this); @@ -69,7 +71,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getCenter() + public final VectVal getCenter() { // lazy init if (c == null) c = cCenter(this); @@ -78,7 +80,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getCenterRight() + public final VectVal getCenterRight() { // lazy init if (cr == null) cr = cCenterRight(this); @@ -87,7 +89,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getBottomLeft() + public final VectVal getBottomLeft() { // lazy init if (bl == null) bl = cBottomLeft(this); @@ -96,7 +98,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getBottomCenter() + public final VectVal getBottomCenter() { // lazy init if (bc == null) bc = cBottomCenter(this); @@ -105,7 +107,7 @@ public abstract class AbstractRect implements Rect { @Override - public final VecView getBottomRight() + public final VectVal getBottomRight() { // lazy init if (br == null) br = cBottomRight(this); @@ -156,28 +158,30 @@ public abstract class AbstractRect implements Rect { @Override - public RectValue view() + public RectProxy view() { - return new RectProxy(this); + if (proxy == null) proxy = new RectProxy(this); + + return proxy; } @Override - public final RectMutable mutable() + public RectMutable mutable() { return RectMutable.make(this); } @Override - public RectValue value() + public RectVal value() { - return RectValue.make(getOrigin(), getSize()); + return RectVal.make(getOrigin(), getSize()); } @Override - public final boolean contains(Vec point) + public final boolean contains(Vect point) { final double x = point.x(); final double y = point.y(); @@ -194,7 +198,7 @@ public abstract class AbstractRect implements Rect { @Override public String toString() { - return String.format("Rect { %s - %s }", getOrigin().toString(), getOrigin().add(getSize())); + return String.format("Rect { %s - %s }", getTopLeft(), getBottomRight()); } } diff --git a/src/mightypork/utils/math/rect/ConstRect.java b/src/mightypork/utils/math/rect/ConstRect.java deleted file mode 100644 index 056c9f0..0000000 --- a/src/mightypork/utils/math/rect/ConstRect.java +++ /dev/null @@ -1,47 +0,0 @@ -package mightypork.utils.math.rect; - - -import mightypork.utils.math.coord.VecView; - - -class ConstRect extends RectValue { - - private final VecView pos; - private final VecView size; - - - /** - * Create at given origin, with given size. - * - * @param x - * @param y - * @param width - * @param height - */ - public ConstRect(double x, double y, double width, double height) { - pos = VecView.make(x, y); - size = VecView.make(Math.abs(width), Math.abs(height)); - } - - - @Override - public ConstRect value() - { - return this; // nothing can change. - } - - - @Override - public VecView getOrigin() - { - return pos; - } - - - @Override - public VecView getSize() - { - return size; - } - -} diff --git a/src/mightypork/utils/math/rect/Rect.java b/src/mightypork/utils/math/rect/Rect.java index 5a7d395..dcc13a2 100644 --- a/src/mightypork/utils/math/rect/Rect.java +++ b/src/mightypork/utils/math/rect/Rect.java @@ -2,8 +2,9 @@ package mightypork.utils.math.rect; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; /** @@ -13,14 +14,14 @@ import mightypork.utils.math.coord.VecView; */ public interface Rect extends RectConstraint { - RectValue ONE = new ConstRect(0, 0, 1, 1); - RectValue ZERO = new ConstRect(0, 0, 0, 0); + RectVal ONE = new RectVal(0, 0, 1, 1); + RectVal ZERO = new RectVal(0, 0, 0, 0); /** * Get a writable copy * - * @return copy + * @return writable copy */ RectMutable mutable(); @@ -30,24 +31,24 @@ public interface Rect extends RectConstraint { * * @return copy */ - RectValue value(); + RectVal value(); /** * Get a proxying view * - * @return copy + * @return proxy */ - RectValue view(); + RectProxy view(); /** * @return origin */ - VecView getOrigin(); + VectVal getOrigin(); - VecView getSize(); + VectVal getSize(); double getWidth(); @@ -56,31 +57,31 @@ public interface Rect extends RectConstraint { double getHeight(); - VecView getTopLeft(); + VectVal getTopLeft(); - VecView getTopCenter(); + VectVal getTopCenter(); - VecView getTopRight(); + VectVal getTopRight(); - VecView getCenterLeft(); + VectVal getCenterLeft(); - VecView getCenter(); + VectVal getCenter(); - VecView getCenterRight(); + VectVal getCenterRight(); - VecView getBottomLeft(); + VectVal getBottomLeft(); - VecView getBottomCenter(); + VectVal getBottomCenter(); - VecView getBottomRight(); + VectVal getBottomRight(); double xMin(); @@ -101,6 +102,6 @@ public interface Rect extends RectConstraint { * @param point point to test * @return is inside */ - boolean contains(Vec point); + boolean contains(Vect point); } diff --git a/src/mightypork/utils/math/rect/RectMath.java b/src/mightypork/utils/math/rect/RectMath.java index 8e41119..5b3c444 100644 --- a/src/mightypork/utils/math/rect/RectMath.java +++ b/src/mightypork/utils/math/rect/RectMath.java @@ -1,7 +1,7 @@ package mightypork.utils.math.rect; -import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.vect.Vect; abstract class RectMath extends AbstractRect { @@ -12,7 +12,7 @@ abstract class RectMath extends AbstractRect { * @param move offset vector * @return result */ - public T move(Vec move) + public T move(Vect move) { return move(move.x(), move.y()); } @@ -35,7 +35,7 @@ abstract class RectMath extends AbstractRect { * @return result */ - public T shrink(Vec shrink) + public T shrink(Vect shrink) { return shrink(shrink.x(), shrink.y()); } @@ -72,7 +72,7 @@ abstract class RectMath extends AbstractRect { * @param grow grow size (added to each side) * @return grown copy */ - public final T grow(Vec grow) + public final T grow(Vect grow) { return grow(grow.x(), grow.y()); } diff --git a/src/mightypork/utils/math/rect/RectMutable.java b/src/mightypork/utils/math/rect/RectMutable.java index 4e4fbc8..40cb8d6 100644 --- a/src/mightypork/utils/math/rect/RectMutable.java +++ b/src/mightypork/utils/math/rect/RectMutable.java @@ -1,8 +1,8 @@ package mightypork.utils.math.rect; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectVal; /** @@ -55,9 +55,9 @@ public abstract class RectMutable extends RectMath { * @param height * @return new mutable rect */ - public static RectMutable make(Vec origin, double width, double height) + public static RectMutable make(Vect origin, double width, double height) { - return make(origin, VecView.make(width, height)); + return make(origin, VectVal.make(width, height)); } @@ -67,9 +67,9 @@ public abstract class RectMutable extends RectMath { * @param size * @return new mutable rect */ - public static RectMutable make(Vec size) + public static RectMutable make(Vect size) { - return make(VecView.zero(), size); + return make(Vect.ZERO, size); } @@ -84,7 +84,7 @@ public abstract class RectMutable extends RectMath { */ public static RectMutable make(double x, double y, double width, double height) { - return make(VecView.make(x, y), VecView.make(width, height)); + return make(x, y, width, height); } @@ -107,9 +107,9 @@ public abstract class RectMutable extends RectMath { * @param size * @return new mutable rect */ - public static RectMutable make(Vec origin, Vec size) + public static RectMutable make(Vect origin, Vect size) { - return new RectMutableImpl(origin, size); + return make(origin.x(), origin.y(), size.x(), size.y()); } @@ -133,9 +133,24 @@ public abstract class RectMutable extends RectMath { * @param height new height * @return this */ - public RectMutable setTo(Vec origin, double width, double height) + public RectMutable setTo(Vect origin, double width, double height) { - return setTo(origin, VecView.make(width, height)); + return setTo(origin, VectVal.make(width, height)); + } + + + /** + * Set to given size and position + * + * @param x origin.x + * @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) + { + return setTo(VectVal.make(x, y), VectVal.make(width, height)); } @@ -146,7 +161,7 @@ public abstract class RectMutable extends RectMath { * @param size new size * @return this */ - public RectMutable setTo(Vec origin, Vec size) + public RectMutable setTo(Vect origin, Vect size) { setOrigin(origin); setSize(size); @@ -160,7 +175,7 @@ public abstract class RectMutable extends RectMath { * @param origin new origin * @return this */ - public abstract RectMutable setOrigin(Vec origin); + public abstract RectMutable setOrigin(Vect origin); /** @@ -169,6 +184,6 @@ public abstract class RectMutable extends RectMath { * @param size new size * @return this */ - public abstract RectMutable setSize(Vec size); + public abstract RectMutable setSize(Vect size); } diff --git a/src/mightypork/utils/math/rect/RectMutableImpl.java b/src/mightypork/utils/math/rect/RectMutableImpl.java index 1ecce8d..55a30f1 100644 --- a/src/mightypork/utils/math/rect/RectMutableImpl.java +++ b/src/mightypork/utils/math/rect/RectMutableImpl.java @@ -1,26 +1,28 @@ package mightypork.utils.math.rect; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecMutable; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectMutable; +import mightypork.utils.math.vect.VectVal; class RectMutableImpl extends RectMutable { - final VecMutable pos = VecMutable.zero(); - final VecMutable size = VecMutable.zero(); + final VectMutable pos = VectMutable.zero(); + final VectMutable size = VectMutable.zero(); /** * Create at given origin, with given size. * - * @param origin - * @param size + * @param x + * @param y + * @param width + * @param height */ - public RectMutableImpl(Vec origin, Vec size) { - this.pos.setTo(origin); - this.size.setTo(size).abs(); + public RectMutableImpl(double x, double y, double width, double height) { + this.pos.setTo(x, y); + this.size.setTo(width, height).abs(); } @@ -32,7 +34,7 @@ class RectMutableImpl extends RectMutable { * @return result */ @Override - public RectMutableImpl move(double x, double y) + public RectMutable move(double x, double y) { pos.add(x, y); return this; @@ -49,7 +51,7 @@ class RectMutableImpl extends RectMutable { * @return result */ @Override - public RectMutableImpl shrink(double left, double right, double top, double bottom) + public RectMutable shrink(double left, double right, double top, double bottom) { pos.add(left, top); size.sub(left + right, top + bottom).abs(); @@ -67,7 +69,7 @@ class RectMutableImpl extends RectMutable { * @return result */ @Override - public RectMutableImpl grow(double left, double right, double top, double bottom) + public RectMutable grow(double left, double right, double top, double bottom) { pos.sub(left, top); size.add(left + right, top + bottom).abs(); @@ -81,7 +83,7 @@ class RectMutableImpl extends RectMutable { * @return result */ @Override - public RectMutableImpl round() + public RectMutable round() { pos.round(); size.round(); @@ -90,21 +92,21 @@ class RectMutableImpl extends RectMutable { @Override - public VecView getOrigin() + public VectVal getOrigin() { - return pos.view(); + return pos.value(); } @Override - public VecView getSize() + public VectVal getSize() { - return size.view(); + return size.value(); } @Override - public RectMutable setOrigin(Vec origin) + public RectMutable setOrigin(Vect origin) { this.pos.setTo(origin); return this; @@ -112,7 +114,7 @@ class RectMutableImpl extends RectMutable { @Override - public RectMutable setSize(Vec size) + public RectMutable setSize(Vect size) { this.size.setTo(size).abs(); return this; diff --git a/src/mightypork/utils/math/rect/RectProxy.java b/src/mightypork/utils/math/rect/RectProxy.java index 35c8406..4b38b2a 100644 --- a/src/mightypork/utils/math/rect/RectProxy.java +++ b/src/mightypork/utils/math/rect/RectProxy.java @@ -1,7 +1,8 @@ package mightypork.utils.math.rect; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; /** @@ -9,7 +10,7 @@ import mightypork.utils.math.coord.VecView; * * @author MightyPork */ -public class RectProxy extends RectValue { +public class RectProxy extends RectView { private final Rect observed; @@ -20,14 +21,14 @@ public class RectProxy extends RectValue { @Override - public VecView getOrigin() + public VectVal getOrigin() { return observed.getOrigin(); } @Override - public VecView getSize() + public VectVal getSize() { return observed.getSize(); } diff --git a/src/mightypork/utils/math/rect/RectVal.java b/src/mightypork/utils/math/rect/RectVal.java new file mode 100644 index 0000000..9d2eb40 --- /dev/null +++ b/src/mightypork/utils/math/rect/RectVal.java @@ -0,0 +1,137 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; + + +public class RectVal extends RectView { + + /** + * Create at 0,0 with zero size + * + * @return new mutable rect + */ + public static RectVal zero() + { + return make(0, 0, 0, 0); + } + + + /** + * Create at 1,1 with zero size + * + * @return new mutable rect + */ + public static RectVal one() + { + return make(0, 0, 1, 1); + } + + + /** + * Create at 0,0 with given size + * + * @param width + * @param height + * @return new mutable rect + */ + public static RectVal make(double width, double height) + { + return make(0, 0, width, height); + } + + + /** + * Create at given origin, with given size. + * + * @param origin + * @param width + * @param height + * @return new mutable rect + */ + public static RectVal make(Vect origin, double width, double height) + { + return make(origin, VectVal.make(width, height)); + } + + + /** + * Create at 0,0 with given size. + * + * @param size + * @return new mutable rect + */ + public static RectVal make(Vect size) + { + return make(Vect.ZERO, size); + } + + + /** + * Create at given origin, with given size. + * + * @param x + * @param y + * @param width + * @param height + * @return new mutable rect + */ + public static RectVal make(double x, double y, double width, double height) + { + return new RectVal(x, y, width, height); + } + + + /** + * Create at given origin, with given size. + * + * @param origin + * @param size + * @return new mutable rect + */ + public static RectVal make(Vect origin, Vect size) + { + return make(origin.x(), origin.y(), size.x(), size.y()); + } + + private final VectVal pos; + private final VectVal size; + + + /** + * Create at given origin, with given size. + * + * @param x + * @param y + * @param width + * @param height + */ + public RectVal(double x, double y, double width, double height) { + pos = VectVal.make(x, y); + size = VectVal.make(width, height); + } + + + @Override + public RectVal value() + { + return this; // nothing can change. + } + + + @Override + public VectVal getOrigin() + { + return pos; + } + + + @Override + public VectVal getSize() + { + return size; + } + +} diff --git a/src/mightypork/utils/math/rect/RectValue.java b/src/mightypork/utils/math/rect/RectValue.java deleted file mode 100644 index 286ea1b..0000000 --- a/src/mightypork/utils/math/rect/RectValue.java +++ /dev/null @@ -1,138 +0,0 @@ -package mightypork.utils.math.rect; - - -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; - - -/** - * Immutable rect - * - * @author MightyPork - */ -public abstract class RectValue extends RectMath { - - /** - * Create at 0,0 with zero size - * - * @return new mutable rect - */ - public static RectValue zero() - { - return make(0, 0, 0, 0); - } - - - /** - * Create at 1,1 with zero size - * - * @return new mutable rect - */ - public static RectValue one() - { - return make(0, 0, 1, 1); - } - - - /** - * Create at 0,0 with given size - * - * @param width - * @param height - * @return new mutable rect - */ - public static RectValue make(double width, double height) - { - return make(0, 0, width, height); - } - - - /** - * Create at given origin, with given size. - * - * @param origin - * @param width - * @param height - * @return new mutable rect - */ - public static RectValue make(Vec origin, double width, double height) - { - return make(origin, VecView.make(width, height)); - } - - - /** - * Create at 0,0 with given size. - * - * @param size - * @return new mutable rect - */ - public static RectValue make(Vec size) - { - return make(VecView.zero(), size); - } - - - /** - * Create at given origin, with given size. - * - * @param x - * @param y - * @param width - * @param height - * @return new mutable rect - */ - public static RectValue make(double x, double y, double width, double height) - { - return new ConstRect(x, y, width, height); - } - - - /** - * Create at given origin, with given size. - * - * @param origin - * @param size - * @return new mutable rect - */ - public static RectValue make(Vec origin, Vec size) - { - return make(origin.x(), origin.y(), size.x(), size.y()); - } - - - @Override - public RectValue move(double x, double y) - { - return RectValue.make(getOrigin().add(x, y), getSize()); - } - - - @Override - public RectValue shrink(double left, double right, double top, double bottom) - { - return RectValue.make(getOrigin().add(left, top), getSize().sub(left + right, top + bottom)); - } - - - @Override - public RectValue grow(double left, double right, double top, double bottom) - { - return RectValue.make(getOrigin().sub(left, top), getSize().add(left + right, top + bottom)); - } - - - @Override - public RectValue round() - { - return RectValue.make(getOrigin().round(), getSize().round()); - } - - - @Override - public RectValue view() - { - return this; - } - -} diff --git a/src/mightypork/utils/math/rect/RectView.java b/src/mightypork/utils/math/rect/RectView.java new file mode 100644 index 0000000..7e08044 --- /dev/null +++ b/src/mightypork/utils/math/rect/RectView.java @@ -0,0 +1,50 @@ +package mightypork.utils.math.rect; + + + + +/** + * Immutable rect + * + * @author MightyPork + */ +public abstract class RectView extends RectMath { + + /** + * Get a proxy at given rect + * + * @param observed observed rect + * @return view + */ + public static RectView make(Rect observed) { + return observed.view(); + } + + @Override + public RectVal move(double x, double y) + { + return RectVal.make(getOrigin().add(x, y), getSize()); + } + + + @Override + public RectVal shrink(double left, double right, double top, double bottom) + { + return RectVal.make(getOrigin().add(left, top), getSize().sub(left + right, top + bottom)); + } + + + @Override + public RectVal grow(double left, double right, double top, double bottom) + { + return RectVal.make(getOrigin().sub(left, top), getSize().add(left + right, top + bottom)); + } + + + @Override + public RectVal round() + { + return RectVal.make(getOrigin().round(), getSize().round()); + } + +} diff --git a/src/mightypork/utils/math/vect/AbstractVect.java b/src/mightypork/utils/math/vect/AbstractVect.java new file mode 100644 index 0000000..0619e9e --- /dev/null +++ b/src/mightypork/utils/math/vect/AbstractVect.java @@ -0,0 +1,219 @@ +package mightypork.utils.math.vect; + + +import mightypork.utils.math.constraints.NumberConstraint; + + +public abstract class AbstractVect implements Vect { + + private VectView proxy; + private NumberConstraint xc; + private NumberConstraint yc; + private NumberConstraint zc; + + + @Override + public final VectVal getVec() + { + return value(); + } + + + @Override + public abstract double x(); + + + @Override + public abstract double y(); + + + @Override + public abstract double z(); + + + @Override + public final int xi() + { + return (int) Math.round(x()); + } + + + @Override + public final int yi() + { + return (int) Math.round(y()); + } + + + @Override + public final int zi() + { + return (int) Math.round(z()); + } + + + @Override + public final NumberConstraint xc() + { + if (xc == null) xc = new NumberConstraint() { + + @Override + public double getValue() + { + return x(); + } + }; + + return xc; + } + + + @Override + public final NumberConstraint yc() + { + if (yc == null) yc = new NumberConstraint() { + + @Override + public double getValue() + { + return y(); + } + }; + + return yc; + } + + + @Override + public final NumberConstraint zc() + { + if (zc == null) zc = new NumberConstraint() { + + @Override + public double getValue() + { + return z(); + } + }; + + return zc; + } + + + @Override + public final double size() + { + final double x = x(), y = y(), z = z(); + return Math.sqrt(x * x + y * y + z * z); + } + + + @Override + public final boolean isZero() + { + return x() == 0 && y() == 0 && z() == 0; + } + + + @Override + public VectVal value() + { + 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 VectMutable mutable() + { + return VectMutable.make(this); + } + + + @Override + public VectView view() + { + if (proxy == null) proxy = new VectProxy(this); + + return proxy; + } + + + + @Override + public int hashCode() + { + final int prime = 31; + int result = 1; + result = prime * result + Double.valueOf(x()).hashCode(); + result = prime * result + Double.valueOf(y()).hashCode(); + result = prime * result + Double.valueOf(z()).hashCode(); + return result; + } + + + @Override + public boolean equals(Object obj) + { + if (this == obj) return true; + if (obj == null) return false; + if (!(obj instanceof Vect)) return false; + final Vect other = (Vect) obj; + + return x() == other.x() && y() == other.y() && z() == other.z(); + } + + + @Override + public String toString() + { + return String.format("(%.1f %.1f %.1f)", x(), y(), z()); + } +} diff --git a/src/mightypork/utils/math/coord/NumConstrVec.java b/src/mightypork/utils/math/vect/NumConstrVect.java similarity index 75% rename from src/mightypork/utils/math/coord/NumConstrVec.java rename to src/mightypork/utils/math/vect/NumConstrVect.java index 6af8773..dcf3454 100644 --- a/src/mightypork/utils/math/coord/NumConstrVec.java +++ b/src/mightypork/utils/math/vect/NumConstrVect.java @@ -1,4 +1,4 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; import mightypork.utils.math.constraints.NumberConstraint; @@ -10,21 +10,21 @@ import mightypork.utils.math.constraints.NumberConstraint; * * @author MightyPork */ -class NumConstrVec extends VecView { +class NumConstrVect extends VectView { private final NumberConstraint constrX; private final NumberConstraint constrY; private final NumberConstraint constrZ; - public NumConstrVec(NumberConstraint x, NumberConstraint y, NumberConstraint z) { + public NumConstrVect(NumberConstraint x, NumberConstraint y, NumberConstraint z) { this.constrX = x; this.constrY = y; this.constrZ = z; } - public NumConstrVec(NumberConstraint x, NumberConstraint y) { + public NumConstrVect(NumberConstraint x, NumberConstraint y) { this.constrX = x; this.constrY = y; this.constrZ = NumberConstraint.ZERO; diff --git a/src/mightypork/utils/math/coord/Vec.java b/src/mightypork/utils/math/vect/Vect.java similarity index 76% rename from src/mightypork/utils/math/coord/Vec.java rename to src/mightypork/utils/math/vect/Vect.java index 748e2cd..203492e 100644 --- a/src/mightypork/utils/math/coord/Vec.java +++ b/src/mightypork/utils/math/vect/Vect.java @@ -1,8 +1,8 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; import mightypork.utils.math.constraints.NumberConstraint; -import mightypork.utils.math.constraints.VecConstraint; +import mightypork.utils.math.constraints.VectConstraint; /** @@ -10,10 +10,10 @@ import mightypork.utils.math.constraints.VecConstraint; * * @author MightyPork */ -public interface Vec extends VecConstraint { +public interface Vect extends VectConstraint { - public static final VecView ZERO = new ConstVec(0, 0, 0); - public static final VecView ONE = new ConstVec(0, 0, 0); + public static final VectVal ZERO = new VectVal(0, 0, 0); + public static final VectVal ONE = new VectVal(0, 0, 0); /** @@ -55,21 +55,18 @@ public interface Vec extends VecConstraint { /** * @return X constraint */ - @Override NumberConstraint xc(); /** * @return Y constraint */ - @Override NumberConstraint yc(); /** * @return Z constraint */ - @Override NumberConstraint zc(); @@ -93,7 +90,7 @@ public interface Vec extends VecConstraint { * @param point other point * @return distance */ - double distTo(Vec point); + double distTo(Vect point); /** @@ -102,7 +99,7 @@ public interface Vec extends VecConstraint { * @param point other point * @return result */ - VecView midTo(Vec point); + VectVal midTo(Vect point); /** @@ -111,7 +108,7 @@ public interface Vec extends VecConstraint { * @param point second point * @return result */ - public VecView vecTo(Vec point); + VectVal vecTo(Vect point); /** @@ -120,7 +117,7 @@ public interface Vec extends VecConstraint { * @param vec other vector * @return result */ - public VecView cross(Vec vec); + VectVal cross(Vect vec); /** @@ -129,7 +126,7 @@ public interface Vec extends VecConstraint { * @param vec other vector * @return dot product */ - public double dot(Vec vec); + double dot(Vect vec); /** @@ -137,7 +134,7 @@ public interface Vec extends VecConstraint { * * @return a immutable copy */ - VecView value(); + VectVal value(); /** @@ -145,7 +142,7 @@ public interface Vec extends VecConstraint { * * @return immutable view */ - VecView view(); + VectView view(); /** @@ -153,5 +150,5 @@ public interface Vec extends VecConstraint { * * @return mutable copy */ - VecMutable mutable(); + VectMutable mutable(); } diff --git a/src/mightypork/utils/math/coord/AbstractVecProxy.java b/src/mightypork/utils/math/vect/VectAdapter.java similarity index 85% rename from src/mightypork/utils/math/coord/AbstractVecProxy.java rename to src/mightypork/utils/math/vect/VectAdapter.java index eecd5e6..0595e31 100644 --- a/src/mightypork/utils/math/coord/AbstractVecProxy.java +++ b/src/mightypork/utils/math/vect/VectAdapter.java @@ -1,13 +1,13 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; -public abstract class AbstractVecProxy extends VecView { +public abstract class VectAdapter extends VectView { /** * @return the proxied coord */ - protected abstract Vec getSource(); - + protected abstract Vect getSource(); + @Override public double x() diff --git a/src/mightypork/utils/math/vect/VectFilters.java b/src/mightypork/utils/math/vect/VectFilters.java new file mode 100644 index 0000000..05d0a37 --- /dev/null +++ b/src/mightypork/utils/math/vect/VectFilters.java @@ -0,0 +1,106 @@ +package mightypork.utils.math.vect; + + +public class VectFilters { + + private static abstract class Uniform extends VectProxy { + + public Uniform(Vect observed) { + super(observed); + } + + + @Override + protected double processX(double x) + { + return super.processX(x); + } + + + @Override + protected double processY(double y) + { + return super.processY(y); + } + + + @Override + protected double processZ(double z) + { + return super.processZ(z); + } + + + protected abstract double process(double a); + } + + public static class Round extends Uniform { + + public Round(Vect observed) { + super(observed); + } + + + @Override + protected double process(double a) + { + return Math.round(a); + } + } + + public static class Ceil extends Uniform { + + public Ceil(Vect observed) { + super(observed); + } + + + @Override + protected double process(double a) + { + return Math.ceil(a); + } + } + + public static class Floor extends Uniform { + + public Floor(Vect observed) { + super(observed); + } + + + @Override + protected double process(double a) + { + return Math.floor(a); + } + } + + public static class Neg extends Uniform { + + public Neg(Vect observed) { + super(observed); + } + + + @Override + protected double process(double a) + { + return -a; + } + } + + public static class Half extends Uniform { + + public Half(Vect observed) { + super(observed); + } + + + @Override + protected double process(double a) + { + return a / 2D; + } + } +} diff --git a/src/mightypork/utils/math/coord/VecMath.java b/src/mightypork/utils/math/vect/VectMath.java similarity index 82% rename from src/mightypork/utils/math/coord/VecMath.java rename to src/mightypork/utils/math/vect/VectMath.java index da17bb7..946bef2 100644 --- a/src/mightypork/utils/math/coord/VecMath.java +++ b/src/mightypork/utils/math/vect/VectMath.java @@ -1,4 +1,4 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; /** @@ -7,7 +7,7 @@ package mightypork.utils.math.coord; * @author MightyPork * @param Return type of methods */ -abstract class VecMath extends AbstractVec { +abstract class VectMath extends AbstractVect { /** *

@@ -79,7 +79,7 @@ abstract class VecMath extends AbstractVec { * @param vec offset * @return result */ - public V add(Vec vec) + public V add(Vect vec) { return add(vec.x(), vec.y(), vec.z()); } @@ -142,7 +142,7 @@ abstract class VecMath extends AbstractVec { * @param vec vector of multipliers * @return result */ - public V mul(Vec vec) + public V mul(Vect vec) { return mul(vec.x(), vec.y(), vec.z()); } @@ -215,7 +215,7 @@ abstract class VecMath extends AbstractVec { * @param vec offset * @return result */ - public V sub(Vec vec) + public V sub(Vect vec) { return sub(vec.x(), vec.y(), vec.z()); } @@ -274,35 +274,4 @@ abstract class VecMath extends AbstractVec { return mul(k); } - - - @Override - public int hashCode() - { - final int prime = 31; - int result = 1; - result = prime * result + Double.valueOf(x()).hashCode(); - result = prime * result + Double.valueOf(y()).hashCode(); - result = prime * result + Double.valueOf(z()).hashCode(); - return result; - } - - - @Override - public boolean equals(Object obj) - { - if (this == obj) return true; - if (obj == null) return false; - if (!(obj instanceof Vec)) return false; - final Vec other = (Vec) obj; - - return x() == other.x() && y() == other.y() && z() == other.z(); - } - - - @Override - public String toString() - { - return String.format("(%.1f %.1f %.1f)", x(), y(), z()); - } } diff --git a/src/mightypork/utils/math/coord/VecMutable.java b/src/mightypork/utils/math/vect/VectMutable.java similarity index 68% rename from src/mightypork/utils/math/coord/VecMutable.java rename to src/mightypork/utils/math/vect/VectMutable.java index b21e8c7..e8102d3 100644 --- a/src/mightypork/utils/math/coord/VecMutable.java +++ b/src/mightypork/utils/math/vect/VectMutable.java @@ -1,4 +1,4 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; import mightypork.utils.math.animation.AnimDouble; @@ -10,14 +10,14 @@ import mightypork.utils.math.animation.Easing; * * @author MightyPork */ -public abstract class VecMutable extends VecMath { - +public abstract class VectMutable extends VectMath { // returns itself on edit + /** * Get a variable initialized as zero (0,0,0) * * @return new mutable vector */ - public static VecMutable zero() + public static VectMutable zero() { return make(ZERO); } @@ -28,7 +28,7 @@ public abstract class VecMutable extends VecMath { * * @return one mutable vector */ - public static VecMutable one() + public static VectMutable one() { return make(ONE); } @@ -41,7 +41,7 @@ public abstract class VecMutable extends VecMath { * @param y Y coordinate * @return mutable vector */ - public static VecMutable make(double x, double y) + public static VectMutable make(double x, double y) { return make(x, y, 0); } @@ -53,7 +53,7 @@ public abstract class VecMutable extends VecMath { * @param copied copied vec * @return mutable vector */ - public static VecMutable make(Vec copied) + public static VectMutable make(Vect copied) { return make(copied.x(), copied.y(), copied.z()); } @@ -67,9 +67,9 @@ public abstract class VecMutable extends VecMath { * @param z Z coordinate * @return mutable vector */ - public static VecMutable make(double x, double y, double z) + public static VectMutable make(double x, double y, double z) { - return new VecMutableImpl(x, y, z); + return new VectMutableImpl(x, y, z); } @@ -82,9 +82,9 @@ public abstract class VecMutable extends VecMath { * @param animZ z animator * @return animated mutable vector */ - public static VecMutableAnim makeAnim(AnimDouble animX, AnimDouble animY, AnimDouble animZ) + public static VectMutableAnim makeAnim(AnimDouble animX, AnimDouble animY, AnimDouble animZ) { - return new VecMutableAnim(animX, animY, animZ); + return new VectMutableAnim(animX, animY, animZ); } @@ -95,9 +95,9 @@ public abstract class VecMutable extends VecMath { * @param easing animation easing * @return animated mutable vector */ - public static VecMutableAnim makeAnim(Vec animStart, Easing easing) + public static VectMutableAnim makeAnim(Vect animStart, Easing easing) { - return new VecMutableAnim(animStart, easing); + return new VectMutableAnim(animStart, easing); } @@ -107,14 +107,14 @@ public abstract class VecMutable extends VecMath { * @param easing animation easing * @return animated mutable vector */ - public static VecMutableAnim makeAnim(Easing easing) + public static VectMutableAnim makeAnim(Easing easing) { - return new VecMutableAnim(Vec.ZERO, easing); + return new VectMutableAnim(Vect.ZERO, easing); } @Override - public abstract VecMutable result(double x, double y, double z); + public abstract VectMutable result(double x, double y, double z); @Override @@ -129,7 +129,7 @@ public abstract class VecMutable extends VecMath { public abstract double z(); - public VecMutable reset() + public VectMutable reset() { return result(0, 0, 0); } @@ -141,7 +141,7 @@ public abstract class VecMutable extends VecMath { * @param copied coord whose coordinates are used * @return result */ - public VecMutable setTo(Vec copied) + public VectMutable setTo(Vect copied) { return result(copied.x(), copied.y(), copied.z()); } @@ -155,7 +155,7 @@ public abstract class VecMutable extends VecMath { * @param y y coordinate * @return result */ - public VecMutable setTo(double x, double y) + public VectMutable setTo(double x, double y) { return result(x, y, z()); } @@ -169,7 +169,7 @@ public abstract class VecMutable extends VecMath { * @param z z coordinate * @return result */ - public VecMutable setTo(double x, double y, double z) + public VectMutable setTo(double x, double y, double z) { return result(x, y, z); } diff --git a/src/mightypork/utils/math/coord/VecMutableAnim.java b/src/mightypork/utils/math/vect/VectMutableAnim.java similarity index 84% rename from src/mightypork/utils/math/coord/VecMutableAnim.java rename to src/mightypork/utils/math/vect/VectMutableAnim.java index 7c02d5c..fb3dc14 100644 --- a/src/mightypork/utils/math/coord/VecMutableAnim.java +++ b/src/mightypork/utils/math/vect/VectMutableAnim.java @@ -1,4 +1,4 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; import mightypork.gamecore.control.timing.Pauseable; @@ -12,20 +12,20 @@ import mightypork.utils.math.animation.Easing; * * @author MightyPork */ -public class VecMutableAnim extends VecMutable implements Pauseable, Updateable { +public class VectMutableAnim extends VectMutable implements Pauseable, Updateable { private final AnimDouble x, y, z; private double defaultDuration = 0; - VecMutableAnim(AnimDouble x, AnimDouble y, AnimDouble z) { + VectMutableAnim(AnimDouble x, AnimDouble y, AnimDouble z) { this.x = x; this.y = y; this.z = z; } - VecMutableAnim(Vec start, Easing easing) { + VectMutableAnim(Vect start, Easing easing) { x = new AnimDouble(start.x(), easing); y = new AnimDouble(start.y(), easing); z = new AnimDouble(start.z(), easing); @@ -74,7 +74,7 @@ public class VecMutableAnim extends VecMutable implements Pauseable, Updateable @Override - public VecMutableAnim result(double x, double y, double z) + public VectMutableAnim result(double x, double y, double z) { this.x.animate(x, defaultDuration); this.y.animate(y, defaultDuration); @@ -84,14 +84,14 @@ public class VecMutableAnim extends VecMutable implements Pauseable, Updateable } - public VecMutableAnim add(Vec offset, double speed) + public VectMutableAnim add(Vect offset, double speed) { animate(view().add(offset), speed); return this; } - public VecMutableAnim animate(double x, double y, double z, double duration) + public VectMutableAnim animate(double x, double y, double z, double duration) { this.x.animate(x, duration); this.y.animate(y, duration); @@ -100,7 +100,7 @@ public class VecMutableAnim extends VecMutable implements Pauseable, Updateable } - public VecMutableAnim animate(Vec target, double duration) + public VectMutableAnim animate(Vect target, double duration) { animate(target.x(), target.y(), target.z(), duration); return this; diff --git a/src/mightypork/utils/math/coord/VecMutableImpl.java b/src/mightypork/utils/math/vect/VectMutableImpl.java similarity index 73% rename from src/mightypork/utils/math/coord/VecMutableImpl.java rename to src/mightypork/utils/math/vect/VectMutableImpl.java index d24b176..12875b2 100644 --- a/src/mightypork/utils/math/coord/VecMutableImpl.java +++ b/src/mightypork/utils/math/vect/VectMutableImpl.java @@ -1,4 +1,4 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; /** @@ -7,7 +7,7 @@ package mightypork.utils.math.coord; * * @author MightyPork */ -class VecMutableImpl extends VecMutable { +class VectMutableImpl extends VectMutable { private double x, y, z; @@ -17,7 +17,7 @@ class VecMutableImpl extends VecMutable { * @param y Y coordinate * @param z Z coordinate */ - public VecMutableImpl(double x, double y, double z) { + public VectMutableImpl(double x, double y, double z) { super(); this.x = x; this.y = y; @@ -47,7 +47,7 @@ class VecMutableImpl extends VecMutable { @Override - public VecMutableImpl result(double x, double y, double z) + public VectMutableImpl result(double x, double y, double z) { this.x = x; this.y = y; diff --git a/src/mightypork/utils/math/coord/VecProxy.java b/src/mightypork/utils/math/vect/VectProxy.java similarity index 65% rename from src/mightypork/utils/math/coord/VecProxy.java rename to src/mightypork/utils/math/vect/VectProxy.java index f0c2642..5cb1b3c 100644 --- a/src/mightypork/utils/math/coord/VecProxy.java +++ b/src/mightypork/utils/math/vect/VectProxy.java @@ -1,4 +1,4 @@ -package mightypork.utils.math.coord; +package mightypork.utils.math.vect; /** @@ -7,9 +7,9 @@ package mightypork.utils.math.coord; * * @author MightyPork */ -class VecProxy extends AbstractVecProxy { +class VectProxy extends VectAdapter { - final Vec observed; + final Vect observed; /** @@ -18,13 +18,13 @@ class VecProxy extends AbstractVecProxy { * * @param observed */ - public VecProxy(Vec observed) { + public VectProxy(Vect observed) { this.observed = observed; } @Override - protected Vec getSource() + protected Vect getSource() { return observed; } diff --git a/src/mightypork/utils/math/vect/VectVal.java b/src/mightypork/utils/math/vect/VectVal.java new file mode 100644 index 0000000..34d28d1 --- /dev/null +++ b/src/mightypork/utils/math/vect/VectVal.java @@ -0,0 +1,97 @@ +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. + * + * @author MightyPork + */ +public final class VectVal extends VectView { + + /** + * Make a constant vector + * + * @param value source vector + * @return new constant vec + */ + public static VectVal make(Vect value) + { + return value.value(); + } + + + /** + * Make a constant vector + * + * @param x X value + * @param y Y value + * @return new constant vec + */ + public static VectVal make(double x, double y) + { + return make(x, y, 0); + } + + + /** + * Make a constant vector + * + * @param x X value + * @param y Y value + * @param z Z value + * @return new constant vector + */ + public static VectVal make(double x, double y, double z) + { + return new VectVal(x, y, z); + } + + private final double x, y, z; + + + protected VectVal(Vect other) { + this(other.x(), other.y(), other.z()); + } + + + protected VectVal(double x, double y, double z) { + this.x = x; + this.y = y; + this.z = z; + } + + + @Override + public double x() + { + return x; + } + + + @Override + public double y() + { + return y; + } + + + @Override + public double z() + { + return z; + } + + + /** + * @deprecated It's constant already. + */ + @Override + @Deprecated + public VectVal value() + { + return this; // it's constant already + } + +} diff --git a/src/mightypork/utils/math/vect/VectView.java b/src/mightypork/utils/math/vect/VectView.java new file mode 100644 index 0000000..b4e6f9e --- /dev/null +++ b/src/mightypork/utils/math/vect/VectView.java @@ -0,0 +1,79 @@ +package mightypork.utils.math.vect; + + +import mightypork.gamecore.control.interf.DefaultImpl; +import mightypork.utils.math.constraints.NumberConstraint; + + +/** + * Read-only coordinate. + * + * @author MightyPork + */ +public abstract class VectView extends VectMath { // returns constant value on edit + + /** + * Make a proxy view at a vector. + * + * @param observed vector to observe + * @return view + */ + public static VectView make(Vect observed) + { + return observed.view(); + } + + + /** + * Make a view at number constraints, reflecting their future changes. + * + * @param xc X value + * @param yc Y value + * @return view at the values + */ + public static VectView make(NumberConstraint xc, NumberConstraint yc) + { + return new NumConstrVect(xc, yc); + } + + + /** + * Make a view at number constraints, reflecting their future changes. + * + * @param xc X value + * @param yc Y value + * @param zc Z value + * @return view at the values + */ + public static VectView make(NumberConstraint xc, NumberConstraint yc, NumberConstraint zc) + { + return new NumConstrVect(xc, yc, zc); + } + + + @Override + public VectVal result(double x, double y, double z) + { + return VectVal.make(x, y, z); + } + + + /** + * @deprecated VecView is not mutable, making a proxy has no effect. + */ + @Override + @Deprecated + public VectView view() + { + return this; // already not mutable + } + + + @Override + @DefaultImpl + public double z() + { + return 0; // implemented for ease with 2D anonymous subtypes + } + +} diff --git a/src/mightypork/utils/objects/Convert.java b/src/mightypork/utils/objects/Convert.java index eecb7d9..ced0cd7 100644 --- a/src/mightypork/utils/objects/Convert.java +++ b/src/mightypork/utils/objects/Convert.java @@ -3,8 +3,9 @@ package mightypork.utils.objects; import mightypork.utils.logging.Log; import mightypork.utils.math.Range; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.vect.Vect; +import mightypork.utils.math.vect.VectVal; +import mightypork.utils.math.vect.VectView; /** @@ -125,8 +126,8 @@ public class Convert { return (Boolean) o ? "True" : "False"; } - if (o instanceof Vec) { - final Vec c = (Vec) o; + if (o instanceof Vect) { + final Vect c = (Vect) o; return String.format("[%f;%f;%f]", c.x(), c.y(), c.z()); } @@ -144,18 +145,17 @@ public class Convert { /** - * Get COORD
- * Converts special constants to magic coordinate instances. + * Get a vector * * @param o object * @param def default value - * @return AiCoord + * @return vector */ - public static VecView toCoord(Object o, Vec def) + public static VectVal toVect(Object o, Vect def) { try { if (o == null) return def.value(); - if (o instanceof Vec) return ((Vec) o).value(); + if (o instanceof Vect) return ((Vect) o).value(); if (o instanceof String) { String s = ((String) o).trim().toUpperCase(); @@ -171,12 +171,12 @@ public class Convert { final double y = Double.parseDouble(parts[1].trim()); if (parts.length == 2) { - return VecView.make(x, y); + return VectVal.make(x, y); } final double z = Double.parseDouble(parts[2].trim()); - return VecView.make(x, y, z); + return VectVal.make(x, y, z); } } } catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) { @@ -289,9 +289,9 @@ public class Convert { * @param o object * @return Coord */ - public static VecView toCoord(Object o) + public static VectView toCoord(Object o) { - return toCoord(o, VecView.zero()); + return toVect(o, Vect.ZERO); }