Added NumBound & friends. Mutable is now a view. Much nicer!!

v5stable
Ondřej Hruška 11 years ago
parent a5c32834c0
commit 3320678f36
  1. 1
      src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java
  2. 7
      src/mightypork/gamecore/gui/components/AbstractComponent.java
  3. 2
      src/mightypork/gamecore/gui/components/layout/AbstractLayout.java
  4. 1
      src/mightypork/gamecore/gui/components/layout/ColumnHolder.java
  5. 1
      src/mightypork/gamecore/gui/components/layout/RowHolder.java
  6. 2
      src/mightypork/gamecore/gui/components/painters/AbstractPainter.java
  7. 2
      src/mightypork/gamecore/render/Render.java
  8. 6
      src/mightypork/gamecore/render/fonts/impl/CachedFont.java
  9. 1
      src/mightypork/rogue/screens/LayerFps.java
  10. 2
      src/mightypork/rogue/screens/test_bouncyboxes/BouncyBox.java
  11. 2
      src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java
  12. 2
      src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java
  13. 1
      src/mightypork/rogue/screens/test_font/ScreenTestFont.java
  14. 1
      src/mightypork/rogue/screens/test_render/LayerTestGradient.java
  15. 84
      src/mightypork/test/TestConstr.java
  16. 16
      src/mightypork/test/TestCoords.java
  17. 2
      src/mightypork/utils/annotations/FactoryMethod.java
  18. 1
      src/mightypork/utils/config/PropertyManager.java
  19. 5
      src/mightypork/utils/math/animation/AnimDouble.java
  20. 1
      src/mightypork/utils/math/animation/Easing.java
  21. 3
      src/mightypork/utils/math/constraints/NumBound.java
  22. 6
      src/mightypork/utils/math/constraints/RectBoundAdapter.java
  23. 2
      src/mightypork/utils/math/constraints/RectCache.java
  24. 1
      src/mightypork/utils/math/constraints/VectBound.java
  25. 20
      src/mightypork/utils/math/num/AbstractNum.java
  26. 1
      src/mightypork/utils/math/num/NumAdapter.java
  27. 11
      src/mightypork/utils/math/num/NumMath.java
  28. 6
      src/mightypork/utils/math/num/NumMathBase.java
  29. 105
      src/mightypork/utils/math/num/NumMathDynamic.java
  30. 12
      src/mightypork/utils/math/num/NumMathStatic.java
  31. 31
      src/mightypork/utils/math/num/NumMutable.java
  32. 3
      src/mightypork/utils/math/num/NumMutableImpl.java
  33. 3
      src/mightypork/utils/math/num/NumProxy.java
  34. 5
      src/mightypork/utils/math/num/NumVal.java
  35. 9
      src/mightypork/utils/math/rect/AbstractRect.java
  36. 4
      src/mightypork/utils/math/rect/RectAdapter.java
  37. 87
      src/mightypork/utils/math/rect/RectMath.java
  38. 117
      src/mightypork/utils/math/rect/RectMathDynamic.java
  39. 58
      src/mightypork/utils/math/rect/RectMathStatic.java
  40. 35
      src/mightypork/utils/math/rect/RectMutable.java
  41. 29
      src/mightypork/utils/math/rect/RectMutableImpl.java
  42. 14
      src/mightypork/utils/math/rect/RectProxy.java
  43. 52
      src/mightypork/utils/math/rect/RectVal.java
  44. 60
      src/mightypork/utils/math/rect/RectView.java
  45. 38
      src/mightypork/utils/math/rect/VectViewRect.java
  46. 6
      src/mightypork/utils/math/vect/AbstractVect.java
  47. 19
      src/mightypork/utils/math/vect/VectAnimated.java
  48. 21
      src/mightypork/utils/math/vect/VectMath.java
  49. 2
      src/mightypork/utils/math/vect/VectMathStatic.java
  50. 34
      src/mightypork/utils/math/vect/VectMutable.java
  51. 13
      src/mightypork/utils/math/vect/VectMutableImpl.java
  52. 3
      src/mightypork/utils/math/vect/VectProxy.java
  53. 34
      src/mightypork/utils/math/vect/VectVal.java
  54. 8
      src/mightypork/utils/math/vect/VectView.java
  55. 1
      src/mightypork/utils/objects/Convert.java

@ -4,7 +4,6 @@ package mightypork.gamecore.control.bus.events;
import mightypork.gamecore.control.bus.events.types.UnloggedEvent; import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
/** /**

@ -3,26 +3,27 @@ package mightypork.gamecore.gui.components;
import mightypork.gamecore.control.AppAccess; import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppSubModule; import mightypork.gamecore.control.AppSubModule;
import mightypork.gamecore.control.bus.BusAccess;
import mightypork.gamecore.control.bus.clients.BusNode;
import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView; import mightypork.utils.math.rect.RectView;
public abstract class AbstractComponent extends AppSubModule implements PluggableRenderable { public abstract class AbstractComponent extends AppSubModule implements PluggableRenderable {
private RectBound context; private RectBound context;
public AbstractComponent(AppAccess app) { public AbstractComponent(AppAccess app) {
super(app); super(app);
} }
@Override @Override
public void setContext(RectBound context) public void setContext(RectBound context)
{ {
this.context = context; this.context = context;
} }
@Override @Override
public RectView getRect() public RectView getRect()
{ {

@ -20,7 +20,7 @@ import mightypork.utils.math.constraints.RectBound;
*/ */
public abstract class AbstractLayout extends AbstractComponent { public abstract class AbstractLayout extends AbstractComponent {
final LinkedList<PluggableRenderable> elements = new LinkedList<>(); final LinkedList<PluggableRenderable> elements = new LinkedList<>();
/** /**

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

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

@ -3,8 +3,8 @@ package mightypork.gamecore.gui.components.painters;
import mightypork.gamecore.gui.components.PluggableRenderable; import mightypork.gamecore.gui.components.PluggableRenderable;
import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.components.Renderable;
import mightypork.utils.math.constraints.RectBoundAdapter;
import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.constraints.RectBoundAdapter;
import mightypork.utils.math.rect.RectView; import mightypork.utils.math.rect.RectView;

@ -352,7 +352,7 @@ public class Render {
*/ */
public static void quad(Rect quad) public static void quad(Rect quad)
{ {
RectView rv = quad.view(); final RectView rv = quad.view();
final double x1 = rv.left().value(); final double x1 = rv.left().value();
final double y1 = rv.top().value(); final double y1 = rv.top().value();

@ -294,7 +294,8 @@ public class CachedFont implements GLFont {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI); byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
} else { } else {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData()); byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder())
.put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
} }
byteBuffer.flip(); byteBuffer.flip();
@ -411,7 +412,8 @@ public class CachedFont implements GLFont {
chtx = chars.get(charCurrent); chtx = chars.get(charCurrent);
if (chtx != null) { if (chtx != null) {
drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + chtx.height); drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY
+ chtx.height);
totalwidth += chtx.width; totalwidth += chtx.width;
} }
} }

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

@ -1,8 +1,6 @@
package mightypork.rogue.screens.test_bouncyboxes; package mightypork.rogue.screens.test_bouncyboxes;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.control.timing.Updateable; import mightypork.gamecore.control.timing.Updateable;

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

