Minor vect/rect changes

v5stable
Ondřej Hruška 11 years ago
parent e1d87df697
commit cacaa9dcce
  1. 2
      src/mightypork/gamecore/audio/SoundSystem.java
  2. 2
      src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java
  3. 4
      src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java
  4. 2
      src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java
  5. 2
      src/mightypork/gamecore/gui/components/layout/ColumnHolder.java
  6. 2
      src/mightypork/gamecore/gui/components/layout/RowHolder.java
  7. 2
      src/mightypork/gamecore/input/InputSystem.java
  8. 10
      src/mightypork/gamecore/render/Render.java
  9. 2
      src/mightypork/gamecore/render/fonts/FontRenderer.java
  10. 2
      src/mightypork/rogue/screens/LayerFps.java
  11. 23
      src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java
  12. 2
      src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java
  13. 12
      src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java
  14. 6
      src/mightypork/rogue/screens/test_font/ScreenTestFont.java
  15. 2
      src/mightypork/rogue/screens/test_render/LayerTestGradient.java
  16. 2
      src/mightypork/test/TestConstr.java
  17. 24
      src/mightypork/test/TestConvert.java
  18. 2
      src/mightypork/utils/config/PropertyManager.java
  19. 7
      src/mightypork/utils/math/Range.java
  20. 4
      src/mightypork/utils/math/animation/AnimDouble.java
  21. 84
      src/mightypork/utils/math/constraints/ConstraintFactory.java
  22. 6
      src/mightypork/utils/math/constraints/NumBound.java
  23. 4
      src/mightypork/utils/math/constraints/NumberConst.java
  24. 2
      src/mightypork/utils/math/constraints/RectCache.java
  25. 18
      src/mightypork/utils/math/constraints/VectBound.java
  26. 19
      src/mightypork/utils/math/constraints/builder/Bounds.java
  27. 56
      src/mightypork/utils/math/rect/AbstractRect.java
  28. 90
      src/mightypork/utils/math/rect/Rect.java
  29. 4
      src/mightypork/utils/math/rect/RectMutableImpl.java
  30. 19
      src/mightypork/utils/math/rect/RectVal.java
  31. 2
      src/mightypork/utils/math/rect/RectView.java
  32. 81
      src/mightypork/utils/math/vect/AbstractVect.java
  33. 17
      src/mightypork/utils/math/vect/NumConstrVect.java
  34. 60
      src/mightypork/utils/math/vect/Vect.java
  35. 69
      src/mightypork/utils/math/vect/VectAnimated.java
  36. 73
      src/mightypork/utils/math/vect/VectMath.java
  37. 60
      src/mightypork/utils/math/vect/VectMutable.java
  38. 6
      src/mightypork/utils/math/vect/VectMutableVariable.java
  39. 15
      src/mightypork/utils/math/vect/VectVal.java
  40. 19
      src/mightypork/utils/math/vect/VectView.java
  41. 64
      src/mightypork/utils/objects/Convert.java

@ -62,7 +62,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
*/
public static VectView getListener()
{
return listener.getView();
return listener.view();
}
// -- instance --

@ -80,7 +80,7 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
*/
public VectView getPos()
{
return pos.getView();
return pos.view();
}

@ -23,8 +23,8 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
* @param move move vector
*/
public MouseMotionEvent(Vect pos, Vect move) {
this.move = move.getValue();
this.pos = pos.getValue();
this.move = move.copy();
this.pos = pos.copy();
}

@ -52,7 +52,7 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
*/
public VectView getScreenSize()
{
return screenSize.getView();
return screenSize.view();
}

@ -1,7 +1,7 @@
package mightypork.gamecore.gui.components.layout;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.components.PluggableRenderable;
import mightypork.utils.math.constraints.RectBound;

@ -1,7 +1,7 @@
package mightypork.gamecore.gui.components.layout;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.components.PluggableRenderable;
import mightypork.utils.math.constraints.RectBound;

@ -155,7 +155,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
move.mul(1, -1, 1);
if (button != -1 || wheeld != 0) {
getEventBus().send(new MouseButtonEvent(pos.getValue(), button, down, wheeld));
getEventBus().send(new MouseButtonEvent(pos.copy(), button, down, wheeld));
}
moveSum.add(move);

