diff --git a/src/mightypork/gamecore/audio/SoundSystem.java b/src/mightypork/gamecore/audio/SoundSystem.java index c42c878..7d7c7a4 100644 --- a/src/mightypork/gamecore/audio/SoundSystem.java +++ b/src/mightypork/gamecore/audio/SoundSystem.java @@ -32,7 +32,7 @@ public class SoundSystem extends RootBusNode implements Updateable { private static final Vec INITIAL_LISTENER_POS = Vec.ZERO; private static final int MAX_SOURCES = 256; - private static VecMutable listener = new MutableCoord(0,0,0); + private static VecMutable listener = new MutableCoord(0, 0, 0); private static boolean inited; diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderable.java b/src/mightypork/gamecore/gui/components/PluggableRenderable.java index 6091ca8..3255a64 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.PluggableContext; import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.rect.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -18,7 +18,7 @@ public interface PluggableRenderable extends Renderable, PluggableContext { @Override - Rect getRect(); + RectView getRect(); @Override diff --git a/src/mightypork/gamecore/gui/components/PluggableRenderer.java b/src/mightypork/gamecore/gui/components/PluggableRenderer.java index 5298bee..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.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -18,7 +18,7 @@ public abstract class PluggableRenderer extends ContextAdapter implements Plugga @Override - public Rect 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 c7866fa..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.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -60,7 +60,7 @@ public abstract class ElementHolder extends BusNode implements PluggableRenderab @Override - public Rect 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 e1729dd..2384b47 100644 --- a/src/mightypork/gamecore/gui/components/painters/TextPainter.java +++ b/src/mightypork/gamecore/gui/components/painters/TextPainter.java @@ -6,11 +6,10 @@ 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.CoordValue; import mightypork.utils.math.coord.MutableCoord; import mightypork.utils.math.coord.Vec; import mightypork.utils.math.coord.VecMutable; -import mightypork.utils.math.rect.Rect; +import mightypork.utils.math.rect.RectView; import mightypork.utils.string.StringProvider; import mightypork.utils.string.StringProvider.StringWrapper; @@ -31,7 +30,7 @@ public class TextPainter extends PluggableRenderer { private boolean shadow; private RGB shadowColor = RGB.BLACK; - private VecMutable shadowOffset = new MutableCoord(1, 1); + private final VecMutable shadowOffset = new MutableCoord(1, 1); /** @@ -87,7 +86,7 @@ public class TextPainter extends PluggableRenderer { if (text == null) return; final String str = text.getString(); - final Rect rect = getRect(); + final RectView rect = getRect(); if (shadow) { font.draw(str, rect.move(shadowOffset), align, shadowColor); diff --git a/src/mightypork/gamecore/gui/screens/Screen.java b/src/mightypork/gamecore/gui/screens/Screen.java index 324a70b..ed7a3e2 100644 --- a/src/mightypork/gamecore/gui/screens/Screen.java +++ b/src/mightypork/gamecore/gui/screens/Screen.java @@ -12,7 +12,7 @@ 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.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind @Override - public Rect getRect() + public RectView getRect() { return getDisplay().getRect(); } diff --git a/src/mightypork/gamecore/gui/screens/ScreenLayer.java b/src/mightypork/gamecore/gui/screens/ScreenLayer.java index 4023283..39d3028 100644 --- a/src/mightypork/gamecore/gui/screens/ScreenLayer.java +++ b/src/mightypork/gamecore/gui/screens/ScreenLayer.java @@ -1,7 +1,6 @@ package mightypork.gamecore.gui.screens; -import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppSubModule; import mightypork.gamecore.control.interf.DefaultImpl; import mightypork.gamecore.gui.components.Renderable; @@ -10,7 +9,7 @@ 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.rect.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -60,7 +59,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable list = new ArrayList<>(); try { - for (File f : dir.listFiles(filter)) { + for (final File f : dir.listFiles(filter)) { list.add(f); } } catch (final Exception e) { @@ -361,7 +361,7 @@ public class FileUtils { */ public static void stringToFile(File file, String text) throws IOException { - try (PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) { + try(PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) { out.print(text); @@ -482,8 +482,8 @@ public class FileUtils { */ public static void resourceToFile(String resname, File file) throws IOException { - try ( InputStream in = FileUtils.getResource(resname); - OutputStream out = new FileOutputStream(file)) { + try(InputStream in = FileUtils.getResource(resname); + OutputStream out = new FileOutputStream(file)) { FileUtils.copyStream(in, out); } @@ -500,7 +500,7 @@ public class FileUtils { */ public static String resourceToString(String resname) throws IOException { - try (InputStream in = FileUtils.getResource(resname)) { + try(InputStream in = FileUtils.getResource(resname)) { return streamToString(in); } } diff --git a/src/mightypork/utils/files/ZipBuilder.java b/src/mightypork/utils/files/ZipBuilder.java index 360a517..abfa0e2 100644 --- a/src/mightypork/utils/files/ZipBuilder.java +++ b/src/mightypork/utils/files/ZipBuilder.java @@ -70,7 +70,7 @@ public class ZipBuilder { out.putNextEntry(new ZipEntry(path)); - try (InputStream in = FileUtils.stringToStream(text)) { + try(InputStream in = FileUtils.stringToStream(text)) { FileUtils.copyStream(in, out); } } @@ -91,7 +91,7 @@ public class ZipBuilder { out.putNextEntry(new ZipEntry(path)); - try (InputStream in = FileUtils.getResource(resPath)) { + try(InputStream in = FileUtils.getResource(resPath)) { FileUtils.copyStream(in, out); } } diff --git a/src/mightypork/utils/files/ZipUtils.java b/src/mightypork/utils/files/ZipUtils.java index d279f68..a0e2f94 100644 --- a/src/mightypork/utils/files/ZipUtils.java +++ b/src/mightypork/utils/files/ZipUtils.java @@ -32,7 +32,7 @@ public class ZipUtils { */ public static List extractZip(File file, File outputDir, StringFilter filter) throws IOException { - try (ZipFile zip = new ZipFile(file)) { + try(ZipFile zip = new ZipFile(file)) { return extractZip(zip, outputDir, filter); } } @@ -88,7 +88,7 @@ public class ZipUtils { */ public static List listZip(File zipFile) throws IOException { - try (ZipFile zip = new ZipFile(zipFile)) { + try(ZipFile zip = new ZipFile(zipFile)) { return listZip(zip); } } @@ -132,10 +132,10 @@ public class ZipUtils { { destFile.getParentFile().mkdirs(); - try ( InputStream in = zip.getInputStream(entry); - BufferedInputStream is = new BufferedInputStream(in); - FileOutputStream fos = new FileOutputStream(destFile); - BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) { + try(InputStream in = zip.getInputStream(entry); + BufferedInputStream is = new BufferedInputStream(in); + FileOutputStream fos = new FileOutputStream(destFile); + BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) { FileUtils.copyStream(is, dest); } @@ -169,7 +169,7 @@ public class ZipUtils { public static boolean entryExists(File selectedFile, String string) { - try (ZipFile zf = new ZipFile(selectedFile)) { + try(ZipFile zf = new ZipFile(selectedFile)) { return zf.getEntry(string) != null; } catch (final Exception e) { return false; diff --git a/src/mightypork/utils/files/ion/Ion.java b/src/mightypork/utils/files/ion/Ion.java index def0264..a65b0f6 100644 --- a/src/mightypork/utils/files/ion/Ion.java +++ b/src/mightypork/utils/files/ion/Ion.java @@ -67,7 +67,7 @@ public class Ion { */ public static Object fromFile(File file) throws IonException { - try (InputStream in = new FileInputStream(file)) { + try(InputStream in = new FileInputStream(file)) { final Object obj = fromStream(in); return obj; @@ -113,7 +113,7 @@ public class Ion { */ public static void toFile(File path, Object obj) throws IonException { - try (OutputStream out = new FileOutputStream(path)) { + try(OutputStream out = new FileOutputStream(path)) { final String f = path.toString(); final File dir = new File(f.substring(0, f.lastIndexOf(File.separator))); diff --git a/src/mightypork/utils/math/Polar.java b/src/mightypork/utils/math/Polar.java index aa4f62a..efe8e14 100644 --- a/src/mightypork/utils/math/Polar.java +++ b/src/mightypork/utils/math/Polar.java @@ -5,8 +5,8 @@ import mightypork.utils.math.Calc.Deg; import mightypork.utils.math.Calc.Rad; import mightypork.utils.math.constraints.NumberConstraint; import mightypork.utils.math.coord.ConstraintCoord; -import mightypork.utils.math.coord.CoordProxy; import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.coord.VecView; /** @@ -137,7 +137,7 @@ public class Polar { * * @return coord */ - public CoordProxy toCoord() + public VecView toCoord() { // lazy init if (coord == null) { @@ -158,7 +158,7 @@ public class Polar { }); } - return coord.view(); + return coord; } diff --git a/src/mightypork/utils/math/Range.java b/src/mightypork/utils/math/Range.java index 860e016..2b21861 100644 --- a/src/mightypork/utils/math/Range.java +++ b/src/mightypork/utils/math/Range.java @@ -24,7 +24,6 @@ public class Range { } - /** * Create new range * @@ -48,10 +47,12 @@ public class Range { this.max = minmax; } + /** * Make sure min is <= max */ - private void norm() { + private void norm() + { if (min > max) { final double t = min; min = max; @@ -167,7 +168,7 @@ public class Range { * @param max max value */ public void setTo(double min, double max) - { + { this.min = min; this.max = max; norm(); diff --git a/src/mightypork/utils/math/animation/AnimDouble.java b/src/mightypork/utils/math/animation/AnimDouble.java index de54cc3..1ce264a 100644 --- a/src/mightypork/utils/math/animation/AnimDouble.java +++ b/src/mightypork/utils/math/animation/AnimDouble.java @@ -88,7 +88,7 @@ public class AnimDouble implements Updateable, Pauseable, NumberConstraint { * * @return number */ - public double getGetStart() + public double getStart() { return from; } @@ -105,6 +105,18 @@ public class AnimDouble implements Updateable, Pauseable, NumberConstraint { } + public double getDuration() + { + return duration; + } + + + public double getElapsed() + { + return elapsedTime; + } + + /** * Get value at delta time * @@ -139,7 +151,7 @@ public class AnimDouble implements Updateable, Pauseable, NumberConstraint { @Override public void update(double delta) { - if (paused) return; + if (paused || isFinished()) return; elapsedTime = Calc.clampd(elapsedTime + delta, 0, duration); if (isFinished()) { diff --git a/src/mightypork/utils/math/constraints/Constraints.java b/src/mightypork/utils/math/constraints/Constraints.java index 8624f2b..de80327 100644 --- a/src/mightypork/utils/math/constraints/Constraints.java +++ b/src/mightypork/utils/math/constraints/Constraints.java @@ -4,8 +4,13 @@ package mightypork.utils.math.constraints; import mightypork.gamecore.control.timing.Poller; import mightypork.gamecore.input.InputSystem; import mightypork.gamecore.render.DisplaySystem; -import mightypork.utils.math.coord.*; +import mightypork.utils.math.coord.FixedCoord; +import mightypork.utils.math.coord.SynthCoord3D; +import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.coord.VecView; +import mightypork.utils.math.rect.FixedRect; import mightypork.utils.math.rect.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -16,54 +21,79 @@ import mightypork.utils.math.rect.Rect; */ public class Constraints { - /* ================= Variables ================= */ + public static RectCache _cache(final RectConstraint rc) + { + return new RectCache(rc); + } - public static final NumberConstraint _mouseX = new NumberConstraint() { - - @Override - public double getValue() - { - return InputSystem.getMousePos().x(); - } - }; - public static final NumberConstraint _mouseY = new NumberConstraint() { + public static RectCache _cache(final Poller poller, final RectConstraint rc) + { + return new RectCache(poller, rc); + } + + + /** + * Convert {@link Number} to {@link NumberConstraint} if needed + * + * @param o unknown numeric value + * @return converted + */ + public static NumberConstraint _n(final Object o) + { + if (o instanceof NumberConstraint) return (NumberConstraint) o; - @Override - public double getValue() - { - return InputSystem.getMousePos().y(); - } - }; - public static final NumberConstraint _mousePos = new NumberConstraint() { + if (o instanceof Number) return new NumberConstraint() { + + @Override + public double getValue() + { + return ((Number) o).doubleValue(); + } + }; - @Override - public double getValue() - { - return InputSystem.getMousePos().y(); - } - }; + throw new IllegalArgumentException("Invalid numeric type."); + } - public static final NumberConstraint _screenW = new NumberConstraint() { - - @Override - public double getValue() - { - return DisplaySystem.getWidth(); - } - }; - public static final NumberConstraint _screenH = new NumberConstraint() { - - @Override - public double getValue() - { - return DisplaySystem.getHeight(); - } - }; + /** + * Convert {@link Number} or {@link NumberConstraint} to double (current + * value) + * + * @param o unknown numeric value + * @return double value + */ + static double toDouble(final Object o) + { + return _n(o).getValue(); + } - /* ================= Arithmetics ================= */ + /** + * Convert {@link VecConstraint} to {@link VecArith}. + * + * @param o unknown numeric value + * @return double value + */ + static VecView vec(final VecConstraint o) + { + return o.getVec(); + } + + + /** + * Convert {@link RectConstraint} to {@link Rect}. + * + * @param o unknown numeric value + * @return double value + */ + static RectView toRect(final RectConstraint o) + { + return o.getRect(); + } + + + // =================== Number constraints ==================== public static NumberConstraint _min(final Object a, final Object b) { @@ -72,7 +102,7 @@ public class Constraints { @Override public double getValue() { - return Math.min(num(a), num(b)); + return Math.min(toDouble(a), toDouble(b)); } }; } @@ -85,7 +115,7 @@ public class Constraints { @Override public double getValue() { - return Math.max(num(a), num(b)); + return Math.max(toDouble(a), toDouble(b)); } }; } @@ -135,9 +165,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).round(); + return toRect(r).round(); } }; } @@ -189,7 +219,7 @@ public class Constraints { @Override public double getValue() { - return num(a) + num(b); + return toDouble(a) + toDouble(b); } }; } @@ -202,7 +232,7 @@ public class Constraints { @Override public double getValue() { - return num(a) - num(b); + return toDouble(a) - toDouble(b); } }; } @@ -215,7 +245,7 @@ public class Constraints { @Override public double getValue() { - return num(a) * num(b); + return toDouble(a) * toDouble(b); } }; } @@ -234,7 +264,7 @@ public class Constraints { @Override public double getValue() { - return num(a) / num(b); + return toDouble(a) / toDouble(b); } }; } @@ -247,28 +277,26 @@ public class Constraints { @Override public double getValue() { - return num(whole) * (num(percent) / 100); + return toDouble(whole) * (toDouble(percent) / 100); } }; } - /* ================= Layout utilities ================= */ - public static RectConstraint _row(final RectConstraint r, final int rows, final int index) { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final double height = rect(r).getHeight(); + final double height = toRect(r).getHeight(); final double perRow = height / rows; - final Vec origin = rect(r).getOrigin().add(0, perRow * index); - final Vec size = rect(r).getSize().setY(perRow); + final Vec origin = toRect(r).getOrigin().add(0, perRow * index); + final Vec size = toRect(r).getSize().setY(perRow); - return new Rect(origin, size); + return new FixedRect(origin, size); } }; } @@ -279,15 +307,15 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final double width = rect(r).getWidth(); + final double width = toRect(r).getWidth(); final double perCol = width / columns; - final Vec origin = rect(r).getOrigin().add(perCol * index, 0); - final Vec size = rect(r).getSize().setX(perCol); + final Vec origin = toRect(r).getOrigin().add(perCol * index, 0); + final Vec size = toRect(r).getSize().setX(perCol); - return new Rect(origin, size); + return new FixedRect(origin, size); } }; } @@ -298,22 +326,22 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final double height = rect(r).getHeight(); - final double width = rect(r).getHeight(); + final double height = toRect(r).getHeight(); + final double width = toRect(r).getHeight(); final double perRow = height / rows; final double perCol = width / cols; - final Vec origin = rect(r).getOrigin().add(perCol * left, perRow * (rows - top - 1)); + final Vec origin = toRect(r).getOrigin().add(perCol * left, perRow * (rows - top - 1)); - return new Rect(origin, perCol, perRow); + return new FixedRect(origin, perCol, perRow); } }; } - /* ================= Rect manipulation ================= */ + /* ================= RectView manipulation ================= */ public static RectConstraint _shrink(RectConstraint r, Object shrink) { @@ -333,9 +361,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(num(left), num(top), num(right), num(bottom)); + return toRect(r).shrink(toDouble(left), toDouble(top), toDouble(right), toDouble(bottom)); } }; } @@ -346,9 +374,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(0, num(shrink), 0, 0); + return toRect(r).shrink(0, toDouble(shrink), 0, 0); } }; } @@ -359,9 +387,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(0, 0, 0, num(shrink)); + return toRect(r).shrink(0, 0, 0, toDouble(shrink)); } }; } @@ -372,9 +400,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(num(shrink), 0, 0, 0); + return toRect(r).shrink(toDouble(shrink), 0, 0, 0); } }; } @@ -385,9 +413,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(0, 0, num(shrink), 0); + return toRect(r).shrink(0, 0, toDouble(shrink), 0); } }; } @@ -411,9 +439,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).grow(num(left), num(top), num(right), num(bottom)); + return toRect(r).grow(toDouble(left), toDouble(top), toDouble(right), toDouble(bottom)); } }; } @@ -424,9 +452,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).grow(0, num(grow), 0, 0); + return toRect(r).grow(0, toDouble(grow), 0, 0); } }; } @@ -437,9 +465,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).grow(0, 0, 0, num(grow)); + return toRect(r).grow(0, 0, 0, toDouble(grow)); } }; } @@ -450,9 +478,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).grow(num(grow), 0, 0, 0); + return toRect(r).grow(toDouble(grow), 0, 0, 0); } }; } @@ -463,9 +491,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).grow(0, 0, num(grow), 0); + return toRect(r).grow(0, 0, toDouble(grow), 0); } }; } @@ -484,9 +512,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return new Rect(vec(origin), num(width), num(height)); + return new FixedRect(vec(origin), toDouble(width), toDouble(height)); } }; } @@ -497,9 +525,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return new Rect(0, 0, num(width), num(height)); + return new FixedRect(0, 0, toDouble(width), toDouble(height)); } }; } @@ -510,11 +538,11 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final Vec origin = rect(r).getOrigin(); + final Vec origin = toRect(r).getOrigin(); - return new Rect(origin.x(), origin.y(), num(width), num(height)); + return new FixedRect(origin.x(), origin.y(), toDouble(width), toDouble(height)); } }; } @@ -525,11 +553,11 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final Vec origin = rect(r).getOrigin(); + final Vec origin = toRect(r).getOrigin(); - return new Rect(origin.x() + num(x), origin.y() + num(y), num(width), num(height)); + return new FixedRect(origin.x() + toDouble(x), origin.y() + toDouble(y), toDouble(width), toDouble(height)); } }; } @@ -540,11 +568,11 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final VecView origin = rect(r).getOrigin(); + final VecView origin = toRect(r).getOrigin(); - return new Rect(origin.add(num(left), num(top)), origin.add(num(right), num(bottom))); + return new FixedRect(origin.add(toDouble(left), toDouble(top)), origin.add(toDouble(right), toDouble(bottom))); } }; } @@ -555,12 +583,12 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final VecView size = rect(r).getSize(); + final VecView size = toRect(r).getSize(); final VecView center = centerTo.getRect().getCenter(); - return new Rect(center.sub(size.half()), size); + return new FixedRect(center.sub(size.half()), size); } }; } @@ -571,15 +599,16 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - VecView size = rect(r).getSize(); + final VecView size = toRect(r).getSize(); - return new Rect(vec(centerTo).sub(size.half()), size); + return new FixedRect(vec(centerTo).sub(size.half()), size); } }; } + public static RectConstraint _align(final RectConstraint r, final Vec centerTo) { return _align(r, new VecWrapper(centerTo)); @@ -591,12 +620,12 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - final VecView size = rect(r).getSize(); - final VecView v = new CoordValue(num(x), num(y)); + final VecView size = toRect(r).getSize(); + final VecView v = new FixedCoord(toDouble(x), toDouble(y)); - return new Rect(v.sub(size.half()), size); + return new FixedRect(v.sub(size.half()), size); } }; } @@ -607,11 +636,11 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - Vec v = move.getVec(); + final Vec v = move.getVec(); - return rect(r).move(v); + return toRect(r).move(v); } }; } @@ -622,24 +651,24 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).move(num(x), num(y)); + return toRect(r).move(toDouble(x), toDouble(y)); } }; } - /* ================= Rect bounds ================= */ + /* ================= RectView bounds ================= */ public static RectConstraint _left_edge(final RectConstraint r) { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(0, 0, rect(r).getWidth(), 0); + return toRect(r).shrink(0, 0, toRect(r).getWidth(), 0); } }; } @@ -650,9 +679,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(0, 0, 0, rect(r).getHeight()); + return toRect(r).shrink(0, 0, 0, toRect(r).getHeight()); } }; } @@ -663,9 +692,9 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(rect(r).getWidth(), 0, 0, 0); + return toRect(r).shrink(toRect(r).getWidth(), 0, 0, 0); } }; } @@ -676,16 +705,14 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - return rect(r).shrink(0, rect(r).getHeight(), 0, 0); + return toRect(r).shrink(0, toRect(r).getHeight(), 0, 0); } }; } - /* ================= Coords ================= */ - public static NumberConstraint _x(final VecConstraint c) { return new NumberConstraint() { @@ -780,21 +807,21 @@ public class Constraints { @Override public double x() { - return vec(c).x() + num(x); + return vec(c).x() + toDouble(x); } @Override public double y() { - return vec(c).y() + num(y); + return vec(c).y() + toDouble(y); } @Override public double z() { - return vec(c).z() + num(z); + return vec(c).z() + toDouble(z); } }); @@ -844,21 +871,21 @@ public class Constraints { @Override public double x() { - return vec(c).x() - num(x); + return vec(c).x() - toDouble(x); } @Override public double y() { - return vec(c).y() - num(y); + return vec(c).y() - toDouble(y); } @Override public double z() { - return vec(c).z() - num(z); + return vec(c).z() - toDouble(z); } }); @@ -874,21 +901,21 @@ public class Constraints { @Override public double x() { - return vec(c).x() * num(mul); + return vec(c).x() * toDouble(mul); } @Override public double y() { - return vec(c).y() * num(mul); + return vec(c).y() * toDouble(mul); } @Override public double z() { - return vec(c).z() * num(mul); + return vec(c).z() * toDouble(mul); } }); @@ -904,7 +931,7 @@ public class Constraints { @Override public VecView getVec() { - return rect(r).getOrigin(); + return toRect(r).getOrigin(); } }; } @@ -917,7 +944,7 @@ public class Constraints { @Override public VecView getVec() { - return rect(r).getSize(); + return toRect(r).getSize(); } }; } @@ -990,7 +1017,7 @@ public class Constraints { /** - * Zero-sized rect at given coord + * Zero-sized RectView at given coord * * @param c coord * @return rect @@ -1000,11 +1027,11 @@ public class Constraints { return new RectConstraint() { @Override - public Rect getRect() + public RectView getRect() { - Vec v = vec(c); + final Vec v = vec(c); - return new Rect(v.x(), v.y(), 0, 0); + return new FixedRect(v.x(), v.y(), 0, 0); } }; } @@ -1041,7 +1068,61 @@ public class Constraints { } }; } - /* ================= Coords ================= */ + + /* ================= Variables ================= */ + + public static final NumberConstraint _mouseX = new NumberConstraint() { + + @Override + public double getValue() + { + return InputSystem.getMousePos().x(); + } + }; + + public static final NumberConstraint _mouseY = new NumberConstraint() { + + @Override + public double getValue() + { + return InputSystem.getMousePos().y(); + } + }; + public static final NumberConstraint _mousePos = new NumberConstraint() { + + @Override + public double getValue() + { + return InputSystem.getMousePos().y(); + } + }; + + public static final NumberConstraint _screenW = new NumberConstraint() { + + @Override + public double getValue() + { + return DisplaySystem.getWidth(); + } + }; + + public static final NumberConstraint _screenH = new NumberConstraint() { + + @Override + public double getValue() + { + return DisplaySystem.getHeight(); + } + }; + + + /* ================= Arithmetics ================= */ + + /* ================= Layout utilities ================= */ + + /* ================= Coords ================= */ + + /* ================= Coords ================= */ public static NumberConstraint _x(final Vec c) { @@ -1116,21 +1197,21 @@ public class Constraints { @Override public double x() { - return c.x() + num(x); + return c.x() + toDouble(x); } @Override public double y() { - return c.y() + num(y); + return c.y() + toDouble(y); } @Override public double z() { - return c.z() + num(z); + return c.z() + toDouble(z); } }; @@ -1180,21 +1261,21 @@ public class Constraints { @Override public double x() { - return c.x() - num(x); + return c.x() - toDouble(x); } @Override public double y() { - return c.y() - num(y); + return c.y() - toDouble(y); } @Override public double z() { - return c.z() - num(z); + return c.z() - toDouble(z); } }; @@ -1210,35 +1291,36 @@ public class Constraints { @Override public double x() { - return c.x() * num(mul); + return c.x() * toDouble(mul); } @Override public double y() { - return c.y() * num(mul); + return c.y() * toDouble(mul); } @Override public double z() { - return c.z() * num(mul); + return c.z() * toDouble(mul); } }; } - + + public static VecView _origin(final Rect r) { - return r.getOrigin().view(); + return r.getOrigin(); } public static VecView _size(final Rect r) { - return r.getSize().view(); + return r.getSize(); } @@ -1306,78 +1388,4 @@ public class Constraints { { return _add(_origin(r), _width(r), _half(_height(r))); } - - /* ================= Helpers ================= */ - - public static RectCache _cache(final RectConstraint rc) - { - return new RectCache(rc); - } - - - public static RectCache _cache(final Poller poller, final RectConstraint rc) - { - return new RectCache(poller, rc); - } - - - /** - * Convert {@link Number} to {@link NumberConstraint} if needed - * - * @param o unknown numeric value - * @return converted - */ - public static NumberConstraint _n(final Object o) - { - if (o instanceof NumberConstraint) return (NumberConstraint) o; - - if (o instanceof Number) return new NumberConstraint() { - - @Override - public double getValue() - { - return ((Number) o).doubleValue(); - } - }; - - throw new IllegalArgumentException("Invalid numeric type."); - } - - - /** - * Convert {@link Number} or {@link NumberConstraint} to double (current - * value) - * - * @param o unknown numeric value - * @return double value - */ - private static double num(final Object o) - { - return _n(o).getValue(); - } - - - /** - * Convert {@link VecConstraint} to {@link VecArith}. - * - * @param o unknown numeric value - * @return double value - */ - private static VecView vec(final VecConstraint o) - { - return o.getVec(); - } - - - /** - * Convert {@link RectConstraint} to {@link Rect}. - * - * @param o unknown numeric value - * @return double value - */ - private static Rect rect(final RectConstraint o) - { - return o.getRect(); - } - } diff --git a/src/mightypork/utils/math/constraints/ContextAdapter.java b/src/mightypork/utils/math/constraints/ContextAdapter.java index bae71e8..bb5250c 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.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -22,7 +22,7 @@ public abstract class ContextAdapter implements PluggableContext { @Override - public Rect getRect() + public RectView getRect() { return backing.getRect(); } diff --git a/src/mightypork/utils/math/constraints/NumberConstraint.java b/src/mightypork/utils/math/constraints/NumberConstraint.java index 137e564..e127fe8 100644 --- a/src/mightypork/utils/math/constraints/NumberConstraint.java +++ b/src/mightypork/utils/math/constraints/NumberConstraint.java @@ -16,7 +16,7 @@ public interface NumberConstraint { return 0; } }; - + public static final NumberConstraint ONE = new NumberConstraint() { @Override @@ -26,6 +26,7 @@ public interface NumberConstraint { } }; + /** * @return current value */ diff --git a/src/mightypork/utils/math/constraints/PluggableContext.java b/src/mightypork/utils/math/constraints/PluggableContext.java index 869b5ad..cb1ed35 100644 --- a/src/mightypork/utils/math/constraints/PluggableContext.java +++ b/src/mightypork/utils/math/constraints/PluggableContext.java @@ -1,7 +1,7 @@ package mightypork.utils.math.constraints; -import mightypork.utils.math.rect.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -18,6 +18,6 @@ public interface PluggableContext extends RectConstraint { @Override - abstract Rect getRect(); + abstract RectView getRect(); } diff --git a/src/mightypork/utils/math/constraints/RectCache.java b/src/mightypork/utils/math/constraints/RectCache.java index 51feefb..2434d34 100644 --- a/src/mightypork/utils/math/constraints/RectCache.java +++ b/src/mightypork/utils/math/constraints/RectCache.java @@ -3,7 +3,8 @@ package mightypork.utils.math.constraints; import mightypork.gamecore.control.timing.Pollable; import mightypork.gamecore.control.timing.Poller; -import mightypork.utils.math.rect.Rect; +import mightypork.utils.math.rect.MutableRect; +import mightypork.utils.math.rect.RectView; /** @@ -16,7 +17,7 @@ import mightypork.utils.math.rect.Rect; public class RectCache implements RectConstraint, Pollable { private final RectConstraint observed; - private final Rect cached = new Rect(); + private final MutableRect cached = new MutableRect(); /** @@ -41,9 +42,9 @@ public class RectCache implements RectConstraint, Pollable { @Override - public Rect getRect() + public RectView getRect() { - return cached; + return cached.view(); } diff --git a/src/mightypork/utils/math/constraints/RectConstraint.java b/src/mightypork/utils/math/constraints/RectConstraint.java index 961082a..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.Rect; +import mightypork.utils.math.rect.RectView; /** @@ -14,5 +14,5 @@ public interface RectConstraint { /** * @return rect region */ - Rect getRect(); + RectView getRect(); } diff --git a/src/mightypork/utils/math/constraints/VecConstraint.java b/src/mightypork/utils/math/constraints/VecConstraint.java index 3113e4e..497d67b 100644 --- a/src/mightypork/utils/math/constraints/VecConstraint.java +++ b/src/mightypork/utils/math/constraints/VecConstraint.java @@ -1,8 +1,10 @@ package mightypork.utils.math.constraints; + import mightypork.utils.math.coord.VecView; public interface VecConstraint { + VecView getVec(); } diff --git a/src/mightypork/utils/math/coord/AnimCoord.java b/src/mightypork/utils/math/coord/AnimCoord.java index 683191a..9e9fee2 100644 --- a/src/mightypork/utils/math/coord/AnimCoord.java +++ b/src/mightypork/utils/math/coord/AnimCoord.java @@ -12,7 +12,7 @@ import mightypork.utils.math.animation.Easing; * * @author MightyPork */ -public class AnimCoord extends VecMutableImpl implements Pauseable, Updateable { +public class AnimCoord extends VecMutableImpl implements Pauseable, Updateable { private final AnimDouble x, y, z; @@ -63,9 +63,18 @@ public class AnimCoord extends VecMutableImpl implements Pauseable, U } - public AnimCoord add(VecArith offset, double speed) + public AnimCoord add(Vec offset, double speed) { - animate(offset.add(this), speed); + animate(offset.x() - x(), offset.y() - y(), offset.z() - z(), speed); + return this; + } + + + public AnimCoord animate(double x, double y, double z, double duration) + { + this.x.animate(x, duration); + this.y.animate(y, duration); + this.z.animate(z, duration); return this; } @@ -81,8 +90,8 @@ public class AnimCoord extends VecMutableImpl implements Pauseable, U public void animateWithSpeed(Vec target, double unitsPerSecond) { - double dist = distTo(target); - double duration = dist / unitsPerSecond; + final double dist = distTo(target); + final double duration = dist / unitsPerSecond; animate(target, duration); } @@ -126,4 +135,21 @@ public class AnimCoord extends VecMutableImpl implements Pauseable, U return x.isFinished(); // BUNO } + + public double getDuration() + { + return x.getDuration(); // BUNO + } + + + public double getElapsed() + { + return x.getElapsed(); // BUNO + } + + + public double getProgress() + { + return x.getProgress(); // BUNO + } } diff --git a/src/mightypork/utils/math/coord/CoordProxy.java b/src/mightypork/utils/math/coord/CoordProxy.java index 0503284..45939fb 100644 --- a/src/mightypork/utils/math/coord/CoordProxy.java +++ b/src/mightypork/utils/math/coord/CoordProxy.java @@ -1,12 +1,14 @@ package mightypork.utils.math.coord; -import mightypork.utils.math.constraints.VecConstraint; - /** - *

[ Use Vec.view() method to make a proxy! ]

- *

View of another coordinate, immutable.
- * Operations yield a new {@link MutableCoord} with the result.

+ *

+ * [ Use Vec.view() method to make a proxy! ] + *

+ *

+ * View of another coordinate, immutable.
+ * Operations yield a new {@link MutableCoord} with the result. + *

* * @author MightyPork */ @@ -25,6 +27,7 @@ public class CoordProxy extends VecView { this.observed = observed; } + @Override public CoordProxy view() { diff --git a/src/mightypork/utils/math/coord/CoordValue.java b/src/mightypork/utils/math/coord/FixedCoord.java similarity index 74% rename from src/mightypork/utils/math/coord/CoordValue.java rename to src/mightypork/utils/math/coord/FixedCoord.java index 04e35ee..3111f76 100644 --- a/src/mightypork/utils/math/coord/CoordValue.java +++ b/src/mightypork/utils/math/coord/FixedCoord.java @@ -1,30 +1,28 @@ package mightypork.utils.math.coord; - - /** * Coordinate with immutable numeric values.
* Operations yield a new {@link MutableCoord} with the result. * * @author MightyPork */ -public class CoordValue extends VecView { +public class FixedCoord extends VecView { private final double x, y, z; - public CoordValue(Vec other) { + public FixedCoord(Vec other) { this(other.x(), other.y(), other.z()); } - public CoordValue(double x, double y) { + public FixedCoord(double x, double y) { this(x, y, 0); } - public CoordValue(double x, double y, double z) { + public FixedCoord(double x, double y, double z) { this.x = x; this.y = y; this.z = z; diff --git a/src/mightypork/utils/math/coord/MutableCoord.java b/src/mightypork/utils/math/coord/MutableCoord.java index 797e100..e376c18 100644 --- a/src/mightypork/utils/math/coord/MutableCoord.java +++ b/src/mightypork/utils/math/coord/MutableCoord.java @@ -7,7 +7,7 @@ package mightypork.utils.math.coord; * * @author MightyPork */ -public class MutableCoord extends VecMutableImpl { +public class MutableCoord extends VecMutableImpl { private double x, y, z; diff --git a/src/mightypork/utils/math/coord/SynthCoord2D.java b/src/mightypork/utils/math/coord/SynthCoord2D.java index fa81f7d..d6d9ef0 100644 --- a/src/mightypork/utils/math/coord/SynthCoord2D.java +++ b/src/mightypork/utils/math/coord/SynthCoord2D.java @@ -1,7 +1,5 @@ package mightypork.utils.math.coord; -import mightypork.utils.math.constraints.NumberConstraint; - /** * 2D coord for anonymous implementations.
@@ -13,10 +11,12 @@ public abstract class SynthCoord2D extends VecView { @Override public abstract double x(); - + + @Override public abstract double y(); + @Override public double z() { diff --git a/src/mightypork/utils/math/coord/SynthCoord3D.java b/src/mightypork/utils/math/coord/SynthCoord3D.java index ac4b857..f29b72f 100644 --- a/src/mightypork/utils/math/coord/SynthCoord3D.java +++ b/src/mightypork/utils/math/coord/SynthCoord3D.java @@ -1,13 +1,10 @@ package mightypork.utils.math.coord; -import mightypork.utils.math.constraints.NumberConstraint; - - /** * 3D immutable coord for anonymous implementations.
* Operations yield a new {@link MutableCoord} with the result. - * + * * @author MightyPork */ public abstract class SynthCoord3D extends VecView { diff --git a/src/mightypork/utils/math/coord/Vec.java b/src/mightypork/utils/math/coord/Vec.java index e6a7d22..15bc049 100644 --- a/src/mightypork/utils/math/coord/Vec.java +++ b/src/mightypork/utils/math/coord/Vec.java @@ -4,10 +4,15 @@ package mightypork.utils.math.coord; import mightypork.utils.math.constraints.NumberConstraint; +/** + * The most basic Vec methods + * + * @author MightyPork + */ public interface Vec { - public static final VecView ZERO = new CoordValue(0, 0, 0); - public static final VecView ONE = new CoordValue(1, 1, 1); + public static final VecView ZERO = new FixedCoord(0, 0, 0); + public static final VecView ONE = new FixedCoord(1, 1, 1); /** @@ -87,7 +92,7 @@ public interface Vec { * * @return a mutable copy */ - MutableCoord copy(); + VecMutable copy(); /** @@ -95,7 +100,6 @@ public interface Vec { * * @return immutable view */ - CoordProxy view(); - + VecView view(); } diff --git a/src/mightypork/utils/math/coord/VecArith.java b/src/mightypork/utils/math/coord/VecMath.java similarity index 81% rename from src/mightypork/utils/math/coord/VecArith.java rename to src/mightypork/utils/math/coord/VecMath.java index e63b0c8..478fddc 100644 --- a/src/mightypork/utils/math/coord/VecArith.java +++ b/src/mightypork/utils/math/coord/VecMath.java @@ -1,14 +1,12 @@ package mightypork.utils.math.coord; -import mightypork.utils.math.constraints.VecConstraint; - /** * 3D coordinate methods * * @author MightyPork */ -interface VecArith extends Vec { +interface VecMath extends Vec { /** * Set X coordinate (if immutable, in a copy). @@ -16,7 +14,7 @@ interface VecArith extends Vec { * @param x x coordinate * @return result */ - Vec setX(double x); + V setX(double x); /** @@ -25,7 +23,7 @@ interface VecArith extends Vec { * @param y y coordinate * @return result */ - Vec setY(double y); + V setY(double y); /** @@ -34,8 +32,8 @@ interface VecArith extends Vec { * @param z z coordinate * @return result */ - Vec setZ(double z); - + V setZ(double z); + /** * Get distance to other point @@ -63,18 +61,27 @@ interface VecArith extends Vec { double size(); + /** + * Get absolute value (positive) + * + * @return result + */ + V abs(); + + /** * @return true if zero */ boolean isZero(); + /** * Create vector from this point to other point * * @param point second point * @return result */ - Vec vecTo(Vec point); + V vecTo(Vec point); /** @@ -83,7 +90,7 @@ interface VecArith extends Vec { * @param point other point * @return result */ - Vec midTo(Vec point); + V midTo(Vec point); /** @@ -92,7 +99,7 @@ interface VecArith extends Vec { * @param vec offset * @return result */ - Vec add(Vec vec); + V add(Vec vec); /** @@ -103,7 +110,7 @@ interface VecArith extends Vec { * @param y y offset * @return result */ - Vec add(double x, double y); + V add(double x, double y); /** @@ -114,7 +121,7 @@ interface VecArith extends Vec { * @param z z offset * @return result */ - Vec add(double x, double y, double z); + V add(double x, double y, double z); /** @@ -122,7 +129,7 @@ interface VecArith extends Vec { * * @return result */ - Vec half(); + V half(); /** @@ -131,7 +138,7 @@ interface VecArith extends Vec { * @param d multiplier * @return result */ - Vec mul(double d); + V mul(double d); /** @@ -140,7 +147,7 @@ interface VecArith extends Vec { * @param vec vector of multipliers * @return result */ - Vec mul(Vec vec); + V mul(Vec vec); /** @@ -151,7 +158,7 @@ interface VecArith extends Vec { * @param y y multiplier * @return result */ - Vec mul(double x, double y); + V mul(double x, double y); /** @@ -162,7 +169,7 @@ interface VecArith extends Vec { * @param z z multiplier * @return result */ - Vec mul(double x, double y, double z); + V mul(double x, double y, double z); /** @@ -170,7 +177,7 @@ interface VecArith extends Vec { * * @return result */ - Vec round(); + V round(); /** @@ -178,7 +185,7 @@ interface VecArith extends Vec { * * @return result */ - Vec floor(); + V floor(); /** @@ -186,7 +193,7 @@ interface VecArith extends Vec { * * @return result */ - Vec ceil(); + V ceil(); /** @@ -195,7 +202,7 @@ interface VecArith extends Vec { * @param vec offset * @return result */ - Vec sub(Vec vec); + V sub(Vec vec); /** @@ -206,7 +213,7 @@ interface VecArith extends Vec { * @param y y offset * @return result */ - VecArith sub(double x, double y); + V sub(double x, double y); /** @@ -217,7 +224,7 @@ interface VecArith extends Vec { * @param z z offset * @return result */ - Vec sub(double x, double y, double z); + V sub(double x, double y, double z); /** @@ -225,7 +232,7 @@ interface VecArith extends Vec { * * @return result */ - Vec neg(); + V neg(); /** @@ -234,7 +241,7 @@ interface VecArith extends Vec { * @param size size we need * @return result */ - Vec norm(double size); + V norm(double size); /** @@ -243,6 +250,6 @@ interface VecArith extends Vec { * @param vec other vector * @return result */ - public Vec cross(Vec vec); + V cross(Vec vec); } diff --git a/src/mightypork/utils/math/coord/VecImpl.java b/src/mightypork/utils/math/coord/VecMathImpl.java similarity index 89% rename from src/mightypork/utils/math/coord/VecImpl.java rename to src/mightypork/utils/math/coord/VecMathImpl.java index e0a0420..5f5d061 100644 --- a/src/mightypork/utils/math/coord/VecImpl.java +++ b/src/mightypork/utils/math/coord/VecMathImpl.java @@ -10,7 +10,7 @@ import mightypork.utils.math.constraints.NumberConstraint; * @author MightyPork * @param Return type of methods */ -abstract class VecImpl implements VecArith { +abstract class VecMathImpl implements VecMath { private NumberConstraint constraintZ, constraintY, constraintX; @@ -89,14 +89,14 @@ abstract class VecImpl implements VecArith { @Override - public MutableCoord copy() + public VecMutable copy() { return new MutableCoord(this); } @Override - public CoordProxy view() + public VecView view() { if (view == null) view = new CoordProxy(this); @@ -176,7 +176,7 @@ abstract class VecImpl implements VecArith { @Override public double size() { - double x = x(), y = y(), z = z(); + final double x = x(), y = y(), z = z(); return Math.sqrt(x * x + y * y + z * z); } @@ -188,6 +188,13 @@ abstract class VecImpl implements VecArith { } + @Override + public V abs() + { + return result(Math.abs(x()), Math.abs(y()), Math.abs(z())); + } + + @Override public V add(Vec vec) { @@ -212,9 +219,9 @@ abstract class VecImpl implements VecArith { @Override public double distTo(Vec point) { - double dx = x() - point.x(); - double dy = y() - point.y(); - double dz = z() - point.z(); + 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); } @@ -223,9 +230,9 @@ abstract class VecImpl implements VecArith { @Override public V midTo(Vec point) { - double dx = (point.x() - x()) * 0.5; - double dy = (point.y() - y()) * 0.5; - double dz = (point.z() - z()) * 0.5; + 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 result(dx, dy, dz); } @@ -346,7 +353,7 @@ abstract class VecImpl implements VecArith { { if (isZero()) return result(x(), y(), z()); // can't norm zero vector - double k = size / size(); + final double k = size / size(); return mul(k); } @@ -355,7 +362,7 @@ abstract class VecImpl implements VecArith { @Override public int hashCode() { - int prime = 31; + final int prime = 31; int result = 1; result = prime * result + Double.valueOf(x()).hashCode(); result = prime * result + Double.valueOf(y()).hashCode(); @@ -370,11 +377,12 @@ abstract class VecImpl implements VecArith { if (this == obj) return true; if (obj == null) return false; if (!(obj instanceof Vec)) return false; - Vec other = (Vec) obj; + final Vec other = (Vec) obj; return x() == other.x() && y() == other.y() && z() == other.z(); } + @Override public String toString() { diff --git a/src/mightypork/utils/math/coord/VecMutable.java b/src/mightypork/utils/math/coord/VecMutable.java index c2c12bb..47b0fe5 100644 --- a/src/mightypork/utils/math/coord/VecMutable.java +++ b/src/mightypork/utils/math/coord/VecMutable.java @@ -2,11 +2,11 @@ package mightypork.utils.math.coord; /** - * Mutable coord interface. This coord can be changed at will. + * Mutable coord * * @author MightyPork */ -public interface VecMutable extends VecArith { +public interface VecMutable extends VecMath { /** * Set coordinates to match other coord. diff --git a/src/mightypork/utils/math/coord/VecMutableImpl.java b/src/mightypork/utils/math/coord/VecMutableImpl.java index e21f646..48fb6c9 100644 --- a/src/mightypork/utils/math/coord/VecMutableImpl.java +++ b/src/mightypork/utils/math/coord/VecMutableImpl.java @@ -5,21 +5,23 @@ package mightypork.utils.math.coord; * Mutable vec default implementation * * @author MightyPork - * @param Return type of methods */ -abstract class VecMutableImpl extends VecImpl implements VecMutable { - +abstract class VecMutableImpl extends VecMathImpl implements VecMutable { + @Override public abstract double x(); - + + @Override public abstract double y(); - + + @Override public abstract double z(); - + + @Override - public abstract V result(double x, double y, double z); + public abstract VecMutable result(double x, double y, double z); @Override @@ -30,14 +32,14 @@ abstract class VecMutableImpl extends VecImpl implement @Override - public V setTo(double x, double y, double z) + public VecMutable setTo(double x, double y, double z) { return result(x, y, z); } @Override - public V setTo(double x, double y) + public VecMutable setTo(double x, double y) { return result(x, y, z()); } diff --git a/src/mightypork/utils/math/coord/VecView.java b/src/mightypork/utils/math/coord/VecView.java index ecde79e..7aa7419 100644 --- a/src/mightypork/utils/math/coord/VecView.java +++ b/src/mightypork/utils/math/coord/VecView.java @@ -1,19 +1,24 @@ package mightypork.utils.math.coord; -import mightypork.utils.math.constraints.VecConstraint; - - /** - * Read-only coordinate, operations with it will yield a new {@link MutableCoord} with the result. + * Read-only coordinate, operations with it will yield a new + * {@link MutableCoord} with the result. * * @author MightyPork */ -public abstract class VecView extends VecImpl { +public abstract class VecView extends VecMathImpl { + + @Override + public VecView result(double x, double y, double z) + { + return new FixedCoord(x, y, z); + } + @Override - public CoordValue result(double x, double y, double z) + public VecView view() { - return new CoordValue(x,y,z); + return this; // already not mutable } } diff --git a/src/mightypork/utils/math/rect/FixedRect.java b/src/mightypork/utils/math/rect/FixedRect.java new file mode 100644 index 0000000..9313a9b --- /dev/null +++ b/src/mightypork/utils/math/rect/FixedRect.java @@ -0,0 +1,105 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.coord.FixedCoord; +import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.coord.VecView; + + +public class FixedRect extends RectView { + + private final VecView pos; + private final VecView size; + + + /** + * Create at 0,0 with zero size + */ + public FixedRect() { + pos = Vec.ZERO; + size = Vec.ZERO; + } + + + /** + * Create at 0,0 with given size + * + * @param width + * @param height + */ + public FixedRect(double width, double height) { + this(0, 0, width, height); + } + + + /** + * Create at given origin, with given size. + * + * @param origin + * @param width + * @param height + */ + public FixedRect(Vec origin, double width, double height) { + this(origin.x(), origin.y(), width, height); + } + + + /** + * Create at 0,0 with given size. + * + * @param size + */ + public FixedRect(Vec size) { + this(0, 0, size.x(), size.y()); + } + + + /** + * Create at given origin, with given size. + * + * @param origin + * @param size + */ + public FixedRect(Vec origin, Vec size) { + this(origin.x(), origin.y(), size.x(), size.y()); + } + + + /** + * Create at given origin, with given size. + * + * @param x + * @param y + * @param width + * @param height + */ + public FixedRect(double x, double y, double width, double height) { + pos = new FixedCoord(x, y); + size = new FixedCoord(Math.abs(width), Math.abs(height)); + } + + + /** + * Create as copy of another + * + * @param other copied + */ + public FixedRect(Rect other) { + this(other.getOrigin(), other.getSize()); + } + + + @Override + public VecView getOrigin() + { + return pos; + } + + + @Override + public VecView getSize() + { + return size; + } + +} diff --git a/src/mightypork/utils/math/rect/MutableRect.java b/src/mightypork/utils/math/rect/MutableRect.java new file mode 100644 index 0000000..ff3112b --- /dev/null +++ b/src/mightypork/utils/math/rect/MutableRect.java @@ -0,0 +1,233 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.coord.MutableCoord; +import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.coord.VecMutable; +import mightypork.utils.math.coord.VecView; + + +public class MutableRect extends RectImpl implements RectMutable { + + private final VecMutable pos = new MutableCoord(); + private final VecMutable size = new MutableCoord(); + + + /** + * Create at 0,0 with zero size + */ + public MutableRect() { + // keep default zeros + } + + + /** + * Create at 0,0 with given size + * + * @param width + * @param height + */ + public MutableRect(double width, double height) { + this.pos.setTo(0, 0); + this.size.setTo(width, height).abs(); + } + + + /** + * Create at given origin, with given size. + * + * @param origin + * @param width + * @param height + */ + public MutableRect(Vec origin, double width, double height) { + this.pos.setTo(origin); + this.size.setTo(width, height).abs(); + } + + + /** + * Create at 0,0 with given size. + * + * @param size + */ + public MutableRect(Vec size) { + this(0, 0, size.x(), size.y()); + } + + + /** + * Create at given origin, with given size. + * + * @param origin + * @param size + */ + public MutableRect(Vec origin, Vec size) { + this.pos.setTo(origin); + this.size.setTo(size).abs(); + } + + + /** + * Create at given origin, with given size. + * + * @param x + * @param y + * @param width + * @param height + */ + public MutableRect(double x, double y, double width, double height) { + pos.setTo(x, y); + size.setTo(width, height).abs(); + } + + + /** + * Create as copy of another + * + * @param other copied + */ + public MutableRect(Rect other) { + this(other.getOrigin(), other.getSize()); + } + + + /** + * Set to other rect's coordinates + * + * @param rect other rect + */ + @Override + public void setTo(Rect rect) + { + setTo(rect.getOrigin(), rect.getSize()); + } + + + @Override + public void setTo(Vec origin, Vec size) + { + this.pos.setTo(origin); + this.size.setTo(size).abs(); + } + + + @Override + public void setTo(Vec origin, double width, double height) + { + this.pos.setTo(origin); + this.size.setTo(width, height).abs(); + } + + + @Override + public void setOrigin(Vec origin) + { + this.pos.setTo(origin); + } + + + @Override + public void setSize(Vec size) + { + this.size.setTo(size).abs(); + } + + + /** + * Add X and Y to origin + * + * @param x x to add + * @param y y to add + * @return result + */ + @Override + public RectMutable move(double x, double y) + { + pos.add(x, y); + return this; + } + + + /** + * Get a copy + * + * @return copy + */ + @Override + public RectMutable copy() + { + return new MutableRect(this); + } + + + /** + * Shrink the rect + * + * @param left shrink + * @param top shrink + * @param right shrink + * @param bottom shrink + * @return result + */ + @Override + public RectMutable shrink(double left, double top, double right, double bottom) + { + pos.add(left, top); + size.sub(left + right, top + bottom).abs(); + return this; + } + + + /** + * Grow the rect + * + * @param left growth + * @param top growth + * @param right growth + * @param bottom growth + * @return result + */ + @Override + public RectMutable grow(double left, double top, double right, double bottom) + { + pos.sub(left, top); + size.add(left + right, top + bottom).abs(); + return this; + } + + + /** + * Round coords + * + * @return result + */ + @Override + public RectMutable round() + { + pos.round(); + size.round(); + return this; + } + + + @Override + public VecView getOrigin() + { + return pos.view(); + } + + + @Override + public VecView getSize() + { + return size.view(); + } + + + @Override + public RectView view() + { + return new FixedRect(this); + } +} diff --git a/src/mightypork/utils/math/rect/Rect.java b/src/mightypork/utils/math/rect/Rect.java index bc536f7..7420b66 100644 --- a/src/mightypork/utils/math/rect/Rect.java +++ b/src/mightypork/utils/math/rect/Rect.java @@ -1,398 +1,75 @@ package mightypork.utils.math.rect; -import mightypork.utils.math.constraints.RectConstraint; -import mightypork.utils.math.constraints.VecConstraint; -import mightypork.utils.math.coord.MutableCoord; -import mightypork.utils.math.coord.SynthCoord2D; -import mightypork.utils.math.coord.Vec; -import mightypork.utils.math.coord.VecMutable; import mightypork.utils.math.coord.VecView; -public class Rect { +/** + * Common methods for all kinds of Rects + * + * @author MightyPork + */ +public interface Rect { - public static final Rect ONE = new Rect(0, 0, 1, 1); // FIXME - private final VecMutable pos = new MutableCoord(); - private final VecMutable size = new MutableCoord(); - private final VecView center = new SynthCoord2D() { - - @Override - public double y() - { - return pos.x() + size.x() / 2; - } - - - @Override - public double x() - { - return pos.y() + size.y() / 2; - } - }; + RectView ONE = new FixedRect(0, 0, 1, 1); + RectView ZERO = new FixedRect(0, 0, 0, 0); /** - * Create at 0,0 with zero size - */ - public Rect() { - // keep default zeros - } - - - /** - * Create at 0,0 with given size - * - * @param width - * @param height - */ - public Rect(double width, double height) { - this.pos.setTo(0, 0); - this.size.setTo(width, height); - norm(); - } - - - /** - * Create at given origin, with given size. - * - * @param origin - * @param width - * @param height - */ - public Rect(Vec origin, double width, double height) { - this.pos.setTo(origin); - this.size.setTo(width, height); - norm(); - } - - - /** - * make sure the rect doesn't have negative size. - */ - private void norm() - { - if (size.x() < 0) { - pos.sub(-size.x(), 0); - size.mul(-1, 1); - } - - if (size.y() < 0) { - pos.sub(0, -size.y()); - size.mul(1, -1); - } - } - - - /** - * Create at given origin, with given size. - * - * @param origin - * @param size - */ - public Rect(Vec origin, Vec size) { - this.pos.setTo(origin); - this.size.setTo(size); - norm(); - } - - - /** - * Create at given origin, with given size. - * - * @param x - * @param y - * @param width - * @param height - */ - public Rect(double x, double y, double width, double height) { - pos.setTo(x, y); - size.setTo(width, height); - norm(); - } - - - /** - * Create as copy of another - * - * @param other copied - */ - public Rect(Rect other) { - this(other.pos, other.size); - } - - - /** - * Set to other rect's coordinates - * - * @param rect other rect - */ - public void setTo(Rect rect) - { - setTo(rect.pos, rect.size); - } - - - public void setTo(Vec origin, Vec size) - { - this.pos.setTo(origin); - this.size.setTo(size); - norm(); - } - - - public void setOrigin(Vec origin) - { - this.pos.setTo(origin); - norm(); - } - - - public void setSize(Vec size) - { - this.size.setTo(size); - norm(); - } - - - /** - * Add vector to origin - * - * @param move offset vector - * @return result - */ - public Rect move(Vec move) - { - move(move.x(), move.y()); - return this; - } - - - /** - * Add X and Y to origin - * - * @param x x to add - * @param y y to add - * @return result - */ - public Rect move(double x, double y) - { - pos.add(x, y); - return this; - } - - - /** - * Get a copy + * Get a writable copy * * @return copy */ - public Rect copy() - { - return new Rect(this); - } - - - /** - * Shrink to sides - * - * @param shrink shrink size (horisontal and vertical) - * @return result - */ - public Rect shrink(Vec shrink) - { - return shrink(shrink.x(), shrink.y()); - } - - - /** - * Shrink to sides at sides - * - * @param x horizontal shrink - * @param y vertical shrink - * @return result - */ - public Rect shrink(double x, double y) - { - return shrink(x, y, x, y); - } - - - /** - * Shrink the rect - * - * @param left shrink - * @param top shrink - * @param right shrink - * @param bottom shrink - * @return result - */ - public Rect shrink(double left, double top, double right, double bottom) - { - pos.add(left, top); - size.sub(left + right, top + bottom); - norm(); - return this; - } + RectMutable copy(); /** - * Grow to sides + * Get a readonly copy * - * @param grow grow size (added to each side) - * @return grown copy + * @return copy */ - public Rect grow(Vec grow) - { - return grow(grow.x(), grow.y()); - } + RectView view(); /** - * Grow to sides - * - * @param x horizontal grow - * @param y vertical grow - * @return result + * @return origin */ - public Rect grow(double x, double y) - { - return grow(x, y, x, y); - } + VecView getOrigin(); /** - * Grow the rect - * - * @param left growth - * @param top growth - * @param right growth - * @param bottom growth - * @return result + * @return center */ - public Rect grow(double left, double top, double right, double bottom) - { - pos.sub(left, top); - size.add(left + right, top + bottom); - norm(); - return this; - } + VecView getCenter(); /** - * Check if point is inside this rectangle - * - * @param point point to test - * @return is inside + * @return rect size */ - public boolean contains(Vec point) - { - final double x = point.x(), y = point.y(); - - final double x1 = pos.x(), y1 = pos.y(); - final double x2 = x1 + size.x(), y2 = y1 + size.y(); - - return x >= x1 && y >= y1 && x <= x2 && y <= y2; - } + VecView getSize(); /** - * Round coords - * - * @return result + * @return rect width */ - public Rect round() - { - pos.round(); - size.round(); - return this; - } + double getWidth(); /** - * Get offset copy (subtract) - * - * @param move offset vector - * @return result - */ - public Rect sub(Vec move) - { - return sub(move.x(), move.y()); - } - - - /** - * Subtract X and Y from all coordinates - * - * @param x x to subtract - * @param y y to subtract - * @return result + * @return rect height */ - Rect sub(double x, double y) - { - pos.sub(x, y); - norm(); - return this; - } - - - public VecView getOrigin() - { - return pos.view(); - } - - - public VecView getSize() - { - return size.view(); - } - - - public VecView getCenter() - { - return center; - } - - - public double getWidth() - { - return size.x(); - } - - - public double getHeight() - { - return size.y(); - } - + double getHeight(); - @Override - public String toString() - { - return String.format("[%s-%s]", pos.toString(), pos.view().add(size).toString()); - } + double xMin(); - public double xMin() - { - return pos.x(); - } + double xMax(); - public double xMax() - { - return pos.x() + size.x(); - } + double yMin(); - public double yMin() - { - return pos.y(); - } + double yMax(); - public double yMax() - { - return pos.y() + size.y(); - } } diff --git a/src/mightypork/utils/math/rect/RectImpl.java b/src/mightypork/utils/math/rect/RectImpl.java new file mode 100644 index 0000000..880ecf7 --- /dev/null +++ b/src/mightypork/utils/math/rect/RectImpl.java @@ -0,0 +1,121 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.coord.VecView; + + +public abstract class RectImpl implements RectMath { + + @Override + public final VecView getCenter() + { + return getOrigin().add(getSize().half()); + } + + + @Override + public final double getWidth() + { + return getSize().x(); + } + + + @Override + public final double getHeight() + { + return getSize().y(); + } + + + @Override + public final double xMin() + { + return getOrigin().x(); + } + + + @Override + public final double xMax() + { + return getOrigin().x() + getSize().x(); + } + + + @Override + public final double yMin() + { + return getOrigin().y(); + } + + + @Override + public final double yMax() + { + return getOrigin().y() + getSize().y(); + } + + + @Override + public final T move(Vec move) + { + return move(move.x(), move.y()); + } + + + @Override + public final T shrink(Vec shrink) + { + return shrink(shrink.x(), shrink.y()); + } + + + @Override + public final T shrink(double x, double y) + { + return shrink(x, y, x, y); + } + + + @Override + public final T grow(Vec grow) + { + return grow(grow.x(), grow.y()); + } + + + @Override + public final T grow(double x, double y) + { + return grow(x, y, x, y); + } + + + @Override + public RectView view() + { + return new RectProxy(this); + } + + + @Override + public final boolean contains(Vec point) + { + final double x = point.x(); + final double y = point.y(); + + final double x1 = getOrigin().x(); + final double y1 = getOrigin().y(); + final double x2 = x1 + getSize().x(); + final double y2 = y1 + getSize().y(); + + return x >= x1 && y >= y1 && x <= x2 && y <= y2; + } + + + @Override + public String toString() + { + return String.format("Rect[ %s - %s ]", getOrigin().toString(), getOrigin().add(getSize())); + } +} diff --git a/src/mightypork/utils/math/rect/RectMath.java b/src/mightypork/utils/math/rect/RectMath.java new file mode 100644 index 0000000..bf8cace --- /dev/null +++ b/src/mightypork/utils/math/rect/RectMath.java @@ -0,0 +1,111 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.coord.Vec; + + +/** + * Operations available in rects + * + * @author MightyPork + */ +interface RectMath extends Rect { + + /** + * Add vector to origin + * + * @param move offset vector + * @return result + */ + T move(Vec move); + + + /** + * Add X and Y to origin + * + * @param x x to add + * @param y y to add + * @return result + */ + T move(double x, double y); + + + /** + * Shrink to sides + * + * @param shrink shrink size (horisontal and vertical) + * @return result + */ + T shrink(Vec shrink); + + + /** + * Shrink to sides at sides + * + * @param x horizontal shrink + * @param y vertical shrink + * @return result + */ + T shrink(double x, double y); + + + /** + * Shrink the rect + * + * @param left shrink + * @param top shrink + * @param right shrink + * @param bottom shrink + * @return result + */ + T shrink(double left, double top, double right, double bottom); + + + /** + * Grow to sides + * + * @param grow grow size (added to each side) + * @return grown copy + */ + T grow(Vec grow); + + + /** + * Grow to sides + * + * @param x horizontal grow + * @param y vertical grow + * @return result + */ + T grow(double x, double y); + + + /** + * Grow the rect + * + * @param left growth + * @param top growth + * @param right growth + * @param bottom growth + * @return result + */ + T grow(double left, double top, double right, double bottom); + + + /** + * Check if point is inside this rectangle + * + * @param point point to test + * @return is inside + */ + boolean contains(Vec point); + + + /** + * Round coords + * + * @return result + */ + T round(); + +} diff --git a/src/mightypork/utils/math/rect/RectMutable.java b/src/mightypork/utils/math/rect/RectMutable.java new file mode 100644 index 0000000..adc1220 --- /dev/null +++ b/src/mightypork/utils/math/rect/RectMutable.java @@ -0,0 +1,28 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.coord.Vec; + + +public interface RectMutable extends Rect { + + /** + * Set to other rect's coordinates + * + * @param rect other rect + */ + void setTo(Rect rect); + + + void setTo(Vec origin, Vec size); + + + void setTo(Vec origin, double width, double height); + + + void setOrigin(Vec origin); + + + void setSize(Vec size); + +} diff --git a/src/mightypork/utils/math/rect/RectProxy.java b/src/mightypork/utils/math/rect/RectProxy.java new file mode 100644 index 0000000..2a78789 --- /dev/null +++ b/src/mightypork/utils/math/rect/RectProxy.java @@ -0,0 +1,35 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.coord.VecView; + + +/** + * Immutable rect accessor + * + * @author MightyPork + */ +public class RectProxy extends RectView { + + private final Rect observed; + + + public RectProxy(Rect observed) { + this.observed = observed; + } + + + @Override + public VecView getOrigin() + { + return observed.getOrigin(); + } + + + @Override + public VecView getSize() + { + return observed.getSize(); + } + +} diff --git a/src/mightypork/utils/math/rect/RectView.java b/src/mightypork/utils/math/rect/RectView.java new file mode 100644 index 0000000..f2d5536 --- /dev/null +++ b/src/mightypork/utils/math/rect/RectView.java @@ -0,0 +1,69 @@ +package mightypork.utils.math.rect; + + +import mightypork.utils.math.coord.VecView; + + +/** + * Immutable rect + * + * @author MightyPork + */ +public abstract class RectView extends RectImpl { + + protected RectView result(VecView origin, VecView size) + { + return new FixedRect(origin, size); + } + + + @Override + public RectView move(double x, double y) + { + return result(getOrigin().add(x, y), getSize()); + } + + + @Override + public RectView shrink(double left, double top, double right, double bottom) + { + return result(getOrigin().add(left, top), getSize().sub(left + right, top + bottom)); + } + + + @Override + public RectView grow(double left, double top, double right, double bottom) + { + return result(getOrigin().sub(left, top), getSize().add(left + right, top + bottom)); + } + + + @Override + public RectView round() + { + return result(getOrigin().round(), getSize().round()); + } + + + @Override + public MutableRect copy() + { + return new MutableRect(this); + } + + + @Override + public RectView view() + { + return this; + } + + + @Override + public abstract VecView getOrigin(); + + + @Override + public abstract VecView getSize(); + +} diff --git a/src/mightypork/utils/math/rect/RectCalc.java b/src/mightypork/utils/math/rect/xx/RectCalc.java similarity index 99% rename from src/mightypork/utils/math/rect/RectCalc.java rename to src/mightypork/utils/math/rect/xx/RectCalc.java index 018352e..1550c85 100644 --- a/src/mightypork/utils/math/rect/RectCalc.java +++ b/src/mightypork/utils/math/rect/xx/RectCalc.java @@ -1,3 +1,6 @@ +package mightypork.utils.math.rect.xx; + + //package mightypork.utils.math.rect; // //import mightypork.utils.math.constraints.NumberConstraint; diff --git a/src/mightypork/utils/math/rect/Rectd.java b/src/mightypork/utils/math/rect/xx/Rectd.java similarity index 97% rename from src/mightypork/utils/math/rect/Rectd.java rename to src/mightypork/utils/math/rect/xx/Rectd.java index 60bf181..fc022de 100644 --- a/src/mightypork/utils/math/rect/Rectd.java +++ b/src/mightypork/utils/math/rect/xx/Rectd.java @@ -1,3 +1,6 @@ +package mightypork.utils.math.rect.xx; + + //package mightypork.utils.math.rect; // // @@ -17,8 +20,8 @@ // */ //public class Rectd implements RectConstraint, IRect { // -// public static final IRect ZERO = new Rect(0, 0, 0, 0).freeze(); -// public static final Rect ONE = new Rect(0, 0, 1, 1).freeze(); +// public static final IRect ZERO = new FixedRect(0, 0, 0, 0).freeze(); +// public static final Rect ONE = new FixedRect(0, 0, 1, 1).freeze(); // // // /** @@ -44,7 +47,7 @@ // */ // public static Rect fromSize(VecArith min, double width, double height) // { -// return new Rect(min.copy(), min.add(width, height)); +// return new FixedRect(min.copy(), min.add(width, height)); // } // // @@ -84,7 +87,7 @@ // */ // public static Rect fromSize(double xmin, double ymin, double width, double height) // { -// return new Rect(xmin, ymin, xmin + width, ymin + height); +// return new FixedRect(xmin, ymin, xmin + width, ymin + height); // } // // /** Lowest coordinates xy */ @@ -304,7 +307,7 @@ // @Override // public Rect copy() // { -// return new Rect(this); +// return new FixedRect(this); // } // // @@ -704,7 +707,7 @@ // @Override // public Rect round() // { -// return new Rect(min.round(), max.round()); +// return new FixedRect(min.round(), max.round()); // } // // @@ -877,7 +880,7 @@ // // // @Override -// public Rect getRect() +// public RectView getRect() // { // return this; // } diff --git a/src/mightypork/utils/objects/Convert.java b/src/mightypork/utils/objects/Convert.java index ee438b6..09338c9 100644 --- a/src/mightypork/utils/objects/Convert.java +++ b/src/mightypork/utils/objects/Convert.java @@ -3,7 +3,9 @@ package mightypork.utils.objects; import mightypork.utils.logging.Log; import mightypork.utils.math.Range; -import mightypork.utils.math.coord.*; +import mightypork.utils.math.coord.FixedCoord; +import mightypork.utils.math.coord.Vec; +import mightypork.utils.math.coord.VecView; /** @@ -153,8 +155,8 @@ public class Convert { public static VecView toCoord(Object o, Vec def) { try { - if (o == null) return new CoordValue(def); - if (o instanceof Vec) return new CoordValue((Vec) o); + if (o == null) return new FixedCoord(def); + if (o instanceof Vec) return new FixedCoord((Vec) o); if (o instanceof String) { String s = ((String) o).trim().toUpperCase(); @@ -170,19 +172,19 @@ public class Convert { final double y = Double.parseDouble(parts[1].trim()); if (parts.length == 2) { - return new CoordValue(x, y); + return new FixedCoord(x, y); } final double z = Double.parseDouble(parts[2].trim()); - return new CoordValue(x, y, z); + return new FixedCoord(x, y, z); } } } catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) { // ignore } - return new CoordValue(def); + return new FixedCoord(def); }