Added bound digests
This commit is contained in:
@@ -83,7 +83,7 @@ public class TestConstr {
|
||||
{
|
||||
final NumVar a = Num.makeVar(100);
|
||||
|
||||
a.assign(a.mul(50).add(10).div(2));
|
||||
a.setTo(a.mul(50).add(10).div(2));
|
||||
|
||||
System.out.println(a);
|
||||
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,41 +0,0 @@
|
||||
//package mightypork.utils.math.constraints.builder;
|
||||
//
|
||||
//
|
||||
//import mightypork.utils.math.constraints.ConstraintFactory;
|
||||
//import mightypork.utils.math.constraints.RectBound;
|
||||
//import mightypork.utils.math.constraints.VectBound;
|
||||
//import mightypork.utils.math.rect.Rect;
|
||||
//import mightypork.utils.math.vect.Vect;
|
||||
//
|
||||
//
|
||||
//public class Bounds {
|
||||
//
|
||||
// public RectBB box(Object side) {
|
||||
// return wrap(ConstraintFactory.box(side));
|
||||
// }
|
||||
// public RectBB box(VectBound origin, Object width, Object height){
|
||||
// return wrap(ConstraintFactory.box(origin, width, height));
|
||||
// }
|
||||
//
|
||||
// public RectBB box(Object width, Object height){
|
||||
// return wrap(ConstraintFactory.box(width, height));
|
||||
// }
|
||||
//
|
||||
// public RectBB box(Object x, Object y, Object width, Object height){
|
||||
// return wrap(ConstraintFactory.box(Rect.ZERO, x,y,width,height));
|
||||
// }
|
||||
//
|
||||
// public RectBB wrap(RectBound rb) {
|
||||
// return new RectBB(rb);
|
||||
// }
|
||||
//
|
||||
// public static class RectBB {
|
||||
//
|
||||
// private final RectBound parent;
|
||||
//
|
||||
// public RectBB(RectBound parent) {
|
||||
// this.parent = parent;
|
||||
// }
|
||||
//
|
||||
// }
|
||||
//}
|
||||
@@ -38,7 +38,7 @@ public abstract class Num implements NumBound {
|
||||
@FactoryMethod
|
||||
public static NumVar makeVar(Num copied)
|
||||
{
|
||||
return new NumVar(eval(copied));
|
||||
return new NumVar(copied.value());
|
||||
}
|
||||
|
||||
private Num p_ceil;
|
||||
@@ -59,36 +59,23 @@ public abstract class Num implements NumBound {
|
||||
private Num p_abs;
|
||||
|
||||
|
||||
/**
|
||||
* Convert to double, turning null into zero.
|
||||
*
|
||||
* @param a num
|
||||
* @return double
|
||||
*/
|
||||
protected static double eval(final NumBound a)
|
||||
{
|
||||
return toNum(a).value();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert {@link NumBound} to {@link Num}, turning null to Num.ZERO.
|
||||
*
|
||||
* @param a numeric bound
|
||||
* @return num
|
||||
*/
|
||||
protected static Num toNum(final NumBound a)
|
||||
{
|
||||
return (a == null) ? Num.ZERO : (a.getNum() == null ? Num.ZERO : a.getNum());
|
||||
}
|
||||
|
||||
|
||||
public NumConst freeze()
|
||||
{
|
||||
return new NumConst(value());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a snapshot of the current state, to be used for processing.
|
||||
*
|
||||
* @return digest
|
||||
*/
|
||||
public NumDigest digest()
|
||||
{
|
||||
return new NumDigest(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Num getNum()
|
||||
{
|
||||
@@ -102,42 +89,6 @@ public abstract class Num implements NumBound {
|
||||
public abstract double value();
|
||||
|
||||
|
||||
public Num abs()
|
||||
{
|
||||
if (p_abs == null) p_abs = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.abs(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_abs;
|
||||
}
|
||||
|
||||
|
||||
public Num acos()
|
||||
{
|
||||
if (p_acos == null) p_acos = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.acos(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_acos;
|
||||
}
|
||||
|
||||
|
||||
public Num add(final double addend)
|
||||
{
|
||||
return new Num() {
|
||||
@@ -164,15 +115,21 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return t.value() + eval(addend);
|
||||
return t.value() + addend.value();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num asin()
|
||||
public Num sub(final double subtrahend)
|
||||
{
|
||||
if (p_asin == null) p_asin = new Num() {
|
||||
return add(-subtrahend);
|
||||
}
|
||||
|
||||
|
||||
public Num abs()
|
||||
{
|
||||
if (p_abs == null) p_abs = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
@@ -180,33 +137,15 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.asin(t.value());
|
||||
return Math.abs(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_asin;
|
||||
return p_abs;
|
||||
}
|
||||
|
||||
|
||||
public Num atan()
|
||||
{
|
||||
if (p_atan == null) p_atan = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.atan(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_atan;
|
||||
}
|
||||
|
||||
|
||||
public Num average(final double other)
|
||||
public Num sub(final Num subtrahend)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
@@ -216,101 +155,12 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return (t.value() + other) / 2;
|
||||
return t.value() - subtrahend.value();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num average(final Num other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return (t.value() + eval(other)) / 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num cbrt()
|
||||
{
|
||||
if (p_cbrt == null) p_cbrt = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.cbrt(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_cbrt;
|
||||
}
|
||||
|
||||
|
||||
public Num ceil()
|
||||
{
|
||||
if (p_ceil == null) p_ceil = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.round(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_ceil;
|
||||
}
|
||||
|
||||
|
||||
public Num cos()
|
||||
{
|
||||
if (p_cos == null) p_cos = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.cos(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_cos;
|
||||
}
|
||||
|
||||
|
||||
public Num cube()
|
||||
{
|
||||
if (p_cube == null) p_cube = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
final double v = t.value();
|
||||
return v * v * v;
|
||||
}
|
||||
};
|
||||
|
||||
return p_cube;
|
||||
}
|
||||
|
||||
|
||||
public Num div(final double factor)
|
||||
{
|
||||
return mul(1 / factor);
|
||||
@@ -328,173 +178,7 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return t.value() / eval(factor);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public boolean eq(double other)
|
||||
{
|
||||
return value() == other;
|
||||
}
|
||||
|
||||
|
||||
public boolean eq(final Num a)
|
||||
{
|
||||
return eq(eval(a));
|
||||
}
|
||||
|
||||
|
||||
public Num floor()
|
||||
{
|
||||
if (p_floor == null) p_floor = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.floor(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_floor;
|
||||
}
|
||||
|
||||
|
||||
public boolean gt(double other)
|
||||
{
|
||||
return Math.signum(value() - other) >= 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean gt(final Num other)
|
||||
{
|
||||
return gt(eval(other));
|
||||
}
|
||||
|
||||
|
||||
public boolean gte(double other)
|
||||
{
|
||||
return Math.signum(value() - other) >= 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean gte(final Num other)
|
||||
{
|
||||
return gte(eval(other));
|
||||
}
|
||||
|
||||
|
||||
public Num half()
|
||||
{
|
||||
return mul(0.5);
|
||||
}
|
||||
|
||||
|
||||
public boolean isNegative()
|
||||
{
|
||||
return value() < 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean isPositive()
|
||||
{
|
||||
return value() > 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean isZero()
|
||||
{
|
||||
return value() == 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean lt(double other)
|
||||
{
|
||||
return !gte(other);
|
||||
}
|
||||
|
||||
|
||||
public boolean lt(final Num other)
|
||||
{
|
||||
return !gte(other);
|
||||
}
|
||||
|
||||
|
||||
public boolean lte(double other)
|
||||
{
|
||||
return !gt(other);
|
||||
}
|
||||
|
||||
|
||||
public boolean lte(final Num other)
|
||||
{
|
||||
return !gt(other);
|
||||
}
|
||||
|
||||
|
||||
public Num max(final double other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.max(t.value(), other);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num max(final Num other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.max(t.value(), eval(other));
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num min(final double other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.min(t.value(), other);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num min(final Num other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.min(t.value(), eval(other));
|
||||
return t.value() / factor.value();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -527,12 +211,210 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return t.value() * eval(factor);
|
||||
return t.value() * factor.value();
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num average(final double other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return (t.value() + other) / 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num average(final Num other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return (t.value() + other.value()) / 2;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num perc(final double percent)
|
||||
{
|
||||
return mul(percent / 100);
|
||||
}
|
||||
|
||||
|
||||
public Num perc(final Num percent)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return t.value() * (percent.value() / 100);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num cos()
|
||||
{
|
||||
if (p_cos == null) p_cos = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.cos(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_cos;
|
||||
}
|
||||
|
||||
|
||||
public Num acos()
|
||||
{
|
||||
if (p_acos == null) p_acos = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.acos(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_acos;
|
||||
}
|
||||
|
||||
|
||||
public Num sin()
|
||||
{
|
||||
if (p_sin == null) p_sin = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.sin(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_sin;
|
||||
}
|
||||
|
||||
|
||||
public Num asin()
|
||||
{
|
||||
if (p_asin == null) p_asin = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.asin(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_asin;
|
||||
}
|
||||
|
||||
|
||||
public Num tan()
|
||||
{
|
||||
if (p_tan == null) p_tan = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.tan(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_tan;
|
||||
}
|
||||
|
||||
|
||||
public Num atan()
|
||||
{
|
||||
if (p_atan == null) p_atan = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.atan(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_atan;
|
||||
}
|
||||
|
||||
|
||||
public Num cbrt()
|
||||
{
|
||||
if (p_cbrt == null) p_cbrt = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.cbrt(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_cbrt;
|
||||
}
|
||||
|
||||
|
||||
public Num sqrt()
|
||||
{
|
||||
if (p_sqrt == null) p_sqrt = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.sqrt(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_sqrt;
|
||||
}
|
||||
|
||||
|
||||
public Num neg()
|
||||
{
|
||||
if (p_neg == null) p_neg = new Num() {
|
||||
@@ -551,15 +433,9 @@ public abstract class Num implements NumBound {
|
||||
}
|
||||
|
||||
|
||||
public Num perc(final double percent)
|
||||
public Num round()
|
||||
{
|
||||
return mul(percent / 100);
|
||||
}
|
||||
|
||||
|
||||
public Num perc(final Num percent)
|
||||
{
|
||||
return new Num() {
|
||||
if (p_round == null) p_round = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
@@ -567,9 +443,47 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return t.value() * (eval(percent) / 100);
|
||||
return Math.round(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_round;
|
||||
}
|
||||
|
||||
|
||||
public Num floor()
|
||||
{
|
||||
if (p_floor == null) p_floor = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.floor(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_floor;
|
||||
}
|
||||
|
||||
|
||||
public Num ceil()
|
||||
{
|
||||
if (p_ceil == null) p_ceil = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.round(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_ceil;
|
||||
}
|
||||
|
||||
|
||||
@@ -599,15 +513,15 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.pow(t.value(), eval(power));
|
||||
return Math.pow(t.value(), power.value());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num round()
|
||||
public Num cube()
|
||||
{
|
||||
if (p_round == null) p_round = new Num() {
|
||||
if (p_cube == null) p_cube = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
@@ -615,65 +529,12 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.round(t.value());
|
||||
final double v = t.value();
|
||||
return v * v * v;
|
||||
}
|
||||
};
|
||||
|
||||
return p_round;
|
||||
}
|
||||
|
||||
|
||||
public Num signum()
|
||||
{
|
||||
if (p_sgn == null) p_sgn = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.signum(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_sgn;
|
||||
}
|
||||
|
||||
|
||||
public Num sin()
|
||||
{
|
||||
if (p_sin == null) p_sin = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.sin(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_sin;
|
||||
}
|
||||
|
||||
|
||||
public Num sqrt()
|
||||
{
|
||||
if (p_sqrt == null) p_sqrt = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.sqrt(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_sqrt;
|
||||
return p_cube;
|
||||
}
|
||||
|
||||
|
||||
@@ -696,13 +557,13 @@ public abstract class Num implements NumBound {
|
||||
}
|
||||
|
||||
|
||||
public Num sub(final double subtrahend)
|
||||
public Num half()
|
||||
{
|
||||
return add(-subtrahend);
|
||||
return mul(0.5);
|
||||
}
|
||||
|
||||
|
||||
public Num sub(final Num subtrahend)
|
||||
public Num max(final double other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
@@ -712,15 +573,15 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return t.value() - eval(subtrahend);
|
||||
return Math.max(t.value(), other);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num tan()
|
||||
public Num max(final Num other)
|
||||
{
|
||||
if (p_tan == null) p_tan = new Num() {
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
@@ -728,11 +589,77 @@ public abstract class Num implements NumBound {
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.tan(t.value());
|
||||
return Math.max(t.value(), other.value());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num min(final Num other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.min(t.value(), other.value());
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num min(final double other)
|
||||
{
|
||||
return new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.min(t.value(), other);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public Num signum()
|
||||
{
|
||||
if (p_sgn == null) p_sgn = new Num() {
|
||||
|
||||
final Num t = Num.this;
|
||||
|
||||
|
||||
@Override
|
||||
public double value()
|
||||
{
|
||||
return Math.signum(t.value());
|
||||
}
|
||||
};
|
||||
|
||||
return p_tan;
|
||||
return p_sgn;
|
||||
}
|
||||
|
||||
|
||||
public boolean isNegative()
|
||||
{
|
||||
return value() < 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean isPositive()
|
||||
{
|
||||
return value() > 0;
|
||||
}
|
||||
|
||||
|
||||
public boolean isZero()
|
||||
{
|
||||
return value() == 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -756,7 +683,7 @@ public abstract class Num implements NumBound {
|
||||
if (!(obj instanceof Num)) return false;
|
||||
final Num other = (Num) obj;
|
||||
|
||||
return eq(other);
|
||||
return value() == other.value();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,17 +1,15 @@
|
||||
package mightypork.utils.math.num;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.NumBound;
|
||||
|
||||
|
||||
/**
|
||||
* Constant number {@link NumBound}
|
||||
* Constant number
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class NumConst extends Num {
|
||||
|
||||
private final double value;
|
||||
private NumDigest digest;
|
||||
|
||||
|
||||
NumConst(Num copied) {
|
||||
@@ -32,7 +30,7 @@ public class NumConst extends Num {
|
||||
|
||||
|
||||
/**
|
||||
* No good to copy a constant.
|
||||
* @deprecated No good to copy a constant.
|
||||
*/
|
||||
@Override
|
||||
@Deprecated
|
||||
@@ -41,6 +39,11 @@ public class NumConst extends Num {
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumDigest digest()
|
||||
{
|
||||
return (digest != null) ? digest : (digest = super.digest());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NumConst add(double addend)
|
||||
@@ -49,6 +52,12 @@ public class NumConst extends Num {
|
||||
}
|
||||
|
||||
|
||||
public NumConst add(NumConst addend)
|
||||
{
|
||||
return Num.make(value + addend.value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NumConst sub(double subtrahend)
|
||||
{
|
||||
@@ -56,6 +65,12 @@ public class NumConst extends Num {
|
||||
}
|
||||
|
||||
|
||||
public NumConst sub(NumConst addend)
|
||||
{
|
||||
return Num.make(value - addend.value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NumConst mul(double factor)
|
||||
{
|
||||
@@ -63,6 +78,12 @@ public class NumConst extends Num {
|
||||
}
|
||||
|
||||
|
||||
public NumConst mul(NumConst addend)
|
||||
{
|
||||
return Num.make(value * addend.value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NumConst div(double factor)
|
||||
{
|
||||
@@ -70,6 +91,12 @@ public class NumConst extends Num {
|
||||
}
|
||||
|
||||
|
||||
public NumConst div(NumConst addend)
|
||||
{
|
||||
return Num.make(value / addend.value);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NumConst perc(double percents)
|
||||
{
|
||||
@@ -198,6 +225,12 @@ public class NumConst extends Num {
|
||||
}
|
||||
|
||||
|
||||
public NumConst average(NumConst other)
|
||||
{
|
||||
return super.average(other).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NumConst round()
|
||||
{
|
||||
@@ -225,27 +258,4 @@ public class NumConst extends Num {
|
||||
return mul(0.5);
|
||||
}
|
||||
|
||||
|
||||
public NumConst add(NumConst addend)
|
||||
{
|
||||
return make(value + addend.value);
|
||||
}
|
||||
|
||||
|
||||
public NumConst sub(NumConst addend)
|
||||
{
|
||||
return make(value - addend.value);
|
||||
}
|
||||
|
||||
|
||||
public NumConst mul(NumConst addend)
|
||||
{
|
||||
return make(value * addend.value);
|
||||
}
|
||||
|
||||
|
||||
public NumConst div(NumConst addend)
|
||||
{
|
||||
return make(value / addend.value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
package mightypork.utils.math.num;
|
||||
|
||||
|
||||
public class NumDigest {
|
||||
|
||||
public final NumConst source;
|
||||
|
||||
public final double value;
|
||||
|
||||
|
||||
public NumDigest(Num num) {
|
||||
this.value = num.value();
|
||||
this.source = num.freeze();
|
||||
}
|
||||
}
|
||||
@@ -21,9 +21,9 @@ public abstract class NumMutable extends Num {
|
||||
*
|
||||
* @param value new value
|
||||
*/
|
||||
public void assign(Num value)
|
||||
public void setTo(Num value)
|
||||
{
|
||||
setTo(eval(value));
|
||||
setTo(value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ public class NumVar extends NumMutable {
|
||||
|
||||
|
||||
public NumVar(Num value) {
|
||||
this.value = eval(value);
|
||||
this(value.value());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -147,6 +147,10 @@ public abstract class Rect implements RectBound {
|
||||
private Num p_r;
|
||||
private Num p_t;
|
||||
private Num p_b;
|
||||
private Rect p_edge_l;
|
||||
private Rect p_edge_r;
|
||||
private Rect p_edge_t;
|
||||
private Rect p_edge_b;
|
||||
|
||||
|
||||
/**
|
||||
@@ -161,6 +165,17 @@ public abstract class Rect implements RectBound {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a snapshot of the current state, to be used for processing.
|
||||
*
|
||||
* @return digest
|
||||
*/
|
||||
public RectDigest digest()
|
||||
{
|
||||
return new RectDigest(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect getRect()
|
||||
{
|
||||
@@ -313,25 +328,7 @@ public abstract class Rect implements RectBound {
|
||||
*/
|
||||
public Rect shrink(final double left, final double right, final double top, final double bottom)
|
||||
{
|
||||
return new Rect() {
|
||||
|
||||
private final Rect t = Rect.this;
|
||||
|
||||
|
||||
@Override
|
||||
public Vect size()
|
||||
{
|
||||
return t.size().sub(left + right, top + bottom);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Vect origin()
|
||||
{
|
||||
return t.origin().add(left, top);
|
||||
}
|
||||
|
||||
};
|
||||
return grow(-left, -right, -top, -bottom);
|
||||
}
|
||||
|
||||
|
||||
@@ -574,6 +571,30 @@ public abstract class Rect implements RectBound {
|
||||
}
|
||||
|
||||
|
||||
public Rect leftEdge()
|
||||
{
|
||||
return p_edge_l != null ? p_edge_l : (p_edge_l = topLeft().expand(Num.ZERO, Num.ZERO, Num.ZERO, height()));
|
||||
}
|
||||
|
||||
|
||||
public Rect rightEdge()
|
||||
{
|
||||
return p_edge_r != null ? p_edge_r : (p_edge_r = topRight().expand(Num.ZERO, Num.ZERO, Num.ZERO, height()));
|
||||
}
|
||||
|
||||
|
||||
public Rect topEdge()
|
||||
{
|
||||
return p_edge_t != null ? p_edge_t : (p_edge_t = topLeft().expand(Num.ZERO, width(), Num.ZERO, Num.ZERO));
|
||||
}
|
||||
|
||||
|
||||
public Rect bottomEdge()
|
||||
{
|
||||
return p_edge_b != null ? p_edge_b : (p_edge_b = bottomLeft().expand(Num.ZERO, width(), Num.ZERO, Num.ZERO));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Center to given point
|
||||
*
|
||||
@@ -623,6 +644,12 @@ public abstract class Rect implements RectBound {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Center to given rect's center
|
||||
*
|
||||
* @param parent rect to center to
|
||||
* @return centered
|
||||
*/
|
||||
public Rect centerTo(Rect parent)
|
||||
{
|
||||
return centerTo(parent.center());
|
||||
|
||||
@@ -14,7 +14,7 @@ import mightypork.utils.math.vect.VectAdapter;
|
||||
public abstract class RectAdapter extends Rect {
|
||||
|
||||
// adapters are needed in case the vect returned from source changes
|
||||
// (is replaced). This way, references to origin and rect will stay intack.
|
||||
// (is replaced). This way, references to origin and rect will stay intact.
|
||||
|
||||
private final VectAdapter originAdapter = new VectAdapter() {
|
||||
|
||||
|
||||
@@ -28,6 +28,11 @@ public class RectConst extends Rect {
|
||||
private VectConst v_bl;
|
||||
private VectConst v_bc;
|
||||
private RectConst v_round;
|
||||
private RectConst v_edge_l;
|
||||
private RectConst v_edge_r;
|
||||
private RectConst v_edge_t;
|
||||
private RectConst v_edge_b;
|
||||
private RectDigest digest;
|
||||
|
||||
|
||||
/**
|
||||
@@ -78,6 +83,12 @@ public class RectConst extends Rect {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectDigest digest()
|
||||
{
|
||||
return (digest != null) ? digest : (digest = super.digest());
|
||||
}
|
||||
|
||||
@Override
|
||||
public VectConst origin()
|
||||
{
|
||||
@@ -106,10 +117,16 @@ public class RectConst extends Rect {
|
||||
}
|
||||
|
||||
|
||||
public RectConst move(NumConst x, NumConst y)
|
||||
{
|
||||
return super.move(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst shrink(double left, double right, double top, double bottom)
|
||||
{
|
||||
return Rect.make(pos.add(left, top), size.sub(left + right, top + bottom)).freeze();
|
||||
return super.shrink(left, right, top, bottom).freeze();
|
||||
|
||||
}
|
||||
|
||||
@@ -117,15 +134,14 @@ public class RectConst extends Rect {
|
||||
@Override
|
||||
public RectConst grow(double left, double right, double top, double bottom)
|
||||
{
|
||||
return Rect.make(pos.sub(left, top), size.add(left + right, top + bottom)).freeze();
|
||||
return super.grow(left, right, top, bottom).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst round()
|
||||
{
|
||||
if (v_round == null) v_round = Rect.make(pos.round(), size.round());
|
||||
return v_round;
|
||||
return (v_round != null) ? v_round : (v_round = Rect.make(pos.round(), size.round()));
|
||||
}
|
||||
|
||||
|
||||
@@ -167,8 +183,7 @@ public class RectConst extends Rect {
|
||||
@Override
|
||||
public NumConst right()
|
||||
{
|
||||
if (v_r == null) v_r = super.right().freeze();
|
||||
return v_r;
|
||||
return (v_r != null) ? v_r : (v_r = super.right().freeze());
|
||||
}
|
||||
|
||||
|
||||
@@ -182,8 +197,7 @@ public class RectConst extends Rect {
|
||||
@Override
|
||||
public NumConst bottom()
|
||||
{
|
||||
if (v_b == null) v_b = super.bottom().freeze();
|
||||
return v_b;
|
||||
return (v_b != null) ? v_b : (v_b = super.bottom().freeze());
|
||||
}
|
||||
|
||||
|
||||
@@ -197,64 +211,123 @@ public class RectConst extends Rect {
|
||||
@Override
|
||||
public VectConst topCenter()
|
||||
{
|
||||
if (v_tc == null) v_tc = super.topCenter().freeze();
|
||||
return v_tc;
|
||||
return (v_tc != null) ? v_tc : (v_tc = super.topCenter().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst topRight()
|
||||
{
|
||||
if (v_tr == null) v_tr = super.topRight().freeze();
|
||||
return v_tr;
|
||||
return (v_tr != null) ? v_tr : (v_tr = super.topRight().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst centerLeft()
|
||||
{
|
||||
if (v_cl == null) v_cl = super.centerLeft().freeze();
|
||||
return v_cl;
|
||||
return (v_cl != null) ? v_cl : (v_cl = super.centerLeft().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst center()
|
||||
{
|
||||
if (v_c == null) v_c = super.center().freeze();
|
||||
return v_c;
|
||||
return (v_c != null) ? v_c : (v_c = super.center().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst centerRight()
|
||||
{
|
||||
if (v_cr == null) v_cr = super.centerRight().freeze();
|
||||
return v_cr;
|
||||
return (v_cr != null) ? v_cr : (v_cr = super.centerRight().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst bottomLeft()
|
||||
{
|
||||
if (v_bl == null) v_bl = super.bottomLeft().freeze();
|
||||
return v_bl;
|
||||
return (v_bl != null) ? v_bl : (v_bl = super.bottomLeft().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst bottomCenter()
|
||||
{
|
||||
if (v_bc == null) v_bc = super.bottomCenter().freeze();
|
||||
return v_bc;
|
||||
return (v_bc != null) ? v_bc : (v_bc = super.bottomCenter().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst bottomRight()
|
||||
{
|
||||
if (v_br == null) v_br = super.bottomRight().freeze();
|
||||
return v_br;
|
||||
return (v_br != null) ? v_br : (v_br = super.bottomRight().freeze());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst leftEdge()
|
||||
{
|
||||
return (v_edge_l != null) ? v_edge_l : (v_edge_l = super.leftEdge().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst rightEdge()
|
||||
{
|
||||
return (v_edge_r != null) ? v_edge_r : (v_edge_r = super.rightEdge().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst topEdge()
|
||||
{
|
||||
return (v_edge_t != null) ? v_edge_t : (v_edge_t = super.topEdge().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst bottomEdge()
|
||||
{
|
||||
return (v_edge_b != null) ? v_edge_b : (v_edge_b = super.bottomEdge().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Rect shrink(Vect shrink)
|
||||
{
|
||||
return super.shrink(shrink);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst shrink(double x, double y)
|
||||
{
|
||||
return super.shrink(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
public RectConst shrink(NumConst left, NumConst right, NumConst top, NumConst bottom)
|
||||
{
|
||||
return super.shrink(left, right, top, bottom).freeze();
|
||||
}
|
||||
|
||||
|
||||
public RectConst grow(NumConst left, NumConst right, NumConst top, NumConst bottom)
|
||||
{
|
||||
return super.grow(left, right, top, bottom).freeze();
|
||||
}
|
||||
|
||||
|
||||
public RectConst centerTo(VectConst point)
|
||||
{
|
||||
return super.centerTo(point).freeze();
|
||||
}
|
||||
|
||||
|
||||
public RectConst centerTo(RectConst parent)
|
||||
{
|
||||
return super.centerTo(parent).freeze();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.math.vect.VectConst;
|
||||
|
||||
|
||||
public class RectDigest {
|
||||
|
||||
public final RectConst source;
|
||||
public final VectConst origin;
|
||||
public final VectConst size;
|
||||
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double width;
|
||||
public final double height;
|
||||
|
||||
public final double left;
|
||||
public final double right;
|
||||
public final double top;
|
||||
public final double bottom;
|
||||
|
||||
|
||||
public RectDigest(Rect rect) {
|
||||
this.source = rect.freeze();
|
||||
|
||||
this.origin = rect.origin().freeze();
|
||||
this.size = rect.size().freeze();
|
||||
|
||||
this.x = rect.x().value();
|
||||
this.y = rect.y().value();
|
||||
|
||||
this.width = rect.width().value();
|
||||
this.height = rect.height().value();
|
||||
|
||||
this.left = rect.left().value();
|
||||
this.right = rect.right().value();
|
||||
this.top = rect.top().value();
|
||||
this.bottom = rect.bottom().value();
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ import mightypork.utils.math.constraints.VectBound;
|
||||
import mightypork.utils.math.num.Num;
|
||||
import mightypork.utils.math.num.NumConst;
|
||||
import mightypork.utils.math.rect.Rect;
|
||||
import mightypork.utils.math.rect.RectDigest;
|
||||
|
||||
|
||||
/**
|
||||
@@ -237,6 +238,18 @@ public abstract class Vect implements VectBound {
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Get a snapshot of the current state, to be used for processing.
|
||||
*
|
||||
* @return digest
|
||||
*/
|
||||
public VectDigest digest()
|
||||
{
|
||||
return new VectDigest(this);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get a view with X set to given value
|
||||
*
|
||||
|
||||
@@ -3,6 +3,7 @@ package mightypork.utils.math.vect;
|
||||
|
||||
import mightypork.utils.math.num.Num;
|
||||
import mightypork.utils.math.num.NumConst;
|
||||
import mightypork.utils.math.rect.RectConst;
|
||||
|
||||
|
||||
/**
|
||||
@@ -25,6 +26,7 @@ public final class VectConst extends Vect {
|
||||
private NumConst v_xc;
|
||||
private NumConst v_yc;
|
||||
private NumConst v_zc;
|
||||
private VectDigest digest;
|
||||
|
||||
|
||||
VectConst(Vect other) {
|
||||
@@ -63,43 +65,40 @@ public final class VectConst extends Vect {
|
||||
/**
|
||||
* @return X constraint
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final NumConst xn()
|
||||
{
|
||||
if (v_xc == null) v_xc = Num.make(this.x);
|
||||
|
||||
return v_xc;
|
||||
return (v_xc != null) ? v_xc : (v_xc = Num.make(this.x));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Y constraint
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final NumConst yn()
|
||||
{
|
||||
if (v_yc == null) v_yc = Num.make(this.y);
|
||||
|
||||
return v_yc;
|
||||
return (v_yc != null) ? v_yc : (v_yc = Num.make(this.y));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return Z constraint
|
||||
*/
|
||||
|
||||
@Override
|
||||
public final NumConst zn()
|
||||
{
|
||||
|
||||
if (v_zc == null) v_zc = Num.make(this.z);
|
||||
|
||||
return v_zc;
|
||||
return (v_zc != null) ? v_zc : (v_zc = Num.make(this.z));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @deprecated it's useless to copy a constant
|
||||
*/
|
||||
|
||||
@Override
|
||||
@Deprecated
|
||||
public VectConst freeze()
|
||||
@@ -108,70 +107,73 @@ public final class VectConst extends Vect {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectDigest digest()
|
||||
{
|
||||
return (digest != null) ? digest : (digest = super.digest());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst abs()
|
||||
{
|
||||
if (v_abs != null) return v_abs;
|
||||
return v_abs = Vect.make(Math.abs(x()), Math.abs(y()), Math.abs(z()));
|
||||
return (v_abs != null) ? v_abs : (v_abs = super.abs().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst add(double x, double y)
|
||||
{
|
||||
return add(x, y, 0);
|
||||
return super.add(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst add(double x, double y, double z)
|
||||
{
|
||||
return Vect.make(x() + x, y() + y, z() + z);
|
||||
return super.add(x, y, z).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst half()
|
||||
{
|
||||
if (v_half != null) return v_half;
|
||||
return v_half = mul(0.5);
|
||||
return (v_half != null) ? v_half : (v_half = super.half().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst mul(double d)
|
||||
{
|
||||
return mul(d, d, d);
|
||||
return super.mul(d).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst mul(double x, double y)
|
||||
{
|
||||
return mul(x, y, 1);
|
||||
return super.mul(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst mul(double x, double y, double z)
|
||||
{
|
||||
return Vect.make(x() * x, y() * y, z() * z);
|
||||
return super.mul(x, y, z).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst round()
|
||||
{
|
||||
if (v_round != null) return v_round;
|
||||
return v_round = Vect.make(Math.round(x()), Math.round(y()), Math.round(z()));
|
||||
return (v_round != null) ? v_round : (v_round = super.round().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst floor()
|
||||
{
|
||||
if (v_floor != null) return v_floor;
|
||||
return v_floor = Vect.make(Math.floor(x()), Math.floor(y()), Math.floor(z()));
|
||||
return (v_floor != null) ? v_floor : (v_floor = super.floor().freeze());
|
||||
}
|
||||
|
||||
|
||||
@@ -179,50 +181,184 @@ public final class VectConst extends Vect {
|
||||
public VectConst ceil()
|
||||
{
|
||||
if (v_ceil != null) return v_ceil;
|
||||
return v_ceil = Vect.make(Math.ceil(x()), Math.ceil(y()), Math.ceil(z()));
|
||||
return v_ceil = super.ceil().freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst sub(double x, double y)
|
||||
{
|
||||
return sub(x, y, 0);
|
||||
return super.sub(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst sub(double x, double y, double z)
|
||||
{
|
||||
return Vect.make(x() - x, y() - y, z() - z);
|
||||
return super.sub(x, y, z).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst neg()
|
||||
{
|
||||
if (v_neg != null) return v_neg;
|
||||
return v_neg = Vect.make(-x(), -y(), -z());
|
||||
return (v_neg != null) ? v_neg : (v_neg = super.neg().freeze());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst norm(double size)
|
||||
{
|
||||
if (isZero()) return this; // can't norm zero vector
|
||||
|
||||
final double k = size().mul(1 / size).value();
|
||||
|
||||
return mul(k);
|
||||
return super.norm(size).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public NumConst size()
|
||||
{
|
||||
if (v_size != null) return v_size;
|
||||
return (v_size != null) ? v_size : (v_size = super.size().freeze());
|
||||
}
|
||||
|
||||
final double x = x(), y = y(), z = z();
|
||||
return v_size = Num.make(Math.sqrt(x * x + y * y + z * z));
|
||||
|
||||
@Override
|
||||
public VectConst withX(double x)
|
||||
{
|
||||
return super.withX(x).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst withY(double y)
|
||||
{
|
||||
return super.withY(y).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VectConst withZ(double z)
|
||||
{
|
||||
return super.withZ(z).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst withX(NumConst x)
|
||||
{
|
||||
return super.withX(x).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst withY(NumConst y)
|
||||
{
|
||||
return super.withY(y).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst withZ(NumConst z)
|
||||
{
|
||||
return super.withZ(z).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst add(VectConst vec)
|
||||
{
|
||||
return super.add(vec).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst add(NumConst x, NumConst y)
|
||||
{
|
||||
return super.add(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst add(NumConst x, NumConst y, NumConst z)
|
||||
{
|
||||
return super.add(x, y, z).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst mul(VectConst vec)
|
||||
{
|
||||
return super.mul(vec).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst mul(NumConst d)
|
||||
{
|
||||
return super.mul(d).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst mul(NumConst x, NumConst y)
|
||||
{
|
||||
return super.mul(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst mul(NumConst x, NumConst y, NumConst z)
|
||||
{
|
||||
return super.mul(x, y, z).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst sub(VectConst vec)
|
||||
{
|
||||
return super.sub(vec).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst sub(NumConst x, NumConst y)
|
||||
{
|
||||
return super.sub(x, y).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst sub(NumConst x, NumConst y, NumConst z)
|
||||
{
|
||||
return super.sub(x, y, z).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst norm(NumConst size)
|
||||
{
|
||||
return super.norm(size).freeze();
|
||||
}
|
||||
|
||||
|
||||
public NumConst dist(VectConst point)
|
||||
{
|
||||
return super.dist(point).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst midTo(VectConst point)
|
||||
{
|
||||
return super.midTo(point).freeze();
|
||||
}
|
||||
|
||||
|
||||
public VectConst vectTo(VectConst point)
|
||||
{
|
||||
return super.vectTo(point).freeze();
|
||||
}
|
||||
|
||||
|
||||
public NumConst dot(VectConst vec)
|
||||
{
|
||||
return super.dot(vec).freeze();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectConst expand(int left, int right, int top, int bottom)
|
||||
{
|
||||
return super.expand(left, right, top, bottom).freeze();
|
||||
}
|
||||
|
||||
|
||||
public RectConst expand(NumConst left, NumConst right, NumConst top, NumConst bottom)
|
||||
{
|
||||
return super.expand(left, right, top, bottom).freeze();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
public class VectDigest {
|
||||
|
||||
public final VectConst source;
|
||||
|
||||
public final double x;
|
||||
public final double y;
|
||||
public final double z;
|
||||
|
||||
|
||||
public VectDigest(Vect vect) {
|
||||
this.source = vect.freeze();
|
||||
|
||||
this.x = vect.x();
|
||||
this.y = vect.y();
|
||||
this.z = vect.z();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user