Now it will be clear what is VALUE, VIEW and MUTABLE.v5stable
							parent
							
								
									4221d5430a
								
							
						
					
					
						commit
						4816e0b539
					
				@ -1,36 +0,0 @@ | 
				
			||||
package mightypork.utils.math.constraints; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.coord.VecView; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public class CReverseProxy extends VecView { | 
				
			||||
	 | 
				
			||||
	private final VecConstraint constraint; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public CReverseProxy(VecConstraint wrapped) { | 
				
			||||
		this.constraint = wrapped; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double x() | 
				
			||||
	{ | 
				
			||||
		return constraint.getVec().x(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double y() | 
				
			||||
	{ | 
				
			||||
		return constraint.getVec().y(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double z() | 
				
			||||
	{ | 
				
			||||
		return constraint.getVec().z(); | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -1,19 +0,0 @@ | 
				
			||||
package mightypork.utils.math.constraints; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.coord.VecView; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public interface VecConstraint { | 
				
			||||
	 | 
				
			||||
	VecView getVec(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	NumberConstraint xc(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	NumberConstraint yc(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	NumberConstraint zc(); | 
				
			||||
} | 
				
			||||
@ -0,0 +1,18 @@ | 
				
			||||
package mightypork.utils.math.constraints; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.vect.VectVal; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Vector constraint. | 
				
			||||
 *  | 
				
			||||
 * @author MightyPork | 
				
			||||
 */ | 
				
			||||
public interface VectConstraint { | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @return the constraint vec | 
				
			||||
	 */ | 
				
			||||
	VectVal getVec(); | 
				
			||||
} | 
				
			||||
@ -1,188 +0,0 @@ | 
				
			||||
package mightypork.utils.math.coord; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.constraints.NumberConstraint; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public abstract class AbstractVec implements Vec { | 
				
			||||
	 | 
				
			||||
	private AbstractVecProxy view; | 
				
			||||
	private NumberConstraint constraintX; | 
				
			||||
	private NumberConstraint constraintY; | 
				
			||||
	private NumberConstraint constraintZ; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView getVec() | 
				
			||||
	{ | 
				
			||||
		return view(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double x(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double y(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double z(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public int xi() | 
				
			||||
	{ | 
				
			||||
		return (int) Math.round(x()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public int yi() | 
				
			||||
	{ | 
				
			||||
		return (int) Math.round(y()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public int zi() | 
				
			||||
	{ | 
				
			||||
		return (int) Math.round(z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public NumberConstraint xc() | 
				
			||||
	{ | 
				
			||||
		if (constraintX == null) constraintX = new NumberConstraint() { | 
				
			||||
			 | 
				
			||||
			@Override | 
				
			||||
			public double getValue() | 
				
			||||
			{ | 
				
			||||
				return x(); | 
				
			||||
			} | 
				
			||||
		}; | 
				
			||||
		 | 
				
			||||
		return constraintX; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public NumberConstraint yc() | 
				
			||||
	{ | 
				
			||||
		if (constraintY == null) constraintY = new NumberConstraint() { | 
				
			||||
			 | 
				
			||||
			@Override | 
				
			||||
			public double getValue() | 
				
			||||
			{ | 
				
			||||
				return y(); | 
				
			||||
			} | 
				
			||||
		}; | 
				
			||||
		 | 
				
			||||
		return constraintY; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public NumberConstraint zc() | 
				
			||||
	{ | 
				
			||||
		if (constraintZ == null) constraintZ = new NumberConstraint() { | 
				
			||||
			 | 
				
			||||
			@Override | 
				
			||||
			public double getValue() | 
				
			||||
			{ | 
				
			||||
				return z(); | 
				
			||||
			} | 
				
			||||
		}; | 
				
			||||
		 | 
				
			||||
		return constraintZ; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double size() | 
				
			||||
	{ | 
				
			||||
		final double x = x(), y = y(), z = z(); | 
				
			||||
		return Math.sqrt(x * x + y * y + z * z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public boolean isZero() | 
				
			||||
	{ | 
				
			||||
		return x() == 0 && y() == 0 && z() == 0; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView value() | 
				
			||||
	{ | 
				
			||||
		return new ConstVec(this); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double distTo(Vec point) | 
				
			||||
	{ | 
				
			||||
		final double dx = x() - point.x(); | 
				
			||||
		final double dy = y() - point.y(); | 
				
			||||
		final double dz = z() - point.z(); | 
				
			||||
		 | 
				
			||||
		return Math.sqrt(dx * dx + dy * dy + dz * dz); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView midTo(Vec point) | 
				
			||||
	{ | 
				
			||||
		final double dx = (point.x() - x()) * 0.5; | 
				
			||||
		final double dy = (point.y() - y()) * 0.5; | 
				
			||||
		final double dz = (point.z() - z()) * 0.5; | 
				
			||||
		 | 
				
			||||
		return VecView.make(dx, dy, dz); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView vecTo(Vec point) | 
				
			||||
	{ | 
				
			||||
		return VecView.make(point.x() - x(), point.y() - y(), point.z() - z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView cross(Vec vec) | 
				
			||||
	{ | 
				
			||||
		//@formatter:off
 | 
				
			||||
		return VecView.make( | 
				
			||||
				y() * vec.z() - z() * vec.y(), | 
				
			||||
				z() * vec.x() - x() * vec.z(), | 
				
			||||
				x() * vec.y() - y() * vec.x()); | 
				
			||||
		//@formatter:on
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double dot(Vec vec) | 
				
			||||
	{ | 
				
			||||
		return x() * vec.x() + y() * vec.y() + z() * vec.z(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecMutable mutable() | 
				
			||||
	{ | 
				
			||||
		return VecMutable.make(this); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView view() | 
				
			||||
	{ | 
				
			||||
		if (view == null) view = new VecProxy(this); | 
				
			||||
		 | 
				
			||||
		return view; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -1,58 +0,0 @@ | 
				
			||||
package mightypork.utils.math.coord; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Coordinate with immutable numeric values. | 
				
			||||
 *  | 
				
			||||
 * @author MightyPork | 
				
			||||
 */ | 
				
			||||
class ConstVec extends VecView { | 
				
			||||
	 | 
				
			||||
	private final double x, y, z; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public ConstVec(Vec other) { | 
				
			||||
		this(other.x(), other.y(), other.z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public ConstVec(double x, double y) { | 
				
			||||
		this(x, y, 0); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	public ConstVec(double x, double y, double z) { | 
				
			||||
		this.x = x; | 
				
			||||
		this.y = y; | 
				
			||||
		this.z = z; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double x() | 
				
			||||
	{ | 
				
			||||
		return x; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double y() | 
				
			||||
	{ | 
				
			||||
		return y; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double z() | 
				
			||||
	{ | 
				
			||||
		return z; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView value() | 
				
			||||
	{ | 
				
			||||
		return this; // it's constant already
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -1,153 +0,0 @@ | 
				
			||||
package mightypork.utils.math.coord; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public class Synths { | 
				
			||||
	 | 
				
			||||
	private static abstract class HeteroSynth extends VecProxy { | 
				
			||||
		 | 
				
			||||
		public HeteroSynth(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected abstract double processX(double x); | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected abstract double processY(double y); | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected abstract double processZ(double z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	private static abstract class UniformSynth extends VecProxy { | 
				
			||||
		 | 
				
			||||
		public UniformSynth(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processX(double x) | 
				
			||||
		{ | 
				
			||||
			return super.processX(x); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processY(double y) | 
				
			||||
		{ | 
				
			||||
			return super.processY(y); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processZ(double z) | 
				
			||||
		{ | 
				
			||||
			return super.processZ(z); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		protected abstract double process(double a); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Round extends UniformSynth { | 
				
			||||
		 | 
				
			||||
		public Round(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return Math.round(a); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Ceil extends UniformSynth { | 
				
			||||
		 | 
				
			||||
		public Ceil(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return Math.ceil(a); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Floor extends UniformSynth { | 
				
			||||
		 | 
				
			||||
		public Floor(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return Math.floor(a); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Neg extends UniformSynth { | 
				
			||||
		 | 
				
			||||
		public Neg(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return -a; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Half extends UniformSynth { | 
				
			||||
		 | 
				
			||||
		public Half(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return a / 2; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Norm extends HeteroSynth { | 
				
			||||
		 | 
				
			||||
		public Norm(Vec observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processX(double x) | 
				
			||||
		{ | 
				
			||||
			return 0; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processY(double y) | 
				
			||||
		{ | 
				
			||||
			return 0; | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processZ(double z) | 
				
			||||
		{ | 
				
			||||
			return 0; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -1,177 +0,0 @@ | 
				
			||||
package mightypork.utils.math.coord; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.gamecore.control.interf.DefaultImpl; | 
				
			||||
import mightypork.utils.math.constraints.NumberConstraint; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Read-only coordinate. | 
				
			||||
 *  | 
				
			||||
 * @author MightyPork | 
				
			||||
 */ | 
				
			||||
public abstract class VecView extends VecMath<VecView> { | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get a zero (0,0,0) constant | 
				
			||||
	 *  | 
				
			||||
	 * @return new constant vec | 
				
			||||
	 */ | 
				
			||||
	public static VecView zero() | 
				
			||||
	{ | 
				
			||||
		return ZERO.view(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get a one (1,1,1) constant | 
				
			||||
	 *  | 
				
			||||
	 * @return one constant | 
				
			||||
	 */ | 
				
			||||
	public static VecView one() | 
				
			||||
	{ | 
				
			||||
		return ONE.view(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a constant vector | 
				
			||||
	 *  | 
				
			||||
	 * @param x X value | 
				
			||||
	 * @param y Y value | 
				
			||||
	 * @return new constant vec | 
				
			||||
	 */ | 
				
			||||
	public static VecView make(double x, double y) | 
				
			||||
	{ | 
				
			||||
		return new ConstVec(x, y); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a constant vector | 
				
			||||
	 *  | 
				
			||||
	 * @param x X value | 
				
			||||
	 * @param y Y value | 
				
			||||
	 * @param z Z value | 
				
			||||
	 * @return new constant vector | 
				
			||||
	 */ | 
				
			||||
	public static VecView make(double x, double y, double z) | 
				
			||||
	{ | 
				
			||||
		return new ConstVec(x, y, z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a view at number constraints, reflecting their future changes. | 
				
			||||
	 *  | 
				
			||||
	 * @param x X value | 
				
			||||
	 * @param y Y value | 
				
			||||
	 * @return view at the values | 
				
			||||
	 */ | 
				
			||||
	public static VecView make(NumberConstraint x, NumberConstraint y) | 
				
			||||
	{ | 
				
			||||
		return new NumConstrVec(x, y); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a view at number constraints, reflecting their future changes. | 
				
			||||
	 *  | 
				
			||||
	 * @param x X value | 
				
			||||
	 * @param y Y value | 
				
			||||
	 * @param z Z value | 
				
			||||
	 * @return view at the values | 
				
			||||
	 */ | 
				
			||||
	public static VecView make(NumberConstraint x, NumberConstraint y, NumberConstraint z) | 
				
			||||
	{ | 
				
			||||
		return new NumConstrVec(x, y, z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	// synth views
 | 
				
			||||
	private VecView view_round; | 
				
			||||
	private VecView view_floor; | 
				
			||||
	private VecView view_ceil; | 
				
			||||
	private VecView view_neg; | 
				
			||||
	private VecView view_half; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView result(double x, double y, double z) | 
				
			||||
	{ | 
				
			||||
		return new ConstVec(x, y, z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	@Deprecated | 
				
			||||
	public VecView view() | 
				
			||||
	{ | 
				
			||||
		return this; // already not mutable
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double x(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double y(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	@DefaultImpl | 
				
			||||
	public double z() | 
				
			||||
	{ | 
				
			||||
		return 0; // implemented for ease with 2D anonymous subtypes
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView round() | 
				
			||||
	{ | 
				
			||||
		// lazy init
 | 
				
			||||
		if (view_round == null) view_round = new Synths.Round(this); | 
				
			||||
		 | 
				
			||||
		return view_round; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView floor() | 
				
			||||
	{ | 
				
			||||
		// lazy init
 | 
				
			||||
		if (view_floor == null) view_floor = new Synths.Floor(this); | 
				
			||||
		 | 
				
			||||
		return view_floor; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView ceil() | 
				
			||||
	{ | 
				
			||||
		// lazy init
 | 
				
			||||
		if (view_ceil == null) view_ceil = new Synths.Ceil(this); | 
				
			||||
		 | 
				
			||||
		return view_ceil; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView half() | 
				
			||||
	{ | 
				
			||||
		// lazy init
 | 
				
			||||
		if (view_half == null) view_half = new Synths.Half(this); | 
				
			||||
		 | 
				
			||||
		return view_half; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView neg() | 
				
			||||
	{ | 
				
			||||
		// lazy init
 | 
				
			||||
		if (view_neg == null) view_neg = new Synths.Neg(this); | 
				
			||||
		 | 
				
			||||
		return view_neg; | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -1,47 +0,0 @@ | 
				
			||||
package mightypork.utils.math.rect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.coord.VecView; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
class ConstRect extends RectValue { | 
				
			||||
	 | 
				
			||||
	private final VecView pos; | 
				
			||||
	private final VecView size; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 */ | 
				
			||||
	public ConstRect(double x, double y, double width, double height) { | 
				
			||||
		pos = VecView.make(x, y); | 
				
			||||
		size = VecView.make(Math.abs(width), Math.abs(height)); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public ConstRect value() | 
				
			||||
	{ | 
				
			||||
		return this; // nothing can change.
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView getOrigin() | 
				
			||||
	{ | 
				
			||||
		return pos; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VecView getSize() | 
				
			||||
	{ | 
				
			||||
		return size; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,137 @@ | 
				
			||||
package mightypork.utils.math.rect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.vect.Vect; | 
				
			||||
import mightypork.utils.math.vect.VectVal; | 
				
			||||
import mightypork.utils.math.vect.VectView; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public class RectVal extends RectView { | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 0,0 with zero size | 
				
			||||
	 *  | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectVal zero() | 
				
			||||
	{ | 
				
			||||
		return make(0, 0, 0, 0); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 1,1 with zero size | 
				
			||||
	 *  | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectVal one() | 
				
			||||
	{ | 
				
			||||
		return make(0, 0, 1, 1); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 0,0 with given size | 
				
			||||
	 *  | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectVal make(double width, double height) | 
				
			||||
	{ | 
				
			||||
		return make(0, 0, width, height); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param origin | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectVal make(Vect origin, double width, double height) | 
				
			||||
	{ | 
				
			||||
		return make(origin, VectVal.make(width, height)); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 0,0 with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param size | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectVal make(Vect size) | 
				
			||||
	{ | 
				
			||||
		return make(Vect.ZERO, size); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectVal make(double x, double y, double width, double height) | 
				
			||||
	{ | 
				
			||||
		return new RectVal(x, y, width, height); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param origin | 
				
			||||
	 * @param size | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectVal make(Vect origin, Vect size) | 
				
			||||
	{ | 
				
			||||
		return make(origin.x(), origin.y(), size.x(), size.y()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	private final VectVal pos; | 
				
			||||
	private final VectVal size; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 */ | 
				
			||||
	public RectVal(double x, double y, double width, double height) { | 
				
			||||
		pos = VectVal.make(x, y); | 
				
			||||
		size = VectVal.make(width, height); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectVal value() | 
				
			||||
	{ | 
				
			||||
		return this; // nothing can change.
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VectVal getOrigin() | 
				
			||||
	{ | 
				
			||||
		return pos; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VectVal getSize() | 
				
			||||
	{ | 
				
			||||
		return size; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -1,138 +0,0 @@ | 
				
			||||
package mightypork.utils.math.rect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.coord.Vec; | 
				
			||||
import mightypork.utils.math.coord.VecView; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Immutable rect | 
				
			||||
 *  | 
				
			||||
 * @author MightyPork | 
				
			||||
 */ | 
				
			||||
public abstract class RectValue extends RectMath<RectValue> { | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 0,0 with zero size | 
				
			||||
	 *  | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectValue zero() | 
				
			||||
	{ | 
				
			||||
		return make(0, 0, 0, 0); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 1,1 with zero size | 
				
			||||
	 *  | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectValue one() | 
				
			||||
	{ | 
				
			||||
		return make(0, 0, 1, 1); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 0,0 with given size | 
				
			||||
	 *  | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectValue make(double width, double height) | 
				
			||||
	{ | 
				
			||||
		return make(0, 0, width, height); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param origin | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectValue make(Vec origin, double width, double height) | 
				
			||||
	{ | 
				
			||||
		return make(origin, VecView.make(width, height)); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at 0,0 with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param size | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectValue make(Vec size) | 
				
			||||
	{ | 
				
			||||
		return make(VecView.zero(), size); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param x | 
				
			||||
	 * @param y | 
				
			||||
	 * @param width | 
				
			||||
	 * @param height | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectValue make(double x, double y, double width, double height) | 
				
			||||
	{ | 
				
			||||
		return new ConstRect(x, y, width, height); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Create at given origin, with given size. | 
				
			||||
	 *  | 
				
			||||
	 * @param origin | 
				
			||||
	 * @param size | 
				
			||||
	 * @return new mutable rect | 
				
			||||
	 */ | 
				
			||||
	public static RectValue make(Vec origin, Vec size) | 
				
			||||
	{ | 
				
			||||
		return make(origin.x(), origin.y(), size.x(), size.y()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectValue move(double x, double y) | 
				
			||||
	{ | 
				
			||||
		return RectValue.make(getOrigin().add(x, y), getSize()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectValue shrink(double left, double right, double top, double bottom) | 
				
			||||
	{ | 
				
			||||
		return RectValue.make(getOrigin().add(left, top), getSize().sub(left + right, top + bottom)); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectValue grow(double left, double right, double top, double bottom) | 
				
			||||
	{ | 
				
			||||
		return RectValue.make(getOrigin().sub(left, top), getSize().add(left + right, top + bottom)); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectValue round() | 
				
			||||
	{ | 
				
			||||
		return RectValue.make(getOrigin().round(), getSize().round()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectValue view() | 
				
			||||
	{ | 
				
			||||
		return this; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,50 @@ | 
				
			||||
package mightypork.utils.math.rect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Immutable rect | 
				
			||||
 *  | 
				
			||||
 * @author MightyPork | 
				
			||||
 */ | 
				
			||||
public abstract class RectView extends RectMath<RectVal> { | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Get a proxy at given rect | 
				
			||||
	 *  | 
				
			||||
	 * @param observed observed rect | 
				
			||||
	 * @return view | 
				
			||||
	 */ | 
				
			||||
	public static RectView make(Rect observed) { | 
				
			||||
		return observed.view(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectVal move(double x, double y) | 
				
			||||
	{ | 
				
			||||
		return RectVal.make(getOrigin().add(x, y), getSize()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectVal shrink(double left, double right, double top, double bottom) | 
				
			||||
	{ | 
				
			||||
		return RectVal.make(getOrigin().add(left, top), getSize().sub(left + right, top + bottom)); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectVal grow(double left, double right, double top, double bottom) | 
				
			||||
	{ | 
				
			||||
		return RectVal.make(getOrigin().sub(left, top), getSize().add(left + right, top + bottom)); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public RectVal round() | 
				
			||||
	{ | 
				
			||||
		return RectVal.make(getOrigin().round(), getSize().round()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,219 @@ | 
				
			||||
package mightypork.utils.math.vect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.utils.math.constraints.NumberConstraint; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public abstract class AbstractVect implements Vect { | 
				
			||||
	 | 
				
			||||
	private VectView proxy; | 
				
			||||
	private NumberConstraint xc; | 
				
			||||
	private NumberConstraint yc; | 
				
			||||
	private NumberConstraint zc; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final VectVal getVec() | 
				
			||||
	{ | 
				
			||||
		return value(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double x(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double y(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public abstract double z(); | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final int xi() | 
				
			||||
	{ | 
				
			||||
		return (int) Math.round(x()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final int yi() | 
				
			||||
	{ | 
				
			||||
		return (int) Math.round(y()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final int zi() | 
				
			||||
	{ | 
				
			||||
		return (int) Math.round(z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final NumberConstraint xc() | 
				
			||||
	{ | 
				
			||||
		if (xc == null) xc = new NumberConstraint() { | 
				
			||||
			 | 
				
			||||
			@Override | 
				
			||||
			public double getValue() | 
				
			||||
			{ | 
				
			||||
				return x(); | 
				
			||||
			} | 
				
			||||
		}; | 
				
			||||
		 | 
				
			||||
		return xc; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final NumberConstraint yc() | 
				
			||||
	{ | 
				
			||||
		if (yc == null) yc = new NumberConstraint() { | 
				
			||||
			 | 
				
			||||
			@Override | 
				
			||||
			public double getValue() | 
				
			||||
			{ | 
				
			||||
				return y(); | 
				
			||||
			} | 
				
			||||
		}; | 
				
			||||
		 | 
				
			||||
		return yc; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final NumberConstraint zc() | 
				
			||||
	{ | 
				
			||||
		if (zc == null) zc = new NumberConstraint() { | 
				
			||||
			 | 
				
			||||
			@Override | 
				
			||||
			public double getValue() | 
				
			||||
			{ | 
				
			||||
				return z(); | 
				
			||||
			} | 
				
			||||
		}; | 
				
			||||
		 | 
				
			||||
		return zc; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final double size() | 
				
			||||
	{ | 
				
			||||
		final double x = x(), y = y(), z = z(); | 
				
			||||
		return Math.sqrt(x * x + y * y + z * z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final boolean isZero() | 
				
			||||
	{ | 
				
			||||
		return x() == 0 && y() == 0 && z() == 0; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VectVal value() | 
				
			||||
	{ | 
				
			||||
		return new VectVal(this); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final double distTo(Vect point) | 
				
			||||
	{ | 
				
			||||
		final double dx = x() - point.x(); | 
				
			||||
		final double dy = y() - point.y(); | 
				
			||||
		final double dz = z() - point.z(); | 
				
			||||
		 | 
				
			||||
		return Math.sqrt(dx * dx + dy * dy + dz * dz); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final VectVal midTo(Vect point) | 
				
			||||
	{ | 
				
			||||
		final double dx = (point.x() - x()) * 0.5; | 
				
			||||
		final double dy = (point.y() - y()) * 0.5; | 
				
			||||
		final double dz = (point.z() - z()) * 0.5; | 
				
			||||
		 | 
				
			||||
		return VectVal.make(dx, dy, dz); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final VectVal vecTo(Vect point) | 
				
			||||
	{ | 
				
			||||
		return VectVal.make(point.x() - x(), point.y() - y(), point.z() - z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final VectVal cross(Vect vec) | 
				
			||||
	{ | 
				
			||||
		//@formatter:off
 | 
				
			||||
		return VectVal.make( | 
				
			||||
				y() * vec.z() - z() * vec.y(), | 
				
			||||
				z() * vec.x() - x() * vec.z(), | 
				
			||||
				x() * vec.y() - y() * vec.x()); | 
				
			||||
		//@formatter:on
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public final double dot(Vect vec) | 
				
			||||
	{ | 
				
			||||
		return x() * vec.x() + y() * vec.y() + z() * vec.z(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VectMutable mutable() | 
				
			||||
	{ | 
				
			||||
		return VectMutable.make(this); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VectView view() | 
				
			||||
	{ | 
				
			||||
		if (proxy == null) proxy = new VectProxy(this); | 
				
			||||
		 | 
				
			||||
		return proxy; | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public int hashCode() | 
				
			||||
	{ | 
				
			||||
		final int prime = 31; | 
				
			||||
		int result = 1; | 
				
			||||
		result = prime * result + Double.valueOf(x()).hashCode(); | 
				
			||||
		result = prime * result + Double.valueOf(y()).hashCode(); | 
				
			||||
		result = prime * result + Double.valueOf(z()).hashCode(); | 
				
			||||
		return result; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public boolean equals(Object obj) | 
				
			||||
	{ | 
				
			||||
		if (this == obj) return true; | 
				
			||||
		if (obj == null) return false; | 
				
			||||
		if (!(obj instanceof Vect)) return false; | 
				
			||||
		final Vect other = (Vect) obj; | 
				
			||||
		 | 
				
			||||
		return x() == other.x() && y() == other.y() && z() == other.z(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public String toString() | 
				
			||||
	{ | 
				
			||||
		return String.format("(%.1f %.1f %.1f)", x(), y(), z()); | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -1,12 +1,12 @@ | 
				
			||||
package mightypork.utils.math.coord; | 
				
			||||
package mightypork.utils.math.vect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public abstract class AbstractVecProxy extends VecView { | 
				
			||||
public abstract class VectAdapter extends VectView { | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @return the proxied coord | 
				
			||||
	 */ | 
				
			||||
	protected abstract Vec getSource(); | 
				
			||||
	protected abstract Vect getSource(); | 
				
			||||
 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
@ -0,0 +1,106 @@ | 
				
			||||
package mightypork.utils.math.vect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
public class VectFilters { | 
				
			||||
	 | 
				
			||||
	private static abstract class Uniform extends VectProxy { | 
				
			||||
		 | 
				
			||||
		public Uniform(Vect observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processX(double x) | 
				
			||||
		{ | 
				
			||||
			return super.processX(x); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processY(double y) | 
				
			||||
		{ | 
				
			||||
			return super.processY(y); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double processZ(double z) | 
				
			||||
		{ | 
				
			||||
			return super.processZ(z); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		protected abstract double process(double a); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Round extends Uniform { | 
				
			||||
		 | 
				
			||||
		public Round(Vect observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return Math.round(a); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Ceil extends Uniform { | 
				
			||||
		 | 
				
			||||
		public Ceil(Vect observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return Math.ceil(a); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Floor extends Uniform { | 
				
			||||
		 | 
				
			||||
		public Floor(Vect observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return Math.floor(a); | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Neg extends Uniform { | 
				
			||||
		 | 
				
			||||
		public Neg(Vect observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return -a; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	public static class Half extends Uniform { | 
				
			||||
		 | 
				
			||||
		public Half(Vect observed) { | 
				
			||||
			super(observed); | 
				
			||||
		} | 
				
			||||
		 | 
				
			||||
		 | 
				
			||||
		@Override | 
				
			||||
		protected double process(double a) | 
				
			||||
		{ | 
				
			||||
			return a / 2D; | 
				
			||||
		} | 
				
			||||
	} | 
				
			||||
} | 
				
			||||
@ -0,0 +1,97 @@ | 
				
			||||
package mightypork.utils.math.vect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Coordinate with immutable numeric values.<br> | 
				
			||||
 * This coordinate is guaranteed to never change, as opposed to view, which can | 
				
			||||
 * be a proxy or a synthetic vector. | 
				
			||||
 *  | 
				
			||||
 * @author MightyPork | 
				
			||||
 */ | 
				
			||||
public final class VectVal extends VectView { | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a constant vector | 
				
			||||
	 *  | 
				
			||||
	 * @param value source vector | 
				
			||||
	 * @return new constant vec | 
				
			||||
	 */ | 
				
			||||
	public static VectVal make(Vect value) | 
				
			||||
	{ | 
				
			||||
		return value.value(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a constant vector | 
				
			||||
	 *  | 
				
			||||
	 * @param x X value | 
				
			||||
	 * @param y Y value | 
				
			||||
	 * @return new constant vec | 
				
			||||
	 */ | 
				
			||||
	public static VectVal make(double x, double y) | 
				
			||||
	{ | 
				
			||||
		return make(x, y, 0); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a constant vector | 
				
			||||
	 *  | 
				
			||||
	 * @param x X value | 
				
			||||
	 * @param y Y value | 
				
			||||
	 * @param z Z value | 
				
			||||
	 * @return new constant vector | 
				
			||||
	 */ | 
				
			||||
	public static VectVal make(double x, double y, double z) | 
				
			||||
	{ | 
				
			||||
		return new VectVal(x, y, z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	private final double x, y, z; | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	protected VectVal(Vect other) { | 
				
			||||
		this(other.x(), other.y(), other.z()); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	protected VectVal(double x, double y, double z) { | 
				
			||||
		this.x = x; | 
				
			||||
		this.y = y; | 
				
			||||
		this.z = z; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double x() | 
				
			||||
	{ | 
				
			||||
		return x; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double y() | 
				
			||||
	{ | 
				
			||||
		return y; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public double z() | 
				
			||||
	{ | 
				
			||||
		return z; | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @deprecated It's constant already. | 
				
			||||
	 */ | 
				
			||||
	@Override | 
				
			||||
	@Deprecated | 
				
			||||
	public VectVal value() | 
				
			||||
	{ | 
				
			||||
		return this; // it's constant already
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
} | 
				
			||||
@ -0,0 +1,79 @@ | 
				
			||||
package mightypork.utils.math.vect; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
import mightypork.gamecore.control.interf.DefaultImpl; | 
				
			||||
import mightypork.utils.math.constraints.NumberConstraint; | 
				
			||||
 | 
				
			||||
 | 
				
			||||
/** | 
				
			||||
 * Read-only coordinate. | 
				
			||||
 *  | 
				
			||||
 * @author MightyPork | 
				
			||||
 */ | 
				
			||||
public abstract class VectView extends VectMath<VectVal> { // returns constant value on edit
 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a proxy view at a vector. | 
				
			||||
	 *  | 
				
			||||
	 * @param observed vector to observe | 
				
			||||
	 * @return view | 
				
			||||
	 */ | 
				
			||||
	public static VectView make(Vect observed) | 
				
			||||
	{ | 
				
			||||
		return observed.view(); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a view at number constraints, reflecting their future changes. | 
				
			||||
	 *  | 
				
			||||
	 * @param xc X value | 
				
			||||
	 * @param yc Y value | 
				
			||||
	 * @return view at the values | 
				
			||||
	 */ | 
				
			||||
	public static VectView make(NumberConstraint xc, NumberConstraint yc) | 
				
			||||
	{ | 
				
			||||
		return new NumConstrVect(xc, yc); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * Make a view at number constraints, reflecting their future changes. | 
				
			||||
	 *  | 
				
			||||
	 * @param xc X value | 
				
			||||
	 * @param yc Y value | 
				
			||||
	 * @param zc Z value | 
				
			||||
	 * @return view at the values | 
				
			||||
	 */ | 
				
			||||
	public static VectView make(NumberConstraint xc, NumberConstraint yc, NumberConstraint zc) | 
				
			||||
	{ | 
				
			||||
		return new NumConstrVect(xc, yc, zc); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	public VectVal result(double x, double y, double z) | 
				
			||||
	{ | 
				
			||||
		return VectVal.make(x, y, z); | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	/** | 
				
			||||
	 * @deprecated VecView is not mutable, making a proxy has no effect. | 
				
			||||
	 */ | 
				
			||||
	@Override | 
				
			||||
	@Deprecated | 
				
			||||
	public VectView view() | 
				
			||||
	{ | 
				
			||||
		return this; // already not mutable
 | 
				
			||||
	} | 
				
			||||
	 | 
				
			||||
	 | 
				
			||||
	@Override | 
				
			||||
	@DefaultImpl | 
				
			||||
	public double z() | 
				
			||||
	{ | 
				
			||||
		return 0; // implemented for ease with 2D anonymous subtypes
 | 
				
			||||
	} | 
				
			||||
 | 
				
			||||
} | 
				
			||||
					Loading…
					
					
				
		Reference in new issue