@ -1,8 +1,6 @@
package mightypork.rogue.screens.test_cat_sound; package mightypork.rogue.screens.test_cat_sound;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.Random; import java.util.Random;
import mightypork.gamecore.control.bus.events.MouseButtonEvent; import mightypork.gamecore.control.bus.events.MouseButtonEvent;

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

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

@ -1,10 +1,16 @@
package mightypork.test; package mightypork.test;
import java.util.Locale; import java.util.Locale;
import mightypork.utils.math.num.NumMutable;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.rect.RectVal; import mightypork.utils.math.rect.RectVal;
import mightypork.utils.math.rect.RectView; import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
public class TestConstr { public class TestConstr {
@ -13,13 +19,81 @@ public class TestConstr {
{ {
Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.ENGLISH);
final RectVal rect = RectVal.make(0, 0, 10, 10); int cnt = -1;
final VectVal point = VectVal.make(50, 50);
{
final RectVal rect = RectVal.make(0, 0, 10, 10);
final VectVal point = VectVal.make(50, 50);
System.out.println("Test " + ++cnt + ": rect = " + rect);
System.out.println("Test " + cnt + ": point = " + point);
System.out.println("Test " + cnt + ": centered rect = " + rect.view().centerTo(point));
}
{
final RectVal rect = RectVal.make(0, 0, 10, 10);
final RectView v = rect.view().view();
System.out.println("\nTest " + ++cnt + ": " + (v == rect.view()));
}
{
final RectVal rect = RectVal.make(0, 0, 10, 10);
final RectView v = rect.view().view().view().view().view().view();
System.out.println("\nTest " + ++cnt + ": " + (v == rect.view()));
}
{
final Vect a = VectVal.make(3, 3);
final VectVal v = a.copy().copy().copy();
System.out.println("\nTest " + ++cnt + ": " + (v == a.copy()));
}
{
final Vect a = VectVal.make(3, 3);
final VectVal v = a.copy().copy().copy();
System.out.println("\nTest " + ++cnt + ": " + (v == a.copy()));
}
{
final VectMutable a = VectMutable.make(10, 10);
final VectView view = a.view().mul(10).half().sub(1, 1);
System.out.println("\nTest " + ++cnt + ": " + (view.equals(VectVal.make(49, 49))));
a.add(10, 0);
System.out.println("Test " + cnt + ": " + (view.equals(VectVal.make(99, 49))));
a.setTo(900, 999);
System.out.println(view);
}
{
final NumMutable side = NumMutable.make(100);
final VectMutable center = VectMutable.make(0, 0);
final Rect box = side.view().box().centerTo(center);
System.out.println(box);
side.setTo(10);
System.out.println(box);
center.setTo(900, -50);
System.out.println(box);
}
{
final NumMutable a = NumMutable.make(100);
a.setTo(a.mul(50).add(10).div(2));
System.out.println(a);
Rect r;
System.out.println(r = a.box());
System.out.println(rect); a.reset();
System.out.println(point);
System.out.println(rect.view().centerTo(point));
System.out.println(r);
}
} }
} }

@ -3,8 +3,6 @@ package mightypork.test;
import java.util.Locale; import java.util.Locale;
import mightypork.utils.math.constraints.NumBound;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumView; import mightypork.utils.math.num.NumView;
import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView; import mightypork.utils.math.vect.VectView;
@ -17,27 +15,27 @@ public class TestCoords {
Locale.setDefault(Locale.ENGLISH); Locale.setDefault(Locale.ENGLISH);
// test // test
VectMutable var = VectMutable.make(1, 2, 3); final VectMutable var = VectMutable.make(1, 2, 3);
VectView cubicRoot = var.view().mul(var).mul(var); final VectView cubicRoot = var.mul(var).mul(var);
VectView half = var.view().half(); final VectView half = var.half();
System.out.println("x, x^3, x/5"); System.out.println("x, x^3, x/5");
System.out.println(var); System.out.println(var);
System.out.println(cubicRoot); System.out.println(cubicRoot);
System.out.println(half); System.out.println(half);
var.mul(10); var.setTo(var.mul(10));
System.out.println("x = x*10; x, x^3, x/5"); System.out.println("x = x*10; x, x^3, x/5");
System.out.println(var); System.out.println(var);
System.out.println(cubicRoot); System.out.println(cubicRoot);
System.out.println(half); System.out.println(half);
NumView y = var.view().yn(); final NumView y = var.yn();
System.out.println("y: "+y.value()); System.out.println("y: " + y.value());
var.add(100,100); var.setTo(var.add(100, 100));
System.out.println("x = x*100; x.y(), x, x^3, x/5"); System.out.println("x = x*100; x.y(), x, x^3, x/5");
System.out.println(y.value()); System.out.println(y.value());

@ -1,11 +1,13 @@
package mightypork.utils.annotations; package mightypork.utils.annotations;
import java.lang.annotation.Documented; import java.lang.annotation.Documented;
import java.lang.annotation.ElementType; import java.lang.annotation.ElementType;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target; import java.lang.annotation.Target;
/** /**
* Marks a static factory method * Marks a static factory method
* *

@ -12,7 +12,6 @@ import java.util.TreeMap;
import mightypork.utils.math.Range; import mightypork.utils.math.Range;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.objects.Convert; import mightypork.utils.objects.Convert;

@ -4,9 +4,7 @@ package mightypork.utils.math.animation;
import mightypork.gamecore.control.timing.Pauseable; import mightypork.gamecore.control.timing.Pauseable;
import mightypork.gamecore.control.timing.Updateable; import mightypork.gamecore.control.timing.Updateable;
import mightypork.utils.math.Calc; import mightypork.utils.math.Calc;
import mightypork.utils.math.constraints.NumBound;
import mightypork.utils.math.num.NumMutable; import mightypork.utils.math.num.NumMutable;
import mightypork.utils.math.num.NumVal;
/** /**
@ -202,12 +200,11 @@ public class AnimDouble extends NumMutable implements Updateable, Pauseable {
* @param value * @param value
*/ */
@Override @Override
public AnimDouble setTo(double value) public void setTo(double value)
{ {
from = to = value; from = to = value;
elapsedTime = 0; elapsedTime = 0;
duration = defaultDuration; duration = defaultDuration;
return this;
} }

@ -1,5 +1,6 @@
package mightypork.utils.math.animation; package mightypork.utils.math.animation;
import mightypork.utils.annotations.FactoryMethod; import mightypork.utils.annotations.FactoryMethod;

@ -1,8 +1,7 @@
package mightypork.utils.math.constraints; package mightypork.utils.math.constraints;
import mightypork.utils.math.num.Num; import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumVal;
import mightypork.utils.math.num.NumView;
/** /**

@ -12,7 +12,6 @@ import mightypork.utils.math.rect.RectAdapter;
*/ */
public abstract class RectBoundAdapter extends RectAdapter implements PluggableRectBound { public abstract class RectBoundAdapter extends RectAdapter implements PluggableRectBound {
private RectBound backing = null; private RectBound backing = null;
@ -22,10 +21,11 @@ public abstract class RectBoundAdapter extends RectAdapter implements PluggableR
this.backing = rect; this.backing = rect;
} }
@Override @Override
public Rect getSource() { public Rect getSource()
{
return backing.getRect(); return backing.getRect();
} }
} }

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