@ -213,7 +213,7 @@ public class Render {
*/
public static void rotate(double angle, Vect axis)
{
final Vect vec = axis.getView().norm(1);
final Vect vec = axis.view().norm(1);
glRotated(angle, vec.x(), vec.y(), vec.z());
}
@ -351,7 +351,7 @@ public class Render {
*/
public static void quad(Rect quad)
{
final double x1 = quad.getLeft();
final double x1 = quad.left();
final double y1 = quad.top();
final double x2 = quad.right();
final double y2 = quad.bottom();
@ -391,12 +391,12 @@ public class Render {
*/
public static void quadUV_nobound(Rect quad, Rect uvs)
{
final double x1 = quad.getLeft();
final double x1 = quad.left();
final double y1 = quad.top();
final double x2 = quad.right();
final double y2 = quad.bottom();
final double tx1 = uvs.getLeft();
final double tx1 = uvs.left();
final double ty1 = uvs.top();
final double tx2 = uvs.right();
final double ty2 = uvs.bottom();
@ -437,7 +437,7 @@ public class Render {
*/
public static void quadColor(Rect quad, RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax)
{
final double x1 = quad.getLeft();
final double x1 = quad.left();
final double y1 = quad.top();
final double x2 = quad.right();
final double y2 = quad.bottom();

@ -110,7 +110,7 @@ public class FontRenderer {
{
Render.pushMatrix();
Render.translate(pos.getValue().round());
Render.translate(pos.copy().round());
Render.scaleXY(getScale(height));
font.draw(text, color);

@ -1,7 +1,7 @@
package mightypork.rogue.screens;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import mightypork.gamecore.gui.Action;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Screen;

@ -1,7 +1,7 @@
package mightypork.rogue.screens.test_bouncyboxes;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.Random;
@ -11,7 +11,7 @@ import mightypork.gamecore.render.Render;
import mightypork.utils.math.animation.AnimDouble;
import mightypork.utils.math.animation.Easing;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.NumberBound;
import mightypork.utils.math.constraints.NumBound;
import mightypork.utils.math.constraints.RectBound;
@ -26,15 +26,28 @@ public class BouncyBox extends PluggableRenderer implements Updateable {
public BouncyBox() {
// create box
final NumberBound side = height(this);
final NumBound side = height(this);
RectBound abox = box(this, side, side);
// move
final NumberBound move_length = sub(width(this), side);
final NumberBound offset = mul(move_length, pos);
final NumBound move_length = sub(width(this), side);
final NumBound offset = mul(move_length, pos);
abox = move(abox, offset, 0);
// add padding
/*
* leftEdge(this)
* .growRight(height(this))
* .move(
* width(this)
* .sub(height(this))
* .mul(pos),
* 0)
* .shrink(
* height(this)
* .perc(10)
* )
*/
abox = shrink(abox, perc(side, 10));
box = abox;

@ -1,7 +1,7 @@
package mightypork.rogue.screens.test_bouncyboxes;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.ArrayList;
import java.util.List;

@ -1,7 +1,7 @@
package mightypork.rogue.screens.test_cat_sound;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.Random;
@ -19,17 +19,15 @@ import mightypork.rogue.Res;
import mightypork.utils.math.animation.AnimDouble;
import mightypork.utils.math.animation.Easing;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.Bounds;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectMutableAnim;
import mightypork.utils.math.vect.VectAnimated;
import mightypork.utils.math.vect.VectVal;
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener {
private final AnimDouble size = new AnimDouble(400, Easing.SINE_BOTH);
private final VectMutableAnim pos = VectMutable.makeAnim(Easing.ELASTIC_OUT);
private final VectAnimated pos = VectAnimated.make(Easing.ELASTIC_OUT);
private final Random rand = new Random();
@ -46,6 +44,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
cat = new ImagePainter(Res.getTxQuad("test.kitten"));
// Bounds.box(size,size).centerTo(pos)
cat.setContext(centerTo(box(size, size), pos));
tp = new TextPainter(Res.getFont("default"));
@ -54,9 +53,12 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
tp.setText("Meow!");
tp.setShadow(RGB.dark(0.8), VectVal.make(2, 2));
// Bounds.box(64,64).centerTo(cMousePos)
tp.setContext(centerTo(box(64, 64), cMousePos));
qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED);
// Bounds.wrap(cat).bottomLeft().expand(0,0,50,50)
qp.setContext(expand(bottomLeft(cat), 0, 0, 50, 50));
/*

@ -1,14 +1,14 @@
package mightypork.rogue.screens.test_font;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.components.painters.TextPainter;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.rogue.Res;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.NumberBound;
import mightypork.utils.math.constraints.NumBound;
import mightypork.utils.math.constraints.RectBound;
@ -23,7 +23,7 @@ public class ScreenTestFont extends Screen {
tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN);
tp.setText("Hello World!");
final NumberBound fontHeight = mul(getDisplay().getSize().yc(), 0.1);
final NumBound fontHeight = mul(getDisplay().getSize().yc(), 0.1);
final RectBound strbox = centerTo(box(fontHeight), this);

@ -1,7 +1,7 @@
package mightypork.rogue.screens.test_render;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import mightypork.gamecore.control.timing.Poller;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;

@ -1,7 +1,7 @@
package mightypork.test;
import static mightypork.utils.math.constraints.Bounds.*;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.Locale;

@ -0,0 +1,24 @@
package mightypork.test;
import mightypork.utils.objects.Convert;
public class TestConvert {
public static void main(String[] args)
{
System.out.println(Convert.toVect("(10:20:30)"));
System.out.println(Convert.toVect("30.6 ; 80"));
System.out.println(Convert.toVect("30.6"));
System.out.println(Convert.toRange("10"));
System.out.println(Convert.toRange("10..60"));
System.out.println(Convert.toRange("10-60"));
System.out.println(Convert.toRange("10--60"));
System.out.println(Convert.toRange("-10--60"));
System.out.println(Convert.toRange("3.1;22"));
System.out.println(Convert.toRange("3.1|22"));
}
}

@ -364,7 +364,7 @@ public class PropertyManager {
*/
public VectView getCoord(String n)
{
return Convert.toCoord(get(n).value);
return Convert.toVect(get(n).value);
}

@ -11,6 +11,11 @@ import java.util.Random;
*/
public class Range {
public static Range make(double low, double high)
{
return new Range(low, high);
}
private double min = 0;
private double max = 1;
@ -132,7 +137,7 @@ public class Range {
@Override
public String toString()
{
return String.format("( %.2f : %.2f )", min, max);
return String.format("Range(%.1f|%.1f)", min, max);
}

@ -4,7 +4,7 @@ package mightypork.utils.math.animation;
import mightypork.gamecore.control.timing.Pauseable;
import mightypork.gamecore.control.timing.Updateable;
import mightypork.utils.math.Calc;
import mightypork.utils.math.constraints.NumberBound;
import mightypork.utils.math.constraints.NumBound;
/**
@ -12,7 +12,7 @@ import mightypork.utils.math.constraints.NumberBound;
*
* @author MightyPork
*/
public class AnimDouble implements Updateable, Pauseable, NumberBound {
public class AnimDouble implements Updateable, Pauseable, NumBound {
/** target double */
protected double to = 0;

@ -16,7 +16,7 @@ import mightypork.utils.math.vect.VectView;
*
* @author MightyPork
*/
public class Bounds {
public class ConstraintFactory {
public static RectCache cached(final Poller poller, final RectBound rc)
{
@ -25,16 +25,16 @@ public class Bounds {
/**
* Convert {@link Number} to {@link NumberBound} if needed
* Convert {@link Number} to {@link NumBound} if needed
*
* @param o unknown numeric value
* @return converted
*/
private static NumberBound toNumberBound(final Object o)
private static NumBound toNumberBound(final Object o)
{
if (o instanceof NumberBound) return (NumberBound) o;
if (o instanceof NumBound) return (NumBound) o;
if (o instanceof Number) return new NumberBound() {
if (o instanceof Number) return new NumBound() {
@Override
public double getValue()
@ -48,7 +48,7 @@ public class Bounds {
/**
* Convert {@link Number} or {@link NumberBound} to double (current value)
* Convert {@link Number} or {@link NumBound} to double (current value)
*
* @param o unknown numeric value
* @return double value
@ -59,9 +59,9 @@ public class Bounds {
}
public static NumberBound min(final Object a, final Object b)
public static NumBound min(final Object a, final Object b)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -72,9 +72,9 @@ public class Bounds {
}
public static NumberBound max(final Object a, final Object b)
public static NumBound max(final Object a, final Object b)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -85,9 +85,9 @@ public class Bounds {
}
public static NumberBound abs(final NumberBound a)
public static NumBound abs(final NumBound a)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -98,9 +98,9 @@ public class Bounds {
}
public static NumberBound half(final NumberBound a)
public static NumBound half(final NumBound a)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -111,9 +111,9 @@ public class Bounds {
}
public static NumberBound round(final NumberBound a)
public static NumBound round(final NumBound a)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -137,9 +137,9 @@ public class Bounds {
}
public static NumberBound ceil(final NumberBound a)
public static NumBound ceil(final NumBound a)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -150,9 +150,9 @@ public class Bounds {
}
public static NumberBound floor(final NumberBound a)
public static NumBound floor(final NumBound a)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -163,9 +163,9 @@ public class Bounds {
}
public static NumberBound neg(final NumberBound a)
public static NumBound neg(final NumBound a)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -176,9 +176,9 @@ public class Bounds {
}
public static NumberBound add(final Object a, final Object b)
public static NumBound add(final Object a, final Object b)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -189,9 +189,9 @@ public class Bounds {
}
public static NumberBound sub(final Object a, final Object b)
public static NumBound sub(final Object a, final Object b)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -202,9 +202,9 @@ public class Bounds {
}
public static NumberBound mul(final Object a, final Object b)
public static NumBound mul(final Object a, final Object b)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -215,15 +215,15 @@ public class Bounds {
}
public static NumberBound half(final Object a)
public static NumBound half(final Object a)
{
return mul(a, 0.5);
}
public static NumberBound div(final Object a, final Object b)
public static NumBound div(final Object a, final Object b)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -234,9 +234,9 @@ public class Bounds {
}
public static NumberBound perc(final Object whole, final Object percent)
public static NumBound perc(final Object whole, final Object percent)
{
return new NumberBound() {
return new NumBound() {
@Override
public double getValue()
@ -546,7 +546,7 @@ public class Bounds {
{
final VectView size = r.getRect().size();
return RectVal.make(centerTo.getValue().sub(size.half()), size);
return RectVal.make(centerTo.copy().sub(size.half()), size);
}
};
}
@ -720,7 +720,7 @@ public class Bounds {
@Override
public VectView getSource()
{
return c1.getValue().add(c2);
return c1.copy().add(c2);
}
};
}
@ -739,7 +739,7 @@ public class Bounds {
@Override
public VectView getSource()
{
return c.getValue().add(eval(x), eval(y), eval(z));
return c.copy().add(eval(x), eval(y), eval(z));
}
};
}
@ -752,7 +752,7 @@ public class Bounds {
@Override
public VectView getSource()
{
return c1.getValue().sub(c2);
return c1.copy().sub(c2);
}
};
}
@ -771,7 +771,7 @@ public class Bounds {
@Override
public VectView getSource()
{
return c.getValue().sub(eval(x), eval(y), eval(z));
return c.copy().sub(eval(x), eval(y), eval(z));
}
};
@ -785,7 +785,7 @@ public class Bounds {
@Override
public VectView getSource()
{
return c.getValue().mul(eval(mul));
return c.copy().mul(eval(mul));
}
};
@ -799,7 +799,7 @@ public class Bounds {
@Override
public VectView getSource()
{
return c.getValue().norm(eval(norm));
return c.copy().norm(eval(norm));
}
};
@ -832,13 +832,13 @@ public class Bounds {
}
public static NumberBound height(final RectBound r)
public static NumBound height(final RectBound r)
{
return size(r).yc();
}
public static NumberBound width(final RectBound r)
public static NumBound width(final RectBound r)
{
return size(r).xc();
}

@ -6,10 +6,10 @@ package mightypork.utils.math.constraints;
*
* @author MightyPork
*/
public interface NumberBound {
public interface NumBound {
public static final NumberBound ZERO = new NumberConst(0);
public static final NumberBound ONE = new NumberConst(1);
public static final NumBound ZERO = new NumberConst(0);
public static final NumBound ONE = new NumberConst(1);
/**

@ -2,11 +2,11 @@ package mightypork.utils.math.constraints;
/**
* Constant number {@link NumberBound}
* Constant number {@link NumBound}
*
* @author MightyPork
*/
public class NumberConst implements NumberBound {
public class NumberConst implements NumBound {
private final double value;

@ -44,7 +44,7 @@ public class RectCache implements RectBound, Pollable {
@Override
public RectView getRect()
{
return cached.getView();
return cached.view();
}

@ -0,0 +1,18 @@
package mightypork.utils.math.constraints;
import mightypork.utils.math.vect.Vect;
/**
* Element holding a vector, used for constraint building.
*
* @author MightyPork
*/
public interface VectBound {
/**
* @return the current vector.
*/
public Vect getVect();
}

@ -0,0 +1,19 @@
package mightypork.utils.math.constraints.builder;
import mightypork.utils.math.constraints.RectBound;
public class Bounds {
public static class RectBB {
private final RectBound parent;
public RectBB(RectBound parent) {
this.parent = parent;
}
}
}

@ -16,119 +16,133 @@ public abstract class AbstractRect implements Rect {
@Override
public final RectView getRect()
public RectView getRect()
{
return this.getView();
return this.view();
}
@Override
public final VectVal topLeft()
public VectVal topLeft()
{
return origin();
}
@Override
public final VectVal topCenter()
public VectVal topCenter()
{
return origin().add(size().x() / 2, 0);
}
@Override
public final VectVal topRight()
public VectVal topRight()
{
return origin().add(size().x(), 0);
}
@Override
public final VectVal centerLeft()
public VectVal centerLeft()
{
return origin().add(0, size().y() / 2);
}
@Override
public final VectVal center()
public VectVal center()
{
return origin().add(size().half());
}
@Override
public final VectVal centerRight()
public VectVal centerRight()
{
return origin().add(size().x(), size().y() / 2);
}
@Override
public final VectVal bottomLeft()
public VectVal bottomLeft()
{
return origin().add(0, size().y());
}
@Override
public final VectVal bottomCenter()
public VectVal bottomCenter()
{
return origin().add(size().x() / 2, size().y());
}
@Override
public final VectVal bottomRight()
public VectVal bottomRight()
{
return origin().add(size().x(), size().y());
}
@Override
public final double width()
public double x()
{
return origin().x();
}
@Override
public double y()
{
return origin().y();
}
@Override
public double width()
{
return size().x();
}
@Override
public final double height()
public double height()
{
return size().y();
}
@Override
public final double getLeft()
public double left()
{
return origin().x();
}
@Override
public final double right()
public double right()
{
return origin().x() + size().x();
}
@Override
public final double top()
public double top()
{
return origin().y();
}
@Override
public final double bottom()
public double bottom()
{
return origin().y() + size().y();
}
@Override
public RectProxy getView()
public RectView view()
{
if (proxy == null) proxy = new RectProxy(this);
@ -137,14 +151,14 @@ public abstract class AbstractRect implements Rect {
@Override
public RectVal getValue()
public RectVal copy()
{
return RectVal.make(origin(), size());
return new RectVal(x(), y(), width(), height());
}
@Override
public final boolean contains(Vect point)
public boolean contains(Vect point)
{
final double x = point.x();
final double y = point.y();

@ -22,7 +22,7 @@ public interface Rect extends RectBound {
*
* @return copy
*/
RectVal getValue();
RectVal copy();
/**
@ -30,63 +30,123 @@ public interface Rect extends RectBound {
*
* @return proxy
*/
RectProxy getView();
RectView view();
/**
* @return origin
* @return origin (top left)
*/
VectVal origin();
/**
* @return size vector
*/
VectVal size();
/**
* @return current width
*/
double width();
/**
* @return current height
*/
double height();
/**
* @return origin X
*/
double x();
/**
* @return origin Y
*/
double y();
/**
* @return left X (low)
*/
double left();
/**
* @return right X (high)
*/
double right();
/**
* @return top Y (low)
*/
double top();
/**
* @return bottom Y (high)
*/
double bottom();
/**
* @return top left corner position
*/
VectVal topLeft();
/**
* @return top center position
*/
VectVal topCenter();
/**
* @return top right corner position
*/
VectVal topRight();
/**
* @return left center position
*/
VectVal centerLeft();
/**
* @return center position
*/
VectVal center();
/**
* @return right center position
*/
VectVal centerRight();
/**
* @return bottom left corner position
*/
VectVal bottomLeft();
/**
* @return bottom center position
*/
VectVal bottomCenter();
/**
* @return bottom right corner position
*/
VectVal bottomRight();
double getLeft();
double right();
double top();
double bottom();
/**
* Check if point is inside this rectangle
*

@ -94,14 +94,14 @@ class RectMutableImpl extends RectMutable {
@Override
public VectVal origin()
{
return pos.getValue();
return pos.copy();
}
@Override
public VectVal size()
{
return size.getValue();
return size.copy();
}

@ -5,8 +5,25 @@ import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal;
/**
* Rectangle with constant bounds, that can never change.
*
* @author MightyPork
*/
public class RectVal extends RectView {
/**
* Get a proxy at given rect
*
* @param observed observed rect
* @return view
*/
public static RectVal make(Rect observed)
{
return observed.copy();
}
/**
* Create at 0,0 with zero size
*
@ -114,7 +131,7 @@ public class RectVal extends RectView {
@Override
public RectVal getValue()
public RectVal copy()
{
return this; // nothing can change.
}

@ -16,7 +16,7 @@ public abstract class RectView extends RectMath<RectVal> {
*/
public static RectView make(Rect observed)
{
return observed.getView();
return observed.view();
}

@ -1,15 +1,15 @@
package mightypork.utils.math.vect;
import mightypork.utils.math.constraints.NumberBound;
import mightypork.utils.math.constraints.NumBound;
public abstract class AbstractVect implements Vect {
private VectView proxy;
private NumberBound xc;
private NumberBound yc;
private NumberBound zc;
private NumBound xc;
private NumBound yc;
private NumBound zc;
@Override
@ -46,9 +46,9 @@ public abstract class AbstractVect implements Vect {
@Override
public final NumberBound xc()
public final NumBound xc()
{
if (xc == null) xc = new NumberBound() {
if (xc == null) xc = new NumBound() {
@Override
public double getValue()
@ -62,9 +62,9 @@ public abstract class AbstractVect implements Vect {
@Override
public final NumberBound yc()
public final NumBound yc()
{
if (yc == null) yc = new NumberBound() {
if (yc == null) yc = new NumBound() {
@Override
public double getValue()
@ -78,9 +78,9 @@ public abstract class AbstractVect implements Vect {
@Override
public final NumberBound zc()
public final NumBound zc()
{
if (zc == null) zc = new NumberBound() {
if (zc == null) zc = new NumBound() {
@Override
public double getValue()
@ -93,6 +93,13 @@ public abstract class AbstractVect implements Vect {
}
@Override
public final Vect getVect()
{
return this;
}
@Override
public final double size()
{
@ -109,62 +116,14 @@ public abstract class AbstractVect implements Vect {
@Override
public VectVal getValue()
public VectVal copy()
{
return new VectVal(this);
}
@Override
public final double distTo(Vect point)
{
final double dx = x() - point.x();
final double dy = y() - point.y();
final double dz = z() - point.z();
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
@Override
public final VectVal midTo(Vect point)
{
final double dx = (point.x() - x()) * 0.5;
final double dy = (point.y() - y()) * 0.5;
final double dz = (point.z() - z()) * 0.5;
return VectVal.make(dx, dy, dz);
}
@Override
public final VectVal vecTo(Vect point)
{
return VectVal.make(point.x() - x(), point.y() - y(), point.z() - z());
}
@Override
public final VectVal cross(Vect vec)
{
//@formatter:off
return VectVal.make(
y() * vec.z() - z() * vec.y(),
z() * vec.x() - x() * vec.z(),
x() * vec.y() - y() * vec.x());
//@formatter:on
}
@Override
public final double dot(Vect vec)
{
return x() * vec.x() + y() * vec.y() + z() * vec.z();
}
@Override
public VectView getView()
public VectView view()
{
if (proxy == null) proxy = new VectProxy(this);
@ -199,6 +158,6 @@ public abstract class AbstractVect implements Vect {
@Override
public String toString()
{
return String.format("(%.1f %.1f %.1f)", x(), y(), z());
return String.format("(%.1f|%.1f|%.1f)", x(), y(), z());
}
}

@ -1,33 +1,32 @@
package mightypork.utils.math.vect;
import mightypork.utils.math.constraints.NumberBound;
import mightypork.utils.math.constraints.NumBound;
/**
* Coord view composed of given {@link NumberBound}s, using their current
* values.
* Coord view composed of given {@link NumBound}s, using their current values.
*
* @author MightyPork
*/
class NumConstrVect extends VectView {
private final NumberBound constrX;
private final NumberBound constrY;
private final NumberBound constrZ;
private final NumBound constrX;
private final NumBound constrY;
private final NumBound constrZ;
public NumConstrVect(NumberBound x, NumberBound y, NumberBound z) {
public NumConstrVect(NumBound x, NumBound y, NumBound z) {
this.constrX = x;
this.constrY = y;
this.constrZ = z;
}
public NumConstrVect(NumberBound x, NumberBound y) {
public NumConstrVect(NumBound x, NumBound y) {
this.constrX = x;
this.constrY = y;
this.constrZ = NumberBound.ZERO;
this.constrZ = NumBound.ZERO;
}

@ -1,7 +1,8 @@
package mightypork.utils.math.vect;
import mightypork.utils.math.constraints.NumberBound;
import mightypork.utils.math.constraints.NumBound;
import mightypork.utils.math.constraints.VectBound;
/**
@ -9,7 +10,7 @@ import mightypork.utils.math.constraints.NumberBound;
*
* @author MightyPork
*/
public interface Vect {
public interface Vect extends VectBound {
public static final VectVal ZERO = new VectVal(0, 0, 0);
public static final VectVal ONE = new VectVal(0, 0, 0);
@ -54,19 +55,19 @@ public interface Vect {
/**
* @return X constraint
*/
NumberBound xc();
NumBound xc();
/**
* @return Y constraint
*/
NumberBound yc();
NumBound yc();
/**
* @return Z constraint
*/
NumberBound zc();
NumBound zc();
/**
@ -83,57 +84,12 @@ public interface Vect {
public boolean isZero();
/**
* Get distance to other point
*
* @param point other point
* @return distance
*/
double distTo(Vect point);
/**
* Get middle of line to other point
*
* @param point other point
* @return result
*/
VectVal midTo(Vect point);
/**
* Create vector from this point to other point
*
* @param point second point
* @return result
*/
VectVal vecTo(Vect point);
/**
* Get cross product (vector multiplication)
*
* @param vec other vector
* @return result
*/
VectVal cross(Vect vec);
/**
* Get dot product (scalar multiplication)
*
* @param vec other vector
* @return dot product
*/
double dot(Vect vec);
/**
* Get a view at current state, not propagating further changes.
*
* @return a immutable copy
*/
VectVal getValue();
VectVal copy();
/**
@ -141,5 +97,5 @@ public interface Vect {
*
* @return immutable view
*/
VectView getView();
VectView view();
}

@ -12,20 +12,73 @@ import mightypork.utils.math.animation.Easing;
*
* @author MightyPork
*/
public class VectMutableAnim extends VectMutable implements Pauseable, Updateable {
public class VectAnimated extends VectMutable implements Pauseable, Updateable {
/**
* Create an animated vector; This way different easing / settings can be
* specified for each coordinate.
*
* @param x x animator
* @param y y animator
* @param z z animator
* @return animated mutable vector
*/
public static VectAnimated make(AnimDouble x, AnimDouble y, AnimDouble z)
{
return new VectAnimated(x, y, z);
}
/**
* Create an animated vector
*
* @param start initial positioon
* @param easing animation easing
* @return animated mutable vector
*/
public static VectAnimated make(Vect start, Easing easing)
{
return new VectAnimated(start, easing);
}
/**
* Create an animated vector, initialized at 0,0,0
*
* @param easing animation easing
* @return animated mutable vector
*/
public static VectAnimated make(Easing easing)
{
return new VectAnimated(Vect.ZERO, easing);
}
private final AnimDouble x, y, z;
private double defaultDuration = 0;
VectMutableAnim(AnimDouble x, AnimDouble y, AnimDouble z) {
/**
* Create an animated vector; This way different easing / settings can be
* specified for each coordinate.
*
* @param x x animator
* @param y y animator
* @param z z animator
*/
public VectAnimated(AnimDouble x, AnimDouble y, AnimDouble z) {
this.x = x;
this.y = y;
this.z = z;
}
VectMutableAnim(Vect start, Easing easing) {
/**
* Create an animated vector
*
* @param start initial positioon
* @param easing animation easing
*/
public VectAnimated(Vect start, Easing easing) {
x = new AnimDouble(start.x(), easing);
y = new AnimDouble(start.y(), easing);
z = new AnimDouble(start.z(), easing);
@ -74,7 +127,7 @@ public class VectMutableAnim extends VectMutable implements Pauseable, Updateabl
@Override
public VectMutableAnim result(double x, double y, double z)
public VectAnimated result(double x, double y, double z)
{
this.x.animate(x, defaultDuration);
this.y.animate(y, defaultDuration);
@ -84,14 +137,14 @@ public class VectMutableAnim extends VectMutable implements Pauseable, Updateabl
}
public VectMutableAnim add(Vect offset, double speed)
public VectAnimated add(Vect offset, double speed)
{
animate(getView().add(offset), speed);
animate(view().add(offset), speed);
return this;
}
public VectMutableAnim animate(double x, double y, double z, double duration)
public VectAnimated animate(double x, double y, double z, double duration)
{
this.x.animate(x, duration);
this.y.animate(y, duration);
@ -100,7 +153,7 @@ public class VectMutableAnim extends VectMutable implements Pauseable, Updateabl
}
public VectMutableAnim animate(Vect target, double duration)
public VectAnimated animate(Vect target, double duration)
{
animate(target.x(), target.y(), target.z(), duration);
return this;

@ -274,4 +274,77 @@ abstract class VectMath<V extends Vect> extends AbstractVect {
return mul(k);
}
/**
* Get distance to other point
*
* @param point other point
* @return distance
*/
public final double distTo(Vect point)
{
final double dx = x() - point.x();
final double dy = y() - point.y();
final double dz = z() - point.z();
return Math.sqrt(dx * dx + dy * dy + dz * dz);
}
/**
* Get middle of line to other point
*
* @param point other point
* @return result
*/
public final VectVal midTo(Vect point)
{
final double dx = (point.x() - x()) * 0.5;
final double dy = (point.y() - y()) * 0.5;
final double dz = (point.z() - z()) * 0.5;
return VectVal.make(dx, dy, dz);
}
/**
* Create vector from this point to other point
*
* @param point second point
* @return result
*/
public final VectVal vectTo(Vect point)
{
return VectVal.make(point.x() - x(), point.y() - y(), point.z() - z());
}
/**
* Get cross product (vector multiplication)
*
* @param vec other vector
* @return result
*/
public final VectVal cross(Vect vec)
{
//@formatter:off
return VectVal.make(
y() * vec.z() - z() * vec.y(),
z() * vec.x() - x() * vec.z(),
x() * vec.y() - y() * vec.x());
//@formatter:on
}
/**
* Get dot product (scalar multiplication)
*
* @param vec other vector
* @return dot product
*/
public final double dot(Vect vec)
{
return x() * vec.x() + y() * vec.y() + z() * vec.z();
}
}

@ -1,8 +1,6 @@
package mightypork.utils.math.vect;
import mightypork.utils.math.animation.AnimDouble;
import mightypork.utils.math.animation.Easing;
/**
@ -69,66 +67,10 @@ public abstract class VectMutable extends VectMath<VectMutable> { // returns its
*/
public static VectMutable make(double x, double y, double z)
{
return new VectMutableImpl(x, y, z);
return new VectMutableVariable(x, y, z);
}
/**
* Create an animated vector; This way different easing / settings can be
* specified for each coordinate.
*
* @param animX x animator
* @param animY y animator
* @param animZ z animator
* @return animated mutable vector
*/
public static VectMutableAnim makeAnim(AnimDouble animX, AnimDouble animY, AnimDouble animZ)
{
return new VectMutableAnim(animX, animY, animZ);
}
/**
* Create an animated vector
*
* @param animStart initial positioon
* @param easing animation easing
* @return animated mutable vector
*/
public static VectMutableAnim makeAnim(Vect animStart, Easing easing)
{
return new VectMutableAnim(animStart, easing);
}
/**
* Create an animated vector, initialized at 0,0,0
*
* @param easing animation easing
* @return animated mutable vector
*/
public static VectMutableAnim makeAnim(Easing easing)
{
return new VectMutableAnim(Vect.ZERO, easing);
}
@Override
public abstract VectMutable result(double x, double y, double z);
@Override
public abstract double x();
@Override
public abstract double y();
@Override
public abstract double z();
public VectMutable reset()
{
return result(0, 0, 0);

@ -7,7 +7,7 @@ package mightypork.utils.math.vect;
*
* @author MightyPork
*/
class VectMutableImpl extends VectMutable {
class VectMutableVariable extends VectMutable {
private double x, y, z;
@ -17,7 +17,7 @@ class VectMutableImpl extends VectMutable {
* @param y Y coordinate
* @param z Z coordinate
*/
public VectMutableImpl(double x, double y, double z) {
public VectMutableVariable(double x, double y, double z) {
super();
this.x = x;
this.y = y;
@ -47,7 +47,7 @@ class VectMutableImpl extends VectMutable {
@Override
public VectMutableImpl result(double x, double y, double z)
public VectMutable result(double x, double y, double z)
{
this.x = x;
this.y = y;

@ -3,8 +3,7 @@ package mightypork.utils.math.vect;
/**
* Coordinate with immutable numeric values.<br>
* This coordinate is guaranteed to never change, as opposed to view, which can
* be a proxy or a synthetic vector.
* This coordinate is guaranteed to never change, as opposed to view.
*
* @author MightyPork
*/
@ -18,7 +17,7 @@ public final class VectVal extends VectView {
*/
public static VectVal make(Vect value)
{
return value.getValue();
return value.copy();
}
@ -51,12 +50,12 @@ public final class VectVal extends VectView {
private final double x, y, z;
protected VectVal(Vect other) {
public VectVal(Vect other) {
this(other.x(), other.y(), other.z());
}
protected VectVal(double x, double y, double z) {
public VectVal(double x, double y, double z) {
this.x = x;
this.y = y;
this.z = z;
@ -84,12 +83,8 @@ public final class VectVal extends VectView {
}
/**
* @deprecated It's constant already.
*/
@Override
@Deprecated
public VectVal getValue()
public VectVal copy()
{
return this; // it's constant already
}

@ -2,11 +2,12 @@ package mightypork.utils.math.vect;
import mightypork.gamecore.control.interf.DefaultImpl;
import mightypork.utils.math.constraints.NumberBound;
import mightypork.utils.math.constraints.NumBound;
/**
* Read-only coordinate.
* Read-only coordinate, whose values cannot be changed directly. To keep
* current state, use the value() method.
*
* @author MightyPork
*/
@ -20,7 +21,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
*/
public static VectView make(Vect observed)
{
return observed.getView();
return observed.view();
}
@ -31,7 +32,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
* @param yc Y value
* @return view at the values
*/
public static VectView make(NumberBound xc, NumberBound yc)
public static VectView make(NumBound xc, NumBound yc)
{
return new NumConstrVect(xc, yc);
}
@ -45,7 +46,7 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
* @param zc Z value
* @return view at the values
*/
public static VectView make(NumberBound xc, NumberBound yc, NumberBound zc)
public static VectView make(NumBound xc, NumBound yc, NumBound zc)
{
return new NumConstrVect(xc, yc, zc);
}
@ -58,14 +59,10 @@ public abstract class VectView extends VectMath<VectVal> { // returns constant v
}
/**
* @deprecated VecView is not mutable, making a proxy has no effect.
*/
@Override
@Deprecated
public VectView getView()
public VectView view()
{
return this; // already not mutable
return this; // already a view
}

@ -154,16 +154,24 @@ public class Convert {
public static VectVal toVect(Object o, Vect def)
{
try {
if (o == null) return def.getValue();
if (o instanceof Vect) return ((Vect) o).getValue();
if (o == null) return def.copy();
if (o instanceof Vect) return ((Vect) o).copy();
if (o instanceof String) {
String s = ((String) o).trim().toUpperCase();
String s = ((String) o).trim();
// drop whitespace
s = s.replaceAll("\\s", "");
// colon to semicolon
s = s.replace(':', ';');
// remove brackets if any
// drop brackets
s = s.replaceAll("[\\(\\[\\{\\)\\]\\}]", "");
final String[] parts = s.split("[;]");
// norm separators
s = s.replaceAll("[:;]", "|");
// norm floating point
s = s.replaceAll("[,]", ".");
final String[] parts = s.split("[|]");
if (parts.length >= 2) {
@ -183,7 +191,7 @@ public class Convert {
// ignore
}
return def.getValue();
return def.copy();
}
@ -203,18 +211,34 @@ public class Convert {
if (o instanceof String) {
String s = ((String) o).trim();
// colon to semicolon
s = s.replace(',', ':');
// comma to dot.
s = s.replace(';', ':');
// dash
s = s.replaceAll("([0-9])\\s?[\\-]", "$1:");
// remove brackets if any
// drop whitespace
s = s.replaceAll("\\s", "");
// drop brackets
s = s.replaceAll("[\\(\\[\\{\\)\\]\\}]", "");
final String[] parts = s.split("[:]");
if (parts.length == 2) return new Range(Double.parseDouble(parts[0].trim()), Double.parseDouble(parts[1].trim()));
return new Range(Double.parseDouble(parts[0].trim()), Double.parseDouble(parts[0].trim()));
// norm separators
s = s.replaceAll("[:;]", "|").replace("..", "|");
// norm floating point
s = s.replaceAll("[,]", ".");
// dash to pipe, if not a minus sign
s = s.replaceAll("([0-9])\\s?[\\-]", "$1|");
final String[] parts = s.split("[|]");
if (parts.length >= 1) {
final double low = Double.parseDouble(parts[0].trim());
if (parts.length == 2) {
final double high = Double.parseDouble(parts[1].trim());
return Range.make(low, high);
}
return Range.make(low, low);
}
}
} catch (final NumberFormatException e) {
// ignore
@ -284,12 +308,12 @@ public class Convert {
/**
* Get Coord
* Get a vector of two or three coordinates
*
* @param o object
* @return Coord
*/
public static VectView toCoord(Object o)
public static VectView toVect(Object o)
{
return toVect(o, Vect.ZERO);
}

Loading…
Cancel
Save