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

This commit is contained in:
Ondřej Hruška
2014-04-13 23:15:42 +02:00
parent a5c32834c0
commit 3320678f36
56 changed files with 652 additions and 431 deletions
@@ -4,7 +4,6 @@ package mightypork.gamecore.control.bus.events;
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
import mightypork.utils.math.vect.Vect;
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.AppSubModule;
import mightypork.gamecore.control.bus.BusAccess;
import mightypork.gamecore.control.bus.clients.BusNode;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView;
public abstract class AbstractComponent extends AppSubModule implements PluggableRenderable {
private RectBound context;
private RectBound context;
public AbstractComponent(AppAccess app) {
super(app);
}
@Override
public void setContext(RectBound context)
{
this.context = context;
}
@Override
public RectView getRect()
{
@@ -20,7 +20,7 @@ import mightypork.utils.math.constraints.RectBound;
*/
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;
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,6 @@
package mightypork.gamecore.gui.components.layout;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.gui.components.PluggableRenderable;
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.Renderable;
import mightypork.utils.math.constraints.RectBoundAdapter;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.constraints.RectBoundAdapter;
import mightypork.utils.math.rect.RectView;
@@ -54,14 +54,14 @@ public class QuadPainter extends AbstractPainter {
Render.quadColor(getRect(), colorHMinVMin, colorHMaxVMin, colorHMaxVMax, colorHMinVMax);
}
@FactoryMethod
public static QuadPainter gradH(RGB colorLeft, RGB colorRight)
{
return new QuadPainter(colorLeft, colorRight, colorRight, colorLeft);
}
@FactoryMethod
public static QuadPainter gradV(RGB colorTop, RGB colorBottom)
{
+1 -1
View File
@@ -352,7 +352,7 @@ public class Render {
*/
public static void quad(Rect quad)
{
RectView rv = quad.view();
final RectView rv = quad.view();
final double x1 = rv.left().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);
} 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();
@@ -411,7 +412,8 @@ public class CachedFont implements GLFont {
chtx = chars.get(charCurrent);
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;
}
}
@@ -1,7 +1,6 @@
package mightypork.rogue.screens;
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,8 +1,6 @@
package mightypork.rogue.screens.test_bouncyboxes;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.Random;
import mightypork.gamecore.control.timing.Updateable;
@@ -1,8 +1,6 @@
package mightypork.rogue.screens.test_bouncyboxes;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.ArrayList;
import java.util.List;
@@ -1,8 +1,6 @@
package mightypork.rogue.screens.test_cat_sound;
import static mightypork.utils.math.constraints.ConstraintFactory.*;
import java.util.Random;
import mightypork.gamecore.control.bus.events.MouseButtonEvent;
@@ -1,7 +1,6 @@
package mightypork.rogue.screens.test_font;
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;
@@ -1,7 +1,6 @@
package mightypork.rogue.screens.test_render;
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;
+79 -5
View File
@@ -1,10 +1,16 @@
package mightypork.test;
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.RectView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
public class TestConstr {
@@ -13,13 +19,81 @@ public class TestConstr {
{
Locale.setDefault(Locale.ENGLISH);
final RectVal rect = RectVal.make(0, 0, 10, 10);
final VectVal point = VectVal.make(50, 50);
int cnt = -1;
System.out.println(rect);
System.out.println(point);
System.out.println(rect.view().centerTo(point));
{
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());
a.reset();
System.out.println(r);
}
}
}
+8 -10
View File
@@ -3,8 +3,6 @@ package mightypork.test;
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.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
@@ -17,28 +15,28 @@ public class TestCoords {
Locale.setDefault(Locale.ENGLISH);
// test
VectMutable var = VectMutable.make(1, 2, 3);
final VectMutable var = VectMutable.make(1, 2, 3);
VectView cubicRoot = var.view().mul(var).mul(var);
VectView half = var.view().half();
final VectView cubicRoot = var.mul(var).mul(var);
final VectView half = var.half();
System.out.println("x, x^3, x/5");
System.out.println(var);
System.out.println(cubicRoot);
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(var);
System.out.println(cubicRoot);
System.out.println(half);
NumView y = var.view().yn();
System.out.println("y: "+y.value());
final NumView y = var.yn();
System.out.println("y: " + y.value());
var.setTo(var.add(100, 100));
var.add(100,100);
System.out.println("x = x*100; x.y(), x, x^3, x/5");
System.out.println(y.value());
System.out.println(var);
@@ -1,11 +1,13 @@
package mightypork.utils.annotations;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* Marks a static factory method
*
@@ -12,7 +12,6 @@ import java.util.TreeMap;
import mightypork.utils.math.Range;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
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.Updateable;
import mightypork.utils.math.Calc;
import mightypork.utils.math.constraints.NumBound;
import mightypork.utils.math.num.NumMutable;
import mightypork.utils.math.num.NumVal;
/**
@@ -135,8 +133,8 @@ public class AnimDouble extends NumMutable implements Updateable, Pauseable {
{
return defaultDuration;
}
/**
* @param defaultDuration default animation duration (seconds)
*/
@@ -144,8 +142,8 @@ public class AnimDouble extends NumMutable implements Updateable, Pauseable {
{
this.defaultDuration = defaultDuration;
}
/**
* Get value at delta time
*
@@ -202,12 +200,11 @@ public class AnimDouble extends NumMutable implements Updateable, Pauseable {
* @param value
*/
@Override
public AnimDouble setTo(double value)
public void setTo(double value)
{
from = to = value;
elapsedTime = 0;
duration = defaultDuration;
return this;
}
@@ -1,5 +1,6 @@
package mightypork.utils.math.animation;
import mightypork.utils.annotations.FactoryMethod;
@@ -1,8 +1,7 @@
package mightypork.utils.math.constraints;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumVal;
import mightypork.utils.math.num.NumView;
/**
@@ -10,7 +9,7 @@ import mightypork.utils.math.num.NumView;
*
* @author MightyPork
*/
public interface NumBound {
public interface NumBound {
/**
* @return current value
@@ -11,8 +11,7 @@ import mightypork.utils.math.rect.RectAdapter;
* @author MightyPork
*/
public abstract class RectBoundAdapter extends RectAdapter implements PluggableRectBound {
private RectBound backing = null;
@@ -22,10 +21,11 @@ public abstract class RectBoundAdapter extends RectAdapter implements PluggableR
this.backing = rect;
}
@Override
public Rect getSource() {
public Rect getSource()
{
return backing.getRect();
}
}
@@ -44,7 +44,7 @@ public class RectCache implements RectBound, Pollable {
@Override
public RectView getRect()
{
return cached.view();
return cached;
}
@@ -1,7 +1,6 @@
package mightypork.utils.math.constraints;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
+17 -3
View File
@@ -1,23 +1,37 @@
package mightypork.utils.math.num;
public abstract class AbstractNum implements Num {
abstract class AbstractNum implements Num {
private NumView proxy;
@Override
public Num getNum() {
public Num getNum()
{
return this;
}
@Override
public NumView view()
{
return new NumProxy(this);
if (proxy == null) proxy = new NumProxy(this);
return proxy;
}
@Override
public NumVal copy()
{
return new NumVal(this);
}
@Override
public String toString()
{
return String.format("#{%.1f}",value());
}
}
@@ -4,7 +4,8 @@ package mightypork.utils.math.num;
public abstract class NumAdapter extends NumView {
protected abstract Num getSource();
@Override
public double value()
{
+12 -1
View File
@@ -1,6 +1,9 @@
package mightypork.utils.math.num;
import mightypork.utils.math.rect.Rect;
/**
* Math operations for numbers
*
@@ -36,7 +39,7 @@ interface NumMath<N extends NumMath<N>> extends Num {
N pow(Num other);
N average(Num other);
N average(Num other);
N add(double addend);
@@ -154,4 +157,12 @@ interface NumMath<N extends NumMath<N>> extends Num {
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;
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.
@@ -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.
*
* @param a numeric bound
* @return num
*/
@@ -144,7 +146,7 @@ public abstract class NumMathBase<N extends NumMath<N>> extends AbstractNum impl
if (this == obj) return true;
if (obj == null) return false;
if (!(obj instanceof NumMathBase)) return false;
NumMathBase<?> other = (NumMathBase<?>) obj;
final NumMathBase<?> other = (NumMathBase<?>) obj;
return eq(other);
}
+105 -50
View File
@@ -1,8 +1,11 @@
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 floor;
private NumView sgn;
@@ -19,13 +22,15 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
private NumView square;
private NumView neg;
private NumView abs;
@Override
public NumView add(final double addend)
{
return new NumView() {
private Num t = NumMathDynamic.this;
private final Num t = NumMathDynamic.this;
@Override
public double value()
@@ -34,19 +39,22 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}
};
}
@Override
public NumView sub(final double subtrahend)
{
return add(-subtrahend);
}
@Override
public NumView mul(final double factor)
{
return new NumView() {
private Num t = NumMathDynamic.this;
private final Num t = NumMathDynamic.this;
@Override
public double value()
@@ -55,43 +63,49 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}
};
}
@Override
public NumView div(final double factor)
{
return mul(1/factor);
return mul(1 / factor);
}
@Override
public NumView perc(final double percent)
{
return mul(percent/100);
return mul(percent / 100);
}
@Override
public NumView neg()
{
if(neg==null) neg = new NumView() {
if (neg == null) neg = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
return -1*t.value();
return -1 * t.value();
}
};
return neg;
}
@Override
public NumView abs()
{
if(abs==null) abs = new NumView() {
if (abs == null) abs = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -101,7 +115,8 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return abs;
}
@Override
public NumView max(final double other)
{
@@ -109,6 +124,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -116,7 +132,8 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}
};
}
@Override
public NumView min(final double other)
{
@@ -124,6 +141,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -131,7 +149,8 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}
};
}
@Override
public NumView pow(final double other)
{
@@ -139,6 +158,7 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -146,50 +166,56 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
}
};
}
@Override
public NumView square()
{
if(square==null) square = new NumView() {
if (square == null) square = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
final double v = t.value();
return v*v;
return v * v;
}
};
return square;
}
@Override
public NumView cube()
{
if(cube==null) cube = new NumView() {
if (cube == null) cube = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
final double v = t.value();
return v*v*v;
return v * v * v;
}
};
return cube;
}
@Override
public NumView sqrt()
{
if(sqrt==null) sqrt = new NumView() {
if (sqrt == null) sqrt = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -199,14 +225,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return sqrt;
}
@Override
public NumView cbrt()
{
if(cbrt==null) cbrt = new NumView() {
if (cbrt == null) cbrt = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -216,14 +244,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return cbrt;
}
@Override
public NumView sin()
{
if(sin==null) sin = new NumView() {
if (sin == null) sin = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -233,14 +263,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return sin;
}
@Override
public NumView cos()
{
if(cos==null) cos = new NumView() {
if (cos == null) cos = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -250,14 +282,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return cos;
}
@Override
public NumView tan()
{
if(tan==null) tan = new NumView() {
if (tan == null) tan = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -267,14 +301,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return tan;
}
@Override
public NumView asin()
{
if(asin==null) asin = new NumView() {
if (asin == null) asin = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -284,14 +320,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return asin;
}
@Override
public NumView acos()
{
if(acos==null) acos = new NumView() {
if (acos == null) acos = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -301,14 +339,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return acos;
}
@Override
public NumView atan()
{
if(atan==null) atan = new NumView() {
if (atan == null) atan = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -318,14 +358,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return atan;
}
@Override
public NumView round()
{
if(round==null) round = new NumView() {
if (round == null) round = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -335,14 +377,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return round;
}
@Override
public NumView floor()
{
if(floor==null) floor = new NumView() {
if (floor == null) floor = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -352,14 +396,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return floor;
}
@Override
public NumView ceil()
{
if(ceil==null) ceil = new NumView() {
if (ceil == null) ceil = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -369,14 +415,16 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return ceil;
}
@Override
public NumView signum()
{
if(sgn==null) sgn = new NumView() {
if (sgn == null) sgn = new NumView() {
final Num t = NumMathDynamic.this;
@Override
public double value()
{
@@ -386,7 +434,8 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
return sgn;
}
@Override
public NumView average(final double other)
{
@@ -399,7 +448,6 @@ public abstract class NumMathDynamic extends NumMathBase<NumView>{
{
return mul(0.5);
}
@Override
@@ -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;
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);
@@ -253,6 +256,13 @@ public abstract class NumMathStatic<N extends NumMathStatic<N>> extends NumMathB
}
@Override
public RectVal box()
{
return RectVal.make(this, this);
}
@Override
public String toString()
{
+18 -17
View File
@@ -10,7 +10,7 @@ import mightypork.utils.math.constraints.NumBound;
*
* @author MightyPork
*/
public abstract class NumMutable extends NumMathStatic<NumMutable> {
public abstract class NumMutable extends NumView {
/**
* 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
*
@@ -49,6 +48,7 @@ public abstract class NumMutable extends NumMathStatic<NumMutable> {
return new NumMutableImpl(value);
}
/**
* Make as copy of another
*
@@ -61,6 +61,7 @@ public abstract class NumMutable extends NumMathStatic<NumMutable> {
return new NumMutableImpl(eval(copied));
}
/**
* Make as copy of another
*
@@ -74,31 +75,31 @@ public abstract class NumMutable extends NumMathStatic<NumMutable> {
}
@Override
protected NumMutable result(double a)
{
return setTo(a);
}
/**
* Assign a value
*
* @param value new value
*/
public abstract void setTo(double value);
/**
* Assign a 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
*
* @param value new value
* @return this
* Set to zero
*/
public abstract NumMutable setTo(double value);
public void reset()
{
setTo(0);
}
}
@@ -29,10 +29,9 @@ class NumMutableImpl extends NumMutable {
@Override
public NumMutable setTo(double value)
public void setTo(double value)
{
this.value = value;
return this;
}
}
+2 -1
View File
@@ -1,7 +1,7 @@
package mightypork.utils.math.num;
public class NumProxy extends NumAdapter {
class NumProxy extends NumAdapter {
private final Num observed;
@@ -10,6 +10,7 @@ public class NumProxy extends NumAdapter {
this.observed = observed;
}
@Override
protected Num getSource()
{
+3 -2
View File
@@ -17,6 +17,7 @@ public class NumVal extends NumMathStatic<NumVal> {
@SuppressWarnings("hiding")
public static final NumVal ONE = NumVal.make(1);
/**
* Make a new constant
*
@@ -58,12 +59,12 @@ public class NumVal extends NumMathStatic<NumVal> {
private final double value;
public NumVal(Num copied) {
NumVal(Num copied) {
this.value = copied.value();
}
public NumVal(double value) {
NumVal(double value) {
this.value = value;
}
@@ -6,9 +6,9 @@ package mightypork.utils.math.rect;
*
* @author MightyPork
*/
public abstract class AbstractRect implements Rect {
abstract class AbstractRect implements Rect {
private RectProxy proxy;
private RectProxy proxy;
@Override
@@ -39,10 +39,7 @@ public abstract class AbstractRect implements Rect {
@Override
public String toString()
{
return String.format(
"Rect { %s - %s }",
origin(),
origin().view().add(size()));
return String.format("Rect { %s - %s }", origin(), origin().copy().add(size()));
}
}
@@ -14,7 +14,7 @@ import mightypork.utils.math.vect.VectView;
*/
public abstract class RectAdapter extends RectView {
private VectAdapter originAdapter = new VectAdapter() {
private final VectAdapter originAdapter = new VectAdapter() {
@Override
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
protected Vect getSource()
+1 -86
View File
@@ -1,97 +1,11 @@
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.VectAdapter;
import mightypork.utils.math.vect.VectView;
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
*
@@ -221,4 +135,5 @@ abstract class RectMath<R extends Rect> extends AbstractRect {
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.NumView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
public abstract class RectMathDynamic extends RectMath<RectView> {
abstract class RectMathDynamic extends RectMath<RectView> {
@Override
public abstract VectView origin();
@@ -22,20 +21,20 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
{
return new RectView() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
public VectView size()
{
return t.p_size;
return t.size();
}
@Override
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
public RectView move(final double xd, final double yd)
public RectView move(final double x, final double y)
{
return new RectView() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
public VectView size()
{
return t.p_size;
return t.size();
}
@Override
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() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
public VectView size()
{
return t.p_size;
return t.size();
}
@Override
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
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() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
public VectView size()
{
return t.p_size.sub(leftd + rightd, topd + bottomd);
return t.size().sub(left + right, top + bottom);
}
@Override
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
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() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
public VectView size()
{
return t.p_size.add(leftd + rightd, topd + bottomd);
return t.size().add(left + right, top + bottom);
}
@Override
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() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
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
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() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
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
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() {
private RectMathDynamic t = RectMathDynamic.this;
private final RectMathDynamic t = RectMathDynamic.this;
@Override
public VectView size()
{
return t.p_size.round();
return t.size().round();
}
@Override
public VectView origin()
{
return t.p_origin.round();
return t.origin().round();
}
};
@@ -217,121 +216,121 @@ public abstract class RectMathDynamic extends RectMath<RectView> {
@Override
public NumView x()
public Num x()
{
return p_x;
return origin().xn();
}
@Override
public NumView y()
public Num y()
{
return p_y;
return origin().yn();
}
@Override
public NumView width()
public Num width()
{
return p_width;
return size().xn();
}
@Override
public NumView height()
public Num height()
{
return p_height;
return size().yn();
}
@Override
public NumView left()
public Num left()
{
return p_left;
return origin().yn();
}
@Override
public NumView right()
public Num right()
{
return p_right;
return origin().xn().add(size().xn());
}
@Override
public NumView top()
public Num top()
{
return p_top;
return origin().yn();
}
@Override
public NumView bottom()
public Num bottom()
{
return p_bottom;
return origin().yn().add(size().yn());
}
@Override
public VectView topLeft()
{
return p_tl;
return origin();
}
@Override
public VectView topCenter()
{
return p_tc;
return origin().add(size().xn().half(), Num.ZERO);
}
@Override
public VectView topRight()
{
return p_tr;
return origin().add(size().xn(), Num.ZERO);
}
@Override
public VectView centerLeft()
{
return p_cl;
return origin().add(Num.ZERO, size().yn().half());
}
@Override
public VectView center()
{
return p_cc;
return origin().add(size().half());
}
@Override
public VectView centerRight()
{
return p_cr;
return origin().add(size().xn(), size().yn().half());
}
@Override
public VectView bottomLeft()
{
return p_bl;
return origin().add(Num.ZERO, size().yn());
}
@Override
public VectView bottomCenter()
{
return p_bc;
return origin().add(size().xn().half(), size().yn());
}
@Override
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
public VectView size()
{
return t.p_size;
return t.size();
}
@Override
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.vect.Vect;
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
public abstract VectVal origin();
@@ -15,6 +16,7 @@ public abstract class RectMathStatic<R extends RectMathStatic<R>> extends RectMa
@Override
public abstract VectVal size();
@Override
public R move(Vect move)
{
@@ -23,36 +25,44 @@ public abstract class RectMathStatic<R extends RectMathStatic<R>> extends RectMa
@Override
public R move(double x, double y) {
return result(p_origin.add(x,y), p_size);
public R move(double x, double y)
{
return result(origin().add(x, y), size());
}
@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
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
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
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
public NumVal x()
{
return p_x.copy();
return origin().xn();
}
@Override
public NumVal y()
{
return p_y.copy();
return origin().yn();
}
@Override
public NumVal width()
{
return p_width.copy();
return size().xn();
}
@Override
public NumVal height()
{
return p_height.copy();
return size().yn();
}
@Override
public NumVal left()
{
return p_left.copy();
return origin().xn();
}
@Override
public NumVal right()
{
return p_right.copy();
return origin().xn().add(size().xn());
}
@Override
public NumVal top()
{
return p_top.copy();
return origin().yn();
}
@Override
public NumVal bottom()
{
return p_bottom.copy();
return origin().yn().add(size().yn());
}
@Override
public VectVal topLeft()
{
return p_tl.copy();
return origin();
}
@Override
public VectVal topCenter()
{
return p_tc.copy();
return origin().add(size().x() / 2, 0);
}
@Override
public VectVal topRight()
{
return p_tr.copy();
return origin().add(size().x(), 0);
}
@Override
public VectVal centerLeft()
{
return p_cl.copy();
return origin().add(0, size().y() / 2);
}
@Override
public VectVal center()
{
return p_cc.copy();
return origin().add(size().view().half());
}
@Override
public VectVal centerRight()
{
return p_cr.copy();
return origin().add(size().x(), size().y() / 2);
}
@Override
public VectVal bottomLeft()
{
return p_bl.copy();
return origin().add(0, size().y());
}
@Override
public VectVal bottomCenter()
{
return p_bc.copy();
return origin().add(size().x() / 2, size().y());
}
@Override
public VectVal bottomRight()
{
return p_br.copy();
return origin().add(size().view());
}
}
+18 -17
View File
@@ -11,7 +11,7 @@ import mightypork.utils.math.vect.VectVal;
*
* @author MightyPork
*/
public abstract class RectMutable extends RectMathStatic<RectMutable> {
public abstract class RectMutable extends RectView {
/**
* Create at 0,0 with zero size
@@ -125,11 +125,10 @@ public abstract class RectMutable extends RectMathStatic<RectMutable> {
* Set to other rect's coordinates
*
* @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 width new width
* @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 width new width
* @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 size new size
* @return this
*/
public RectMutable setTo(Vect origin, Vect size)
public void setTo(Vect origin, Vect size)
{
setOrigin(origin);
setSize(size);
return this;
}
/**
* Set to zero
*/
public void reset()
{
setTo(Vect.ZERO, Vect.ZERO);
}
/**
* Set new origin
*
* @param origin new origin
* @return this
*/
public abstract RectMutable setOrigin(Vect origin);
public abstract void setOrigin(Vect origin);
/**
* Set 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.VectMutable;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
class RectMutableImpl extends RectMutable {
@@ -22,45 +22,34 @@ class RectMutableImpl extends RectMutable {
*/
public RectMutableImpl(double x, double y, double width, double height) {
this.pos.setTo(x, y);
this.size.setTo(width, height).abs();
this.size.setTo(width, height);
}
@Override
public VectVal origin()
public VectView origin()
{
return pos.copy();
return pos;
}
@Override
public VectVal size()
public VectView size()
{
return size.copy();
return size;
}
@Override
protected RectMutable result(Vect newOrigin, Vect newSize)
{
setOrigin(newOrigin);
setSize(newSize);
return this;
}
@Override
public RectMutable setOrigin(Vect origin)
public void setOrigin(Vect origin)
{
this.pos.setTo(origin);
return this;
}
@Override
public RectMutable setSize(Vect size)
public void setSize(Vect size)
{
this.size.setTo(size).abs();
return this;
this.size.setTo(size);
}
}
@@ -1,5 +1,6 @@
package mightypork.utils.math.rect;
import mightypork.utils.math.vect.VectView;
@@ -8,26 +9,29 @@ import mightypork.utils.math.vect.VectView;
*
* @author MightyPork
*/
public class RectProxy extends RectView {
class RectProxy extends RectView {
private final RectView observed;
private final Rect observed;
public RectProxy(Rect observed) {
this.observed = observed.view();
assert (!(observed instanceof RectView));
this.observed = observed;
}
@Override
public VectView origin()
{
return observed.p_origin;
return observed.origin().view();
}
@Override
public VectView size()
{
return observed.p_size;
return observed.size().view();
}
}
+49 -3
View File
@@ -2,6 +2,7 @@ package mightypork.utils.math.rect;
import mightypork.utils.annotations.FactoryMethod;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.vect.Vect;
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
*
@@ -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.
*
@@ -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.
*
@@ -115,7 +161,7 @@ public class RectVal extends RectMathStatic<RectVal> {
* @param width
* @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.size = VectVal.make(width, height);
}
@@ -127,7 +173,7 @@ public class RectVal extends RectMathStatic<RectVal> {
* @param origin
* @param size
*/
public RectVal(Vect origin, Vect size) {
RectVal(Vect origin, Vect size) {
this.pos = origin.copy();
this.size = size.copy();
}
@@ -138,7 +184,7 @@ public class RectVal extends RectMathStatic<RectVal> {
*
* @param another other coord
*/
public RectVal(Rect another) {
RectVal(Rect another) {
this.pos = another.origin().copy();
this.size = another.size().copy();
}
+53 -7
View File
@@ -2,6 +2,9 @@ package mightypork.utils.math.rect;
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 {
@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
*
@@ -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
*/
@@ -37,7 +84,6 @@ public abstract class RectView extends RectMathDynamic {
@Deprecated
public RectView view()
{
// must NOT call RectView.make, it'd cause infinite recursion.
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;
public abstract class AbstractVect implements Vect {
abstract class AbstractVect implements Vect {
private VectView proxy;
@@ -47,8 +45,6 @@ public abstract class AbstractVect implements Vect {
@Override
public VectView view()
{
// must NOT call VectView.make, it'd cause infinite recursion.
if (proxy == null) proxy = new VectProxy(this);
return proxy;
@@ -111,37 +111,32 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
@Override
public VectAnimated result(double x, double y, double z)
public void setTo(double x, double y, double z)
{
setX(x);
setY(y);
setZ(z);
return this;
}
@Override
public VectMutable setX(double x)
public void setX(double x)
{
this.x.animate(x, defaultDuration);
return this;
}
@Override
public VectMutable setY(double y)
public void setY(double y)
{
this.y.animate(y, defaultDuration);
return this;
}
@Override
public VectMutable setZ(double z)
public void setZ(double z)
{
this.z.animate(z, defaultDuration);
return this;
}
@@ -150,12 +145,10 @@ public class VectAnimated extends VectMutable implements Pauseable, Updateable {
*
* @param offset added offset
* @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);
return this;
animate(this.add(offset), duration);
}
@@ -252,12 +252,33 @@ abstract class VectMath<V extends Vect, N> extends AbstractVect {
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);
/**
* Multiply each component.
*
* @param x x multiplier
* @param y y multiplier
* @return result
*/
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);
@@ -11,7 +11,7 @@ import mightypork.utils.math.num.NumVal;
* @author MightyPork
* @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
public NumVal xn()
+12 -22
View File
@@ -9,7 +9,7 @@ import mightypork.utils.annotations.FactoryMethod;
*
* @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)
@@ -79,12 +79,10 @@ public abstract class VectMutable extends VectMathStatic<VectMutable> { // retur
/**
* 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.
*
* @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 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 y y coordinate
* @param z z coordinate
* @return this
*/
public VectMutable setTo(double x, double y, double z)
{
return result(x, y, z);
}
public abstract void setTo(double x, double y, double z);
/**
* Set X coordinate.
*
* @param x x coordinate
* @return this
*/
public abstract VectMutable setX(double x);
public abstract void setX(double x);
/**
* Set Y coordinate.
*
* @param y y coordinate
* @return this
*/
public abstract VectMutable setY(double y);
public abstract void setY(double y);
/**
* Set 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
public VectMutable result(double x, double y, double z)
public void setTo(double x, double y, double z)
{
this.x = x;
this.y = y;
this.z = z;
return this;
}
@Override
public VectMutable setX(double x)
public void setX(double x)
{
this.x = x;
return this;
}
@Override
public VectMutable setY(double y)
public void setY(double y)
{
this.y = y;
return this;
}
@Override
public VectMutable setZ(double z)
public void setZ(double z)
{
this.z = z;
return this;
}
}
@@ -19,6 +19,9 @@ class VectProxy extends VectAdapter {
* @param observed
*/
public VectProxy(Vect observed) {
assert (!(observed instanceof VectView));
this.observed = observed;
}
+32 -2
View File
@@ -2,6 +2,7 @@ package mightypork.utils.math.vect;
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
*
@@ -59,15 +74,30 @@ public final class VectVal extends VectMathStatic<VectVal> {
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;
public VectVal(Vect other) {
VectVal(Vect other) {
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.y = y;
this.z = z;
+1 -7
View File
@@ -15,12 +15,6 @@ import mightypork.utils.math.num.Num;
*/
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.
*
@@ -78,7 +72,7 @@ public abstract class VectView extends VectMathDynamic { // returns constant val
@Deprecated
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.vect.Vect;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
/**