almost fixed constraints and rects; about time to go sleep now, lol
This commit is contained in:
@@ -32,7 +32,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
|
|||||||
private static final Vec INITIAL_LISTENER_POS = Vec.ZERO;
|
private static final Vec INITIAL_LISTENER_POS = Vec.ZERO;
|
||||||
private static final int MAX_SOURCES = 256;
|
private static final int MAX_SOURCES = 256;
|
||||||
|
|
||||||
private static VecMutable listener = new MutableCoord(0,0,0);
|
private static VecMutable listener = new MutableCoord(0, 0, 0);
|
||||||
|
|
||||||
private static boolean inited;
|
private static boolean inited;
|
||||||
|
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
|
|||||||
|
|
||||||
import mightypork.utils.math.constraints.PluggableContext;
|
import mightypork.utils.math.constraints.PluggableContext;
|
||||||
import mightypork.utils.math.constraints.RectConstraint;
|
import mightypork.utils.math.constraints.RectConstraint;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +18,7 @@ public interface PluggableRenderable extends Renderable, PluggableContext {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
Rect getRect();
|
RectView getRect();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
|
|||||||
|
|
||||||
import mightypork.utils.math.constraints.ContextAdapter;
|
import mightypork.utils.math.constraints.ContextAdapter;
|
||||||
import mightypork.utils.math.constraints.RectConstraint;
|
import mightypork.utils.math.constraints.RectConstraint;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,7 +18,7 @@ public abstract class PluggableRenderer extends ContextAdapter implements Plugga
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return super.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.PluggableRenderer;
|
||||||
import mightypork.gamecore.gui.components.Renderable;
|
import mightypork.gamecore.gui.components.Renderable;
|
||||||
import mightypork.utils.math.constraints.RectConstraint;
|
import mightypork.utils.math.constraints.RectConstraint;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +60,7 @@ public abstract class ElementHolder extends BusNode implements PluggableRenderab
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return context.getRect();
|
return context.getRect();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,11 +6,10 @@ import mightypork.gamecore.render.fonts.FontRenderer;
|
|||||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||||
import mightypork.gamecore.render.fonts.GLFont;
|
import mightypork.gamecore.render.fonts.GLFont;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.RGB;
|
||||||
import mightypork.utils.math.coord.CoordValue;
|
|
||||||
import mightypork.utils.math.coord.MutableCoord;
|
import mightypork.utils.math.coord.MutableCoord;
|
||||||
import mightypork.utils.math.coord.Vec;
|
import mightypork.utils.math.coord.Vec;
|
||||||
import mightypork.utils.math.coord.VecMutable;
|
import mightypork.utils.math.coord.VecMutable;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
import mightypork.utils.string.StringProvider;
|
import mightypork.utils.string.StringProvider;
|
||||||
import mightypork.utils.string.StringProvider.StringWrapper;
|
import mightypork.utils.string.StringProvider.StringWrapper;
|
||||||
|
|
||||||
@@ -31,7 +30,7 @@ public class TextPainter extends PluggableRenderer {
|
|||||||
private boolean shadow;
|
private boolean shadow;
|
||||||
|
|
||||||
private RGB shadowColor = RGB.BLACK;
|
private RGB shadowColor = RGB.BLACK;
|
||||||
private VecMutable shadowOffset = new MutableCoord(1, 1);
|
private final VecMutable shadowOffset = new MutableCoord(1, 1);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +86,7 @@ public class TextPainter extends PluggableRenderer {
|
|||||||
if (text == null) return;
|
if (text == null) return;
|
||||||
|
|
||||||
final String str = text.getString();
|
final String str = text.getString();
|
||||||
final Rect rect = getRect();
|
final RectView rect = getRect();
|
||||||
|
|
||||||
if (shadow) {
|
if (shadow) {
|
||||||
font.draw(str, rect.move(shadowOffset), align, shadowColor);
|
font.draw(str, rect.move(shadowOffset), align, shadowColor);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import mightypork.gamecore.input.KeyStroke;
|
|||||||
import mightypork.gamecore.render.Render;
|
import mightypork.gamecore.render.Render;
|
||||||
import mightypork.utils.math.constraints.RectConstraint;
|
import mightypork.utils.math.constraints.RectConstraint;
|
||||||
import mightypork.utils.math.coord.Vec;
|
import mightypork.utils.math.coord.Vec;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return getDisplay().getRect();
|
return getDisplay().getRect();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package mightypork.gamecore.gui.screens;
|
package mightypork.gamecore.gui.screens;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.control.AppAccess;
|
|
||||||
import mightypork.gamecore.control.AppSubModule;
|
import mightypork.gamecore.control.AppSubModule;
|
||||||
import mightypork.gamecore.control.interf.DefaultImpl;
|
import mightypork.gamecore.control.interf.DefaultImpl;
|
||||||
import mightypork.gamecore.gui.components.Renderable;
|
import mightypork.gamecore.gui.components.Renderable;
|
||||||
@@ -10,7 +9,7 @@ import mightypork.gamecore.input.KeyBindingPool;
|
|||||||
import mightypork.gamecore.input.KeyStroke;
|
import mightypork.gamecore.input.KeyStroke;
|
||||||
import mightypork.utils.math.constraints.RectConstraint;
|
import mightypork.utils.math.constraints.RectConstraint;
|
||||||
import mightypork.utils.math.coord.Vec;
|
import mightypork.utils.math.coord.Vec;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -60,7 +59,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return screen.getRect();
|
return screen.getRect();
|
||||||
}
|
}
|
||||||
@@ -110,6 +109,4 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
|
|||||||
*/
|
*/
|
||||||
public abstract int getPriority();
|
public abstract int getPriority();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,11 @@ import mightypork.gamecore.control.AppModule;
|
|||||||
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
|
||||||
import mightypork.gamecore.control.timing.FpsMeter;
|
import mightypork.gamecore.control.timing.FpsMeter;
|
||||||
import mightypork.utils.logging.Log;
|
import mightypork.utils.logging.Log;
|
||||||
import mightypork.utils.math.constraints.Constraints;
|
|
||||||
import mightypork.utils.math.constraints.NumberConstraint;
|
|
||||||
import mightypork.utils.math.constraints.RectConstraint;
|
import mightypork.utils.math.constraints.RectConstraint;
|
||||||
import mightypork.utils.math.coord.ConstraintCoord;
|
import mightypork.utils.math.coord.FixedCoord;
|
||||||
import mightypork.utils.math.coord.SynthCoord2D;
|
|
||||||
import mightypork.utils.math.coord.Vec;
|
|
||||||
import mightypork.utils.math.coord.VecView;
|
import mightypork.utils.math.coord.VecView;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.FixedRect;
|
||||||
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
import org.lwjgl.LWJGLException;
|
import org.lwjgl.LWJGLException;
|
||||||
@@ -180,7 +177,7 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
|||||||
*/
|
*/
|
||||||
public static VecView getSize()
|
public static VecView getSize()
|
||||||
{
|
{
|
||||||
return size;
|
return new FixedCoord(getWidth(), getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -229,9 +226,9 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return new Rect(Vec.ZERO, getSize());
|
return new FixedRect(getSize());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -243,48 +240,48 @@ public class DisplaySystem extends AppModule implements RectConstraint {
|
|||||||
return fpsMeter.getFPS();
|
return fpsMeter.getFPS();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Vec getCenter()
|
|
||||||
|
public VecView getCenter()
|
||||||
{
|
{
|
||||||
return center;
|
return getSize().half();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final VecView size = new SynthCoord2D() {
|
// private static final VecView size = new SynthCoord2D() {
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public double y()
|
// public double y()
|
||||||
{
|
// {
|
||||||
return getHeight();
|
// return getHeight();
|
||||||
}
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
@Override
|
// @Override
|
||||||
public double x()
|
// public double x()
|
||||||
{
|
// {
|
||||||
return getWidth();
|
// return getWidth();
|
||||||
}
|
// }
|
||||||
};
|
// };
|
||||||
|
//
|
||||||
/** Screen width constraint */
|
// /** Screen width constraint */
|
||||||
private static final NumberConstraint width = size.xc();
|
// private static final NumberConstraint width = size.xc();
|
||||||
|
//
|
||||||
/** Screen height constaint */
|
// /** Screen height constaint */
|
||||||
private static final NumberConstraint height = size.yc();
|
// private static final NumberConstraint height = size.yc();
|
||||||
|
//
|
||||||
|
// private static final VecView center = new SynthCoord2D() {
|
||||||
private static final VecView center = new SynthCoord2D() {
|
//
|
||||||
|
// @Override
|
||||||
@Override
|
// public double y()
|
||||||
public double y()
|
// {
|
||||||
{
|
// return size.half().x();
|
||||||
return size.half().x();
|
// }
|
||||||
}
|
//
|
||||||
|
//
|
||||||
|
// @Override
|
||||||
@Override
|
// public double x()
|
||||||
public double x()
|
// {
|
||||||
{
|
// return size.half().y();
|
||||||
return size.half().y();
|
// }
|
||||||
}
|
// };
|
||||||
};
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,10 +9,8 @@ import mightypork.gamecore.render.textures.TxQuad;
|
|||||||
import mightypork.utils.files.FileUtils;
|
import mightypork.utils.files.FileUtils;
|
||||||
import mightypork.utils.logging.Log;
|
import mightypork.utils.logging.Log;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.RGB;
|
||||||
import mightypork.utils.math.coord.CoordValue;
|
import mightypork.utils.math.coord.FixedCoord;
|
||||||
import mightypork.utils.math.coord.Vec;
|
import mightypork.utils.math.coord.Vec;
|
||||||
import mightypork.utils.math.coord.VecView;
|
|
||||||
import mightypork.utils.math.rect.Rect;
|
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.Rect;
|
||||||
|
|
||||||
import org.lwjgl.opengl.GL11;
|
import org.lwjgl.opengl.GL11;
|
||||||
@@ -29,9 +27,9 @@ import org.newdawn.slick.util.ResourceLoader;
|
|||||||
*/
|
*/
|
||||||
public class Render {
|
public class Render {
|
||||||
|
|
||||||
public static final Vec AXIS_X = new CoordValue(1, 0, 0);
|
public static final Vec AXIS_X = new FixedCoord(1, 0, 0);
|
||||||
public static final Vec AXIS_Y = new CoordValue(0, 1, 0);
|
public static final Vec AXIS_Y = new FixedCoord(0, 1, 0);
|
||||||
public static final Vec AXIS_Z = new CoordValue(0, 0, 1);
|
public static final Vec AXIS_Z = new FixedCoord(0, 0, 1);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -511,7 +509,7 @@ public class Render {
|
|||||||
*/
|
*/
|
||||||
public static void quadTextured(Rect quad, Texture texture)
|
public static void quadTextured(Rect quad, Texture texture)
|
||||||
{
|
{
|
||||||
quadTextured(quad, new Rect(0,0,1,1), texture, RGB.WHITE);
|
quadTextured(quad, Rect.ONE, texture, RGB.WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
package mightypork.gamecore.render.fonts;
|
package mightypork.gamecore.render.fonts;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.gamecore.render.Render;
|
|
||||||
import static mightypork.utils.math.constraints.Constraints.*;
|
import static mightypork.utils.math.constraints.Constraints.*;
|
||||||
|
import mightypork.gamecore.render.Render;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.RGB;
|
||||||
import mightypork.utils.math.coord.Vec;
|
import mightypork.utils.math.coord.Vec;
|
||||||
import mightypork.utils.math.coord.VecView;
|
import mightypork.utils.math.coord.VecView;
|
||||||
@@ -173,7 +173,7 @@ public class FontRenderer {
|
|||||||
* @param height drawing height
|
* @param height drawing height
|
||||||
* @param align horizontal alignment
|
* @param align horizontal alignment
|
||||||
*/
|
*/
|
||||||
public void draw(String text, VecView pos, double height, Align align)
|
public void draw(String text, Vec pos, double height, Align align)
|
||||||
{
|
{
|
||||||
draw(text, pos, height, align, this.color);
|
draw(text, pos, height, align, this.color);
|
||||||
}
|
}
|
||||||
@@ -188,25 +188,25 @@ public class FontRenderer {
|
|||||||
* @param align horizontal alignment
|
* @param align horizontal alignment
|
||||||
* @param color drawing color
|
* @param color drawing color
|
||||||
*/
|
*/
|
||||||
public void draw(String text, VecView pos, double height, Align align, RGB color)
|
public void draw(String text, Vec pos, double height, Align align, RGB color)
|
||||||
{
|
{
|
||||||
|
|
||||||
final double w = getWidth(text, height);
|
final double w = getWidth(text, height);
|
||||||
|
|
||||||
final VecView start;
|
final Vec start;
|
||||||
|
|
||||||
switch (align) {
|
switch (align) {
|
||||||
case LEFT:
|
case LEFT:
|
||||||
start = pos;
|
start = pos.view();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case CENTER:
|
case CENTER:
|
||||||
start = pos.sub(w / 2D, 0);
|
start = pos.view().sub(w / 2D, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case RIGHT:
|
case RIGHT:
|
||||||
default:
|
default:
|
||||||
start = pos.sub(w, 0);
|
start = pos.view().sub(w, 0);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ import mightypork.gamecore.render.fonts.GLFont;
|
|||||||
import mightypork.gamecore.render.textures.FilterMode;
|
import mightypork.gamecore.render.textures.FilterMode;
|
||||||
import mightypork.utils.logging.Log;
|
import mightypork.utils.logging.Log;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.RGB;
|
||||||
import mightypork.utils.math.coord.CoordValue;
|
import mightypork.utils.math.coord.FixedCoord;
|
||||||
import mightypork.utils.math.coord.VecView;
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
import org.lwjgl.BufferUtils;
|
import org.lwjgl.BufferUtils;
|
||||||
@@ -425,7 +425,7 @@ public class CachedFont implements GLFont {
|
|||||||
@Override
|
@Override
|
||||||
public VecView getNeededSpace(String text)
|
public VecView getNeededSpace(String text)
|
||||||
{
|
{
|
||||||
return new CoordValue(getWidth(text), getHeight());
|
return new FixedCoord(getWidth(text), getHeight());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ public class DeferredFont extends DeferredResource implements GLFont {
|
|||||||
*/
|
*/
|
||||||
protected Font getAwtFont(String resource, float size, int style) throws FontFormatException, IOException
|
protected Font getAwtFont(String resource, float size, int style) throws FontFormatException, IOException
|
||||||
{
|
{
|
||||||
try (InputStream in = FileUtils.getResource(resource)) {
|
try(InputStream in = FileUtils.getResource(resource)) {
|
||||||
|
|
||||||
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in);
|
Font awtFont = Font.createFont(Font.TRUETYPE_FONT, in);
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package mightypork.gamecore.render.textures;
|
package mightypork.gamecore.render.textures;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.rect.FixedRect;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.Rect;
|
||||||
|
|
||||||
import org.newdawn.slick.opengl.Texture;
|
import org.newdawn.slick.opengl.Texture;
|
||||||
@@ -64,7 +65,7 @@ public class TxQuad {
|
|||||||
* @param y2 right bottom Y (0-1)
|
* @param y2 right bottom Y (0-1)
|
||||||
*/
|
*/
|
||||||
public TxQuad(Texture tx, double x1, double y1, double x2, double y2) {
|
public TxQuad(Texture tx, double x1, double y1, double x2, double y2) {
|
||||||
this(tx, new Rect(x1, y1, x2, y2));
|
this(tx, new FixedRect(x1, y1, x2, y2));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -13,14 +13,13 @@ import mightypork.gamecore.gui.screens.Screen;
|
|||||||
import mightypork.gamecore.gui.screens.ScreenLayer;
|
import mightypork.gamecore.gui.screens.ScreenLayer;
|
||||||
import mightypork.gamecore.input.KeyStroke;
|
import mightypork.gamecore.input.KeyStroke;
|
||||||
import mightypork.gamecore.input.Keys;
|
import mightypork.gamecore.input.Keys;
|
||||||
import mightypork.gamecore.render.DisplaySystem;
|
|
||||||
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
import mightypork.gamecore.render.fonts.FontRenderer.Align;
|
||||||
import mightypork.rogue.Res;
|
import mightypork.rogue.Res;
|
||||||
import mightypork.utils.math.animation.AnimDouble;
|
import mightypork.utils.math.animation.AnimDouble;
|
||||||
import mightypork.utils.math.animation.Easing;
|
import mightypork.utils.math.animation.Easing;
|
||||||
import mightypork.utils.math.color.RGB;
|
import mightypork.utils.math.color.RGB;
|
||||||
import mightypork.utils.math.coord.AnimCoord;
|
import mightypork.utils.math.coord.AnimCoord;
|
||||||
import mightypork.utils.math.coord.CoordValue;
|
import mightypork.utils.math.coord.FixedCoord;
|
||||||
import mightypork.utils.math.coord.Vec;
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
|
||||||
|
|
||||||
@@ -48,7 +47,7 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
|||||||
tp.setAlign(Align.CENTER);
|
tp.setAlign(Align.CENTER);
|
||||||
tp.setColor(RGB.YELLOW);
|
tp.setColor(RGB.YELLOW);
|
||||||
tp.setText("Meow!");
|
tp.setText("Meow!");
|
||||||
tp.setShadow(RGB.dark(0.8), new CoordValue(2, 2));
|
tp.setShadow(RGB.dark(0.8), new FixedCoord(2, 2));
|
||||||
tp.setContext(_align(_box(64, 64), _mouseX, _mouseY));
|
tp.setContext(_align(_box(64, 64), _mouseX, _mouseY));
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -80,11 +79,9 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
|
|||||||
|
|
||||||
final Vec pos = event.getPos();
|
final Vec pos = event.getPos();
|
||||||
|
|
||||||
final double time = 100;
|
this.pos.animateWithSpeed(pos, 200);
|
||||||
|
|
||||||
size.animate(100 + rand.nextInt(700), time/2D);
|
size.animate(200 + rand.nextInt(600), this.pos.getDuration() / 2);
|
||||||
|
|
||||||
this.pos.animateWithSpeed(pos, 300);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ public class PropertyManager {
|
|||||||
boolean needsSave = false;
|
boolean needsSave = false;
|
||||||
new File(file.getParent()).mkdirs();
|
new File(file.getParent()).mkdirs();
|
||||||
|
|
||||||
try (FileInputStream fis = new FileInputStream(file)) {
|
try(FileInputStream fis = new FileInputStream(file)) {
|
||||||
props.load(fis);
|
props.load(fis);
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
needsSave = true;
|
needsSave = true;
|
||||||
|
|||||||
@@ -72,10 +72,10 @@ public class FileTreeDiff {
|
|||||||
ck1.reset();
|
ck1.reset();
|
||||||
ck2.reset();
|
ck2.reset();
|
||||||
|
|
||||||
try ( FileInputStream in1 = new FileInputStream(pair.a);
|
try(FileInputStream in1 = new FileInputStream(pair.a);
|
||||||
FileInputStream in2 = new FileInputStream(pair.b)) {
|
FileInputStream in2 = new FileInputStream(pair.b)) {
|
||||||
|
|
||||||
try ( CheckedInputStream cin1 = new CheckedInputStream(in1, ck1);
|
try(CheckedInputStream cin1 = new CheckedInputStream(in1, ck1);
|
||||||
CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
|
CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ public class FileUtils {
|
|||||||
public static void copyFile(File source, File target) throws IOException
|
public static void copyFile(File source, File target) throws IOException
|
||||||
{
|
{
|
||||||
|
|
||||||
try ( InputStream in = new FileInputStream(source);
|
try(InputStream in = new FileInputStream(source);
|
||||||
OutputStream out = new FileOutputStream(target)) {
|
OutputStream out = new FileOutputStream(target)) {
|
||||||
|
|
||||||
copyStream(in, out);
|
copyStream(in, out);
|
||||||
@@ -161,7 +161,7 @@ public class FileUtils {
|
|||||||
*/
|
*/
|
||||||
public static String fileToString(File file) throws IOException
|
public static String fileToString(File file) throws IOException
|
||||||
{
|
{
|
||||||
try (FileInputStream fin = new FileInputStream(file)) {
|
try(FileInputStream fin = new FileInputStream(file)) {
|
||||||
|
|
||||||
return streamToString(fin);
|
return streamToString(fin);
|
||||||
}
|
}
|
||||||
@@ -198,7 +198,7 @@ public class FileUtils {
|
|||||||
final List<File> list = new ArrayList<>();
|
final List<File> list = new ArrayList<>();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (File f : dir.listFiles(filter)) {
|
for (final File f : dir.listFiles(filter)) {
|
||||||
list.add(f);
|
list.add(f);
|
||||||
}
|
}
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
@@ -361,7 +361,7 @@ public class FileUtils {
|
|||||||
*/
|
*/
|
||||||
public static void stringToFile(File file, String text) throws IOException
|
public static void stringToFile(File file, String text) throws IOException
|
||||||
{
|
{
|
||||||
try (PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) {
|
try(PrintStream out = new PrintStream(new FileOutputStream(file), false, "UTF-8")) {
|
||||||
|
|
||||||
out.print(text);
|
out.print(text);
|
||||||
|
|
||||||
@@ -482,7 +482,7 @@ public class FileUtils {
|
|||||||
*/
|
*/
|
||||||
public static void resourceToFile(String resname, File file) throws IOException
|
public static void resourceToFile(String resname, File file) throws IOException
|
||||||
{
|
{
|
||||||
try ( InputStream in = FileUtils.getResource(resname);
|
try(InputStream in = FileUtils.getResource(resname);
|
||||||
OutputStream out = new FileOutputStream(file)) {
|
OutputStream out = new FileOutputStream(file)) {
|
||||||
|
|
||||||
FileUtils.copyStream(in, out);
|
FileUtils.copyStream(in, out);
|
||||||
@@ -500,7 +500,7 @@ public class FileUtils {
|
|||||||
*/
|
*/
|
||||||
public static String resourceToString(String resname) throws IOException
|
public static String resourceToString(String resname) throws IOException
|
||||||
{
|
{
|
||||||
try (InputStream in = FileUtils.getResource(resname)) {
|
try(InputStream in = FileUtils.getResource(resname)) {
|
||||||
return streamToString(in);
|
return streamToString(in);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ public class ZipBuilder {
|
|||||||
|
|
||||||
out.putNextEntry(new ZipEntry(path));
|
out.putNextEntry(new ZipEntry(path));
|
||||||
|
|
||||||
try (InputStream in = FileUtils.stringToStream(text)) {
|
try(InputStream in = FileUtils.stringToStream(text)) {
|
||||||
FileUtils.copyStream(in, out);
|
FileUtils.copyStream(in, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -91,7 +91,7 @@ public class ZipBuilder {
|
|||||||
|
|
||||||
out.putNextEntry(new ZipEntry(path));
|
out.putNextEntry(new ZipEntry(path));
|
||||||
|
|
||||||
try (InputStream in = FileUtils.getResource(resPath)) {
|
try(InputStream in = FileUtils.getResource(resPath)) {
|
||||||
FileUtils.copyStream(in, out);
|
FileUtils.copyStream(in, out);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ public class ZipUtils {
|
|||||||
*/
|
*/
|
||||||
public static List<String> extractZip(File file, File outputDir, StringFilter filter) throws IOException
|
public static List<String> extractZip(File file, File outputDir, StringFilter filter) throws IOException
|
||||||
{
|
{
|
||||||
try (ZipFile zip = new ZipFile(file)) {
|
try(ZipFile zip = new ZipFile(file)) {
|
||||||
return extractZip(zip, outputDir, filter);
|
return extractZip(zip, outputDir, filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -88,7 +88,7 @@ public class ZipUtils {
|
|||||||
*/
|
*/
|
||||||
public static List<String> listZip(File zipFile) throws IOException
|
public static List<String> listZip(File zipFile) throws IOException
|
||||||
{
|
{
|
||||||
try (ZipFile zip = new ZipFile(zipFile)) {
|
try(ZipFile zip = new ZipFile(zipFile)) {
|
||||||
return listZip(zip);
|
return listZip(zip);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,7 +132,7 @@ public class ZipUtils {
|
|||||||
{
|
{
|
||||||
destFile.getParentFile().mkdirs();
|
destFile.getParentFile().mkdirs();
|
||||||
|
|
||||||
try ( InputStream in = zip.getInputStream(entry);
|
try(InputStream in = zip.getInputStream(entry);
|
||||||
BufferedInputStream is = new BufferedInputStream(in);
|
BufferedInputStream is = new BufferedInputStream(in);
|
||||||
FileOutputStream fos = new FileOutputStream(destFile);
|
FileOutputStream fos = new FileOutputStream(destFile);
|
||||||
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
|
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
|
||||||
@@ -169,7 +169,7 @@ public class ZipUtils {
|
|||||||
|
|
||||||
public static boolean entryExists(File selectedFile, String string)
|
public static boolean entryExists(File selectedFile, String string)
|
||||||
{
|
{
|
||||||
try (ZipFile zf = new ZipFile(selectedFile)) {
|
try(ZipFile zf = new ZipFile(selectedFile)) {
|
||||||
return zf.getEntry(string) != null;
|
return zf.getEntry(string) != null;
|
||||||
} catch (final Exception e) {
|
} catch (final Exception e) {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ public class Ion {
|
|||||||
*/
|
*/
|
||||||
public static Object fromFile(File file) throws IonException
|
public static Object fromFile(File file) throws IonException
|
||||||
{
|
{
|
||||||
try (InputStream in = new FileInputStream(file)) {
|
try(InputStream in = new FileInputStream(file)) {
|
||||||
|
|
||||||
final Object obj = fromStream(in);
|
final Object obj = fromStream(in);
|
||||||
return obj;
|
return obj;
|
||||||
@@ -113,7 +113,7 @@ public class Ion {
|
|||||||
*/
|
*/
|
||||||
public static void toFile(File path, Object obj) throws IonException
|
public static void toFile(File path, Object obj) throws IonException
|
||||||
{
|
{
|
||||||
try (OutputStream out = new FileOutputStream(path)) {
|
try(OutputStream out = new FileOutputStream(path)) {
|
||||||
final String f = path.toString();
|
final String f = path.toString();
|
||||||
final File dir = new File(f.substring(0, f.lastIndexOf(File.separator)));
|
final File dir = new File(f.substring(0, f.lastIndexOf(File.separator)));
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import mightypork.utils.math.Calc.Deg;
|
|||||||
import mightypork.utils.math.Calc.Rad;
|
import mightypork.utils.math.Calc.Rad;
|
||||||
import mightypork.utils.math.constraints.NumberConstraint;
|
import mightypork.utils.math.constraints.NumberConstraint;
|
||||||
import mightypork.utils.math.coord.ConstraintCoord;
|
import mightypork.utils.math.coord.ConstraintCoord;
|
||||||
import mightypork.utils.math.coord.CoordProxy;
|
|
||||||
import mightypork.utils.math.coord.Vec;
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -137,7 +137,7 @@ public class Polar {
|
|||||||
*
|
*
|
||||||
* @return coord
|
* @return coord
|
||||||
*/
|
*/
|
||||||
public CoordProxy toCoord()
|
public VecView toCoord()
|
||||||
{
|
{
|
||||||
// lazy init
|
// lazy init
|
||||||
if (coord == null) {
|
if (coord == null) {
|
||||||
@@ -158,7 +158,7 @@ public class Polar {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
return coord.view();
|
return coord;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ public class Range {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new range
|
* Create new range
|
||||||
*
|
*
|
||||||
@@ -48,10 +47,12 @@ public class Range {
|
|||||||
this.max = minmax;
|
this.max = minmax;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Make sure min is <= max
|
* Make sure min is <= max
|
||||||
*/
|
*/
|
||||||
private void norm() {
|
private void norm()
|
||||||
|
{
|
||||||
if (min > max) {
|
if (min > max) {
|
||||||
final double t = min;
|
final double t = min;
|
||||||
min = max;
|
min = max;
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ public class AnimDouble implements Updateable, Pauseable, NumberConstraint {
|
|||||||
*
|
*
|
||||||
* @return number
|
* @return number
|
||||||
*/
|
*/
|
||||||
public double getGetStart()
|
public double getStart()
|
||||||
{
|
{
|
||||||
return from;
|
return from;
|
||||||
}
|
}
|
||||||
@@ -105,6 +105,18 @@ public class AnimDouble implements Updateable, Pauseable, NumberConstraint {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double getDuration()
|
||||||
|
{
|
||||||
|
return duration;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double getElapsed()
|
||||||
|
{
|
||||||
|
return elapsedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get value at delta time
|
* Get value at delta time
|
||||||
*
|
*
|
||||||
@@ -139,7 +151,7 @@ public class AnimDouble implements Updateable, Pauseable, NumberConstraint {
|
|||||||
@Override
|
@Override
|
||||||
public void update(double delta)
|
public void update(double delta)
|
||||||
{
|
{
|
||||||
if (paused) return;
|
if (paused || isFinished()) return;
|
||||||
|
|
||||||
elapsedTime = Calc.clampd(elapsedTime + delta, 0, duration);
|
elapsedTime = Calc.clampd(elapsedTime + delta, 0, duration);
|
||||||
if (isFinished()) {
|
if (isFinished()) {
|
||||||
|
|||||||
@@ -4,8 +4,13 @@ package mightypork.utils.math.constraints;
|
|||||||
import mightypork.gamecore.control.timing.Poller;
|
import mightypork.gamecore.control.timing.Poller;
|
||||||
import mightypork.gamecore.input.InputSystem;
|
import mightypork.gamecore.input.InputSystem;
|
||||||
import mightypork.gamecore.render.DisplaySystem;
|
import mightypork.gamecore.render.DisplaySystem;
|
||||||
import mightypork.utils.math.coord.*;
|
import mightypork.utils.math.coord.FixedCoord;
|
||||||
|
import mightypork.utils.math.coord.SynthCoord3D;
|
||||||
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
import mightypork.utils.math.rect.FixedRect;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.Rect;
|
||||||
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,54 +21,79 @@ import mightypork.utils.math.rect.Rect;
|
|||||||
*/
|
*/
|
||||||
public class Constraints {
|
public class Constraints {
|
||||||
|
|
||||||
/* ================= Variables ================= */
|
public static RectCache _cache(final RectConstraint rc)
|
||||||
|
{
|
||||||
|
return new RectCache(rc);
|
||||||
|
}
|
||||||
|
|
||||||
public static final NumberConstraint _mouseX = new NumberConstraint() {
|
|
||||||
|
public static RectCache _cache(final Poller poller, final RectConstraint rc)
|
||||||
|
{
|
||||||
|
return new RectCache(poller, rc);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert {@link Number} to {@link NumberConstraint} if needed
|
||||||
|
*
|
||||||
|
* @param o unknown numeric value
|
||||||
|
* @return converted
|
||||||
|
*/
|
||||||
|
public static NumberConstraint _n(final Object o)
|
||||||
|
{
|
||||||
|
if (o instanceof NumberConstraint) return (NumberConstraint) o;
|
||||||
|
|
||||||
|
if (o instanceof Number) return new NumberConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return InputSystem.getMousePos().x();
|
return ((Number) o).doubleValue();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
public static final NumberConstraint _mouseY = new NumberConstraint() {
|
throw new IllegalArgumentException("Invalid numeric type.");
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getValue()
|
/**
|
||||||
|
* Convert {@link Number} or {@link NumberConstraint} to double (current
|
||||||
|
* value)
|
||||||
|
*
|
||||||
|
* @param o unknown numeric value
|
||||||
|
* @return double value
|
||||||
|
*/
|
||||||
|
static double toDouble(final Object o)
|
||||||
{
|
{
|
||||||
return InputSystem.getMousePos().y();
|
return _n(o).getValue();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
public static final NumberConstraint _mousePos = new NumberConstraint() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getValue()
|
/**
|
||||||
|
* Convert {@link VecConstraint} to {@link VecArith}.
|
||||||
|
*
|
||||||
|
* @param o unknown numeric value
|
||||||
|
* @return double value
|
||||||
|
*/
|
||||||
|
static VecView vec(final VecConstraint o)
|
||||||
{
|
{
|
||||||
return InputSystem.getMousePos().y();
|
return o.getVec();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
public static final NumberConstraint _screenW = new NumberConstraint() {
|
|
||||||
|
|
||||||
@Override
|
/**
|
||||||
public double getValue()
|
* Convert {@link RectConstraint} to {@link Rect}.
|
||||||
|
*
|
||||||
|
* @param o unknown numeric value
|
||||||
|
* @return double value
|
||||||
|
*/
|
||||||
|
static RectView toRect(final RectConstraint o)
|
||||||
{
|
{
|
||||||
return DisplaySystem.getWidth();
|
return o.getRect();
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
public static final NumberConstraint _screenH = new NumberConstraint() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getValue()
|
|
||||||
{
|
|
||||||
return DisplaySystem.getHeight();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/* ================= Arithmetics ================= */
|
// =================== Number constraints ====================
|
||||||
|
|
||||||
public static NumberConstraint _min(final Object a, final Object b)
|
public static NumberConstraint _min(final Object a, final Object b)
|
||||||
{
|
{
|
||||||
@@ -72,7 +102,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return Math.min(num(a), num(b));
|
return Math.min(toDouble(a), toDouble(b));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -85,7 +115,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return Math.max(num(a), num(b));
|
return Math.max(toDouble(a), toDouble(b));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -135,9 +165,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).round();
|
return toRect(r).round();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -189,7 +219,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return num(a) + num(b);
|
return toDouble(a) + toDouble(b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -202,7 +232,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return num(a) - num(b);
|
return toDouble(a) - toDouble(b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -215,7 +245,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return num(a) * num(b);
|
return toDouble(a) * toDouble(b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -234,7 +264,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return num(a) / num(b);
|
return toDouble(a) / toDouble(b);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -247,28 +277,26 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double getValue()
|
public double getValue()
|
||||||
{
|
{
|
||||||
return num(whole) * (num(percent) / 100);
|
return toDouble(whole) * (toDouble(percent) / 100);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ================= Layout utilities ================= */
|
|
||||||
|
|
||||||
public static RectConstraint _row(final RectConstraint r, final int rows, final int index)
|
public static RectConstraint _row(final RectConstraint r, final int rows, final int index)
|
||||||
{
|
{
|
||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final double height = rect(r).getHeight();
|
final double height = toRect(r).getHeight();
|
||||||
final double perRow = height / rows;
|
final double perRow = height / rows;
|
||||||
|
|
||||||
final Vec origin = rect(r).getOrigin().add(0, perRow * index);
|
final Vec origin = toRect(r).getOrigin().add(0, perRow * index);
|
||||||
final Vec size = rect(r).getSize().setY(perRow);
|
final Vec size = toRect(r).getSize().setY(perRow);
|
||||||
|
|
||||||
return new Rect(origin, size);
|
return new FixedRect(origin, size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -279,15 +307,15 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final double width = rect(r).getWidth();
|
final double width = toRect(r).getWidth();
|
||||||
final double perCol = width / columns;
|
final double perCol = width / columns;
|
||||||
|
|
||||||
final Vec origin = rect(r).getOrigin().add(perCol * index, 0);
|
final Vec origin = toRect(r).getOrigin().add(perCol * index, 0);
|
||||||
final Vec size = rect(r).getSize().setX(perCol);
|
final Vec size = toRect(r).getSize().setX(perCol);
|
||||||
|
|
||||||
return new Rect(origin, size);
|
return new FixedRect(origin, size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -298,22 +326,22 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final double height = rect(r).getHeight();
|
final double height = toRect(r).getHeight();
|
||||||
final double width = rect(r).getHeight();
|
final double width = toRect(r).getHeight();
|
||||||
final double perRow = height / rows;
|
final double perRow = height / rows;
|
||||||
final double perCol = width / cols;
|
final double perCol = width / cols;
|
||||||
|
|
||||||
final Vec origin = rect(r).getOrigin().add(perCol * left, perRow * (rows - top - 1));
|
final Vec origin = toRect(r).getOrigin().add(perCol * left, perRow * (rows - top - 1));
|
||||||
|
|
||||||
return new Rect(origin, perCol, perRow);
|
return new FixedRect(origin, perCol, perRow);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ================= Rect manipulation ================= */
|
/* ================= RectView manipulation ================= */
|
||||||
|
|
||||||
public static RectConstraint _shrink(RectConstraint r, Object shrink)
|
public static RectConstraint _shrink(RectConstraint r, Object shrink)
|
||||||
{
|
{
|
||||||
@@ -333,9 +361,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(num(left), num(top), num(right), num(bottom));
|
return toRect(r).shrink(toDouble(left), toDouble(top), toDouble(right), toDouble(bottom));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -346,9 +374,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(0, num(shrink), 0, 0);
|
return toRect(r).shrink(0, toDouble(shrink), 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -359,9 +387,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(0, 0, 0, num(shrink));
|
return toRect(r).shrink(0, 0, 0, toDouble(shrink));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -372,9 +400,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(num(shrink), 0, 0, 0);
|
return toRect(r).shrink(toDouble(shrink), 0, 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -385,9 +413,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(0, 0, num(shrink), 0);
|
return toRect(r).shrink(0, 0, toDouble(shrink), 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -411,9 +439,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).grow(num(left), num(top), num(right), num(bottom));
|
return toRect(r).grow(toDouble(left), toDouble(top), toDouble(right), toDouble(bottom));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -424,9 +452,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).grow(0, num(grow), 0, 0);
|
return toRect(r).grow(0, toDouble(grow), 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -437,9 +465,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).grow(0, 0, 0, num(grow));
|
return toRect(r).grow(0, 0, 0, toDouble(grow));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -450,9 +478,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).grow(num(grow), 0, 0, 0);
|
return toRect(r).grow(toDouble(grow), 0, 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -463,9 +491,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).grow(0, 0, num(grow), 0);
|
return toRect(r).grow(0, 0, toDouble(grow), 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -484,9 +512,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return new Rect(vec(origin), num(width), num(height));
|
return new FixedRect(vec(origin), toDouble(width), toDouble(height));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -497,9 +525,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return new Rect(0, 0, num(width), num(height));
|
return new FixedRect(0, 0, toDouble(width), toDouble(height));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -510,11 +538,11 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final Vec origin = rect(r).getOrigin();
|
final Vec origin = toRect(r).getOrigin();
|
||||||
|
|
||||||
return new Rect(origin.x(), origin.y(), num(width), num(height));
|
return new FixedRect(origin.x(), origin.y(), toDouble(width), toDouble(height));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -525,11 +553,11 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final Vec origin = rect(r).getOrigin();
|
final Vec origin = toRect(r).getOrigin();
|
||||||
|
|
||||||
return new Rect(origin.x() + num(x), origin.y() + num(y), num(width), num(height));
|
return new FixedRect(origin.x() + toDouble(x), origin.y() + toDouble(y), toDouble(width), toDouble(height));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -540,11 +568,11 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final VecView origin = rect(r).getOrigin();
|
final VecView origin = toRect(r).getOrigin();
|
||||||
|
|
||||||
return new Rect(origin.add(num(left), num(top)), origin.add(num(right), num(bottom)));
|
return new FixedRect(origin.add(toDouble(left), toDouble(top)), origin.add(toDouble(right), toDouble(bottom)));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -555,12 +583,12 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final VecView size = rect(r).getSize();
|
final VecView size = toRect(r).getSize();
|
||||||
final VecView center = centerTo.getRect().getCenter();
|
final VecView center = centerTo.getRect().getCenter();
|
||||||
|
|
||||||
return new Rect(center.sub(size.half()), size);
|
return new FixedRect(center.sub(size.half()), size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -571,15 +599,16 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
VecView size = rect(r).getSize();
|
final VecView size = toRect(r).getSize();
|
||||||
|
|
||||||
return new Rect(vec(centerTo).sub(size.half()), size);
|
return new FixedRect(vec(centerTo).sub(size.half()), size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static RectConstraint _align(final RectConstraint r, final Vec centerTo)
|
public static RectConstraint _align(final RectConstraint r, final Vec centerTo)
|
||||||
{
|
{
|
||||||
return _align(r, new VecWrapper(centerTo));
|
return _align(r, new VecWrapper(centerTo));
|
||||||
@@ -591,12 +620,12 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
final VecView size = rect(r).getSize();
|
final VecView size = toRect(r).getSize();
|
||||||
final VecView v = new CoordValue(num(x), num(y));
|
final VecView v = new FixedCoord(toDouble(x), toDouble(y));
|
||||||
|
|
||||||
return new Rect(v.sub(size.half()), size);
|
return new FixedRect(v.sub(size.half()), size);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -607,11 +636,11 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
Vec v = move.getVec();
|
final Vec v = move.getVec();
|
||||||
|
|
||||||
return rect(r).move(v);
|
return toRect(r).move(v);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -622,24 +651,24 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).move(num(x), num(y));
|
return toRect(r).move(toDouble(x), toDouble(y));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ================= Rect bounds ================= */
|
/* ================= RectView bounds ================= */
|
||||||
|
|
||||||
public static RectConstraint _left_edge(final RectConstraint r)
|
public static RectConstraint _left_edge(final RectConstraint r)
|
||||||
{
|
{
|
||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(0, 0, rect(r).getWidth(), 0);
|
return toRect(r).shrink(0, 0, toRect(r).getWidth(), 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -650,9 +679,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(0, 0, 0, rect(r).getHeight());
|
return toRect(r).shrink(0, 0, 0, toRect(r).getHeight());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -663,9 +692,9 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(rect(r).getWidth(), 0, 0, 0);
|
return toRect(r).shrink(toRect(r).getWidth(), 0, 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -676,16 +705,14 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return rect(r).shrink(0, rect(r).getHeight(), 0, 0);
|
return toRect(r).shrink(0, toRect(r).getHeight(), 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* ================= Coords ================= */
|
|
||||||
|
|
||||||
public static NumberConstraint _x(final VecConstraint c)
|
public static NumberConstraint _x(final VecConstraint c)
|
||||||
{
|
{
|
||||||
return new NumberConstraint() {
|
return new NumberConstraint() {
|
||||||
@@ -780,21 +807,21 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double x()
|
public double x()
|
||||||
{
|
{
|
||||||
return vec(c).x() + num(x);
|
return vec(c).x() + toDouble(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double y()
|
public double y()
|
||||||
{
|
{
|
||||||
return vec(c).y() + num(y);
|
return vec(c).y() + toDouble(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
return vec(c).z() + num(z);
|
return vec(c).z() + toDouble(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -844,21 +871,21 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double x()
|
public double x()
|
||||||
{
|
{
|
||||||
return vec(c).x() - num(x);
|
return vec(c).x() - toDouble(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double y()
|
public double y()
|
||||||
{
|
{
|
||||||
return vec(c).y() - num(y);
|
return vec(c).y() - toDouble(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
return vec(c).z() - num(z);
|
return vec(c).z() - toDouble(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -874,21 +901,21 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double x()
|
public double x()
|
||||||
{
|
{
|
||||||
return vec(c).x() * num(mul);
|
return vec(c).x() * toDouble(mul);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double y()
|
public double y()
|
||||||
{
|
{
|
||||||
return vec(c).y() * num(mul);
|
return vec(c).y() * toDouble(mul);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
return vec(c).z() * num(mul);
|
return vec(c).z() * toDouble(mul);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
@@ -904,7 +931,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public VecView getVec()
|
public VecView getVec()
|
||||||
{
|
{
|
||||||
return rect(r).getOrigin();
|
return toRect(r).getOrigin();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -917,7 +944,7 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public VecView getVec()
|
public VecView getVec()
|
||||||
{
|
{
|
||||||
return rect(r).getSize();
|
return toRect(r).getSize();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -990,7 +1017,7 @@ public class Constraints {
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Zero-sized rect at given coord
|
* Zero-sized RectView at given coord
|
||||||
*
|
*
|
||||||
* @param c coord
|
* @param c coord
|
||||||
* @return rect
|
* @return rect
|
||||||
@@ -1000,11 +1027,11 @@ public class Constraints {
|
|||||||
return new RectConstraint() {
|
return new RectConstraint() {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
Vec v = vec(c);
|
final Vec v = vec(c);
|
||||||
|
|
||||||
return new Rect(v.x(), v.y(), 0, 0);
|
return new FixedRect(v.x(), v.y(), 0, 0);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -1041,6 +1068,60 @@ public class Constraints {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================= Variables ================= */
|
||||||
|
|
||||||
|
public static final NumberConstraint _mouseX = new NumberConstraint() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getValue()
|
||||||
|
{
|
||||||
|
return InputSystem.getMousePos().x();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final NumberConstraint _mouseY = new NumberConstraint() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getValue()
|
||||||
|
{
|
||||||
|
return InputSystem.getMousePos().y();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
public static final NumberConstraint _mousePos = new NumberConstraint() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getValue()
|
||||||
|
{
|
||||||
|
return InputSystem.getMousePos().y();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final NumberConstraint _screenW = new NumberConstraint() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getValue()
|
||||||
|
{
|
||||||
|
return DisplaySystem.getWidth();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public static final NumberConstraint _screenH = new NumberConstraint() {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public double getValue()
|
||||||
|
{
|
||||||
|
return DisplaySystem.getHeight();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/* ================= Arithmetics ================= */
|
||||||
|
|
||||||
|
/* ================= Layout utilities ================= */
|
||||||
|
|
||||||
|
/* ================= Coords ================= */
|
||||||
|
|
||||||
/* ================= Coords ================= */
|
/* ================= Coords ================= */
|
||||||
|
|
||||||
public static NumberConstraint _x(final Vec c)
|
public static NumberConstraint _x(final Vec c)
|
||||||
@@ -1116,21 +1197,21 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double x()
|
public double x()
|
||||||
{
|
{
|
||||||
return c.x() + num(x);
|
return c.x() + toDouble(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double y()
|
public double y()
|
||||||
{
|
{
|
||||||
return c.y() + num(y);
|
return c.y() + toDouble(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
return c.z() + num(z);
|
return c.z() + toDouble(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -1180,21 +1261,21 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double x()
|
public double x()
|
||||||
{
|
{
|
||||||
return c.x() - num(x);
|
return c.x() - toDouble(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double y()
|
public double y()
|
||||||
{
|
{
|
||||||
return c.y() - num(y);
|
return c.y() - toDouble(y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
return c.z() - num(z);
|
return c.z() - toDouble(z);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@@ -1210,35 +1291,36 @@ public class Constraints {
|
|||||||
@Override
|
@Override
|
||||||
public double x()
|
public double x()
|
||||||
{
|
{
|
||||||
return c.x() * num(mul);
|
return c.x() * toDouble(mul);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double y()
|
public double y()
|
||||||
{
|
{
|
||||||
return c.y() * num(mul);
|
return c.y() * toDouble(mul);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
return c.z() * num(mul);
|
return c.z() * toDouble(mul);
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static VecView _origin(final Rect r)
|
public static VecView _origin(final Rect r)
|
||||||
{
|
{
|
||||||
return r.getOrigin().view();
|
return r.getOrigin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static VecView _size(final Rect r)
|
public static VecView _size(final Rect r)
|
||||||
{
|
{
|
||||||
return r.getSize().view();
|
return r.getSize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -1306,78 +1388,4 @@ public class Constraints {
|
|||||||
{
|
{
|
||||||
return _add(_origin(r), _width(r), _half(_height(r)));
|
return _add(_origin(r), _width(r), _half(_height(r)));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* ================= Helpers ================= */
|
|
||||||
|
|
||||||
public static RectCache _cache(final RectConstraint rc)
|
|
||||||
{
|
|
||||||
return new RectCache(rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public static RectCache _cache(final Poller poller, final RectConstraint rc)
|
|
||||||
{
|
|
||||||
return new RectCache(poller, rc);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert {@link Number} to {@link NumberConstraint} if needed
|
|
||||||
*
|
|
||||||
* @param o unknown numeric value
|
|
||||||
* @return converted
|
|
||||||
*/
|
|
||||||
public static NumberConstraint _n(final Object o)
|
|
||||||
{
|
|
||||||
if (o instanceof NumberConstraint) return (NumberConstraint) o;
|
|
||||||
|
|
||||||
if (o instanceof Number) return new NumberConstraint() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double getValue()
|
|
||||||
{
|
|
||||||
return ((Number) o).doubleValue();
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
throw new IllegalArgumentException("Invalid numeric type.");
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert {@link Number} or {@link NumberConstraint} to double (current
|
|
||||||
* value)
|
|
||||||
*
|
|
||||||
* @param o unknown numeric value
|
|
||||||
* @return double value
|
|
||||||
*/
|
|
||||||
private static double num(final Object o)
|
|
||||||
{
|
|
||||||
return _n(o).getValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert {@link VecConstraint} to {@link VecArith}.
|
|
||||||
*
|
|
||||||
* @param o unknown numeric value
|
|
||||||
* @return double value
|
|
||||||
*/
|
|
||||||
private static VecView vec(final VecConstraint o)
|
|
||||||
{
|
|
||||||
return o.getVec();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Convert {@link RectConstraint} to {@link Rect}.
|
|
||||||
*
|
|
||||||
* @param o unknown numeric value
|
|
||||||
* @return double value
|
|
||||||
*/
|
|
||||||
private static Rect rect(final RectConstraint o)
|
|
||||||
{
|
|
||||||
return o.getRect();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.utils.math.constraints;
|
package mightypork.utils.math.constraints;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -22,7 +22,7 @@ public abstract class ContextAdapter implements PluggableContext {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return backing.getRect();
|
return backing.getRect();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ public interface NumberConstraint {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return current value
|
* @return current value
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.utils.math.constraints;
|
package mightypork.utils.math.constraints;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -18,6 +18,6 @@ public interface PluggableContext extends RectConstraint {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
abstract Rect getRect();
|
abstract RectView getRect();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ package mightypork.utils.math.constraints;
|
|||||||
|
|
||||||
import mightypork.gamecore.control.timing.Pollable;
|
import mightypork.gamecore.control.timing.Pollable;
|
||||||
import mightypork.gamecore.control.timing.Poller;
|
import mightypork.gamecore.control.timing.Poller;
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.MutableRect;
|
||||||
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -16,7 +17,7 @@ import mightypork.utils.math.rect.Rect;
|
|||||||
public class RectCache implements RectConstraint, Pollable {
|
public class RectCache implements RectConstraint, Pollable {
|
||||||
|
|
||||||
private final RectConstraint observed;
|
private final RectConstraint observed;
|
||||||
private final Rect cached = new Rect();
|
private final MutableRect cached = new MutableRect();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,9 +42,9 @@ public class RectCache implements RectConstraint, Pollable {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rect getRect()
|
public RectView getRect()
|
||||||
{
|
{
|
||||||
return cached;
|
return cached.view();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package mightypork.utils.math.constraints;
|
package mightypork.utils.math.constraints;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.rect.Rect;
|
import mightypork.utils.math.rect.RectView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -14,5 +14,5 @@ public interface RectConstraint {
|
|||||||
/**
|
/**
|
||||||
* @return rect region
|
* @return rect region
|
||||||
*/
|
*/
|
||||||
Rect getRect();
|
RectView getRect();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
package mightypork.utils.math.constraints;
|
package mightypork.utils.math.constraints;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.coord.VecView;
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
public interface VecConstraint {
|
public interface VecConstraint {
|
||||||
|
|
||||||
VecView getVec();
|
VecView getVec();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import mightypork.utils.math.animation.Easing;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class AnimCoord extends VecMutableImpl<AnimCoord> implements Pauseable, Updateable {
|
public class AnimCoord extends VecMutableImpl implements Pauseable, Updateable {
|
||||||
|
|
||||||
private final AnimDouble x, y, z;
|
private final AnimDouble x, y, z;
|
||||||
|
|
||||||
@@ -63,9 +63,18 @@ public class AnimCoord extends VecMutableImpl<AnimCoord> implements Pauseable, U
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public AnimCoord add(VecArith offset, double speed)
|
public AnimCoord add(Vec offset, double speed)
|
||||||
{
|
{
|
||||||
animate(offset.add(this), speed);
|
animate(offset.x() - x(), offset.y() - y(), offset.z() - z(), speed);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public AnimCoord animate(double x, double y, double z, double duration)
|
||||||
|
{
|
||||||
|
this.x.animate(x, duration);
|
||||||
|
this.y.animate(y, duration);
|
||||||
|
this.z.animate(z, duration);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -81,8 +90,8 @@ public class AnimCoord extends VecMutableImpl<AnimCoord> implements Pauseable, U
|
|||||||
|
|
||||||
public void animateWithSpeed(Vec target, double unitsPerSecond)
|
public void animateWithSpeed(Vec target, double unitsPerSecond)
|
||||||
{
|
{
|
||||||
double dist = distTo(target);
|
final double dist = distTo(target);
|
||||||
double duration = dist / unitsPerSecond;
|
final double duration = dist / unitsPerSecond;
|
||||||
animate(target, duration);
|
animate(target, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,4 +135,21 @@ public class AnimCoord extends VecMutableImpl<AnimCoord> implements Pauseable, U
|
|||||||
return x.isFinished(); // BUNO
|
return x.isFinished(); // BUNO
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double getDuration()
|
||||||
|
{
|
||||||
|
return x.getDuration(); // BUNO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double getElapsed()
|
||||||
|
{
|
||||||
|
return x.getElapsed(); // BUNO
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public double getProgress()
|
||||||
|
{
|
||||||
|
return x.getProgress(); // BUNO
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
package mightypork.utils.math.coord;
|
package mightypork.utils.math.coord;
|
||||||
|
|
||||||
import mightypork.utils.math.constraints.VecConstraint;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <p><b>[ Use Vec.view() method to make a proxy! ]</b></p>
|
* <p>
|
||||||
* <p>View of another coordinate, immutable.<br>
|
* <b>[ Use Vec.view() method to make a proxy! ]</b>
|
||||||
* Operations yield a new {@link MutableCoord} with the result.</p>
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* View of another coordinate, immutable.<br>
|
||||||
|
* Operations yield a new {@link MutableCoord} with the result.
|
||||||
|
* </p>
|
||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
@@ -25,6 +27,7 @@ public class CoordProxy extends VecView {
|
|||||||
this.observed = observed;
|
this.observed = observed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoordProxy view()
|
public CoordProxy view()
|
||||||
{
|
{
|
||||||
|
|||||||
+4
-6
@@ -1,30 +1,28 @@
|
|||||||
package mightypork.utils.math.coord;
|
package mightypork.utils.math.coord;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Coordinate with immutable numeric values.<br>
|
* Coordinate with immutable numeric values.<br>
|
||||||
* Operations yield a new {@link MutableCoord} with the result.
|
* Operations yield a new {@link MutableCoord} with the result.
|
||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class CoordValue extends VecView {
|
public class FixedCoord extends VecView {
|
||||||
|
|
||||||
private final double x, y, z;
|
private final double x, y, z;
|
||||||
|
|
||||||
|
|
||||||
public CoordValue(Vec other) {
|
public FixedCoord(Vec other) {
|
||||||
this(other.x(), other.y(), other.z());
|
this(other.x(), other.y(), other.z());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CoordValue(double x, double y) {
|
public FixedCoord(double x, double y) {
|
||||||
this(x, y, 0);
|
this(x, y, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public CoordValue(double x, double y, double z) {
|
public FixedCoord(double x, double y, double z) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
@@ -7,7 +7,7 @@ package mightypork.utils.math.coord;
|
|||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public class MutableCoord extends VecMutableImpl<MutableCoord> {
|
public class MutableCoord extends VecMutableImpl {
|
||||||
|
|
||||||
private double x, y, z;
|
private double x, y, z;
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package mightypork.utils.math.coord;
|
package mightypork.utils.math.coord;
|
||||||
|
|
||||||
import mightypork.utils.math.constraints.NumberConstraint;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 2D coord for anonymous implementations.<br>
|
* 2D coord for anonymous implementations.<br>
|
||||||
@@ -14,9 +12,11 @@ public abstract class SynthCoord2D extends VecView {
|
|||||||
@Override
|
@Override
|
||||||
public abstract double x();
|
public abstract double x();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract double y();
|
public abstract double y();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public double z()
|
public double z()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,9 +1,6 @@
|
|||||||
package mightypork.utils.math.coord;
|
package mightypork.utils.math.coord;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.constraints.NumberConstraint;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 3D immutable coord for anonymous implementations.<br>
|
* 3D immutable coord for anonymous implementations.<br>
|
||||||
* Operations yield a new {@link MutableCoord} with the result.
|
* Operations yield a new {@link MutableCoord} with the result.
|
||||||
|
|||||||
@@ -4,10 +4,15 @@ package mightypork.utils.math.coord;
|
|||||||
import mightypork.utils.math.constraints.NumberConstraint;
|
import mightypork.utils.math.constraints.NumberConstraint;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The most basic Vec methods
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
public interface Vec {
|
public interface Vec {
|
||||||
|
|
||||||
public static final VecView ZERO = new CoordValue(0, 0, 0);
|
public static final VecView ZERO = new FixedCoord(0, 0, 0);
|
||||||
public static final VecView ONE = new CoordValue(1, 1, 1);
|
public static final VecView ONE = new FixedCoord(1, 1, 1);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -87,7 +92,7 @@ public interface Vec {
|
|||||||
*
|
*
|
||||||
* @return a mutable copy
|
* @return a mutable copy
|
||||||
*/
|
*/
|
||||||
MutableCoord copy();
|
VecMutable copy();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +100,6 @@ public interface Vec {
|
|||||||
*
|
*
|
||||||
* @return immutable view
|
* @return immutable view
|
||||||
*/
|
*/
|
||||||
CoordProxy view();
|
VecView view();
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
+32
-25
@@ -1,14 +1,12 @@
|
|||||||
package mightypork.utils.math.coord;
|
package mightypork.utils.math.coord;
|
||||||
|
|
||||||
import mightypork.utils.math.constraints.VecConstraint;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 3D coordinate methods
|
* 3D coordinate methods
|
||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
interface VecArith extends Vec {
|
interface VecMath<V> extends Vec {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set X coordinate (if immutable, in a copy).
|
* Set X coordinate (if immutable, in a copy).
|
||||||
@@ -16,7 +14,7 @@ interface VecArith extends Vec {
|
|||||||
* @param x x coordinate
|
* @param x x coordinate
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec setX(double x);
|
V setX(double x);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,7 +23,7 @@ interface VecArith extends Vec {
|
|||||||
* @param y y coordinate
|
* @param y y coordinate
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec setY(double y);
|
V setY(double y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -34,7 +32,7 @@ interface VecArith extends Vec {
|
|||||||
* @param z z coordinate
|
* @param z z coordinate
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec setZ(double z);
|
V setZ(double z);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -63,18 +61,27 @@ interface VecArith extends Vec {
|
|||||||
double size();
|
double size();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get absolute value (positive)
|
||||||
|
*
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
V abs();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if zero
|
* @return true if zero
|
||||||
*/
|
*/
|
||||||
boolean isZero();
|
boolean isZero();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create vector from this point to other point
|
* Create vector from this point to other point
|
||||||
*
|
*
|
||||||
* @param point second point
|
* @param point second point
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec vecTo(Vec point);
|
V vecTo(Vec point);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -83,7 +90,7 @@ interface VecArith extends Vec {
|
|||||||
* @param point other point
|
* @param point other point
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec midTo(Vec point);
|
V midTo(Vec point);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -92,7 +99,7 @@ interface VecArith extends Vec {
|
|||||||
* @param vec offset
|
* @param vec offset
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec add(Vec vec);
|
V add(Vec vec);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -103,7 +110,7 @@ interface VecArith extends Vec {
|
|||||||
* @param y y offset
|
* @param y y offset
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec add(double x, double y);
|
V add(double x, double y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -114,7 +121,7 @@ interface VecArith extends Vec {
|
|||||||
* @param z z offset
|
* @param z z offset
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec add(double x, double y, double z);
|
V add(double x, double y, double z);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -122,7 +129,7 @@ interface VecArith extends Vec {
|
|||||||
*
|
*
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec half();
|
V half();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -131,7 +138,7 @@ interface VecArith extends Vec {
|
|||||||
* @param d multiplier
|
* @param d multiplier
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec mul(double d);
|
V mul(double d);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,7 +147,7 @@ interface VecArith extends Vec {
|
|||||||
* @param vec vector of multipliers
|
* @param vec vector of multipliers
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec mul(Vec vec);
|
V mul(Vec vec);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -151,7 +158,7 @@ interface VecArith extends Vec {
|
|||||||
* @param y y multiplier
|
* @param y y multiplier
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec mul(double x, double y);
|
V mul(double x, double y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -162,7 +169,7 @@ interface VecArith extends Vec {
|
|||||||
* @param z z multiplier
|
* @param z z multiplier
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec mul(double x, double y, double z);
|
V mul(double x, double y, double z);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -170,7 +177,7 @@ interface VecArith extends Vec {
|
|||||||
*
|
*
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec round();
|
V round();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -178,7 +185,7 @@ interface VecArith extends Vec {
|
|||||||
*
|
*
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec floor();
|
V floor();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -186,7 +193,7 @@ interface VecArith extends Vec {
|
|||||||
*
|
*
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec ceil();
|
V ceil();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -195,7 +202,7 @@ interface VecArith extends Vec {
|
|||||||
* @param vec offset
|
* @param vec offset
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec sub(Vec vec);
|
V sub(Vec vec);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -206,7 +213,7 @@ interface VecArith extends Vec {
|
|||||||
* @param y y offset
|
* @param y y offset
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
VecArith sub(double x, double y);
|
V sub(double x, double y);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -217,7 +224,7 @@ interface VecArith extends Vec {
|
|||||||
* @param z z offset
|
* @param z z offset
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec sub(double x, double y, double z);
|
V sub(double x, double y, double z);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -225,7 +232,7 @@ interface VecArith extends Vec {
|
|||||||
*
|
*
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec neg();
|
V neg();
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -234,7 +241,7 @@ interface VecArith extends Vec {
|
|||||||
* @param size size we need
|
* @param size size we need
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
Vec norm(double size);
|
V norm(double size);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -243,6 +250,6 @@ interface VecArith extends Vec {
|
|||||||
* @param vec other vector
|
* @param vec other vector
|
||||||
* @return result
|
* @return result
|
||||||
*/
|
*/
|
||||||
public Vec cross(Vec vec);
|
V cross(Vec vec);
|
||||||
|
|
||||||
}
|
}
|
||||||
+21
-13
@@ -10,7 +10,7 @@ import mightypork.utils.math.constraints.NumberConstraint;
|
|||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
* @param <V> Return type of methods
|
* @param <V> Return type of methods
|
||||||
*/
|
*/
|
||||||
abstract class VecImpl<V extends VecArith> implements VecArith {
|
abstract class VecMathImpl<V> implements VecMath<V> {
|
||||||
|
|
||||||
private NumberConstraint constraintZ, constraintY, constraintX;
|
private NumberConstraint constraintZ, constraintY, constraintX;
|
||||||
|
|
||||||
@@ -89,14 +89,14 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public MutableCoord copy()
|
public VecMutable copy()
|
||||||
{
|
{
|
||||||
return new MutableCoord(this);
|
return new MutableCoord(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoordProxy view()
|
public VecView view()
|
||||||
{
|
{
|
||||||
if (view == null) view = new CoordProxy(this);
|
if (view == null) view = new CoordProxy(this);
|
||||||
|
|
||||||
@@ -176,7 +176,7 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
@Override
|
@Override
|
||||||
public double size()
|
public double size()
|
||||||
{
|
{
|
||||||
double x = x(), y = y(), z = z();
|
final double x = x(), y = y(), z = z();
|
||||||
return Math.sqrt(x * x + y * y + z * z);
|
return Math.sqrt(x * x + y * y + z * z);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +188,13 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public V abs()
|
||||||
|
{
|
||||||
|
return result(Math.abs(x()), Math.abs(y()), Math.abs(z()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V add(Vec vec)
|
public V add(Vec vec)
|
||||||
{
|
{
|
||||||
@@ -212,9 +219,9 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
@Override
|
@Override
|
||||||
public double distTo(Vec point)
|
public double distTo(Vec point)
|
||||||
{
|
{
|
||||||
double dx = x() - point.x();
|
final double dx = x() - point.x();
|
||||||
double dy = y() - point.y();
|
final double dy = y() - point.y();
|
||||||
double dz = z() - point.z();
|
final double dz = z() - point.z();
|
||||||
|
|
||||||
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
return Math.sqrt(dx * dx + dy * dy + dz * dz);
|
||||||
}
|
}
|
||||||
@@ -223,9 +230,9 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
@Override
|
@Override
|
||||||
public V midTo(Vec point)
|
public V midTo(Vec point)
|
||||||
{
|
{
|
||||||
double dx = (point.x() - x()) * 0.5;
|
final double dx = (point.x() - x()) * 0.5;
|
||||||
double dy = (point.y() - y()) * 0.5;
|
final double dy = (point.y() - y()) * 0.5;
|
||||||
double dz = (point.z() - z()) * 0.5;
|
final double dz = (point.z() - z()) * 0.5;
|
||||||
|
|
||||||
return result(dx, dy, dz);
|
return result(dx, dy, dz);
|
||||||
}
|
}
|
||||||
@@ -346,7 +353,7 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
{
|
{
|
||||||
if (isZero()) return result(x(), y(), z()); // can't norm zero vector
|
if (isZero()) return result(x(), y(), z()); // can't norm zero vector
|
||||||
|
|
||||||
double k = size / size();
|
final double k = size / size();
|
||||||
|
|
||||||
return mul(k);
|
return mul(k);
|
||||||
}
|
}
|
||||||
@@ -355,7 +362,7 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode()
|
public int hashCode()
|
||||||
{
|
{
|
||||||
int prime = 31;
|
final int prime = 31;
|
||||||
int result = 1;
|
int result = 1;
|
||||||
result = prime * result + Double.valueOf(x()).hashCode();
|
result = prime * result + Double.valueOf(x()).hashCode();
|
||||||
result = prime * result + Double.valueOf(y()).hashCode();
|
result = prime * result + Double.valueOf(y()).hashCode();
|
||||||
@@ -370,11 +377,12 @@ abstract class VecImpl<V extends VecArith> implements VecArith {
|
|||||||
if (this == obj) return true;
|
if (this == obj) return true;
|
||||||
if (obj == null) return false;
|
if (obj == null) return false;
|
||||||
if (!(obj instanceof Vec)) return false;
|
if (!(obj instanceof Vec)) return false;
|
||||||
Vec other = (Vec) obj;
|
final Vec other = (Vec) obj;
|
||||||
|
|
||||||
return x() == other.x() && y() == other.y() && z() == other.z();
|
return x() == other.x() && y() == other.y() && z() == other.z();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString()
|
public String toString()
|
||||||
{
|
{
|
||||||
@@ -2,11 +2,11 @@ package mightypork.utils.math.coord;
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mutable coord interface. This coord can be changed at will.
|
* Mutable coord
|
||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public interface VecMutable extends VecArith {
|
public interface VecMutable extends VecMath<VecMutable> {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set coordinates to match other coord.
|
* Set coordinates to match other coord.
|
||||||
|
|||||||
@@ -5,21 +5,23 @@ package mightypork.utils.math.coord;
|
|||||||
* Mutable vec default implementation
|
* Mutable vec default implementation
|
||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
* @param <V> Return type of methods
|
|
||||||
*/
|
*/
|
||||||
abstract class VecMutableImpl<V extends VecMutable> extends VecImpl<V> implements VecMutable {
|
abstract class VecMutableImpl extends VecMathImpl<VecMutable> implements VecMutable {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract double x();
|
public abstract double x();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract double y();
|
public abstract double y();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract double z();
|
public abstract double z();
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract V result(double x, double y, double z);
|
public abstract VecMutable result(double x, double y, double z);
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -30,14 +32,14 @@ abstract class VecMutableImpl<V extends VecMutable> extends VecImpl<V> implement
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V setTo(double x, double y, double z)
|
public VecMutable setTo(double x, double y, double z)
|
||||||
{
|
{
|
||||||
return result(x, y, z);
|
return result(x, y, z);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public V setTo(double x, double y)
|
public VecMutable setTo(double x, double y)
|
||||||
{
|
{
|
||||||
return result(x, y, z());
|
return result(x, y, z());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,19 +1,24 @@
|
|||||||
package mightypork.utils.math.coord;
|
package mightypork.utils.math.coord;
|
||||||
|
|
||||||
import mightypork.utils.math.constraints.VecConstraint;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Read-only coordinate, operations with it will yield a new {@link MutableCoord} with the result.
|
* Read-only coordinate, operations with it will yield a new
|
||||||
|
* {@link MutableCoord} with the result.
|
||||||
*
|
*
|
||||||
* @author MightyPork
|
* @author MightyPork
|
||||||
*/
|
*/
|
||||||
public abstract class VecView extends VecImpl<CoordValue> {
|
public abstract class VecView extends VecMathImpl<VecView> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CoordValue result(double x, double y, double z)
|
public VecView result(double x, double y, double z)
|
||||||
{
|
{
|
||||||
return new CoordValue(x,y,z);
|
return new FixedCoord(x, y, z);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VecView view()
|
||||||
|
{
|
||||||
|
return this; // already not mutable
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.coord.FixedCoord;
|
||||||
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
|
public class FixedRect extends RectView {
|
||||||
|
|
||||||
|
private final VecView pos;
|
||||||
|
private final VecView size;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at 0,0 with zero size
|
||||||
|
*/
|
||||||
|
public FixedRect() {
|
||||||
|
pos = Vec.ZERO;
|
||||||
|
size = Vec.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at 0,0 with given size
|
||||||
|
*
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public FixedRect(double width, double height) {
|
||||||
|
this(0, 0, width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at given origin, with given size.
|
||||||
|
*
|
||||||
|
* @param origin
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public FixedRect(Vec origin, double width, double height) {
|
||||||
|
this(origin.x(), origin.y(), width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at 0,0 with given size.
|
||||||
|
*
|
||||||
|
* @param size
|
||||||
|
*/
|
||||||
|
public FixedRect(Vec size) {
|
||||||
|
this(0, 0, size.x(), size.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at given origin, with given size.
|
||||||
|
*
|
||||||
|
* @param origin
|
||||||
|
* @param size
|
||||||
|
*/
|
||||||
|
public FixedRect(Vec origin, Vec size) {
|
||||||
|
this(origin.x(), origin.y(), size.x(), size.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at given origin, with given size.
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public FixedRect(double x, double y, double width, double height) {
|
||||||
|
pos = new FixedCoord(x, y);
|
||||||
|
size = new FixedCoord(Math.abs(width), Math.abs(height));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create as copy of another
|
||||||
|
*
|
||||||
|
* @param other copied
|
||||||
|
*/
|
||||||
|
public FixedRect(Rect other) {
|
||||||
|
this(other.getOrigin(), other.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VecView getOrigin()
|
||||||
|
{
|
||||||
|
return pos;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VecView getSize()
|
||||||
|
{
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,233 @@
|
|||||||
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.coord.MutableCoord;
|
||||||
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
import mightypork.utils.math.coord.VecMutable;
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
|
public class MutableRect extends RectImpl<RectMutable> implements RectMutable {
|
||||||
|
|
||||||
|
private final VecMutable pos = new MutableCoord();
|
||||||
|
private final VecMutable size = new MutableCoord();
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at 0,0 with zero size
|
||||||
|
*/
|
||||||
|
public MutableRect() {
|
||||||
|
// keep default zeros
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at 0,0 with given size
|
||||||
|
*
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public MutableRect(double width, double height) {
|
||||||
|
this.pos.setTo(0, 0);
|
||||||
|
this.size.setTo(width, height).abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at given origin, with given size.
|
||||||
|
*
|
||||||
|
* @param origin
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public MutableRect(Vec origin, double width, double height) {
|
||||||
|
this.pos.setTo(origin);
|
||||||
|
this.size.setTo(width, height).abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at 0,0 with given size.
|
||||||
|
*
|
||||||
|
* @param size
|
||||||
|
*/
|
||||||
|
public MutableRect(Vec size) {
|
||||||
|
this(0, 0, size.x(), size.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at given origin, with given size.
|
||||||
|
*
|
||||||
|
* @param origin
|
||||||
|
* @param size
|
||||||
|
*/
|
||||||
|
public MutableRect(Vec origin, Vec size) {
|
||||||
|
this.pos.setTo(origin);
|
||||||
|
this.size.setTo(size).abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create at given origin, with given size.
|
||||||
|
*
|
||||||
|
* @param x
|
||||||
|
* @param y
|
||||||
|
* @param width
|
||||||
|
* @param height
|
||||||
|
*/
|
||||||
|
public MutableRect(double x, double y, double width, double height) {
|
||||||
|
pos.setTo(x, y);
|
||||||
|
size.setTo(width, height).abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create as copy of another
|
||||||
|
*
|
||||||
|
* @param other copied
|
||||||
|
*/
|
||||||
|
public MutableRect(Rect other) {
|
||||||
|
this(other.getOrigin(), other.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to other rect's coordinates
|
||||||
|
*
|
||||||
|
* @param rect other rect
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void setTo(Rect rect)
|
||||||
|
{
|
||||||
|
setTo(rect.getOrigin(), rect.getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTo(Vec origin, Vec size)
|
||||||
|
{
|
||||||
|
this.pos.setTo(origin);
|
||||||
|
this.size.setTo(size).abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setTo(Vec origin, double width, double height)
|
||||||
|
{
|
||||||
|
this.pos.setTo(origin);
|
||||||
|
this.size.setTo(width, height).abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setOrigin(Vec origin)
|
||||||
|
{
|
||||||
|
this.pos.setTo(origin);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setSize(Vec size)
|
||||||
|
{
|
||||||
|
this.size.setTo(size).abs();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add X and Y to origin
|
||||||
|
*
|
||||||
|
* @param x x to add
|
||||||
|
* @param y y to add
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RectMutable move(double x, double y)
|
||||||
|
{
|
||||||
|
pos.add(x, y);
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a copy
|
||||||
|
*
|
||||||
|
* @return copy
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RectMutable copy()
|
||||||
|
{
|
||||||
|
return new MutableRect(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink the rect
|
||||||
|
*
|
||||||
|
* @param left shrink
|
||||||
|
* @param top shrink
|
||||||
|
* @param right shrink
|
||||||
|
* @param bottom shrink
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RectMutable shrink(double left, double top, double right, double bottom)
|
||||||
|
{
|
||||||
|
pos.add(left, top);
|
||||||
|
size.sub(left + right, top + bottom).abs();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grow the rect
|
||||||
|
*
|
||||||
|
* @param left growth
|
||||||
|
* @param top growth
|
||||||
|
* @param right growth
|
||||||
|
* @param bottom growth
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RectMutable grow(double left, double top, double right, double bottom)
|
||||||
|
{
|
||||||
|
pos.sub(left, top);
|
||||||
|
size.add(left + right, top + bottom).abs();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Round coords
|
||||||
|
*
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public RectMutable round()
|
||||||
|
{
|
||||||
|
pos.round();
|
||||||
|
size.round();
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VecView getOrigin()
|
||||||
|
{
|
||||||
|
return pos.view();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VecView getSize()
|
||||||
|
{
|
||||||
|
return size.view();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RectView view()
|
||||||
|
{
|
||||||
|
return new FixedRect(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,398 +1,75 @@
|
|||||||
package mightypork.utils.math.rect;
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
import mightypork.utils.math.constraints.RectConstraint;
|
|
||||||
import mightypork.utils.math.constraints.VecConstraint;
|
|
||||||
import mightypork.utils.math.coord.MutableCoord;
|
|
||||||
import mightypork.utils.math.coord.SynthCoord2D;
|
|
||||||
import mightypork.utils.math.coord.Vec;
|
|
||||||
import mightypork.utils.math.coord.VecMutable;
|
|
||||||
import mightypork.utils.math.coord.VecView;
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
public class Rect {
|
/**
|
||||||
|
* Common methods for all kinds of Rects
|
||||||
public static final Rect ONE = new Rect(0, 0, 1, 1); // FIXME
|
|
||||||
private final VecMutable pos = new MutableCoord();
|
|
||||||
private final VecMutable size = new MutableCoord();
|
|
||||||
private final VecView center = new SynthCoord2D() {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double y()
|
|
||||||
{
|
|
||||||
return pos.x() + size.x() / 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public double x()
|
|
||||||
{
|
|
||||||
return pos.y() + size.y() / 2;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create at 0,0 with zero size
|
|
||||||
*/
|
|
||||||
public Rect() {
|
|
||||||
// keep default zeros
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create at 0,0 with given size
|
|
||||||
*
|
*
|
||||||
* @param width
|
* @author MightyPork
|
||||||
* @param height
|
|
||||||
*/
|
*/
|
||||||
public Rect(double width, double height) {
|
public interface Rect {
|
||||||
this.pos.setTo(0, 0);
|
|
||||||
this.size.setTo(width, height);
|
RectView ONE = new FixedRect(0, 0, 1, 1);
|
||||||
norm();
|
RectView ZERO = new FixedRect(0, 0, 0, 0);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create at given origin, with given size.
|
* Get a writable copy
|
||||||
*
|
|
||||||
* @param origin
|
|
||||||
* @param width
|
|
||||||
* @param height
|
|
||||||
*/
|
|
||||||
public Rect(Vec origin, double width, double height) {
|
|
||||||
this.pos.setTo(origin);
|
|
||||||
this.size.setTo(width, height);
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* make sure the rect doesn't have negative size.
|
|
||||||
*/
|
|
||||||
private void norm()
|
|
||||||
{
|
|
||||||
if (size.x() < 0) {
|
|
||||||
pos.sub(-size.x(), 0);
|
|
||||||
size.mul(-1, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (size.y() < 0) {
|
|
||||||
pos.sub(0, -size.y());
|
|
||||||
size.mul(1, -1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create at given origin, with given size.
|
|
||||||
*
|
|
||||||
* @param origin
|
|
||||||
* @param size
|
|
||||||
*/
|
|
||||||
public Rect(Vec origin, Vec size) {
|
|
||||||
this.pos.setTo(origin);
|
|
||||||
this.size.setTo(size);
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create at given origin, with given size.
|
|
||||||
*
|
|
||||||
* @param x
|
|
||||||
* @param y
|
|
||||||
* @param width
|
|
||||||
* @param height
|
|
||||||
*/
|
|
||||||
public Rect(double x, double y, double width, double height) {
|
|
||||||
pos.setTo(x, y);
|
|
||||||
size.setTo(width, height);
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create as copy of another
|
|
||||||
*
|
|
||||||
* @param other copied
|
|
||||||
*/
|
|
||||||
public Rect(Rect other) {
|
|
||||||
this(other.pos, other.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set to other rect's coordinates
|
|
||||||
*
|
|
||||||
* @param rect other rect
|
|
||||||
*/
|
|
||||||
public void setTo(Rect rect)
|
|
||||||
{
|
|
||||||
setTo(rect.pos, rect.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setTo(Vec origin, Vec size)
|
|
||||||
{
|
|
||||||
this.pos.setTo(origin);
|
|
||||||
this.size.setTo(size);
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setOrigin(Vec origin)
|
|
||||||
{
|
|
||||||
this.pos.setTo(origin);
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public void setSize(Vec size)
|
|
||||||
{
|
|
||||||
this.size.setTo(size);
|
|
||||||
norm();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add vector to origin
|
|
||||||
*
|
|
||||||
* @param move offset vector
|
|
||||||
* @return result
|
|
||||||
*/
|
|
||||||
public Rect move(Vec move)
|
|
||||||
{
|
|
||||||
move(move.x(), move.y());
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Add X and Y to origin
|
|
||||||
*
|
|
||||||
* @param x x to add
|
|
||||||
* @param y y to add
|
|
||||||
* @return result
|
|
||||||
*/
|
|
||||||
public Rect move(double x, double y)
|
|
||||||
{
|
|
||||||
pos.add(x, y);
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Get a copy
|
|
||||||
*
|
*
|
||||||
* @return copy
|
* @return copy
|
||||||
*/
|
*/
|
||||||
public Rect copy()
|
RectMutable copy();
|
||||||
{
|
|
||||||
return new Rect(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shrink to sides
|
* Get a readonly copy
|
||||||
*
|
*
|
||||||
* @param shrink shrink size (horisontal and vertical)
|
* @return copy
|
||||||
* @return result
|
|
||||||
*/
|
*/
|
||||||
public Rect shrink(Vec shrink)
|
RectView view();
|
||||||
{
|
|
||||||
return shrink(shrink.x(), shrink.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shrink to sides at sides
|
* @return origin
|
||||||
*
|
|
||||||
* @param x horizontal shrink
|
|
||||||
* @param y vertical shrink
|
|
||||||
* @return result
|
|
||||||
*/
|
*/
|
||||||
public Rect shrink(double x, double y)
|
VecView getOrigin();
|
||||||
{
|
|
||||||
return shrink(x, y, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Shrink the rect
|
* @return center
|
||||||
*
|
|
||||||
* @param left shrink
|
|
||||||
* @param top shrink
|
|
||||||
* @param right shrink
|
|
||||||
* @param bottom shrink
|
|
||||||
* @return result
|
|
||||||
*/
|
*/
|
||||||
public Rect shrink(double left, double top, double right, double bottom)
|
VecView getCenter();
|
||||||
{
|
|
||||||
pos.add(left, top);
|
|
||||||
size.sub(left + right, top + bottom);
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grow to sides
|
* @return rect size
|
||||||
*
|
|
||||||
* @param grow grow size (added to each side)
|
|
||||||
* @return grown copy
|
|
||||||
*/
|
*/
|
||||||
public Rect grow(Vec grow)
|
VecView getSize();
|
||||||
{
|
|
||||||
return grow(grow.x(), grow.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grow to sides
|
* @return rect width
|
||||||
*
|
|
||||||
* @param x horizontal grow
|
|
||||||
* @param y vertical grow
|
|
||||||
* @return result
|
|
||||||
*/
|
*/
|
||||||
public Rect grow(double x, double y)
|
double getWidth();
|
||||||
{
|
|
||||||
return grow(x, y, x, y);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Grow the rect
|
* @return rect height
|
||||||
*
|
|
||||||
* @param left growth
|
|
||||||
* @param top growth
|
|
||||||
* @param right growth
|
|
||||||
* @param bottom growth
|
|
||||||
* @return result
|
|
||||||
*/
|
*/
|
||||||
public Rect grow(double left, double top, double right, double bottom)
|
double getHeight();
|
||||||
{
|
|
||||||
pos.sub(left, top);
|
|
||||||
size.add(left + right, top + bottom);
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
double xMin();
|
||||||
* Check if point is inside this rectangle
|
|
||||||
*
|
|
||||||
* @param point point to test
|
|
||||||
* @return is inside
|
|
||||||
*/
|
|
||||||
public boolean contains(Vec point)
|
|
||||||
{
|
|
||||||
final double x = point.x(), y = point.y();
|
|
||||||
|
|
||||||
final double x1 = pos.x(), y1 = pos.y();
|
|
||||||
final double x2 = x1 + size.x(), y2 = y1 + size.y();
|
|
||||||
|
|
||||||
return x >= x1 && y >= y1 && x <= x2 && y <= y2;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
double xMax();
|
||||||
* Round coords
|
|
||||||
*
|
|
||||||
* @return result
|
|
||||||
*/
|
|
||||||
public Rect round()
|
|
||||||
{
|
|
||||||
pos.round();
|
|
||||||
size.round();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
double yMin();
|
||||||
* Get offset copy (subtract)
|
|
||||||
*
|
|
||||||
* @param move offset vector
|
|
||||||
* @return result
|
|
||||||
*/
|
|
||||||
public Rect sub(Vec move)
|
|
||||||
{
|
|
||||||
return sub(move.x(), move.y());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
double yMax();
|
||||||
* Subtract X and Y from all coordinates
|
|
||||||
*
|
|
||||||
* @param x x to subtract
|
|
||||||
* @param y y to subtract
|
|
||||||
* @return result
|
|
||||||
*/
|
|
||||||
Rect sub(double x, double y)
|
|
||||||
{
|
|
||||||
pos.sub(x, y);
|
|
||||||
norm();
|
|
||||||
return this;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public VecView getOrigin()
|
|
||||||
{
|
|
||||||
return pos.view();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public VecView getSize()
|
|
||||||
{
|
|
||||||
return size.view();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public VecView getCenter()
|
|
||||||
{
|
|
||||||
return center;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double getWidth()
|
|
||||||
{
|
|
||||||
return size.x();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double getHeight()
|
|
||||||
{
|
|
||||||
return size.y();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString()
|
|
||||||
{
|
|
||||||
return String.format("[%s-%s]", pos.toString(), pos.view().add(size).toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double xMin()
|
|
||||||
{
|
|
||||||
return pos.x();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double xMax()
|
|
||||||
{
|
|
||||||
return pos.x() + size.x();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double yMin()
|
|
||||||
{
|
|
||||||
return pos.y();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public double yMax()
|
|
||||||
{
|
|
||||||
return pos.y() + size.y();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,121 @@
|
|||||||
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
|
public abstract class RectImpl<T extends Rect> implements RectMath<T> {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final VecView getCenter()
|
||||||
|
{
|
||||||
|
return getOrigin().add(getSize().half());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final double getWidth()
|
||||||
|
{
|
||||||
|
return getSize().x();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final double getHeight()
|
||||||
|
{
|
||||||
|
return getSize().y();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final double xMin()
|
||||||
|
{
|
||||||
|
return getOrigin().x();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final double xMax()
|
||||||
|
{
|
||||||
|
return getOrigin().x() + getSize().x();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final double yMin()
|
||||||
|
{
|
||||||
|
return getOrigin().y();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final double yMax()
|
||||||
|
{
|
||||||
|
return getOrigin().y() + getSize().y();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final T move(Vec move)
|
||||||
|
{
|
||||||
|
return move(move.x(), move.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final T shrink(Vec shrink)
|
||||||
|
{
|
||||||
|
return shrink(shrink.x(), shrink.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final T shrink(double x, double y)
|
||||||
|
{
|
||||||
|
return shrink(x, y, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final T grow(Vec grow)
|
||||||
|
{
|
||||||
|
return grow(grow.x(), grow.y());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final T grow(double x, double y)
|
||||||
|
{
|
||||||
|
return grow(x, y, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RectView view()
|
||||||
|
{
|
||||||
|
return new RectProxy(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public final boolean contains(Vec point)
|
||||||
|
{
|
||||||
|
final double x = point.x();
|
||||||
|
final double y = point.y();
|
||||||
|
|
||||||
|
final double x1 = getOrigin().x();
|
||||||
|
final double y1 = getOrigin().y();
|
||||||
|
final double x2 = x1 + getSize().x();
|
||||||
|
final double y2 = y1 + getSize().y();
|
||||||
|
|
||||||
|
return x >= x1 && y >= y1 && x <= x2 && y <= y2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString()
|
||||||
|
{
|
||||||
|
return String.format("Rect[ %s - %s ]", getOrigin().toString(), getOrigin().add(getSize()));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,111 @@
|
|||||||
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Operations available in rects
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
|
interface RectMath<T extends Rect> extends Rect {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add vector to origin
|
||||||
|
*
|
||||||
|
* @param move offset vector
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T move(Vec move);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add X and Y to origin
|
||||||
|
*
|
||||||
|
* @param x x to add
|
||||||
|
* @param y y to add
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T move(double x, double y);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink to sides
|
||||||
|
*
|
||||||
|
* @param shrink shrink size (horisontal and vertical)
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T shrink(Vec shrink);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink to sides at sides
|
||||||
|
*
|
||||||
|
* @param x horizontal shrink
|
||||||
|
* @param y vertical shrink
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T shrink(double x, double y);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Shrink the rect
|
||||||
|
*
|
||||||
|
* @param left shrink
|
||||||
|
* @param top shrink
|
||||||
|
* @param right shrink
|
||||||
|
* @param bottom shrink
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T shrink(double left, double top, double right, double bottom);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grow to sides
|
||||||
|
*
|
||||||
|
* @param grow grow size (added to each side)
|
||||||
|
* @return grown copy
|
||||||
|
*/
|
||||||
|
T grow(Vec grow);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grow to sides
|
||||||
|
*
|
||||||
|
* @param x horizontal grow
|
||||||
|
* @param y vertical grow
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T grow(double x, double y);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Grow the rect
|
||||||
|
*
|
||||||
|
* @param left growth
|
||||||
|
* @param top growth
|
||||||
|
* @param right growth
|
||||||
|
* @param bottom growth
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T grow(double left, double top, double right, double bottom);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check if point is inside this rectangle
|
||||||
|
*
|
||||||
|
* @param point point to test
|
||||||
|
* @return is inside
|
||||||
|
*/
|
||||||
|
boolean contains(Vec point);
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Round coords
|
||||||
|
*
|
||||||
|
* @return result
|
||||||
|
*/
|
||||||
|
T round();
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,28 @@
|
|||||||
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
|
||||||
|
|
||||||
|
public interface RectMutable extends Rect {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set to other rect's coordinates
|
||||||
|
*
|
||||||
|
* @param rect other rect
|
||||||
|
*/
|
||||||
|
void setTo(Rect rect);
|
||||||
|
|
||||||
|
|
||||||
|
void setTo(Vec origin, Vec size);
|
||||||
|
|
||||||
|
|
||||||
|
void setTo(Vec origin, double width, double height);
|
||||||
|
|
||||||
|
|
||||||
|
void setOrigin(Vec origin);
|
||||||
|
|
||||||
|
|
||||||
|
void setSize(Vec size);
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immutable rect accessor
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
|
public class RectProxy extends RectView {
|
||||||
|
|
||||||
|
private final Rect observed;
|
||||||
|
|
||||||
|
|
||||||
|
public RectProxy(Rect observed) {
|
||||||
|
this.observed = observed;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VecView getOrigin()
|
||||||
|
{
|
||||||
|
return observed.getOrigin();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VecView getSize()
|
||||||
|
{
|
||||||
|
return observed.getSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package mightypork.utils.math.rect;
|
||||||
|
|
||||||
|
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Immutable rect
|
||||||
|
*
|
||||||
|
* @author MightyPork
|
||||||
|
*/
|
||||||
|
public abstract class RectView extends RectImpl<RectView> {
|
||||||
|
|
||||||
|
protected RectView result(VecView origin, VecView size)
|
||||||
|
{
|
||||||
|
return new FixedRect(origin, size);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RectView move(double x, double y)
|
||||||
|
{
|
||||||
|
return result(getOrigin().add(x, y), getSize());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RectView shrink(double left, double top, double right, double bottom)
|
||||||
|
{
|
||||||
|
return result(getOrigin().add(left, top), getSize().sub(left + right, top + bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RectView grow(double left, double top, double right, double bottom)
|
||||||
|
{
|
||||||
|
return result(getOrigin().sub(left, top), getSize().add(left + right, top + bottom));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RectView round()
|
||||||
|
{
|
||||||
|
return result(getOrigin().round(), getSize().round());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public MutableRect copy()
|
||||||
|
{
|
||||||
|
return new MutableRect(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public RectView view()
|
||||||
|
{
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract VecView getOrigin();
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public abstract VecView getSize();
|
||||||
|
|
||||||
|
}
|
||||||
+3
@@ -1,3 +1,6 @@
|
|||||||
|
package mightypork.utils.math.rect.xx;
|
||||||
|
|
||||||
|
|
||||||
//package mightypork.utils.math.rect;
|
//package mightypork.utils.math.rect;
|
||||||
//
|
//
|
||||||
//import mightypork.utils.math.constraints.NumberConstraint;
|
//import mightypork.utils.math.constraints.NumberConstraint;
|
||||||
+10
-7
@@ -1,3 +1,6 @@
|
|||||||
|
package mightypork.utils.math.rect.xx;
|
||||||
|
|
||||||
|
|
||||||
//package mightypork.utils.math.rect;
|
//package mightypork.utils.math.rect;
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -17,8 +20,8 @@
|
|||||||
// */
|
// */
|
||||||
//public class Rectd implements RectConstraint, IRect {
|
//public class Rectd implements RectConstraint, IRect {
|
||||||
//
|
//
|
||||||
// public static final IRect ZERO = new Rect(0, 0, 0, 0).freeze();
|
// public static final IRect ZERO = new FixedRect(0, 0, 0, 0).freeze();
|
||||||
// public static final Rect ONE = new Rect(0, 0, 1, 1).freeze();
|
// public static final Rect ONE = new FixedRect(0, 0, 1, 1).freeze();
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
// /**
|
// /**
|
||||||
@@ -44,7 +47,7 @@
|
|||||||
// */
|
// */
|
||||||
// public static Rect fromSize(VecArith min, double width, double height)
|
// public static Rect fromSize(VecArith min, double width, double height)
|
||||||
// {
|
// {
|
||||||
// return new Rect(min.copy(), min.add(width, height));
|
// return new FixedRect(min.copy(), min.add(width, height));
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -84,7 +87,7 @@
|
|||||||
// */
|
// */
|
||||||
// public static Rect fromSize(double xmin, double ymin, double width, double height)
|
// public static Rect fromSize(double xmin, double ymin, double width, double height)
|
||||||
// {
|
// {
|
||||||
// return new Rect(xmin, ymin, xmin + width, ymin + height);
|
// return new FixedRect(xmin, ymin, xmin + width, ymin + height);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
// /** Lowest coordinates xy */
|
// /** Lowest coordinates xy */
|
||||||
@@ -304,7 +307,7 @@
|
|||||||
// @Override
|
// @Override
|
||||||
// public Rect copy()
|
// public Rect copy()
|
||||||
// {
|
// {
|
||||||
// return new Rect(this);
|
// return new FixedRect(this);
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -704,7 +707,7 @@
|
|||||||
// @Override
|
// @Override
|
||||||
// public Rect round()
|
// public Rect round()
|
||||||
// {
|
// {
|
||||||
// return new Rect(min.round(), max.round());
|
// return new FixedRect(min.round(), max.round());
|
||||||
// }
|
// }
|
||||||
//
|
//
|
||||||
//
|
//
|
||||||
@@ -877,7 +880,7 @@
|
|||||||
//
|
//
|
||||||
//
|
//
|
||||||
// @Override
|
// @Override
|
||||||
// public Rect getRect()
|
// public RectView getRect()
|
||||||
// {
|
// {
|
||||||
// return this;
|
// return this;
|
||||||
// }
|
// }
|
||||||
@@ -3,7 +3,9 @@ package mightypork.utils.objects;
|
|||||||
|
|
||||||
import mightypork.utils.logging.Log;
|
import mightypork.utils.logging.Log;
|
||||||
import mightypork.utils.math.Range;
|
import mightypork.utils.math.Range;
|
||||||
import mightypork.utils.math.coord.*;
|
import mightypork.utils.math.coord.FixedCoord;
|
||||||
|
import mightypork.utils.math.coord.Vec;
|
||||||
|
import mightypork.utils.math.coord.VecView;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,8 +155,8 @@ public class Convert {
|
|||||||
public static VecView toCoord(Object o, Vec def)
|
public static VecView toCoord(Object o, Vec def)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (o == null) return new CoordValue(def);
|
if (o == null) return new FixedCoord(def);
|
||||||
if (o instanceof Vec) return new CoordValue((Vec) o);
|
if (o instanceof Vec) return new FixedCoord((Vec) o);
|
||||||
if (o instanceof String) {
|
if (o instanceof String) {
|
||||||
String s = ((String) o).trim().toUpperCase();
|
String s = ((String) o).trim().toUpperCase();
|
||||||
|
|
||||||
@@ -170,19 +172,19 @@ public class Convert {
|
|||||||
final double y = Double.parseDouble(parts[1].trim());
|
final double y = Double.parseDouble(parts[1].trim());
|
||||||
|
|
||||||
if (parts.length == 2) {
|
if (parts.length == 2) {
|
||||||
return new CoordValue(x, y);
|
return new FixedCoord(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
final double z = Double.parseDouble(parts[2].trim());
|
final double z = Double.parseDouble(parts[2].trim());
|
||||||
|
|
||||||
return new CoordValue(x, y, z);
|
return new FixedCoord(x, y, z);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
} catch (final NumberFormatException | ArrayIndexOutOfBoundsException e) {
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
|
|
||||||
return new CoordValue(def);
|
return new FixedCoord(def);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user