@ -1,7 +1,6 @@
package mightypork.utils.math.constraints; package mightypork.utils.math.constraints;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView; import mightypork.utils.math.vect.VectView;

@ -1,23 +1,37 @@
package mightypork.utils.math.num; package mightypork.utils.math.num;
public abstract class AbstractNum implements Num { abstract class AbstractNum implements Num {
private NumView proxy;
@Override @Override
public Num getNum() { public Num getNum()
{
return this; return this;
} }
@Override @Override
public NumView view() public NumView view()
{ {
return new NumProxy(this); if (proxy == null) proxy = new NumProxy(this);
return proxy;
} }
@Override @Override
public NumVal copy() public NumVal copy()
{ {
return new NumVal(this); return new NumVal(this);
} }
@Override
public String toString()
{
return String.format("#{%.1f}",value());
}
} }

@ -5,6 +5,7 @@ public abstract class NumAdapter extends NumView {
protected abstract Num getSource(); protected abstract Num getSource();
@Override @Override
public double value() public double value()
{ {

@ -1,6 +1,9 @@
package mightypork.utils.math.num; package mightypork.utils.math.num;
import mightypork.utils.math.rect.Rect;
/** /**
* Math operations for numbers * Math operations for numbers
* *
@ -154,4 +157,12 @@ interface NumMath<N extends NumMath<N>> extends Num {
boolean isZero(); boolean isZero();
/**
* Make a square rect with this side, positioned at 0,0
*
* @return new rect
*/
Rect box();
} }

@ -1,9 +1,10 @@
package mightypork.utils.math.num; package mightypork.utils.math.num;
import mightypork.utils.math.constraints.NumBound; import mightypork.utils.math.constraints.NumBound;
public abstract class NumMathBase<N extends NumMath<N>> extends AbstractNum implements NumMath<N> { abstract class NumMathBase<N extends NumMath<N>> extends AbstractNum implements NumMath<N> {
/** /**
* Convert to double, turning null into zero. * Convert to double, turning null into zero.
@ -19,6 +20,7 @@ public abstract class NumMathBase<N extends NumMath<N>> extends AbstractNum impl
/** /**
* Convert {@link NumBound} to {@link Num}, turning null to Num.ZERO. * Convert {@link NumBound} to {@link Num}, turning null to Num.ZERO.
*
* @param a numeric bound * @param a numeric bound
* @return num * @return num
*/ */
@ -144,7 +146,7 @@ public abstract class NumMathBase<N extends NumMath<N>> extends AbstractNum impl
if (this == obj) return true; if (this == obj) return true;
if (obj == null) return false; if (obj == null) return false;
if (!(obj instanceof NumMathBase)) return false; if (!(obj instanceof NumMathBase)) return false;
NumMathBase<?> other = (NumMathBase<?>) obj; final NumMathBase<?> other = (NumMathBase<?>) obj;
return eq(other); return eq(other);
} }

@ -1,7 +1,10 @@
package mightypork.utils.math.num; package mightypork.utils.math.num;
public abstract class NumMathDynamic extends NumMathBase<NumView>{ import mightypork.utils.math.rect.RectView;
abstract class NumMathDynamic extends NumMathBase<NumView> {
private NumView ceil; private NumView ceil;
private NumView floor; private NumView floor;
@ -20,12 +23,14 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
private NumView neg; private NumView neg;
private NumView abs; private NumView abs;
@Override @Override
public NumView add(final double addend) public NumView add(final double addend)
{ {
return new NumView() { return new NumView() {
private Num t = NumMathDynamic.this; private final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
@ -35,18 +40,21 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}; };
} }
@Override @Override
public NumView sub(final double subtrahend) public NumView sub(final double subtrahend)
{ {
return add(-subtrahend); return add(-subtrahend);
} }
@Override @Override
public NumView mul(final double factor) public NumView mul(final double factor)
{ {
return new NumView() { return new NumView() {
private Num t = NumMathDynamic.this; private final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
@ -56,42 +64,48 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}; };
} }
@Override @Override
public NumView div(final double factor) public NumView div(final double factor)
{ {
return mul(1/factor); return mul(1 / factor);
} }
@Override @Override
public NumView perc(final double percent) public NumView perc(final double percent)
{ {
return mul(percent/100); return mul(percent / 100);
} }
@Override @Override
public NumView neg() public NumView neg()
{ {
if(neg==null) neg = new NumView() { if (neg == null) neg = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
return -1*t.value(); return -1 * t.value();
} }
}; };
return neg; return neg;
} }
@Override @Override
public NumView abs() public NumView abs()
{ {
if(abs==null) abs = new NumView() { if (abs == null) abs = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -102,6 +116,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return abs; return abs;
} }
@Override @Override
public NumView max(final double other) public NumView max(final double other)
{ {
@ -109,6 +124,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -117,6 +133,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}; };
} }
@Override @Override
public NumView min(final double other) public NumView min(final double other)
{ {
@ -124,6 +141,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -132,6 +150,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}; };
} }
@Override @Override
public NumView pow(final double other) public NumView pow(final double other)
{ {
@ -139,6 +158,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -147,49 +167,55 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}; };
} }
@Override @Override
public NumView square() public NumView square()
{ {
if(square==null) square = new NumView() { if (square == null) square = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
final double v = t.value(); final double v = t.value();
return v*v; return v * v;
} }
}; };
return square; return square;
} }
@Override @Override
public NumView cube() public NumView cube()
{ {
if(cube==null) cube = new NumView() { if (cube == null) cube = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
final double v = t.value(); final double v = t.value();
return v*v*v; return v * v * v;
} }
}; };
return cube; return cube;
} }
@Override @Override
public NumView sqrt() public NumView sqrt()
{ {
if(sqrt==null) sqrt = new NumView() { if (sqrt == null) sqrt = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -200,13 +226,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return sqrt; return sqrt;
} }
@Override @Override
public NumView cbrt() public NumView cbrt()
{ {
if(cbrt==null) cbrt = new NumView() { if (cbrt == null) cbrt = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -217,13 +245,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return cbrt; return cbrt;
} }
@Override @Override
public NumView sin() public NumView sin()
{ {
if(sin==null) sin = new NumView() { if (sin == null) sin = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -234,13 +264,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return sin; return sin;
} }
@Override @Override
public NumView cos() public NumView cos()
{ {
if(cos==null) cos = new NumView() { if (cos == null) cos = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -251,13 +283,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return cos; return cos;
} }
@Override @Override
public NumView tan() public NumView tan()
{ {
if(tan==null) tan = new NumView() { if (tan == null) tan = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -268,13 +302,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return tan; return tan;
} }
@Override @Override
public NumView asin() public NumView asin()
{ {
if(asin==null) asin = new NumView() { if (asin == null) asin = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -285,13 +321,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return asin; return asin;
} }
@Override @Override
public NumView acos() public NumView acos()
{ {
if(acos==null) acos = new NumView() { if (acos == null) acos = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -302,13 +340,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return acos; return acos;
} }
@Override @Override
public NumView atan() public NumView atan()
{ {
if(atan==null) atan = new NumView() { if (atan == null) atan = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -319,13 +359,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return atan; return atan;
} }
@Override @Override
public NumView round() public NumView round()
{ {
if(round==null) round = new NumView() { if (round == null) round = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -336,13 +378,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return round; return round;
} }
@Override @Override
public NumView floor() public NumView floor()
{ {
if(floor==null) floor = new NumView() { if (floor == null) floor = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -353,13 +397,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return floor; return floor;
} }
@Override @Override
public NumView ceil() public NumView ceil()
{ {
if(ceil==null) ceil = new NumView() { if (ceil == null) ceil = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -370,13 +416,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return ceil; return ceil;
} }
@Override @Override
public NumView signum() public NumView signum()
{ {
if(sgn==null) sgn = new NumView() { if (sgn == null) sgn = new NumView() {
final Num t = NumMathDynamic.this; final Num t = NumMathDynamic.this;
@Override @Override
public double value() public double value()
{ {
@ -387,6 +435,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return sgn; return sgn;
} }
@Override @Override
public NumView average(final double other) public NumView average(final double other)
{ {
@ -401,7 +450,6 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
} }
@Override @Override
public NumView add(final Num addend) public NumView add(final Num addend)
{ {
@ -555,4 +603,11 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
} }
}; };
} }
@Override
public RectView box()
{
return RectView.make(this, this);
}
} }

@ -1,7 +1,10 @@
package mightypork.utils.math.num; package mightypork.utils.math.num;
public abstract class NumMathStatic<N extends NumMathStatic<N>> extends NumMathBase<N> { import mightypork.utils.math.rect.RectVal;
abstract class NumMathStatic<N extends NumMathStatic<N>> extends NumMathBase<N> {
protected abstract N result(double a); protected abstract N result(double a);
@ -253,6 +256,13 @@ public abstract class NumMathStatic<N extends NumMathStatic<N>> extends NumMathB
} }
@Override
public RectVal box()
{
return RectVal.make(this, this);
}
@Override @Override
public String toString() public String toString()
{ {

@ -10,7 +10,7 @@ import mightypork.utils.math.constraints.NumBound;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class NumMutable extends NumMathStatic<NumMutable> { public abstract class NumMutable extends NumView {
/** /**
* Make a new mutable number initialized as zero (0) * Make a new mutable number initialized as zero (0)
@ -36,7 +36,6 @@ public abstract class NumMutable extends NumMathStatic<NumMutable> {
} }
/** /**
* Make as copy of another * Make as copy of another
* *
@ -49,6 +48,7 @@ public abstract class NumMutable extends NumMathStatic<NumMutable> {
return new NumMutableImpl(value); return new NumMutableImpl(value);
} }
/** /**
* Make as copy of another * Make as copy of another
* *
@ -61,6 +61,7 @@ public abstract class NumMutable extends NumMathStatic<NumMutable> {
return new NumMutableImpl(eval(copied)); return new NumMutableImpl(eval(copied));
} }
/** /**
* Make as copy of another * Make as copy of another
* *
@ -74,31 +75,31 @@ public abstract class NumMutable extends NumMathStatic<NumMutable> {
} }
@Override /**
protected NumMutable result(double a) * Assign a value
{ *
return setTo(a); * @param value new value
} */
public abstract void setTo(double value);
/** /**
* Assign a value * Assign a value
* *
* @param value new value * @param value new value
* @return this
*/ */
public NumMutable set(Num value) public void setTo(Num value)
{ {
return setTo(eval(value)); setTo(eval(value));
} }
/** /**
* Assign a value * Set to zero
*
* @param value new value
* @return this
*/ */
public abstract NumMutable setTo(double value); public void reset()
{
setTo(0);
}
} }

@ -29,10 +29,9 @@ class NumMutableImpl extends NumMutable {
@Override @Override
public NumMutable setTo(double value) public void setTo(double value)
{ {
this.value = value; this.value = value;
return this;
} }
} }

@ -1,7 +1,7 @@
package mightypork.utils.math.num; package mightypork.utils.math.num;
public class NumProxy extends NumAdapter { class NumProxy extends NumAdapter {
private final Num observed; private final Num observed;
@ -10,6 +10,7 @@ public class NumProxy extends NumAdapter {
this.observed = observed; this.observed = observed;
} }
@Override @Override
protected Num getSource() protected Num getSource()
{ {

@ -17,6 +17,7 @@ public class NumVal extends NumMathStatic<NumVal> {
@SuppressWarnings("hiding") @SuppressWarnings("hiding")
public static final NumVal ONE = NumVal.make(1); public static final NumVal ONE = NumVal.make(1);
/** /**
* Make a new constant * Make a new constant
* *
@ -58,12 +59,12 @@ public class NumVal extends NumMathStatic<NumVal> {
private final double value; private final double value;
public NumVal(Num copied) { NumVal(Num copied) {
this.value = copied.value(); this.value = copied.value();
} }
public NumVal(double value) { NumVal(double value) {
this.value = value; this.value = value;
} }

@ -6,9 +6,9 @@ package mightypork.utils.math.rect;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class AbstractRect implements Rect { abstract class AbstractRect implements Rect {
private RectProxy proxy; private RectProxy proxy;
@Override @Override
@ -39,10 +39,7 @@ public abstract class AbstractRect implements Rect {
@Override @Override
public String toString() public String toString()
{ {
return String.format( return String.format("Rect { %s - %s }", origin(), origin().copy().add(size()));
"Rect { %s - %s }",
origin(),
origin().view().add(size()));
} }
} }

@ -14,7 +14,7 @@ import mightypork.utils.math.vect.VectView;
*/ */
public abstract class RectAdapter extends RectView { public abstract class RectAdapter extends RectView {
private VectAdapter originAdapter = new VectAdapter() { private final VectAdapter originAdapter = new VectAdapter() {
@Override @Override
protected Vect getSource() protected Vect getSource()
@ -23,7 +23,7 @@ public abstract class RectAdapter extends RectView {
} }
}; };
private VectAdapter sizeAdapter = new VectAdapter() { private final VectAdapter sizeAdapter = new VectAdapter() {
@Override @Override
protected Vect getSource() protected Vect getSource()

@ -1,97 +1,11 @@
package mightypork.utils.math.rect; package mightypork.utils.math.rect;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumView;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectAdapter;
import mightypork.utils.math.vect.VectView;
abstract class RectMath<R extends Rect> extends AbstractRect { abstract class RectMath<R extends Rect> extends AbstractRect {
protected NumView p_x;
protected NumView p_y;
protected NumView p_width;
protected NumView p_height;
protected NumView p_left;
protected NumView p_top;
protected NumView p_right;
protected NumView p_bottom;
protected VectView p_tl;
protected VectView p_tc;
protected VectView p_tr;
protected VectView p_cl;
protected VectView p_cc;
protected VectView p_cr;
protected VectView p_bl;
protected VectView p_bc;
protected VectView p_br;
protected VectView p_origin;
protected VectView p_size;
public RectMath() {
p_origin = new VectAdapter() {
@Override
protected Vect getSource()
{
return RectMath.this.origin();
}
};
p_size = new VectAdapter() {
@Override
protected Vect getSource()
{
return RectMath.this.size();
}
};
// setup proxies
// origin, size disassembled
p_width = p_size.xn();
p_height = p_size.yn();
p_x = p_origin.xn();
p_y = p_origin.yn();
// coordinates
p_top = p_y;
p_left = p_x;
p_right = p_left.add(p_width);
p_bottom = p_top.add(p_height);
// corners
// -- top line --
Num width_half = p_width.half();
Num ya = Num.ZERO;
p_tl = p_origin;
p_tc = p_origin.add(width_half, ya);
p_tr = p_origin.add(p_width, ya);
// --center line--
ya = p_height.half();
p_cl = p_origin.add(Num.ZERO, ya);
p_cc = p_origin.add(width_half, ya);
p_cr = p_origin.add(p_width, ya);
// -- bottom line --
ya = p_height;
p_bl = p_origin.add(Num.ZERO, ya);
p_bc = p_origin.add(width_half, ya);
p_br = p_origin.add(p_width, ya);
}
/** /**
* Add vector to origin * Add vector to origin
* *
@ -221,4 +135,5 @@ abstract class RectMath<R extends Rect> extends AbstractRect {
return x >= x1 && y >= y1 && x <= x2 && y <= y2; return x >= x1 && y >= y1 && x <= x2 && y <= y2;
} }
} }

@ -2,12 +2,11 @@ package mightypork.utils.math.rect;
import mightypork.utils.math.num.Num; import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumView;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView; import mightypork.utils.math.vect.VectView;
public abstract class RectMathDynamic extends RectMath<RectView> { abstract class RectMathDynamic extends RectMath<RectView> {
@Override @Override
public abstract VectView origin(); public abstract VectView origin();
@ -22,20 +21,20 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
{ {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size; return t.size();
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.add(move); return t.origin().add(move);
} }
}; };
@ -43,48 +42,48 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
@Override @Override
public RectView move(final double xd, final double yd) public RectView move(final double x, final double y)
{ {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size; return t.size();
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.add(xd, yd); return t.origin().add(x, y);
} }
}; };
} }
public RectView move(final Num xd, final Num yd) public RectView move(final Num x, final Num y)
{ {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size; return t.size();
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.add(xd, yd); return t.origin().add(x, y);
} }
}; };
@ -92,24 +91,24 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
@Override @Override
public RectView shrink(final double leftd, final double rightd, final double topd, final double bottomd) public RectView shrink(final double left, final double right, final double top, final double bottom)
{ {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size.sub(leftd + rightd, topd + bottomd); return t.size().sub(left + right, top + bottom);
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.add(leftd, topd); return t.origin().add(left, top);
} }
}; };
@ -117,73 +116,73 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
@Override @Override
public RectView grow(final double leftd, final double rightd, final double topd, final double bottomd) public RectView grow(final double left, final double right, final double top, final double bottom)
{ {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size.add(leftd + rightd, topd + bottomd); return t.size().add(left + right, top + bottom);
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.sub(leftd, topd); return t.origin().sub(left, top);
} }
}; };
} }
public RectView shrink(final Num leftd, final Num rightd, final Num topd, final Num bottomd) public RectView shrink(final Num left, final Num right, final Num top, final Num bottom)
{ {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size.sub(leftd.view().add(rightd), topd.view().add(bottomd)); return t.size().sub(left.view().add(right), top.view().add(bottom));
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.add(leftd, topd); return t.origin().add(left, top);
} }
}; };
} }
public RectView grow(final Num leftd, final Num rightd, final Num topd, final Num bottomd) public RectView grow(final Num left, final Num right, final Num top, final Num bottom)
{ {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size.add(leftd.view().add(rightd), topd.view().add(bottomd)); return t.size().add(left.view().add(right), top.view().add(bottom));
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.sub(leftd, topd); return t.origin().sub(left, top);
} }
}; };
@ -196,20 +195,20 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
return new RectView() { return new RectView() {
private RectMathDynamic t = RectMathDynamic.this; private final RectMathDynamic t = RectMathDynamic.this;
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size.round(); return t.size().round();
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return t.p_origin.round(); return t.origin().round();
} }
}; };
@ -217,121 +216,121 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
@Override @Override
public NumView x() public Num x()
{ {
return p_x; return origin().xn();
} }
@Override @Override
public NumView y() public Num y()
{ {
return p_y; return origin().yn();
} }
@Override @Override
public NumView width() public Num width()
{ {
return p_width; return size().xn();
} }
@Override @Override
public NumView height() public Num height()
{ {
return p_height; return size().yn();
} }
@Override @Override
public NumView left() public Num left()
{ {
return p_left; return origin().yn();
} }
@Override @Override
public NumView right() public Num right()
{ {
return p_right; return origin().xn().add(size().xn());
} }
@Override @Override
public NumView top() public Num top()
{ {
return p_top; return origin().yn();
} }
@Override @Override
public NumView bottom() public Num bottom()
{ {
return p_bottom; return origin().yn().add(size().yn());
} }
@Override @Override
public VectView topLeft() public VectView topLeft()
{ {
return p_tl; return origin();
} }
@Override @Override
public VectView topCenter() public VectView topCenter()
{ {
return p_tc; return origin().add(size().xn().half(), Num.ZERO);
} }
@Override @Override
public VectView topRight() public VectView topRight()
{ {
return p_tr; return origin().add(size().xn(), Num.ZERO);
} }
@Override @Override
public VectView centerLeft() public VectView centerLeft()
{ {
return p_cl; return origin().add(Num.ZERO, size().yn().half());
} }
@Override @Override
public VectView center() public VectView center()
{ {
return p_cc; return origin().add(size().half());
} }
@Override @Override
public VectView centerRight() public VectView centerRight()
{ {
return p_cr; return origin().add(size().xn(), size().yn().half());
} }
@Override @Override
public VectView bottomLeft() public VectView bottomLeft()
{ {
return p_bl; return origin().add(Num.ZERO, size().yn());
} }
@Override @Override
public VectView bottomCenter() public VectView bottomCenter()
{ {
return p_bc; return origin().add(size().xn().half(), size().yn());
} }
@Override @Override
public VectView bottomRight() public VectView bottomRight()
{ {
return p_br; return origin().add(size().xn(), size().yn());
} }
@ -346,14 +345,14 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
@Override @Override
public VectView size() public VectView size()
{ {
return t.p_size; return t.size();
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return point.view().sub(t.p_size.half()); return point.view().sub(t.size().half());
} }
}; };
} }

@ -4,9 +4,10 @@ package mightypork.utils.math.rect;
import mightypork.utils.math.num.NumVal; import mightypork.utils.math.num.NumVal;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
public abstract class RectMathStatic<R extends RectMathStatic<R>> extends RectMath<R> { abstract class RectMathStatic<R extends RectMathStatic<R>> extends RectMath<R> {
@Override @Override
public abstract VectVal origin(); public abstract VectVal origin();
@ -15,6 +16,7 @@ public abstract class RectMathStatic<R extends RectMathStatic<R>> extends RectMa
@Override @Override
public abstract VectVal size(); public abstract VectVal size();
@Override @Override
public R move(Vect move) public R move(Vect move)
{ {
@ -23,36 +25,44 @@ public abstract class RectMathStatic<R extends RectMathStatic<R>> extends RectMa
@Override @Override
public R move(double x, double y) { public R move(double x, double y)
return result(p_origin.add(x,y), p_size); {
return result(origin().add(x, y), size());
} }
@Override @Override
public R shrink(double left, double right, double top, double bottom) public R shrink(double left, double right, double top, double bottom)
{ {
return result(p_origin.add(left, top), p_size.sub(left + right, top + bottom)); return result(origin().add(left, top), size().sub(left + right, top + bottom));
} }
@Override @Override
public R grow(double left, double right, double top, double bottom) public R grow(double left, double right, double top, double bottom)
{ {
return result(p_origin.sub(left, top), p_size.add(left + right, top + bottom)); return result(origin().sub(left, top), size().add(left + right, top + bottom));
} }
@Override @Override
public R centerTo(final Vect point) public R centerTo(final Vect point)
{ {
return result(p_origin.sub(p_size.half()), p_size); final VectView s = size().view();
final VectView o = origin().view();
return result(o.sub(s.half()), s);
} }
@Override @Override
public R round() public R round()
{ {
return result(p_origin.round(), p_size.round()); final VectView s = size().view();
final VectView o = origin().view();
return result(o.round(), s.round());
} }
@ -62,118 +72,118 @@ public abstract class RectMathStatic<R extends RectMathStatic<R>> extends RectMa
@Override @Override
public NumVal x() public NumVal x()
{ {
return p_x.copy(); return origin().xn();
} }
@Override @Override
public NumVal y() public NumVal y()
{ {
return p_y.copy(); return origin().yn();
} }
@Override @Override
public NumVal width() public NumVal width()
{ {
return p_width.copy(); return size().xn();
} }
@Override @Override
public NumVal height() public NumVal height()
{ {
return p_height.copy(); return size().yn();
} }
@Override @Override
public NumVal left() public NumVal left()
{ {
return p_left.copy(); return origin().xn();
} }
@Override @Override
public NumVal right() public NumVal right()
{ {
return p_right.copy(); return origin().xn().add(size().xn());
} }
@Override @Override
public NumVal top() public NumVal top()
{ {
return p_top.copy(); return origin().yn();
} }
@Override @Override
public NumVal bottom() public NumVal bottom()
{ {
return p_bottom.copy(); return origin().yn().add(size().yn());
} }
@Override @Override
public VectVal topLeft() public VectVal topLeft()
{ {
return p_tl.copy(); return origin();
} }
@Override @Override
public VectVal topCenter() public VectVal topCenter()
{ {
return p_tc.copy(); return origin().add(size().x() / 2, 0);
} }
@Override @Override
public VectVal topRight() public VectVal topRight()
{ {
return p_tr.copy(); return origin().add(size().x(), 0);
} }
@Override @Override
public VectVal centerLeft() public VectVal centerLeft()
{ {
return p_cl.copy(); return origin().add(0, size().y() / 2);
} }
@Override @Override
public VectVal center() public VectVal center()
{ {
return p_cc.copy(); return origin().add(size().view().half());
} }
@Override @Override
public VectVal centerRight() public VectVal centerRight()
{ {
return p_cr.copy(); return origin().add(size().x(), size().y() / 2);
} }
@Override @Override
public VectVal bottomLeft() public VectVal bottomLeft()
{ {
return p_bl.copy(); return origin().add(0, size().y());
} }
@Override @Override
public VectVal bottomCenter() public VectVal bottomCenter()
{ {
return p_bc.copy(); return origin().add(size().x() / 2, size().y());
} }
@Override @Override
public VectVal bottomRight() public VectVal bottomRight()
{ {
return p_br.copy(); return origin().add(size().view());
} }
} }

@ -11,7 +11,7 @@ import mightypork.utils.math.vect.VectVal;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class RectMutable extends RectMathStatic<RectMutable> { public abstract class RectMutable extends RectView {
/** /**
* Create at 0,0 with zero size * Create at 0,0 with zero size
@ -125,11 +125,10 @@ public abstract class RectMutable extends RectMathStatic<RectMutable> {
* Set to other rect's coordinates * Set to other rect's coordinates
* *
* @param rect other rect * @param rect other rect
* @return this
*/ */
public RectMutable setTo(Rect rect) public void setTo(Rect rect)
{ {
return setTo(rect.origin(), rect.size()); setTo(rect.origin(), rect.size());
} }
@ -139,11 +138,10 @@ public abstract class RectMutable extends RectMathStatic<RectMutable> {
* @param origin new origin * @param origin new origin
* @param width new width * @param width new width
* @param height new height * @param height new height
* @return this
*/ */
public RectMutable setTo(Vect origin, double width, double height) public void setTo(Vect origin, double width, double height)
{ {
return setTo(origin, VectVal.make(width, height)); setTo(origin, VectVal.make(width, height));
} }
@ -154,11 +152,10 @@ public abstract class RectMutable extends RectMathStatic<RectMutable> {
* @param y origin.y * @param y origin.y
* @param width new width * @param width new width
* @param height new height * @param height new height
* @return this
*/ */
public RectMutable setTo(double x, double y, double width, double height) public void setTo(double x, double y, double width, double height)
{ {
return setTo(VectVal.make(x, y), VectVal.make(width, height)); setTo(VectVal.make(x, y), VectVal.make(width, height));
} }
@ -167,31 +164,35 @@ public abstract class RectMutable extends RectMathStatic<RectMutable> {
* *
* @param origin new origin * @param origin new origin
* @param size new size * @param size new size
* @return this
*/ */
public RectMutable setTo(Vect origin, Vect size) public void setTo(Vect origin, Vect size)
{ {
setOrigin(origin); setOrigin(origin);
setSize(size); setSize(size);
return this;
} }
/**
* Set to zero
*/
public void reset()
{
setTo(Vect.ZERO, Vect.ZERO);
}
/** /**
* Set new origin * Set new origin
* *
* @param origin new origin * @param origin new origin
* @return this
*/ */
public abstract RectMutable setOrigin(Vect origin); public abstract void setOrigin(Vect origin);
/** /**
* Set new size * Set new size
* *
* @param size new size * @param size new size
* @return this
*/ */
public abstract RectMutable setSize(Vect size); public abstract void setSize(Vect size);
} }

@ -3,7 +3,7 @@ package mightypork.utils.math.rect;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectView;
class RectMutableImpl extends RectMutable { class RectMutableImpl extends RectMutable {
@ -22,45 +22,34 @@ class RectMutableImpl extends RectMutable {
*/ */
public RectMutableImpl(double x, double y, double width, double height) { public RectMutableImpl(double x, double y, double width, double height) {
this.pos.setTo(x, y); this.pos.setTo(x, y);
this.size.setTo(width, height).abs(); this.size.setTo(width, height);
} }
@Override @Override
public VectVal origin() public VectView origin()
{ {
return pos.copy(); return pos;
} }
@Override @Override
public VectVal size() public VectView size()
{ {
return size.copy(); return size;
} }
@Override @Override
protected RectMutable result(Vect newOrigin, Vect newSize) public void setOrigin(Vect origin)
{
setOrigin(newOrigin);
setSize(newSize);
return this;
}
@Override
public RectMutable setOrigin(Vect origin)
{ {
this.pos.setTo(origin); this.pos.setTo(origin);
return this;
} }
@Override @Override
public RectMutable setSize(Vect size) public void setSize(Vect size)
{ {
this.size.setTo(size).abs(); this.size.setTo(size);
return this;
} }
} }

@ -1,5 +1,6 @@
package mightypork.utils.math.rect; package mightypork.utils.math.rect;
import mightypork.utils.math.vect.VectView; import mightypork.utils.math.vect.VectView;
@ -8,26 +9,29 @@ import mightypork.utils.math.vect.VectView;
* *
* @author MightyPork * @author MightyPork
*/ */
public class RectProxy extends RectView { class RectProxy extends RectView {
private final RectView observed; private final Rect observed;
public RectProxy(Rect observed) { public RectProxy(Rect observed) {
this.observed = observed.view();
assert (!(observed instanceof RectView));
this.observed = observed;
} }
@Override @Override
public VectView origin() public VectView origin()
{ {
return observed.p_origin; return observed.origin().view();
} }
@Override @Override
public VectView size() public VectView size()
{ {
return observed.p_size; return observed.size().view();
} }
} }

@ -2,6 +2,7 @@ package mightypork.utils.math.rect;
import mightypork.utils.annotations.FactoryMethod; import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
@ -32,6 +33,20 @@ public class RectVal extends RectMathStatic<RectVal> {
} }
/**
* Create at 0,0 with given size
*
* @param width
* @param height
* @return new mutable rect
*/
@FactoryMethod
public static RectVal make(Num width, Num height)
{
return make(0, 0, width.value(), height.value());
}
/** /**
* Create at 0,0 with given size * Create at 0,0 with given size
* *
@ -61,6 +76,21 @@ public class RectVal extends RectMathStatic<RectVal> {
} }
/**
* Create at given origin, with given size.
*
* @param origin
* @param width
* @param height
* @return new mutable rect
*/
@FactoryMethod
public static RectVal make(Vect origin, Num width, Num height)
{
return make(origin, VectVal.make(width, height));
}
/** /**
* Create at 0,0 with given size. * Create at 0,0 with given size.
* *
@ -90,6 +120,22 @@ public class RectVal extends RectMathStatic<RectVal> {
} }
/**
* Create at given origin, with given size.
*
* @param x
* @param y
* @param width
* @param height
* @return new mutable rect
*/
@FactoryMethod
public static RectVal make(Num x, Num y, Num width, Num height)
{
return new RectVal(x.value(), y.value(), width.value(), height.value());
}
/** /**
* Create at given origin, with given size. * Create at given origin, with given size.
* *
@ -115,7 +161,7 @@ public class RectVal extends RectMathStatic<RectVal> {
* @param width * @param width
* @param height * @param height
*/ */
public RectVal(double x, double y, double width, double height) { RectVal(double x, double y, double width, double height) {
this.pos = VectVal.make(x, y); this.pos = VectVal.make(x, y);
this.size = VectVal.make(width, height); this.size = VectVal.make(width, height);
} }
@ -127,7 +173,7 @@ public class RectVal extends RectMathStatic<RectVal> {
* @param origin * @param origin
* @param size * @param size
*/ */
public RectVal(Vect origin, Vect size) { RectVal(Vect origin, Vect size) {
this.pos = origin.copy(); this.pos = origin.copy();
this.size = size.copy(); this.size = size.copy();
} }
@ -138,7 +184,7 @@ public class RectVal extends RectMathStatic<RectVal> {
* *
* @param another other coord * @param another other coord
*/ */
public RectVal(Rect another) { RectVal(Rect another) {
this.pos = another.origin().copy(); this.pos = another.origin().copy();
this.size = another.size().copy(); this.size = another.size().copy();
} }

@ -2,6 +2,9 @@ package mightypork.utils.math.rect;
import mightypork.utils.annotations.FactoryMethod; import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/** /**
@ -11,12 +14,6 @@ import mightypork.utils.annotations.FactoryMethod;
*/ */
public abstract class RectView extends RectMathDynamic { public abstract class RectView extends RectMathDynamic {
@SuppressWarnings("hiding")
public static final RectView ZERO = Rect.ZERO.view();
@SuppressWarnings("hiding")
public static final RectView ONE = Rect.ONE.view();
/** /**
* Get a proxy at given rect * Get a proxy at given rect
* *
@ -30,6 +27,56 @@ public abstract class RectView extends RectMathDynamic {
} }
/**
* Get a rect made of numeric constraints
*
* @param width width
* @param height height
* @return view rect
*/
@FactoryMethod
public static RectView make(Num width, Num height)
{
final Vect origin = Vect.ZERO;
final Vect size = VectView.make(width, height);
return new VectViewRect(origin, size);
}
/**
* Get a rect made of numeric constraints
*
* @param x x coord
* @param y y coord
* @param width width
* @param height height
* @return view rect
*/
@FactoryMethod
public static RectView make(Num x, Num y, Num width, Num height)
{
final Vect origin = VectView.make(x, y);
final Vect size = VectView.make(width, height);
return new VectViewRect(origin, size);
}
/**
* Get a rect made of two vect views
*
* @param origin origin view
* @param size size view
* @return view rect
*/
@FactoryMethod
public static RectView make(final Vect origin, final Vect size)
{
return new VectViewRect(origin, size);
}
/** /**
* @deprecated No point in taking view of a view * @deprecated No point in taking view of a view
*/ */
@ -37,7 +84,6 @@ public abstract class RectView extends RectMathDynamic {
@Deprecated @Deprecated
public RectView view() public RectView view()
{ {
// must NOT call RectView.make, it'd cause infinite recursion.
return this; // wont change return this; // wont change
} }

@ -0,0 +1,38 @@
package mightypork.utils.math.rect;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
* Rect made of two {@link VectView}s
*
* @author MightyPork
*/
class VectViewRect extends RectView {
private final VectView origin;
private final VectView size;
public VectViewRect(Vect origin, Vect size) {
this.origin = origin.view();
this.size = size.view();
}
@Override
public VectView origin()
{
return origin;
}
@Override
public VectView size()
{
return size;
}
}

@ -1,9 +1,7 @@
package mightypork.utils.math.vect; package mightypork.utils.math.vect;
abstract class AbstractVect implements Vect {
public abstract class AbstractVect implements Vect {
private VectView proxy; private VectView proxy;
@ -47,8 +45,6 @@ public abstract class AbstractVect implements Vect {
@Override @Override
public VectView view() public VectView view()
{ {
// must NOT call VectView.make, it'd cause infinite recursion.
if (proxy == null) proxy = new VectProxy(this); if (proxy == null) proxy = new VectProxy(this);
return proxy; return proxy;

@ -111,37 +111,32 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
@Override @Override
public VectAnimated result(double x, double y, double z) public void setTo(double x, double y, double z)
{ {
setX(x); setX(x);
setY(y); setY(y);
setZ(z); setZ(z);
return this;
} }
@Override @Override
public VectMutable setX(double x) public void setX(double x)
{ {
this.x.animate(x, defaultDuration); this.x.animate(x, defaultDuration);
return this;
} }
@Override @Override
public VectMutable setY(double y) public void setY(double y)
{ {
this.y.animate(y, defaultDuration); this.y.animate(y, defaultDuration);
return this;
} }
@Override @Override
public VectMutable setZ(double z) public void setZ(double z)
{ {
this.z.animate(z, defaultDuration); this.z.animate(z, defaultDuration);
return this;
} }
@ -150,12 +145,10 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
* *
* @param offset added offset * @param offset added offset
* @param duration animation time (seconds) * @param duration animation time (seconds)
* @return this
*/ */
public VectAnimated add(Vect offset, double duration) public void add(Vect offset, double duration)
{ {
animate(view().add(offset), duration); animate(this.add(offset), duration);
return this;
} }

@ -252,12 +252,33 @@ abstract class VectMath<V extends Vect, N> extends AbstractVect {
public abstract V mul(double x, double y, double z); public abstract V mul(double x, double y, double z);
/**
* Multiply each component.
*
* @param d multiplier
* @return result
*/
public abstract V mul(final Num d); public abstract V mul(final Num d);
/**
* Multiply each component.
*
* @param x x multiplier
* @param y y multiplier
* @return result
*/
public abstract V mul(final Num x, final Num y); public abstract V mul(final Num x, final Num y);
/**
* Multiply each component.
*
* @param x x multiplier
* @param y y multiplier
* @param z z multiplier
* @return result
*/
public abstract V mul(final Num x, final Num y, final Num z); public abstract V mul(final Num x, final Num y, final Num z);

@ -11,7 +11,7 @@ import mightypork.utils.math.num.NumVal;
* @author MightyPork * @author MightyPork
* @param <V> Return type of methods * @param <V> Return type of methods
*/ */
public abstract class VectMathStatic<V extends VectMathStatic<V>> extends VectMath<V, NumVal> { abstract class VectMathStatic<V extends VectMathStatic<V>> extends VectMath<V, NumVal> {
@Override @Override
public NumVal xn() public NumVal xn()

@ -9,7 +9,7 @@ import mightypork.utils.annotations.FactoryMethod;
* *
* @author MightyPork * @author MightyPork
*/ */
public abstract class VectMutable extends VectMathStatic<VectMutable> { // returns itself on edit public abstract class VectMutable extends VectView { // returns itself on edit
/** /**
* Get a variable initialized as zero (0,0,0) * Get a variable initialized as zero (0,0,0)
@ -79,12 +79,10 @@ public abstract class VectMutable extends VectMathStatic<VectMutable> { // retur
/** /**
* Set all to zeros. * Set all to zeros.
*
* @return this
*/ */
public VectMutable reset() public void reset()
{ {
return result(0, 0, 0); setTo(0, 0, 0);
} }
@ -92,11 +90,10 @@ public abstract class VectMutable extends VectMathStatic<VectMutable> { // retur
* Set coordinates to match other coord. * Set coordinates to match other coord.
* *
* @param copied coord whose coordinates are used * @param copied coord whose coordinates are used
* @return this
*/ */
public VectMutable setTo(Vect copied) public void setTo(Vect copied)
{ {
return result(copied.x(), copied.y(), copied.z()); setTo(copied.x(), copied.y(), copied.z());
} }
@ -106,11 +103,11 @@ public abstract class VectMutable extends VectMathStatic<VectMutable> { // retur
* *
* @param x x coordinate * @param x x coordinate
* @param y y coordinate * @param y y coordinate
* @return this
*/ */
public VectMutable setTo(double x, double y) public void setTo(double x, double y)
{ {
return result(x, y, z()); setX(x);
setY(y);
} }
@ -120,37 +117,30 @@ public abstract class VectMutable extends VectMathStatic<VectMutable> { // retur
* @param x x coordinate * @param x x coordinate
* @param y y coordinate * @param y y coordinate
* @param z z coordinate * @param z z coordinate
* @return this
*/ */
public VectMutable setTo(double x, double y, double z) public abstract void setTo(double x, double y, double z);
{
return result(x, y, z);
}
/** /**
* Set X coordinate. * Set X coordinate.
* *
* @param x x coordinate * @param x x coordinate
* @return this
*/ */
public abstract VectMutable setX(double x); public abstract void setX(double x);
/** /**
* Set Y coordinate. * Set Y coordinate.
* *
* @param y y coordinate * @param y y coordinate
* @return this
*/ */
public abstract VectMutable setY(double y); public abstract void setY(double y);
/** /**
* Set Z coordinate. * Set Z coordinate.
* *
* @param z z coordinate * @param z z coordinate
* @return this
*/ */
public abstract VectMutable setZ(double z); public abstract void setZ(double z);
} }

@ -47,36 +47,31 @@ class VectMutableImpl extends VectMutable {
@Override @Override
public VectMutable result(double x, double y, double z) public void setTo(double x, double y, double z)
{ {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;
return this;
} }
@Override @Override
public VectMutable setX(double x) public void setX(double x)
{ {
this.x = x; this.x = x;
return this;
} }
@Override @Override
public VectMutable setY(double y) public void setY(double y)
{ {
this.y = y; this.y = y;
return this;
} }
@Override @Override
public VectMutable setZ(double z) public void setZ(double z)
{ {
this.z = z; this.z = z;
return this;
} }
} }

@ -19,6 +19,9 @@ class VectProxy extends VectAdapter {
* @param observed * @param observed
*/ */
public VectProxy(Vect observed) { public VectProxy(Vect observed) {
assert (!(observed instanceof VectView));
this.observed = observed; this.observed = observed;
} }

@ -2,6 +2,7 @@ package mightypork.utils.math.vect;
import mightypork.utils.annotations.FactoryMethod; import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.num.Num;
/** /**
@ -45,6 +46,20 @@ public final class VectVal extends VectMathStatic<VectVal> {
} }
/**
* Make a constant vector
*
* @param x X value
* @param y Y value
* @return new constant vec
*/
@FactoryMethod
public static VectVal make(Num x, Num y)
{
return make(x, y, Num.ZERO);
}
/** /**
* Make a constant vector * Make a constant vector
* *
@ -59,15 +74,30 @@ public final class VectVal extends VectMathStatic<VectVal> {
return new VectVal(x, y, z); return new VectVal(x, y, z);
} }
/**
* Make a constant vector
*
* @param x X value
* @param y Y value
* @param z Z value
* @return new constant vector
*/
@FactoryMethod
public static VectVal make(Num x, Num y, Num z)
{
return new VectVal(x.value(), y.value(), z.value());
}
private final double x, y, z; private final double x, y, z;
public VectVal(Vect other) { VectVal(Vect other) {
this(other.x(), other.y(), other.z()); this(other.x(), other.y(), other.z());
} }
public VectVal(double x, double y, double z) { VectVal(double x, double y, double z) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.z = z; this.z = z;

@ -15,12 +15,6 @@ import mightypork.utils.math.num.Num;
*/ */
public abstract class VectView extends VectMathDynamic { // returns constant value on edit public abstract class VectView extends VectMathDynamic { // returns constant value on edit
@SuppressWarnings("hiding")
public static final VectView ZERO = new VectVal(0, 0, 0).view();
@SuppressWarnings("hiding")
public static final VectView ONE = new VectVal(1, 1, 1).view();
/** /**
* Make a proxy view at a vector. * Make a proxy view at a vector.
* *
@ -78,7 +72,7 @@ public abstract class VectView extends VectMathDynamic { // returns constant val
@Deprecated @Deprecated
public VectView view() public VectView view()
{ {
return super.view(); return this;
} }
} }

@ -6,7 +6,6 @@ import mightypork.utils.math.Calc;
import mightypork.utils.math.Range; import mightypork.utils.math.Range;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
/** /**

Loading…
Cancel
Save