Refactoring and polishing of the constraint system
Now it will be clear what is VALUE, VIEW and MUTABLE.
This commit is contained in:
@@ -6,7 +6,7 @@ import java.io.IOException;
|
||||
import mightypork.gamecore.loading.DeferredResource;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.logging.LoggedName;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
import org.newdawn.slick.openal.Audio;
|
||||
import org.newdawn.slick.openal.SoundStore;
|
||||
@@ -204,7 +204,7 @@ public class DeferredAudio extends DeferredResource {
|
||||
* @param pos coord
|
||||
* @return source id
|
||||
*/
|
||||
public int playAsEffect(double pitch, double gain, boolean loop, Vec pos)
|
||||
public int playAsEffect(double pitch, double gain, boolean loop, Vect pos)
|
||||
{
|
||||
if (!ensureLoaded()) return -1;
|
||||
|
||||
|
||||
@@ -12,9 +12,9 @@ import mightypork.gamecore.control.bus.clients.RootBusNode;
|
||||
import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.utils.math.Calc.Buffers;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecMutable;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectMutable;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
import org.lwjgl.openal.AL;
|
||||
import org.lwjgl.openal.AL10;
|
||||
@@ -28,10 +28,10 @@ import org.newdawn.slick.openal.SoundStore;
|
||||
*/
|
||||
public class SoundSystem extends RootBusNode implements Updateable {
|
||||
|
||||
private static final Vec INITIAL_LISTENER_POS = Vec.ZERO;
|
||||
private static final Vect INITIAL_LISTENER_POS = Vect.ZERO;
|
||||
private static final int MAX_SOURCES = 256;
|
||||
|
||||
private static VecMutable listener = VecMutable.zero();
|
||||
private static VectMutable listener = VectMutable.zero();
|
||||
private static boolean soundSystemInited = false;
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
|
||||
*
|
||||
* @param pos
|
||||
*/
|
||||
public static void setListener(Vec pos)
|
||||
public static void setListener(Vect pos)
|
||||
{
|
||||
listener.setTo(pos);
|
||||
final FloatBuffer buf3 = Buffers.alloc(3);
|
||||
@@ -60,7 +60,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
|
||||
/**
|
||||
* @return listener coordinate
|
||||
*/
|
||||
public static VecView getListener()
|
||||
public static VectView getListener()
|
||||
{
|
||||
return listener.view();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.audio.players;
|
||||
|
||||
import mightypork.gamecore.audio.DeferredAudio;
|
||||
import mightypork.gamecore.audio.Volume;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
@@ -59,7 +59,7 @@ public class EffectPlayer extends BaseAudioPlayer {
|
||||
* @param pos play position
|
||||
* @return source id
|
||||
*/
|
||||
public int play(double pitch, double gain, Vec pos)
|
||||
public int play(double pitch, double gain, Vect pos)
|
||||
{
|
||||
if (!hasAudio()) return -1;
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@ package mightypork.gamecore.control.bus.events;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -19,7 +19,7 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
|
||||
|
||||
private final int button;
|
||||
private final int wheeld;
|
||||
private final Vec pos;
|
||||
private final Vect pos;
|
||||
private final boolean down;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
|
||||
* @param down button pressed
|
||||
* @param wheeld wheel change
|
||||
*/
|
||||
public MouseButtonEvent(Vec pos, int button, boolean down, int wheeld) {
|
||||
public MouseButtonEvent(Vect pos, int button, boolean down, int wheeld) {
|
||||
this.button = button;
|
||||
this.down = down;
|
||||
this.pos = pos;
|
||||
@@ -78,7 +78,7 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
|
||||
/**
|
||||
* @return mouse position when the event occurred
|
||||
*/
|
||||
public VecView getPos()
|
||||
public VectView getPos()
|
||||
{
|
||||
return pos.view();
|
||||
}
|
||||
|
||||
@@ -2,8 +2,8 @@ package mightypork.gamecore.control.bus.events;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,15 +14,15 @@ import mightypork.utils.math.coord.VecView;
|
||||
@UnloggedEvent
|
||||
public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
|
||||
|
||||
private final VecView move;
|
||||
private final VecView pos;
|
||||
private final VectView move;
|
||||
private final VectView pos;
|
||||
|
||||
|
||||
/**
|
||||
* @param pos end pos
|
||||
* @param move move vector
|
||||
*/
|
||||
public MouseMotionEvent(Vec pos, Vec move) {
|
||||
public MouseMotionEvent(Vect pos, Vect move) {
|
||||
this.move = move.value();
|
||||
this.pos = pos.value();
|
||||
}
|
||||
@@ -31,7 +31,7 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
|
||||
/**
|
||||
* @return movement since last {@link MouseMotionEvent}
|
||||
*/
|
||||
public VecView getMove()
|
||||
public VectView getMove()
|
||||
{
|
||||
return move;
|
||||
}
|
||||
@@ -40,7 +40,7 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
|
||||
/**
|
||||
* @return current mouse position
|
||||
*/
|
||||
public VecView getPos()
|
||||
public VectView getPos()
|
||||
{
|
||||
return pos;
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mightypork.gamecore.control.bus.events;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,7 +13,7 @@ import mightypork.utils.math.coord.VecView;
|
||||
public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
|
||||
|
||||
private final boolean fullscreen;
|
||||
private final Vec screenSize;
|
||||
private final Vect screenSize;
|
||||
private final boolean fsChanged;
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
|
||||
* @param fullscreen is now fullscreen
|
||||
* @param size new screen size
|
||||
*/
|
||||
public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Vec size) {
|
||||
public ScreenChangeEvent(boolean fsChanged, boolean fullscreen, Vect size) {
|
||||
this.fullscreen = fullscreen;
|
||||
this.screenSize = size;
|
||||
this.fsChanged = fsChanged;
|
||||
@@ -50,7 +50,7 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
|
||||
/**
|
||||
* @return new screen size
|
||||
*/
|
||||
public VecView getScreenSize()
|
||||
public VectView getScreenSize()
|
||||
{
|
||||
return screenSize.view();
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
|
||||
|
||||
import mightypork.utils.math.constraints.PluggableRect;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,7 +18,7 @@ public interface PluggableRenderable extends Renderable, PluggableRect {
|
||||
|
||||
|
||||
@Override
|
||||
RectValue getRect();
|
||||
RectView getRect();
|
||||
|
||||
|
||||
@Override
|
||||
|
||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
|
||||
|
||||
import mightypork.utils.math.constraints.ContextAdapter;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,7 +18,7 @@ public abstract class PluggableRenderer extends ContextAdapter implements Plugga
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return super.getRect();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ import mightypork.gamecore.gui.components.PluggableRenderable;
|
||||
import mightypork.gamecore.gui.components.PluggableRenderer;
|
||||
import mightypork.gamecore.gui.components.Renderable;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -60,7 +60,7 @@ public abstract class ElementHolder extends BusNode implements PluggableRenderab
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return context.getRect();
|
||||
}
|
||||
|
||||
@@ -6,9 +6,9 @@ import mightypork.gamecore.render.fonts.FontRenderer;
|
||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecMutable;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectMutable;
|
||||
import mightypork.utils.string.StringProvider;
|
||||
import mightypork.utils.string.StringProvider.StringWrapper;
|
||||
|
||||
@@ -29,7 +29,7 @@ public class TextPainter extends PluggableRenderer {
|
||||
private boolean shadow;
|
||||
|
||||
private RGB shadowColor = RGB.BLACK;
|
||||
private final VecMutable shadowOffset = VecMutable.make(1, 1);
|
||||
private final VectMutable shadowOffset = VectMutable.make(1, 1);
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,7 @@ public class TextPainter extends PluggableRenderer {
|
||||
if (text == null) return;
|
||||
|
||||
final String str = text.getString();
|
||||
final RectValue rect = getRect();
|
||||
final RectView rect = getRect();
|
||||
|
||||
if (shadow) {
|
||||
font.draw(str, rect.move(shadowOffset), align, shadowColor);
|
||||
@@ -94,7 +94,7 @@ public class TextPainter extends PluggableRenderer {
|
||||
}
|
||||
|
||||
|
||||
public void setShadow(RGB color, Vec offset)
|
||||
public void setShadow(RGB color, Vect offset)
|
||||
{
|
||||
setShadow(true);
|
||||
setShadowColor(color);
|
||||
@@ -114,7 +114,7 @@ public class TextPainter extends PluggableRenderer {
|
||||
}
|
||||
|
||||
|
||||
public void setShadowOffset(Vec shadowOffset)
|
||||
public void setShadowOffset(Vect shadowOffset)
|
||||
{
|
||||
this.shadowOffset.setTo(shadowOffset);
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import java.util.Collection;
|
||||
import java.util.TreeSet;
|
||||
|
||||
import mightypork.gamecore.control.AppAccess;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
@@ -79,7 +79,7 @@ public abstract class LayeredScreen extends Screen {
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(Vec size)
|
||||
protected void onSizeChanged(Vect size)
|
||||
{
|
||||
for (final ScreenLayer layer : layers) {
|
||||
layer.onSizeChanged(size);
|
||||
|
||||
@@ -11,8 +11,8 @@ import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
|
||||
/**
|
||||
@@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return getDisplay().getRect();
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
|
||||
* @param size screen size
|
||||
*/
|
||||
@DefaultImpl
|
||||
protected void onSizeChanged(Vec size)
|
||||
protected void onSizeChanged(Vect size)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
@@ -8,9 +8,9 @@ import mightypork.gamecore.input.KeyBinder;
|
||||
import mightypork.gamecore.input.KeyBindingPool;
|
||||
import mightypork.gamecore.input.KeyStroke;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,9 +27,9 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
||||
private final KeyBindingPool keybindings = new KeyBindingPool();
|
||||
|
||||
/** Mouse position constraint */
|
||||
protected final VecView cMousePos = getInput().getMousePos();
|
||||
protected final VectView cMousePos = getInput().getMousePos();
|
||||
/** Screen size constraint */
|
||||
protected final VecView cScreenSize = getDisplay().getSize();
|
||||
protected final VectView cScreenSize = getDisplay().getSize();
|
||||
|
||||
|
||||
/**
|
||||
@@ -67,7 +67,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return screen.getRect();
|
||||
}
|
||||
@@ -118,7 +118,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
||||
* @param size screen size
|
||||
*/
|
||||
@DefaultImpl
|
||||
protected void onSizeChanged(Vec size)
|
||||
protected void onSizeChanged(Vect size)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
@@ -9,8 +9,8 @@ import mightypork.gamecore.control.bus.events.MouseMotionEvent;
|
||||
import mightypork.gamecore.control.timing.Updateable;
|
||||
import mightypork.rogue.events.ActionRequest;
|
||||
import mightypork.rogue.events.ActionRequest.RequestType;
|
||||
import mightypork.utils.math.coord.VecMutable;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.VectMutable;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
import org.lwjgl.LWJGLException;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
@@ -29,7 +29,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
private final KeyBindingPool keybindings;
|
||||
|
||||
/** Current mouse position */
|
||||
private final VecView mousePos = new VecView() {
|
||||
private final VectView mousePos = new VectView() {
|
||||
|
||||
@Override
|
||||
public double x()
|
||||
@@ -103,8 +103,8 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
}
|
||||
|
||||
// counters as fields to save memory.
|
||||
private final VecMutable mouseMove = VecMutable.zero();
|
||||
private final VecMutable mouseLastPos = VecMutable.zero();
|
||||
private final VectMutable mouseMove = VectMutable.zero();
|
||||
private final VectMutable mouseLastPos = VectMutable.zero();
|
||||
|
||||
|
||||
@Override
|
||||
@@ -140,13 +140,13 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
}
|
||||
|
||||
|
||||
private void onMouseEvent(VecMutable moveSum, VecMutable lastPos)
|
||||
private void onMouseEvent(VectMutable moveSum, VectMutable lastPos)
|
||||
{
|
||||
final int button = Mouse.getEventButton();
|
||||
final boolean down = Mouse.getEventButtonState();
|
||||
|
||||
final VecMutable pos = VecMutable.make(Mouse.getEventX(), Mouse.getEventY());
|
||||
final VecMutable move = VecMutable.make(Mouse.getEventDX(), Mouse.getEventDY());
|
||||
final VectMutable pos = VectMutable.make(Mouse.getEventX(), Mouse.getEventY());
|
||||
final VectMutable move = VectMutable.make(Mouse.getEventDX(), Mouse.getEventDY());
|
||||
|
||||
final int wheeld = Mouse.getEventDWheel();
|
||||
|
||||
@@ -178,7 +178,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
|
||||
*
|
||||
* @return mouse position
|
||||
*/
|
||||
public VecView getMousePos()
|
||||
public VectView getMousePos()
|
||||
{
|
||||
return mousePos;
|
||||
}
|
||||
|
||||
@@ -11,8 +11,9 @@ import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||
import mightypork.gamecore.control.timing.FpsMeter;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectVal;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.LWJGLException;
|
||||
@@ -32,7 +33,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
private FpsMeter fpsMeter;
|
||||
|
||||
/** Current screen size */
|
||||
private final VecView screenSize = new VecView() {
|
||||
private final VectView screenSize = new VectView() {
|
||||
|
||||
@Override
|
||||
public double y()
|
||||
@@ -188,7 +189,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
*
|
||||
* @return size
|
||||
*/
|
||||
public VecView getSize()
|
||||
public VectView getSize()
|
||||
{
|
||||
return screenSize;
|
||||
}
|
||||
@@ -239,9 +240,9 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return RectValue.make(getSize());
|
||||
return RectVal.make(getSize());
|
||||
}
|
||||
|
||||
|
||||
@@ -254,7 +255,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
||||
}
|
||||
|
||||
|
||||
public VecView getCenter()
|
||||
public VectView getCenter()
|
||||
{
|
||||
return getSize().half();
|
||||
}
|
||||
|
||||
@@ -9,9 +9,10 @@ import mightypork.gamecore.render.textures.TxQuad;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.Rect;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
@@ -27,9 +28,9 @@ import org.newdawn.slick.util.ResourceLoader;
|
||||
*/
|
||||
public class Render {
|
||||
|
||||
public static final VecView AXIS_X = VecView.make(1, 0, 0);
|
||||
public static final VecView AXIS_Y = VecView.make(0, 1, 0);
|
||||
public static final VecView AXIS_Z = VecView.make(0, 0, 1);
|
||||
public static final VectView AXIS_X = VectVal.make(1, 0, 0);
|
||||
public static final VectView AXIS_Y = VectVal.make(0, 1, 0);
|
||||
public static final VectView AXIS_Z = VectVal.make(0, 0, 1);
|
||||
|
||||
|
||||
/**
|
||||
@@ -85,7 +86,7 @@ public class Render {
|
||||
*
|
||||
* @param coord coord
|
||||
*/
|
||||
public static void translate(Vec coord)
|
||||
public static void translate(Vect coord)
|
||||
{
|
||||
glTranslated(coord.x(), coord.y(), coord.z());
|
||||
}
|
||||
@@ -121,7 +122,7 @@ public class Render {
|
||||
*
|
||||
* @param factor vector of scaling factors
|
||||
*/
|
||||
public static void scale(Vec factor)
|
||||
public static void scale(Vect factor)
|
||||
{
|
||||
glScaled(factor.x(), factor.y(), factor.z());
|
||||
}
|
||||
@@ -210,9 +211,9 @@ public class Render {
|
||||
* @param angle rotate angle
|
||||
* @param axis rotation axis
|
||||
*/
|
||||
public static void rotate(double angle, Vec axis)
|
||||
public static void rotate(double angle, Vect axis)
|
||||
{
|
||||
final Vec vec = axis.view().norm(1);
|
||||
final Vect vec = axis.view().norm(1);
|
||||
glRotated(angle, vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
@@ -543,7 +544,7 @@ public class Render {
|
||||
*
|
||||
* @param size viewport size (screen size)
|
||||
*/
|
||||
public static void setupOrtho(VecView size)
|
||||
public static void setupOrtho(VectView size)
|
||||
{
|
||||
// fix projection for changed size
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
|
||||
@@ -3,10 +3,10 @@ package mightypork.gamecore.render.fonts;
|
||||
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecMutable;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.Rect;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectMutable;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -51,7 +51,7 @@ public class FontRenderer {
|
||||
* @param height drawing height
|
||||
* @return taken space (width, height)
|
||||
*/
|
||||
public Vec getNeededSpace(String text, double height)
|
||||
public Vect getNeededSpace(String text, double height)
|
||||
{
|
||||
return font.getNeededSpace(text).mul(getScale(height));
|
||||
}
|
||||
@@ -106,7 +106,7 @@ public class FontRenderer {
|
||||
* @param height drawing height
|
||||
* @param color drawing color
|
||||
*/
|
||||
public void draw(String text, Vec pos, double height, RGB color)
|
||||
public void draw(String text, Vect pos, double height, RGB color)
|
||||
{
|
||||
Render.pushMatrix();
|
||||
|
||||
@@ -144,7 +144,7 @@ public class FontRenderer {
|
||||
*/
|
||||
public void draw(String text, Rect bounds, Align align, RGB color)
|
||||
{
|
||||
VecView start;
|
||||
VectView start;
|
||||
|
||||
switch (align) {
|
||||
case LEFT:
|
||||
@@ -173,7 +173,7 @@ public class FontRenderer {
|
||||
* @param height drawing height
|
||||
* @param align horizontal alignment
|
||||
*/
|
||||
public void draw(String text, Vec pos, double height, Align align)
|
||||
public void draw(String text, Vect pos, double height, Align align)
|
||||
{
|
||||
draw(text, pos, height, align, this.color);
|
||||
}
|
||||
@@ -188,12 +188,12 @@ public class FontRenderer {
|
||||
* @param align horizontal alignment
|
||||
* @param color drawing color
|
||||
*/
|
||||
public void draw(String text, Vec pos, double height, Align align, RGB color)
|
||||
public void draw(String text, Vect pos, double height, Align align, RGB color)
|
||||
{
|
||||
|
||||
final double w = getWidth(text, height);
|
||||
|
||||
final VecMutable start = pos.mutable();
|
||||
final VectMutable start = pos.mutable();
|
||||
|
||||
switch (align) {
|
||||
case LEFT:
|
||||
|
||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.render.fonts;
|
||||
|
||||
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -27,7 +27,7 @@ public interface GLFont {
|
||||
* @param text string to check
|
||||
* @return coord (width, height)
|
||||
*/
|
||||
VecView getNeededSpace(String text);
|
||||
VectView getNeededSpace(String text);
|
||||
|
||||
|
||||
/**
|
||||
|
||||
@@ -23,7 +23,8 @@ import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
import org.lwjgl.util.glu.GLU;
|
||||
@@ -422,9 +423,9 @@ public class CachedFont implements GLFont {
|
||||
|
||||
|
||||
@Override
|
||||
public VecView getNeededSpace(String text)
|
||||
public VectVal getNeededSpace(String text)
|
||||
{
|
||||
return VecView.make(getWidth(text), getLineHeight());
|
||||
return VectVal.make(getWidth(text), getLineHeight());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,8 +13,8 @@ import mightypork.gamecore.render.textures.FilterMode;
|
||||
import mightypork.utils.files.FileUtils;
|
||||
import mightypork.utils.logging.LoggedName;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -164,9 +164,9 @@ public class DeferredFont extends DeferredResource implements GLFont {
|
||||
* @return coord (width, height)
|
||||
*/
|
||||
@Override
|
||||
public VecView getNeededSpace(String text)
|
||||
public VectView getNeededSpace(String text)
|
||||
{
|
||||
if (!ensureLoaded()) return Vec.ZERO;
|
||||
if (!ensureLoaded()) return Vect.ZERO;
|
||||
|
||||
return font.getNeededSpace(text);
|
||||
}
|
||||
|
||||
@@ -4,8 +4,8 @@ package mightypork.gamecore.render.fonts.impl;
|
||||
import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -23,9 +23,9 @@ public class NullFont implements GLFont {
|
||||
|
||||
|
||||
@Override
|
||||
public VecView getNeededSpace(String str)
|
||||
public VectView getNeededSpace(String str)
|
||||
{
|
||||
return Vec.ZERO;
|
||||
return Vect.ZERO;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@ package mightypork.gamecore.render.textures;
|
||||
|
||||
|
||||
import mightypork.utils.math.rect.Rect;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectVal;
|
||||
|
||||
import org.newdawn.slick.opengl.Texture;
|
||||
|
||||
@@ -65,7 +65,7 @@ public class TxQuad {
|
||||
* @param y2 right bottom Y (0-1)
|
||||
*/
|
||||
public TxQuad(Texture tx, double x1, double y1, double x2, double y2) {
|
||||
this(tx, RectValue.make(x1, y1, x2, y2));
|
||||
this(tx, RectVal.make(x1, y1, x2, y2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import mightypork.gamecore.render.fonts.GLFont;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.string.StringProvider;
|
||||
|
||||
|
||||
@@ -52,7 +52,7 @@ public class LayerFps extends ScreenLayer {
|
||||
|
||||
tp.setContext(constraint);
|
||||
|
||||
tp.setShadow(RGB.BLACK, Vec.ONE);
|
||||
tp.setShadow(RGB.BLACK, Vect.ONE);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||
import mightypork.rogue.Res;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
|
||||
|
||||
public class LayerBouncyBoxes extends ScreenLayer {
|
||||
@@ -59,7 +59,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
|
||||
|
||||
final TextPainter tp = new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE);
|
||||
tp.setText("Press \"C\" for \"Cat\" screen.");
|
||||
tp.setShadow(RGB.RED, VecView.make(2, 2));
|
||||
tp.setShadow(RGB.RED, VectVal.make(2, 2));
|
||||
|
||||
layout.add(tp);
|
||||
}
|
||||
|
||||
@@ -19,16 +19,16 @@ import mightypork.rogue.Res;
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
import mightypork.utils.math.animation.Easing;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecMutable;
|
||||
import mightypork.utils.math.coord.VecMutableAnim;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectMutable;
|
||||
import mightypork.utils.math.vect.VectMutableAnim;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
|
||||
|
||||
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener {
|
||||
|
||||
private final AnimDouble size = new AnimDouble(400, Easing.SINE_BOTH);
|
||||
private final VecMutableAnim pos = VecMutable.makeAnim(Easing.ELASTIC_OUT);
|
||||
private final VectMutableAnim pos = VectMutable.makeAnim(Easing.ELASTIC_OUT);
|
||||
|
||||
private final Random rand = new Random();
|
||||
|
||||
@@ -51,7 +51,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
tp.setAlign(Align.CENTER);
|
||||
tp.setColor(RGB.YELLOW);
|
||||
tp.setText("Meow!");
|
||||
tp.setShadow(RGB.dark(0.8), VecView.make(2, 2));
|
||||
tp.setShadow(RGB.dark(0.8), VectVal.make(2, 2));
|
||||
|
||||
tp.setContext(cCenterTo(cBox(64, 64), cMousePos));
|
||||
|
||||
@@ -85,7 +85,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
||||
{
|
||||
if (!event.isDown()) return;
|
||||
|
||||
final Vec pos = event.getPos();
|
||||
final Vect pos = event.getPos();
|
||||
|
||||
this.pos.setTo(pos);
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||
import mightypork.gamecore.render.Render;
|
||||
import mightypork.utils.math.color.RGB;
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
|
||||
public class LayerTestGradient extends ScreenLayer {
|
||||
@@ -44,7 +44,7 @@ public class LayerTestGradient extends ScreenLayer {
|
||||
|
||||
|
||||
@Override
|
||||
protected void onSizeChanged(Vec size)
|
||||
protected void onSizeChanged(Vect size)
|
||||
{
|
||||
p.poll();
|
||||
}
|
||||
|
||||
@@ -1,24 +1,38 @@
|
||||
package mightypork.test;
|
||||
|
||||
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import java.util.Locale;
|
||||
|
||||
import mightypork.utils.math.rect.RectVal;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import static mightypork.utils.math.constraints.Constraints.*;
|
||||
|
||||
|
||||
public class TestConstr {
|
||||
|
||||
public static void main(String[] args)
|
||||
{
|
||||
Locale.setDefault(Locale.ENGLISH);
|
||||
|
||||
final RectValue rm = RectValue.make(0, 0, 100, 100);
|
||||
System.out.println(rm);
|
||||
final RectView rect = RectVal.make(0, 0, 10, 10);
|
||||
final VectVal point = VectVal.make(50,50);
|
||||
|
||||
final RectValue added = rm.move(10, 10);
|
||||
System.out.println(rect);
|
||||
System.out.println(point);
|
||||
System.out.println(cCenterTo(rect, point).getRect());
|
||||
|
||||
System.out.println(added);
|
||||
System.out.println(added.getOrigin());
|
||||
System.out.println(added.getSize());
|
||||
|
||||
System.out.println(added.getOrigin().add(added.getSize()));
|
||||
// final RectValue rm = RectValue.make(0, 0, 100, 100);
|
||||
// System.out.println(rm);
|
||||
//
|
||||
// final RectValue added = rm.move(10, 10);
|
||||
//
|
||||
// System.out.println(added);
|
||||
// System.out.println(added.getOrigin());
|
||||
// System.out.println(added.getSize());
|
||||
//
|
||||
// System.out.println(added.getOrigin().add(added.getSize()));
|
||||
|
||||
// VecMutable vv = new MutableCoord(0,0);
|
||||
//
|
||||
|
||||
@@ -10,8 +10,8 @@ import java.util.Map.Entry;
|
||||
import java.util.TreeMap;
|
||||
|
||||
import mightypork.utils.math.Range;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
import mightypork.utils.objects.Convert;
|
||||
|
||||
|
||||
@@ -122,9 +122,9 @@ public class PropertyManager {
|
||||
}
|
||||
}
|
||||
|
||||
private class CoordProperty extends Property<Vec> {
|
||||
private class CoordProperty extends Property<Vect> {
|
||||
|
||||
public CoordProperty(String key, Vec defaultValue, String comment) {
|
||||
public CoordProperty(String key, Vect defaultValue, String comment) {
|
||||
super(key, defaultValue, comment);
|
||||
}
|
||||
|
||||
@@ -132,7 +132,7 @@ public class PropertyManager {
|
||||
@Override
|
||||
public void parse(String string)
|
||||
{
|
||||
value = Convert.toCoord(string, defaultValue);
|
||||
value = Convert.toVect(string, defaultValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,8 +173,10 @@ public class PropertyManager {
|
||||
public void apply()
|
||||
{
|
||||
boolean needsSave = false;
|
||||
if (!new File(file.getParent()).mkdirs()) {
|
||||
throw new RuntimeException("Cound not create config file.");
|
||||
if (!file.getParentFile().mkdirs()) {
|
||||
if (!file.getParentFile().exists()) {
|
||||
throw new RuntimeException("Cound not create config file.");
|
||||
}
|
||||
}
|
||||
|
||||
try(FileInputStream fis = new FileInputStream(file)) {
|
||||
@@ -360,7 +362,7 @@ public class PropertyManager {
|
||||
* @param n key
|
||||
* @return the coord found, or null
|
||||
*/
|
||||
public VecView getCoord(String n)
|
||||
public VectView getCoord(String n)
|
||||
{
|
||||
return Convert.toCoord(get(n).value);
|
||||
}
|
||||
@@ -425,7 +427,7 @@ public class PropertyManager {
|
||||
* @param d default value
|
||||
* @param comment the in-file comment
|
||||
*/
|
||||
public void putCoord(String n, Vec d, String comment)
|
||||
public void putCoord(String n, Vect d, String comment)
|
||||
{
|
||||
entries.put(n, new CoordProperty(n, d, comment));
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import mightypork.utils.math.animation.Easing;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
import org.lwjgl.BufferUtils;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class Calc {
|
||||
* @param point point coordinate
|
||||
* @return distance
|
||||
*/
|
||||
public static double linePointDist(Vec lineDirVec, Vec linePoint, Vec point)
|
||||
public static double linePointDist(Vect lineDirVec, Vect linePoint, Vect point)
|
||||
{
|
||||
// line point L[lx,ly]
|
||||
final double lx = linePoint.x();
|
||||
|
||||
@@ -3,8 +3,8 @@ package mightypork.utils.math;
|
||||
|
||||
import mightypork.utils.math.Calc.Deg;
|
||||
import mightypork.utils.math.Calc.Rad;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -20,7 +20,7 @@ public class Polar {
|
||||
/** distance in units */
|
||||
private double radius = 0;
|
||||
|
||||
private VecView coord = null;
|
||||
private VectView coord = null;
|
||||
|
||||
|
||||
/**
|
||||
@@ -107,7 +107,7 @@ public class Polar {
|
||||
* @param coord coord
|
||||
* @return polar
|
||||
*/
|
||||
public static Polar fromCoord(Vec coord)
|
||||
public static Polar fromCoord(Vect coord)
|
||||
{
|
||||
return Polar.fromCoord(coord.x(), coord.y());
|
||||
|
||||
@@ -135,11 +135,11 @@ public class Polar {
|
||||
*
|
||||
* @return coord
|
||||
*/
|
||||
public VecView toCoord()
|
||||
public VectView toCoord()
|
||||
{
|
||||
// lazy init
|
||||
if (coord == null) {
|
||||
coord = new VecView() {
|
||||
coord = new VectView() {
|
||||
|
||||
@Override
|
||||
public double x()
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
}
|
||||
@@ -2,10 +2,12 @@ package mightypork.utils.math.constraints;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.timing.Poller;
|
||||
import mightypork.utils.math.coord.AbstractVecProxy;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectVal;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
import mightypork.utils.math.vect.VectAdapter;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -58,8 +60,6 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
// =================== Number constraints ====================
|
||||
|
||||
public static NumberConstraint cMin(final Object a, final Object b)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
@@ -130,7 +130,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().round();
|
||||
}
|
||||
@@ -253,15 +253,15 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final double height = r.getRect().getHeight();
|
||||
final double perRow = height / rows;
|
||||
|
||||
final Vec origin = r.getRect().getOrigin().add(0, perRow * index);
|
||||
final Vec size = r.getRect().getSize().setY(perRow);
|
||||
final Vect origin = r.getRect().getOrigin().add(0, perRow * index);
|
||||
final Vect size = r.getRect().getSize().setY(perRow);
|
||||
|
||||
return RectValue.make(origin, size);
|
||||
return RectVal.make(origin, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -272,15 +272,15 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final double width = r.getRect().getWidth();
|
||||
final double perCol = width / columns;
|
||||
|
||||
final Vec origin = r.getRect().getOrigin().add(perCol * index, 0);
|
||||
final Vec size = r.getRect().getSize().setX(perCol);
|
||||
final Vect origin = r.getRect().getOrigin().add(perCol * index, 0);
|
||||
final Vect size = r.getRect().getSize().setX(perCol);
|
||||
|
||||
return RectValue.make(origin, size);
|
||||
return RectVal.make(origin, size);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -291,23 +291,21 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final double height = r.getRect().getHeight();
|
||||
final double width = r.getRect().getHeight();
|
||||
final double perRow = height / rows;
|
||||
final double perCol = width / cols;
|
||||
|
||||
final Vec origin = r.getRect().getOrigin().add(perCol * left, perRow * (rows - top - 1));
|
||||
final Vect origin = r.getRect().getOrigin().add(perCol * left, perRow * (rows - top - 1));
|
||||
|
||||
return RectValue.make(origin, perCol, perRow);
|
||||
return RectVal.make(origin, perCol, perRow);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* ================= RectView manipulation ================= */
|
||||
|
||||
public static RectConstraint cShrink(RectConstraint r, Object shrink)
|
||||
{
|
||||
final NumberConstraint n = toConstraint(shrink);
|
||||
@@ -326,7 +324,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(toDouble(left), toDouble(top), toDouble(right), toDouble(bottom));
|
||||
}
|
||||
@@ -339,7 +337,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, toDouble(shrink), 0, 0);
|
||||
}
|
||||
@@ -352,7 +350,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, 0, toDouble(shrink));
|
||||
}
|
||||
@@ -365,7 +363,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(toDouble(shrink), 0, 0, 0);
|
||||
}
|
||||
@@ -378,7 +376,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, toDouble(shrink), 0);
|
||||
}
|
||||
@@ -404,7 +402,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().grow(toDouble(left), toDouble(right), toDouble(top), toDouble(bottom));
|
||||
}
|
||||
@@ -417,7 +415,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().grow(0, toDouble(grow), 0, 0);
|
||||
}
|
||||
@@ -430,7 +428,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().grow(0, 0, 0, toDouble(grow));
|
||||
}
|
||||
@@ -443,7 +441,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().grow(toDouble(grow), 0, 0, 0);
|
||||
}
|
||||
@@ -456,7 +454,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().grow(0, 0, toDouble(grow), 0);
|
||||
}
|
||||
@@ -464,22 +462,20 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
/* ================= Box creation ================= */
|
||||
|
||||
public static RectConstraint cBox(final Object side)
|
||||
{
|
||||
return cBox(side, side);
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint cBox(final VecConstraint origin, final Object width, final Object height)
|
||||
public static RectConstraint cBox(final VectConstraint origin, final Object width, final Object height)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return RectValue.make(origin.getVec(), toDouble(width), toDouble(height));
|
||||
return RectVal.make(origin.getVec(), toDouble(width), toDouble(height));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -490,9 +486,9 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return RectValue.make(0, 0, toDouble(width), toDouble(height));
|
||||
return RectVal.make(0, 0, toDouble(width), toDouble(height));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -503,11 +499,11 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final Vec origin = r.getRect().getOrigin();
|
||||
final Vect origin = r.getRect().getOrigin();
|
||||
|
||||
return RectValue.make(origin.x(), origin.y(), toDouble(width), toDouble(height));
|
||||
return RectVal.make(origin.x(), origin.y(), toDouble(width), toDouble(height));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -518,11 +514,11 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final Vec origin = r.getRect().getOrigin();
|
||||
final Vect origin = r.getRect().getOrigin();
|
||||
|
||||
return RectValue.make(origin.x() + toDouble(x), origin.y() + toDouble(y), toDouble(width), toDouble(height));
|
||||
return RectVal.make(origin.x() + toDouble(x), origin.y() + toDouble(y), toDouble(width), toDouble(height));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -533,27 +529,27 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final VecView size = r.getRect().getSize();
|
||||
final VecView center = centerTo.getRect().getCenter();
|
||||
final VectView size = r.getRect().getSize();
|
||||
final VectView center = centerTo.getRect().getCenter();
|
||||
|
||||
return RectValue.make(center.sub(size.half()), size);
|
||||
return RectVal.make(center.sub(size.half()), size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint cCenterTo(final RectConstraint r, final VecConstraint centerTo)
|
||||
public static RectConstraint cCenterTo(final RectConstraint r, final VectConstraint centerTo)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final VecView size = r.getRect().getSize();
|
||||
final VectView size = r.getRect().getSize();
|
||||
|
||||
return RectValue.make(centerTo.getVec().sub(size.half()), size);
|
||||
return RectVal.make(centerTo.getVec().sub(size.half()), size);
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -564,23 +560,23 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final VecView size = r.getRect().getSize();
|
||||
final VecView v = VecView.make(toDouble(x), toDouble(y));
|
||||
final VectView size = r.getRect().getSize();
|
||||
final VectView v = VectVal.make(toDouble(x), toDouble(y));
|
||||
|
||||
return RectValue.make(v.sub(size.half()), size);
|
||||
return RectVal.make(v.sub(size.half()), size);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
public static RectConstraint cMove(final RectConstraint r, final VecConstraint move)
|
||||
public static RectConstraint cMove(final RectConstraint r, final VectConstraint move)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().move(move.getVec());
|
||||
}
|
||||
@@ -593,7 +589,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().move(toDouble(x), toDouble(y));
|
||||
}
|
||||
@@ -608,7 +604,7 @@ public class Constraints {
|
||||
* @param allSides size to grow on all sides
|
||||
* @return rect constraint
|
||||
*/
|
||||
public static RectConstraint cExpand(final VecConstraint c, final Object allSides)
|
||||
public static RectConstraint cExpand(final VectConstraint c, final Object allSides)
|
||||
{
|
||||
return cExpand(c, allSides, allSides, allSides, allSides);
|
||||
}
|
||||
@@ -622,7 +618,7 @@ public class Constraints {
|
||||
* @param vertical vertical grow (top, bottom)
|
||||
* @return rect constraint
|
||||
*/
|
||||
public static RectConstraint cExpand(final VecConstraint c, final Object horizontal, final Object vertical)
|
||||
public static RectConstraint cExpand(final VectConstraint c, final Object horizontal, final Object vertical)
|
||||
{
|
||||
return cExpand(c, horizontal, vertical, horizontal, vertical);
|
||||
}
|
||||
@@ -638,12 +634,12 @@ public class Constraints {
|
||||
* @param left
|
||||
* @return rect constraint
|
||||
*/
|
||||
public static RectConstraint cExpand(final VecConstraint c, final Object top, final Object right, final Object bottom, final Object left)
|
||||
public static RectConstraint cExpand(final VectConstraint c, final Object top, final Object right, final Object bottom, final Object left)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final double t = toDouble(top);
|
||||
final double r = toDouble(right);
|
||||
@@ -653,20 +649,18 @@ public class Constraints {
|
||||
final double x = c.getVec().x();
|
||||
final double y = c.getVec().y();
|
||||
|
||||
return RectValue.make(x - l, y - t, l + r, t + b);
|
||||
return RectVal.make(x - l, y - t, l + r, t + b);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/* ================= RectView bounds ================= */
|
||||
|
||||
public static RectConstraint cLeftEdge(final RectConstraint r)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, r.getRect().getWidth(), 0);
|
||||
}
|
||||
@@ -679,7 +673,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, 0, 0, r.getRect().getHeight());
|
||||
}
|
||||
@@ -692,7 +686,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(r.getRect().getWidth(), 0, 0, 0);
|
||||
}
|
||||
@@ -705,7 +699,7 @@ public class Constraints {
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return r.getRect().shrink(0, r.getRect().getHeight(), 0, 0);
|
||||
}
|
||||
@@ -713,7 +707,7 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint cX(final VecConstraint c)
|
||||
public static NumberConstraint cX(final VectConstraint c)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@@ -726,7 +720,7 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint cY(final VecConstraint c)
|
||||
public static NumberConstraint cY(final VectConstraint c)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@@ -739,7 +733,7 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static NumberConstraint cZ(final VecConstraint c)
|
||||
public static NumberConstraint cZ(final VectConstraint c)
|
||||
{
|
||||
return new NumberConstraint() {
|
||||
|
||||
@@ -752,26 +746,24 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cNeg(final VecConstraint c)
|
||||
public static VectConstraint cNeg(final VectConstraint c)
|
||||
{
|
||||
return cMul(c, -1);
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cHalf(final VecConstraint c)
|
||||
public static VectConstraint cHalf(final VectConstraint c)
|
||||
{
|
||||
return cMul(c, 0.5);
|
||||
}
|
||||
|
||||
|
||||
// --- add ---
|
||||
|
||||
public static VecConstraint cAdd(final VecConstraint c1, final VecConstraint c2)
|
||||
public static VectConstraint cAdd(final VectConstraint c1, final VectConstraint c2)
|
||||
{
|
||||
return new AbstractVecProxy() {
|
||||
return new VectAdapter() {
|
||||
|
||||
@Override
|
||||
public VecView getSource()
|
||||
public VectView getSource()
|
||||
{
|
||||
return c1.getVec().add(c2.getVec());
|
||||
}
|
||||
@@ -779,18 +771,18 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cAdd(final VecConstraint c, final Object x, final Object y)
|
||||
public static VectConstraint cAdd(final VectConstraint c, final Object x, final Object y)
|
||||
{
|
||||
return cAdd(c, x, y, 0);
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cAdd(final VecConstraint c, final Object x, final Object y, final Object z)
|
||||
public static VectConstraint cAdd(final VectConstraint c, final Object x, final Object y, final Object z)
|
||||
{
|
||||
return new AbstractVecProxy() {
|
||||
return new VectAdapter() {
|
||||
|
||||
@Override
|
||||
public VecView getSource()
|
||||
public VectView getSource()
|
||||
{
|
||||
return c.getVec().add(toDouble(x), toDouble(y), toDouble(z));
|
||||
}
|
||||
@@ -798,14 +790,12 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
// --- sub ---
|
||||
|
||||
public static VecConstraint cSub(final VecConstraint c1, final VecConstraint c2)
|
||||
public static VectConstraint cSub(final VectConstraint c1, final VectConstraint c2)
|
||||
{
|
||||
return new AbstractVecProxy() {
|
||||
return new VectAdapter() {
|
||||
|
||||
@Override
|
||||
public VecView getSource()
|
||||
public VectView getSource()
|
||||
{
|
||||
return c1.getVec().sub(c2.getVec());
|
||||
}
|
||||
@@ -813,18 +803,18 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cSub(final VecConstraint c, final Object x, final Object y)
|
||||
public static VectConstraint cSub(final VectConstraint c, final Object x, final Object y)
|
||||
{
|
||||
return cSub(c, x, y, 0);
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cSub(final VecConstraint c, final Object x, final Object y, final Object z)
|
||||
public static VectConstraint cSub(final VectConstraint c, final Object x, final Object y, final Object z)
|
||||
{
|
||||
return new AbstractVecProxy() {
|
||||
return new VectAdapter() {
|
||||
|
||||
@Override
|
||||
public VecView getSource()
|
||||
public VectView getSource()
|
||||
{
|
||||
return c.getVec().sub(toDouble(x), toDouble(y), toDouble(z));
|
||||
}
|
||||
@@ -833,14 +823,12 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
// --- mul ---
|
||||
|
||||
public static VecConstraint cMul(final VecConstraint c, final Object mul)
|
||||
public static VectConstraint cMul(final VectConstraint c, final Object mul)
|
||||
{
|
||||
return new AbstractVecProxy() {
|
||||
return new VectAdapter() {
|
||||
|
||||
@Override
|
||||
public VecView getSource()
|
||||
public VectView getSource()
|
||||
{
|
||||
return c.getVec().mul(toDouble(mul));
|
||||
}
|
||||
@@ -849,14 +837,12 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
// --- rects ---
|
||||
|
||||
public static VecConstraint cOrigin(final RectConstraint r)
|
||||
public static VectConstraint cOrigin(final RectConstraint r)
|
||||
{
|
||||
return new AbstractVecProxy() {
|
||||
return new VectAdapter() {
|
||||
|
||||
@Override
|
||||
public VecView getSource()
|
||||
public VectView getSource()
|
||||
{
|
||||
return r.getRect().getOrigin();
|
||||
}
|
||||
@@ -864,12 +850,12 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cSize(final RectConstraint r)
|
||||
public static VectConstraint cSize(final RectConstraint r)
|
||||
{
|
||||
return new AbstractVecProxy() {
|
||||
return new VectAdapter() {
|
||||
|
||||
@Override
|
||||
public VecView getSource()
|
||||
public VectView getSource()
|
||||
{
|
||||
return r.getRect().getSize();
|
||||
}
|
||||
@@ -889,55 +875,55 @@ public class Constraints {
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cCenter(final RectConstraint r)
|
||||
public static VectConstraint cCenter(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), cHalf(cSize(r)));
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cTopLeft(final RectConstraint r)
|
||||
public static VectConstraint cTopLeft(final RectConstraint r)
|
||||
{
|
||||
return cOrigin(r);
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cTopRight(final RectConstraint r)
|
||||
public static VectConstraint cTopRight(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), cWidth(r), 0);
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cBottomLeft(final RectConstraint r)
|
||||
public static VectConstraint cBottomLeft(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), 0, cWidth(r));
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cBottomRight(final RectConstraint r)
|
||||
public static VectConstraint cBottomRight(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), cSize(r));
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cTopCenter(final RectConstraint r)
|
||||
public static VectConstraint cTopCenter(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), cHalf(cWidth(r)), 0);
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cBottomCenter(final RectConstraint r)
|
||||
public static VectConstraint cBottomCenter(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), cHalf(cWidth(r)), cWidth(r));
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cCenterLeft(final RectConstraint r)
|
||||
public static VectConstraint cCenterLeft(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), 0, cHalf(cWidth(r)));
|
||||
}
|
||||
|
||||
|
||||
public static VecConstraint cCenterRight(final RectConstraint r)
|
||||
public static VectConstraint cCenterRight(final RectConstraint r)
|
||||
{
|
||||
return cAdd(cOrigin(r), cWidth(r), cHalf(cWidth(r)));
|
||||
}
|
||||
@@ -949,30 +935,18 @@ public class Constraints {
|
||||
* @param c coord
|
||||
* @return rect
|
||||
*/
|
||||
public static RectConstraint cZeroRect(final VecConstraint c)
|
||||
public static RectConstraint cZeroRect(final VectConstraint c)
|
||||
{
|
||||
return new RectConstraint() {
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
final Vec v = c.getVec();
|
||||
final Vect v = c.getVec();
|
||||
|
||||
return RectValue.make(v.x(), v.y(), 0, 0);
|
||||
return RectVal.make(v.x(), v.y(), 0, 0);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convert VecConstraint to VecView
|
||||
*
|
||||
* @param c vec constraint
|
||||
* @return CReverseProxy
|
||||
*/
|
||||
public static VecView cVec(final VecConstraint c)
|
||||
{
|
||||
return new CReverseProxy(c);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -22,7 +22,7 @@ public abstract class ContextAdapter implements PluggableRect {
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return backing.getRect();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,6 +18,6 @@ public interface PluggableRect extends RectConstraint {
|
||||
|
||||
|
||||
@Override
|
||||
abstract RectValue getRect();
|
||||
abstract RectView getRect();
|
||||
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ package mightypork.utils.math.constraints;
|
||||
import mightypork.gamecore.control.timing.Pollable;
|
||||
import mightypork.gamecore.control.timing.Poller;
|
||||
import mightypork.utils.math.rect.RectMutable;
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -42,7 +42,7 @@ public class RectCache implements RectConstraint, Pollable {
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue getRect()
|
||||
public RectView getRect()
|
||||
{
|
||||
return cached.view();
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.utils.math.constraints;
|
||||
|
||||
|
||||
import mightypork.utils.math.rect.RectValue;
|
||||
import mightypork.utils.math.rect.RectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,5 +14,5 @@ public interface RectConstraint {
|
||||
/**
|
||||
* @return rect region
|
||||
*/
|
||||
RectValue getRect();
|
||||
RectView getRect();
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,10 @@ package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import static mightypork.utils.math.constraints.Constraints.*;
|
||||
import mightypork.utils.math.constraints.VecConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.constraints.VectConstraint;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -14,26 +15,27 @@ import mightypork.utils.math.coord.VecView;
|
||||
*/
|
||||
public abstract class AbstractRect implements Rect {
|
||||
|
||||
private VecConstraint tl;
|
||||
private VecConstraint tc;
|
||||
private VecConstraint tr;
|
||||
private VecConstraint cl;
|
||||
private VecConstraint c;
|
||||
private VecConstraint cr;
|
||||
private VecConstraint bl;
|
||||
private VecConstraint bc;
|
||||
private VecConstraint br;
|
||||
private RectProxy proxy;
|
||||
private VectConstraint tl;
|
||||
private VectConstraint tc;
|
||||
private VectConstraint tr;
|
||||
private VectConstraint cl;
|
||||
private VectConstraint c;
|
||||
private VectConstraint cr;
|
||||
private VectConstraint bl;
|
||||
private VectConstraint bc;
|
||||
private VectConstraint br;
|
||||
|
||||
|
||||
@Override
|
||||
public final RectValue getRect()
|
||||
public final RectView getRect()
|
||||
{
|
||||
return this.view();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getTopLeft()
|
||||
public final VectVal getTopLeft()
|
||||
{
|
||||
// lazy init
|
||||
if (tl == null) tl = cTopLeft(this);
|
||||
@@ -42,7 +44,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getTopCenter()
|
||||
public final VectVal getTopCenter()
|
||||
{
|
||||
// lazy init
|
||||
if (tc == null) tc = cTopCenter(this);
|
||||
@@ -51,7 +53,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getTopRight()
|
||||
public final VectVal getTopRight()
|
||||
{
|
||||
// lazy init
|
||||
if (tr == null) tr = cTopRight(this);
|
||||
@@ -60,7 +62,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getCenterLeft()
|
||||
public final VectVal getCenterLeft()
|
||||
{
|
||||
// lazy init
|
||||
if (cl == null) cl = cCenterLeft(this);
|
||||
@@ -69,7 +71,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getCenter()
|
||||
public final VectVal getCenter()
|
||||
{
|
||||
// lazy init
|
||||
if (c == null) c = cCenter(this);
|
||||
@@ -78,7 +80,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getCenterRight()
|
||||
public final VectVal getCenterRight()
|
||||
{
|
||||
// lazy init
|
||||
if (cr == null) cr = cCenterRight(this);
|
||||
@@ -87,7 +89,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getBottomLeft()
|
||||
public final VectVal getBottomLeft()
|
||||
{
|
||||
// lazy init
|
||||
if (bl == null) bl = cBottomLeft(this);
|
||||
@@ -96,7 +98,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getBottomCenter()
|
||||
public final VectVal getBottomCenter()
|
||||
{
|
||||
// lazy init
|
||||
if (bc == null) bc = cBottomCenter(this);
|
||||
@@ -105,7 +107,7 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public final VecView getBottomRight()
|
||||
public final VectVal getBottomRight()
|
||||
{
|
||||
// lazy init
|
||||
if (br == null) br = cBottomRight(this);
|
||||
@@ -156,28 +158,30 @@ public abstract class AbstractRect implements Rect {
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue view()
|
||||
public RectProxy view()
|
||||
{
|
||||
return new RectProxy(this);
|
||||
if (proxy == null) proxy = new RectProxy(this);
|
||||
|
||||
return proxy;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final RectMutable mutable()
|
||||
public RectMutable mutable()
|
||||
{
|
||||
return RectMutable.make(this);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectValue value()
|
||||
public RectVal value()
|
||||
{
|
||||
return RectValue.make(getOrigin(), getSize());
|
||||
return RectVal.make(getOrigin(), getSize());
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public final boolean contains(Vec point)
|
||||
public final boolean contains(Vect point)
|
||||
{
|
||||
final double x = point.x();
|
||||
final double y = point.y();
|
||||
@@ -194,7 +198,7 @@ public abstract class AbstractRect implements Rect {
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("Rect { %s - %s }", getOrigin().toString(), getOrigin().add(getSize()));
|
||||
return String.format("Rect { %s - %s }", getTopLeft(), getBottomRight());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -2,8 +2,9 @@ package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.RectConstraint;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -13,14 +14,14 @@ import mightypork.utils.math.coord.VecView;
|
||||
*/
|
||||
public interface Rect extends RectConstraint {
|
||||
|
||||
RectValue ONE = new ConstRect(0, 0, 1, 1);
|
||||
RectValue ZERO = new ConstRect(0, 0, 0, 0);
|
||||
RectVal ONE = new RectVal(0, 0, 1, 1);
|
||||
RectVal ZERO = new RectVal(0, 0, 0, 0);
|
||||
|
||||
|
||||
/**
|
||||
* Get a writable copy
|
||||
*
|
||||
* @return copy
|
||||
* @return writable copy
|
||||
*/
|
||||
RectMutable mutable();
|
||||
|
||||
@@ -30,24 +31,24 @@ public interface Rect extends RectConstraint {
|
||||
*
|
||||
* @return copy
|
||||
*/
|
||||
RectValue value();
|
||||
RectVal value();
|
||||
|
||||
|
||||
/**
|
||||
* Get a proxying view
|
||||
*
|
||||
* @return copy
|
||||
* @return proxy
|
||||
*/
|
||||
RectValue view();
|
||||
RectProxy view();
|
||||
|
||||
|
||||
/**
|
||||
* @return origin
|
||||
*/
|
||||
VecView getOrigin();
|
||||
VectVal getOrigin();
|
||||
|
||||
|
||||
VecView getSize();
|
||||
VectVal getSize();
|
||||
|
||||
|
||||
double getWidth();
|
||||
@@ -56,31 +57,31 @@ public interface Rect extends RectConstraint {
|
||||
double getHeight();
|
||||
|
||||
|
||||
VecView getTopLeft();
|
||||
VectVal getTopLeft();
|
||||
|
||||
|
||||
VecView getTopCenter();
|
||||
VectVal getTopCenter();
|
||||
|
||||
|
||||
VecView getTopRight();
|
||||
VectVal getTopRight();
|
||||
|
||||
|
||||
VecView getCenterLeft();
|
||||
VectVal getCenterLeft();
|
||||
|
||||
|
||||
VecView getCenter();
|
||||
VectVal getCenter();
|
||||
|
||||
|
||||
VecView getCenterRight();
|
||||
VectVal getCenterRight();
|
||||
|
||||
|
||||
VecView getBottomLeft();
|
||||
VectVal getBottomLeft();
|
||||
|
||||
|
||||
VecView getBottomCenter();
|
||||
VectVal getBottomCenter();
|
||||
|
||||
|
||||
VecView getBottomRight();
|
||||
VectVal getBottomRight();
|
||||
|
||||
|
||||
double xMin();
|
||||
@@ -101,6 +102,6 @@ public interface Rect extends RectConstraint {
|
||||
* @param point point to test
|
||||
* @return is inside
|
||||
*/
|
||||
boolean contains(Vec point);
|
||||
boolean contains(Vect point);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
|
||||
|
||||
abstract class RectMath<T extends Rect> extends AbstractRect {
|
||||
@@ -12,7 +12,7 @@ abstract class RectMath<T extends Rect> extends AbstractRect {
|
||||
* @param move offset vector
|
||||
* @return result
|
||||
*/
|
||||
public T move(Vec move)
|
||||
public T move(Vect move)
|
||||
{
|
||||
return move(move.x(), move.y());
|
||||
}
|
||||
@@ -35,7 +35,7 @@ abstract class RectMath<T extends Rect> extends AbstractRect {
|
||||
* @return result
|
||||
*/
|
||||
|
||||
public T shrink(Vec shrink)
|
||||
public T shrink(Vect shrink)
|
||||
{
|
||||
return shrink(shrink.x(), shrink.y());
|
||||
}
|
||||
@@ -72,7 +72,7 @@ abstract class RectMath<T extends Rect> extends AbstractRect {
|
||||
* @param grow grow size (added to each side)
|
||||
* @return grown copy
|
||||
*/
|
||||
public final T grow(Vec grow)
|
||||
public final T grow(Vect grow)
|
||||
{
|
||||
return grow(grow.x(), grow.y());
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,9 +55,9 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param height
|
||||
* @return new mutable rect
|
||||
*/
|
||||
public static RectMutable make(Vec origin, double width, double height)
|
||||
public static RectMutable make(Vect origin, double width, double height)
|
||||
{
|
||||
return make(origin, VecView.make(width, height));
|
||||
return make(origin, VectVal.make(width, height));
|
||||
}
|
||||
|
||||
|
||||
@@ -67,9 +67,9 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param size
|
||||
* @return new mutable rect
|
||||
*/
|
||||
public static RectMutable make(Vec size)
|
||||
public static RectMutable make(Vect size)
|
||||
{
|
||||
return make(VecView.zero(), size);
|
||||
return make(Vect.ZERO, size);
|
||||
}
|
||||
|
||||
|
||||
@@ -84,7 +84,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
*/
|
||||
public static RectMutable make(double x, double y, double width, double height)
|
||||
{
|
||||
return make(VecView.make(x, y), VecView.make(width, height));
|
||||
return make(x, y, width, height);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,9 +107,9 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param size
|
||||
* @return new mutable rect
|
||||
*/
|
||||
public static RectMutable make(Vec origin, Vec size)
|
||||
public static RectMutable make(Vect origin, Vect size)
|
||||
{
|
||||
return new RectMutableImpl(origin, size);
|
||||
return make(origin.x(), origin.y(), size.x(), size.y());
|
||||
}
|
||||
|
||||
|
||||
@@ -133,9 +133,24 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param height new height
|
||||
* @return this
|
||||
*/
|
||||
public RectMutable setTo(Vec origin, double width, double height)
|
||||
public RectMutable setTo(Vect origin, double width, double height)
|
||||
{
|
||||
return setTo(origin, VecView.make(width, height));
|
||||
return setTo(origin, VectVal.make(width, height));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Set to given size and position
|
||||
*
|
||||
* @param x origin.x
|
||||
* @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)
|
||||
{
|
||||
return setTo(VectVal.make(x, y), VectVal.make(width, height));
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +161,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param size new size
|
||||
* @return this
|
||||
*/
|
||||
public RectMutable setTo(Vec origin, Vec size)
|
||||
public RectMutable setTo(Vect origin, Vect size)
|
||||
{
|
||||
setOrigin(origin);
|
||||
setSize(size);
|
||||
@@ -160,7 +175,7 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param origin new origin
|
||||
* @return this
|
||||
*/
|
||||
public abstract RectMutable setOrigin(Vec origin);
|
||||
public abstract RectMutable setOrigin(Vect origin);
|
||||
|
||||
|
||||
/**
|
||||
@@ -169,6 +184,6 @@ public abstract class RectMutable extends RectMath<RectMutable> {
|
||||
* @param size new size
|
||||
* @return this
|
||||
*/
|
||||
public abstract RectMutable setSize(Vec size);
|
||||
public abstract RectMutable setSize(Vect size);
|
||||
|
||||
}
|
||||
|
||||
@@ -1,26 +1,28 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecMutable;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectMutable;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
|
||||
|
||||
class RectMutableImpl extends RectMutable {
|
||||
|
||||
final VecMutable pos = VecMutable.zero();
|
||||
final VecMutable size = VecMutable.zero();
|
||||
final VectMutable pos = VectMutable.zero();
|
||||
final VectMutable size = VectMutable.zero();
|
||||
|
||||
|
||||
/**
|
||||
* Create at given origin, with given size.
|
||||
*
|
||||
* @param origin
|
||||
* @param size
|
||||
* @param x
|
||||
* @param y
|
||||
* @param width
|
||||
* @param height
|
||||
*/
|
||||
public RectMutableImpl(Vec origin, Vec size) {
|
||||
this.pos.setTo(origin);
|
||||
this.size.setTo(size).abs();
|
||||
public RectMutableImpl(double x, double y, double width, double height) {
|
||||
this.pos.setTo(x, y);
|
||||
this.size.setTo(width, height).abs();
|
||||
}
|
||||
|
||||
|
||||
@@ -32,7 +34,7 @@ class RectMutableImpl extends RectMutable {
|
||||
* @return result
|
||||
*/
|
||||
@Override
|
||||
public RectMutableImpl move(double x, double y)
|
||||
public RectMutable move(double x, double y)
|
||||
{
|
||||
pos.add(x, y);
|
||||
return this;
|
||||
@@ -49,7 +51,7 @@ class RectMutableImpl extends RectMutable {
|
||||
* @return result
|
||||
*/
|
||||
@Override
|
||||
public RectMutableImpl shrink(double left, double right, double top, double bottom)
|
||||
public RectMutable shrink(double left, double right, double top, double bottom)
|
||||
{
|
||||
pos.add(left, top);
|
||||
size.sub(left + right, top + bottom).abs();
|
||||
@@ -67,7 +69,7 @@ class RectMutableImpl extends RectMutable {
|
||||
* @return result
|
||||
*/
|
||||
@Override
|
||||
public RectMutableImpl grow(double left, double right, double top, double bottom)
|
||||
public RectMutable grow(double left, double right, double top, double bottom)
|
||||
{
|
||||
pos.sub(left, top);
|
||||
size.add(left + right, top + bottom).abs();
|
||||
@@ -81,7 +83,7 @@ class RectMutableImpl extends RectMutable {
|
||||
* @return result
|
||||
*/
|
||||
@Override
|
||||
public RectMutableImpl round()
|
||||
public RectMutable round()
|
||||
{
|
||||
pos.round();
|
||||
size.round();
|
||||
@@ -90,21 +92,21 @@ class RectMutableImpl extends RectMutable {
|
||||
|
||||
|
||||
@Override
|
||||
public VecView getOrigin()
|
||||
public VectVal getOrigin()
|
||||
{
|
||||
return pos.view();
|
||||
return pos.value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VecView getSize()
|
||||
public VectVal getSize()
|
||||
{
|
||||
return size.view();
|
||||
return size.value();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public RectMutable setOrigin(Vec origin)
|
||||
public RectMutable setOrigin(Vect origin)
|
||||
{
|
||||
this.pos.setTo(origin);
|
||||
return this;
|
||||
@@ -112,7 +114,7 @@ class RectMutableImpl extends RectMutable {
|
||||
|
||||
|
||||
@Override
|
||||
public RectMutable setSize(Vec size)
|
||||
public RectMutable setSize(Vect size)
|
||||
{
|
||||
this.size.setTo(size).abs();
|
||||
return this;
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
package mightypork.utils.math.rect;
|
||||
|
||||
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -9,7 +10,7 @@ import mightypork.utils.math.coord.VecView;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class RectProxy extends RectValue {
|
||||
public class RectProxy extends RectView {
|
||||
|
||||
private final Rect observed;
|
||||
|
||||
@@ -20,14 +21,14 @@ public class RectProxy extends RectValue {
|
||||
|
||||
|
||||
@Override
|
||||
public VecView getOrigin()
|
||||
public VectVal getOrigin()
|
||||
{
|
||||
return observed.getOrigin();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public VecView getSize()
|
||||
public VectVal getSize()
|
||||
{
|
||||
return observed.getSize();
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.coord;
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.NumberConstraint;
|
||||
@@ -10,21 +10,21 @@ import mightypork.utils.math.constraints.NumberConstraint;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
class NumConstrVec extends VecView {
|
||||
class NumConstrVect extends VectView {
|
||||
|
||||
private final NumberConstraint constrX;
|
||||
private final NumberConstraint constrY;
|
||||
private final NumberConstraint constrZ;
|
||||
|
||||
|
||||
public NumConstrVec(NumberConstraint x, NumberConstraint y, NumberConstraint z) {
|
||||
public NumConstrVect(NumberConstraint x, NumberConstraint y, NumberConstraint z) {
|
||||
this.constrX = x;
|
||||
this.constrY = y;
|
||||
this.constrZ = z;
|
||||
}
|
||||
|
||||
|
||||
public NumConstrVec(NumberConstraint x, NumberConstraint y) {
|
||||
public NumConstrVect(NumberConstraint x, NumberConstraint y) {
|
||||
this.constrX = x;
|
||||
this.constrY = y;
|
||||
this.constrZ = NumberConstraint.ZERO;
|
||||
+13
-16
@@ -1,8 +1,8 @@
|
||||
package mightypork.utils.math.coord;
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
import mightypork.utils.math.constraints.NumberConstraint;
|
||||
import mightypork.utils.math.constraints.VecConstraint;
|
||||
import mightypork.utils.math.constraints.VectConstraint;
|
||||
|
||||
|
||||
/**
|
||||
@@ -10,10 +10,10 @@ import mightypork.utils.math.constraints.VecConstraint;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public interface Vec extends VecConstraint {
|
||||
public interface Vect extends VectConstraint {
|
||||
|
||||
public static final VecView ZERO = new ConstVec(0, 0, 0);
|
||||
public static final VecView ONE = new ConstVec(0, 0, 0);
|
||||
public static final VectVal ZERO = new VectVal(0, 0, 0);
|
||||
public static final VectVal ONE = new VectVal(0, 0, 0);
|
||||
|
||||
|
||||
/**
|
||||
@@ -55,21 +55,18 @@ public interface Vec extends VecConstraint {
|
||||
/**
|
||||
* @return X constraint
|
||||
*/
|
||||
@Override
|
||||
NumberConstraint xc();
|
||||
|
||||
|
||||
/**
|
||||
* @return Y constraint
|
||||
*/
|
||||
@Override
|
||||
NumberConstraint yc();
|
||||
|
||||
|
||||
/**
|
||||
* @return Z constraint
|
||||
*/
|
||||
@Override
|
||||
NumberConstraint zc();
|
||||
|
||||
|
||||
@@ -93,7 +90,7 @@ public interface Vec extends VecConstraint {
|
||||
* @param point other point
|
||||
* @return distance
|
||||
*/
|
||||
double distTo(Vec point);
|
||||
double distTo(Vect point);
|
||||
|
||||
|
||||
/**
|
||||
@@ -102,7 +99,7 @@ public interface Vec extends VecConstraint {
|
||||
* @param point other point
|
||||
* @return result
|
||||
*/
|
||||
VecView midTo(Vec point);
|
||||
VectVal midTo(Vect point);
|
||||
|
||||
|
||||
/**
|
||||
@@ -111,7 +108,7 @@ public interface Vec extends VecConstraint {
|
||||
* @param point second point
|
||||
* @return result
|
||||
*/
|
||||
public VecView vecTo(Vec point);
|
||||
VectVal vecTo(Vect point);
|
||||
|
||||
|
||||
/**
|
||||
@@ -120,7 +117,7 @@ public interface Vec extends VecConstraint {
|
||||
* @param vec other vector
|
||||
* @return result
|
||||
*/
|
||||
public VecView cross(Vec vec);
|
||||
VectVal cross(Vect vec);
|
||||
|
||||
|
||||
/**
|
||||
@@ -129,7 +126,7 @@ public interface Vec extends VecConstraint {
|
||||
* @param vec other vector
|
||||
* @return dot product
|
||||
*/
|
||||
public double dot(Vec vec);
|
||||
double dot(Vect vec);
|
||||
|
||||
|
||||
/**
|
||||
@@ -137,7 +134,7 @@ public interface Vec extends VecConstraint {
|
||||
*
|
||||
* @return a immutable copy
|
||||
*/
|
||||
VecView value();
|
||||
VectVal value();
|
||||
|
||||
|
||||
/**
|
||||
@@ -145,7 +142,7 @@ public interface Vec extends VecConstraint {
|
||||
*
|
||||
* @return immutable view
|
||||
*/
|
||||
VecView view();
|
||||
VectView view();
|
||||
|
||||
|
||||
/**
|
||||
@@ -153,5 +150,5 @@ public interface Vec extends VecConstraint {
|
||||
*
|
||||
* @return mutable copy
|
||||
*/
|
||||
VecMutable mutable();
|
||||
VectMutable mutable();
|
||||
}
|
||||
+4
-4
@@ -1,13 +1,13 @@
|
||||
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
|
||||
public double x()
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-36
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.coord;
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
/**
|
||||
@@ -7,7 +7,7 @@ package mightypork.utils.math.coord;
|
||||
* @author MightyPork
|
||||
* @param <V> Return type of methods
|
||||
*/
|
||||
abstract class VecMath<V extends Vec> extends AbstractVec {
|
||||
abstract class VectMath<V extends Vect> extends AbstractVect {
|
||||
|
||||
/**
|
||||
* <p>
|
||||
@@ -79,7 +79,7 @@ abstract class VecMath<V extends Vec> extends AbstractVec {
|
||||
* @param vec offset
|
||||
* @return result
|
||||
*/
|
||||
public V add(Vec vec)
|
||||
public V add(Vect vec)
|
||||
{
|
||||
return add(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
@@ -142,7 +142,7 @@ abstract class VecMath<V extends Vec> extends AbstractVec {
|
||||
* @param vec vector of multipliers
|
||||
* @return result
|
||||
*/
|
||||
public V mul(Vec vec)
|
||||
public V mul(Vect vec)
|
||||
{
|
||||
return mul(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
@@ -215,7 +215,7 @@ abstract class VecMath<V extends Vec> extends AbstractVec {
|
||||
* @param vec offset
|
||||
* @return result
|
||||
*/
|
||||
public V sub(Vec vec)
|
||||
public V sub(Vect vec)
|
||||
{
|
||||
return sub(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
@@ -274,35 +274,4 @@ abstract class VecMath<V extends Vec> extends AbstractVec {
|
||||
|
||||
return mul(k);
|
||||
}
|
||||
|
||||
|
||||
@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 Vec)) return false;
|
||||
final Vec other = (Vec) obj;
|
||||
|
||||
return x() == other.x() && y() == other.y() && z() == other.z();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("(%.1f %.1f %.1f)", x(), y(), z());
|
||||
}
|
||||
}
|
||||
+20
-20
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.coord;
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
import mightypork.utils.math.animation.AnimDouble;
|
||||
@@ -10,14 +10,14 @@ import mightypork.utils.math.animation.Easing;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
|
||||
public abstract class VectMutable extends VectMath<VectMutable> { // returns itself on edit
|
||||
|
||||
/**
|
||||
* Get a variable initialized as zero (0,0,0)
|
||||
*
|
||||
* @return new mutable vector
|
||||
*/
|
||||
public static VecMutable zero()
|
||||
public static VectMutable zero()
|
||||
{
|
||||
return make(ZERO);
|
||||
}
|
||||
@@ -28,7 +28,7 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
*
|
||||
* @return one mutable vector
|
||||
*/
|
||||
public static VecMutable one()
|
||||
public static VectMutable one()
|
||||
{
|
||||
return make(ONE);
|
||||
}
|
||||
@@ -41,7 +41,7 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param y Y coordinate
|
||||
* @return mutable vector
|
||||
*/
|
||||
public static VecMutable make(double x, double y)
|
||||
public static VectMutable make(double x, double y)
|
||||
{
|
||||
return make(x, y, 0);
|
||||
}
|
||||
@@ -53,7 +53,7 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param copied copied vec
|
||||
* @return mutable vector
|
||||
*/
|
||||
public static VecMutable make(Vec copied)
|
||||
public static VectMutable make(Vect copied)
|
||||
{
|
||||
return make(copied.x(), copied.y(), copied.z());
|
||||
}
|
||||
@@ -67,9 +67,9 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param z Z coordinate
|
||||
* @return mutable vector
|
||||
*/
|
||||
public static VecMutable make(double x, double y, double z)
|
||||
public static VectMutable make(double x, double y, double z)
|
||||
{
|
||||
return new VecMutableImpl(x, y, z);
|
||||
return new VectMutableImpl(x, y, z);
|
||||
}
|
||||
|
||||
|
||||
@@ -82,9 +82,9 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param animZ z animator
|
||||
* @return animated mutable vector
|
||||
*/
|
||||
public static VecMutableAnim makeAnim(AnimDouble animX, AnimDouble animY, AnimDouble animZ)
|
||||
public static VectMutableAnim makeAnim(AnimDouble animX, AnimDouble animY, AnimDouble animZ)
|
||||
{
|
||||
return new VecMutableAnim(animX, animY, animZ);
|
||||
return new VectMutableAnim(animX, animY, animZ);
|
||||
}
|
||||
|
||||
|
||||
@@ -95,9 +95,9 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param easing animation easing
|
||||
* @return animated mutable vector
|
||||
*/
|
||||
public static VecMutableAnim makeAnim(Vec animStart, Easing easing)
|
||||
public static VectMutableAnim makeAnim(Vect animStart, Easing easing)
|
||||
{
|
||||
return new VecMutableAnim(animStart, easing);
|
||||
return new VectMutableAnim(animStart, easing);
|
||||
}
|
||||
|
||||
|
||||
@@ -107,14 +107,14 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param easing animation easing
|
||||
* @return animated mutable vector
|
||||
*/
|
||||
public static VecMutableAnim makeAnim(Easing easing)
|
||||
public static VectMutableAnim makeAnim(Easing easing)
|
||||
{
|
||||
return new VecMutableAnim(Vec.ZERO, easing);
|
||||
return new VectMutableAnim(Vect.ZERO, easing);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public abstract VecMutable result(double x, double y, double z);
|
||||
public abstract VectMutable result(double x, double y, double z);
|
||||
|
||||
|
||||
@Override
|
||||
@@ -129,7 +129,7 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
public abstract double z();
|
||||
|
||||
|
||||
public VecMutable reset()
|
||||
public VectMutable reset()
|
||||
{
|
||||
return result(0, 0, 0);
|
||||
}
|
||||
@@ -141,7 +141,7 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param copied coord whose coordinates are used
|
||||
* @return result
|
||||
*/
|
||||
public VecMutable setTo(Vec copied)
|
||||
public VectMutable setTo(Vect copied)
|
||||
{
|
||||
return result(copied.x(), copied.y(), copied.z());
|
||||
}
|
||||
@@ -155,7 +155,7 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param y y coordinate
|
||||
* @return result
|
||||
*/
|
||||
public VecMutable setTo(double x, double y)
|
||||
public VectMutable setTo(double x, double y)
|
||||
{
|
||||
return result(x, y, z());
|
||||
}
|
||||
@@ -169,7 +169,7 @@ public abstract class VecMutable extends VecMath<VecMutable> {
|
||||
* @param z z coordinate
|
||||
* @return result
|
||||
*/
|
||||
public VecMutable setTo(double x, double y, double z)
|
||||
public VectMutable setTo(double x, double y, double z)
|
||||
{
|
||||
return result(x, y, z);
|
||||
}
|
||||
+8
-8
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.coord;
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
import mightypork.gamecore.control.timing.Pauseable;
|
||||
@@ -12,20 +12,20 @@ import mightypork.utils.math.animation.Easing;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
public class VecMutableAnim extends VecMutable implements Pauseable, Updateable {
|
||||
public class VectMutableAnim extends VectMutable implements Pauseable, Updateable {
|
||||
|
||||
private final AnimDouble x, y, z;
|
||||
private double defaultDuration = 0;
|
||||
|
||||
|
||||
VecMutableAnim(AnimDouble x, AnimDouble y, AnimDouble z) {
|
||||
VectMutableAnim(AnimDouble x, AnimDouble y, AnimDouble z) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
}
|
||||
|
||||
|
||||
VecMutableAnim(Vec start, Easing easing) {
|
||||
VectMutableAnim(Vect start, Easing easing) {
|
||||
x = new AnimDouble(start.x(), easing);
|
||||
y = new AnimDouble(start.y(), easing);
|
||||
z = new AnimDouble(start.z(), easing);
|
||||
@@ -74,7 +74,7 @@ public class VecMutableAnim extends VecMutable implements Pauseable, Updateable
|
||||
|
||||
|
||||
@Override
|
||||
public VecMutableAnim result(double x, double y, double z)
|
||||
public VectMutableAnim result(double x, double y, double z)
|
||||
{
|
||||
this.x.animate(x, defaultDuration);
|
||||
this.y.animate(y, defaultDuration);
|
||||
@@ -84,14 +84,14 @@ public class VecMutableAnim extends VecMutable implements Pauseable, Updateable
|
||||
}
|
||||
|
||||
|
||||
public VecMutableAnim add(Vec offset, double speed)
|
||||
public VectMutableAnim add(Vect offset, double speed)
|
||||
{
|
||||
animate(view().add(offset), speed);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public VecMutableAnim animate(double x, double y, double z, double duration)
|
||||
public VectMutableAnim animate(double x, double y, double z, double duration)
|
||||
{
|
||||
this.x.animate(x, duration);
|
||||
this.y.animate(y, duration);
|
||||
@@ -100,7 +100,7 @@ public class VecMutableAnim extends VecMutable implements Pauseable, Updateable
|
||||
}
|
||||
|
||||
|
||||
public VecMutableAnim animate(Vec target, double duration)
|
||||
public VectMutableAnim animate(Vect target, double duration)
|
||||
{
|
||||
animate(target.x(), target.y(), target.z(), duration);
|
||||
return this;
|
||||
+4
-4
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.coord;
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
/**
|
||||
@@ -7,7 +7,7 @@ package mightypork.utils.math.coord;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
class VecMutableImpl extends VecMutable {
|
||||
class VectMutableImpl extends VectMutable {
|
||||
|
||||
private double x, y, z;
|
||||
|
||||
@@ -17,7 +17,7 @@ class VecMutableImpl extends VecMutable {
|
||||
* @param y Y coordinate
|
||||
* @param z Z coordinate
|
||||
*/
|
||||
public VecMutableImpl(double x, double y, double z) {
|
||||
public VectMutableImpl(double x, double y, double z) {
|
||||
super();
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
@@ -47,7 +47,7 @@ class VecMutableImpl extends VecMutable {
|
||||
|
||||
|
||||
@Override
|
||||
public VecMutableImpl result(double x, double y, double z)
|
||||
public VectMutableImpl result(double x, double y, double z)
|
||||
{
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
+5
-5
@@ -1,4 +1,4 @@
|
||||
package mightypork.utils.math.coord;
|
||||
package mightypork.utils.math.vect;
|
||||
|
||||
|
||||
/**
|
||||
@@ -7,9 +7,9 @@ package mightypork.utils.math.coord;
|
||||
*
|
||||
* @author MightyPork
|
||||
*/
|
||||
class VecProxy extends AbstractVecProxy {
|
||||
class VectProxy extends VectAdapter {
|
||||
|
||||
final Vec observed;
|
||||
final Vect observed;
|
||||
|
||||
|
||||
/**
|
||||
@@ -18,13 +18,13 @@ class VecProxy extends AbstractVecProxy {
|
||||
*
|
||||
* @param observed
|
||||
*/
|
||||
public VecProxy(Vec observed) {
|
||||
public VectProxy(Vect observed) {
|
||||
this.observed = observed;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
protected Vec getSource()
|
||||
protected Vect getSource()
|
||||
{
|
||||
return observed;
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
|
||||
}
|
||||
@@ -3,8 +3,9 @@ package mightypork.utils.objects;
|
||||
|
||||
import mightypork.utils.logging.Log;
|
||||
import mightypork.utils.math.Range;
|
||||
import mightypork.utils.math.coord.Vec;
|
||||
import mightypork.utils.math.coord.VecView;
|
||||
import mightypork.utils.math.vect.Vect;
|
||||
import mightypork.utils.math.vect.VectVal;
|
||||
import mightypork.utils.math.vect.VectView;
|
||||
|
||||
|
||||
/**
|
||||
@@ -125,8 +126,8 @@ public class Convert {
|
||||
return (Boolean) o ? "True" : "False";
|
||||
}
|
||||
|
||||
if (o instanceof Vec) {
|
||||
final Vec c = (Vec) o;
|
||||
if (o instanceof Vect) {
|
||||
final Vect c = (Vect) o;
|
||||
return String.format("[%f;%f;%f]", c.x(), c.y(), c.z());
|
||||
}
|
||||
|
||||
@@ -144,18 +145,17 @@ public class Convert {
|
||||
|
||||
|
||||
/**
|
||||
* Get COORD<br>
|
||||
* Converts special constants to magic coordinate instances.
|
||||
* Get a vector
|
||||
*
|
||||
* @param o object
|
||||
* @param def default value
|
||||
* @return AiCoord
|
||||
* @return vector
|
||||
*/
|
||||
public static VecView toCoord(Object o, Vec def)
|
||||
public static VectVal toVect(Object o, Vect def)
|
||||
{
|
||||
try {
|
||||
if (o == null) return def.value();
|
||||
if (o instanceof Vec) return ((Vec) o).value();
|
||||
if (o instanceof Vect) return ((Vect) o).value();
|
||||
if (o instanceof String) {
|
||||
String s = ((String) o).trim().toUpperCase();
|
||||
|
||||
@@ -171,12 +171,12 @@ public class Convert {
|
||||
final double y = Double.parseDouble(parts[1].trim());
|
||||
|
||||
if (parts.length == 2) {
|
||||
return VecView.make(x, y);
|
||||
return VectVal.make(x, y);
|
||||
}
|
||||
|
||||
final double z = Double.parseDouble(parts[2].trim());
|
||||
|
||||
return VecView.make(x, y, z);
|
||||
return VectVal.make(x, y, z);
|
||||
}
|
||||
}
|
||||
} catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||
@@ -289,9 +289,9 @@ public class Convert {
|
||||
* @param o object
|
||||
* @return Coord
|
||||
*/
|
||||
public static VecView toCoord(Object o)
|
||||
public static VectView toCoord(Object o)
|
||||
{
|
||||
return toCoord(o, VecView.zero());
|
||||
return toVect(o, Vect.ZERO);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user