fixed most compile errors caused by constraint system refactoring

v5stable
ondra 10 years ago
parent 2690e6c5f3
commit 7011184c88
  1. 9
      src/mightypork/gamecore/audio/SoundSystem.java
  2. 5
      src/mightypork/gamecore/control/bus/events/MouseButtonEvent.java
  3. 14
      src/mightypork/gamecore/control/bus/events/MouseMotionEvent.java
  4. 5
      src/mightypork/gamecore/control/bus/events/ScreenChangeEvent.java
  5. 4
      src/mightypork/gamecore/gui/components/AbstractComponent.java
  6. 4
      src/mightypork/gamecore/gui/components/PluggableRenderable.java
  7. 4
      src/mightypork/gamecore/gui/components/painters/AbstractPainter.java
  8. 8
      src/mightypork/gamecore/gui/components/painters/TextPainter.java
  9. 17
      src/mightypork/gamecore/gui/screens/Screen.java
  10. 22
      src/mightypork/gamecore/gui/screens/ScreenLayer.java
  11. 20
      src/mightypork/gamecore/input/InputSystem.java
  12. 17
      src/mightypork/gamecore/render/DisplaySystem.java
  13. 48
      src/mightypork/gamecore/render/Render.java
  14. 11
      src/mightypork/gamecore/render/fonts/FontRenderer.java
  15. 4
      src/mightypork/gamecore/render/fonts/GLFont.java
  16. 12
      src/mightypork/gamecore/render/fonts/impl/CachedFont.java
  17. 5
      src/mightypork/gamecore/render/fonts/impl/DeferredFont.java
  18. 3
      src/mightypork/gamecore/render/fonts/impl/NullFont.java
  19. 4
      src/mightypork/gamecore/render/textures/TxQuad.java
  20. 2
      src/mightypork/rogue/screens/LayerFps.java
  21. 4
      src/mightypork/rogue/screens/test_bouncyboxes/LayerBouncyBoxes.java
  22. 16
      src/mightypork/rogue/screens/test_cat_sound/LayerFlyingCat.java
  23. 9
      src/mightypork/rogue/screens/test_font/ScreenTestFont.java
  24. 15
      src/mightypork/rogue/screens/test_render/LayerTestGradient.java
  25. 65
      src/mightypork/test/TestConstr.java
  26. 73
      src/mightypork/test/TestCoords.java
  27. 33
      src/mightypork/test/TestVec.java
  28. 6
      src/mightypork/utils/config/PropertyManager.java
  29. 6
      src/mightypork/utils/files/FileTreeDiff.java
  30. 12
      src/mightypork/utils/files/FileUtils.java
  31. 4
      src/mightypork/utils/files/ZipBuilder.java
  32. 11
      src/mightypork/utils/files/ZipUtils.java
  33. 4
      src/mightypork/utils/files/ion/Ion.java
  34. 76
      src/mightypork/utils/math/constraints/ConstraintFactory.java
  35. 2
      src/mightypork/utils/math/num/NumMutable.java
  36. 65
      src/mightypork/utils/math/rect/Rect.java
  37. 69
      src/mightypork/utils/math/rect/RectConst.java
  38. 2
      src/mightypork/utils/math/rect/RectVectAdapter.java
  39. 31
      src/mightypork/utils/math/vect/Vect.java

@ -13,8 +13,7 @@ import mightypork.gamecore.control.bus.events.ResourceLoadRequest;
import mightypork.gamecore.control.timing.Updateable;
import mightypork.utils.math.Calc.Buffers;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.vect.VectVar;
import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10;
@ -31,7 +30,7 @@ public class SoundSystem extends RootBusNode implements Updateable {
private static final Vect INITIAL_LISTENER_POS = Vect.ZERO;
private static final int MAX_SOURCES = 256;
private static VectMutable listener = VectMutable.zero();
private static VectVar listener = Vect.makeVar();
private static boolean soundSystemInited = false;
@ -60,9 +59,9 @@ public class SoundSystem extends RootBusNode implements Updateable {
/**
* @return listener coordinate
*/
public static VectView getListener()
public static Vect getListener()
{
return listener.view();
return listener;
}
// -- instance --

@ -3,7 +3,6 @@ package mightypork.gamecore.control.bus.events;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@ -78,9 +77,9 @@ public class MouseButtonEvent implements Event<MouseButtonEvent.Listener> {
/**
* @return mouse position when the event occurred
*/
public VectView getPos()
public Vect getPos()
{
return pos.view();
return pos;
}

@ -3,7 +3,7 @@ package mightypork.gamecore.control.bus.events;
import mightypork.gamecore.control.bus.events.types.UnloggedEvent;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectConst;
/**
@ -14,8 +14,8 @@ import mightypork.utils.math.vect.VectVal;
@UnloggedEvent
public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
private final VectVal move;
private final VectVal pos;
private final VectConst move;
private final VectConst pos;
/**
@ -23,15 +23,15 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
* @param move move vector
*/
public MouseMotionEvent(Vect pos, Vect move) {
this.move = move.copy();
this.pos = pos.copy();
this.move = move.freeze();
this.pos = pos.freeze();
}
/**
* @return movement since last {@link MouseMotionEvent}
*/
public VectVal getMove()
public VectConst getMove()
{
return move;
}
@ -40,7 +40,7 @@ public class MouseMotionEvent implements Event<MouseMotionEvent.Listener> {
/**
* @return current mouse position
*/
public VectVal getPos()
public VectConst getPos()
{
return pos;
}

@ -2,7 +2,6 @@ package mightypork.gamecore.control.bus.events;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@ -50,9 +49,9 @@ public class ScreenChangeEvent implements Event<ScreenChangeEvent.Listener> {
/**
* @return new screen size
*/
public VectView getScreenSize()
public Vect getScreenSize()
{
return screenSize.view();
return screenSize;
}

@ -4,7 +4,7 @@ package mightypork.gamecore.gui.components;
import mightypork.gamecore.control.AppAccess;
import mightypork.gamecore.control.AppSubModule;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.rect.Rect;
public abstract class AbstractComponent extends AppSubModule implements PluggableRenderable {
@ -25,7 +25,7 @@ public abstract class AbstractComponent extends AppSubModule implements Pluggabl
@Override
public RectView getRect()
public Rect getRect()
{
return context.getRect();
}

@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
import mightypork.utils.math.constraints.PluggableRectBound;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.rect.Rect;
/**
@ -18,7 +18,7 @@ public interface PluggableRenderable extends Renderable, PluggableRectBound {
@Override
RectView getRect();
Rect getRect();
@Override

@ -5,7 +5,7 @@ import mightypork.gamecore.gui.components.PluggableRenderable;
import mightypork.gamecore.gui.components.Renderable;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.constraints.RectBoundAdapter;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.rect.Rect;
/**
@ -20,7 +20,7 @@ public abstract class AbstractPainter extends RectBoundAdapter implements Plugga
@Override
public RectView getRect()
public Rect getRect()
{
return super.getRect();
}

@ -5,9 +5,9 @@ import mightypork.gamecore.render.fonts.FontRenderer;
import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.gamecore.render.fonts.GLFont;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectVar;
import mightypork.utils.string.StringProvider;
import mightypork.utils.string.StringProvider.StringWrapper;
@ -28,7 +28,7 @@ public class TextPainter extends AbstractPainter {
private boolean shadow;
private RGB shadowColor = RGB.BLACK;
private final VectMutable shadowOffset = VectMutable.make(1, 1);
private final VectVar shadowOffset = Vect.makeVar(1, 1);
/**
@ -84,7 +84,7 @@ public class TextPainter extends AbstractPainter {
if (text == null) return;
final String str = text.getString();
final RectView rect = getRect();
final Rect rect = getRect();
if (shadow) {
font.draw(str, rect.move(shadowOffset), align, shadowColor);

@ -11,7 +11,7 @@ import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.Render;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@Override
public RectView getRect()
public Rect getRect()
{
return getDisplay().getRect();
}
@ -169,4 +169,17 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
* @return screen identifier to be used for requests.
*/
public abstract String getName();
protected final Rect bounds()
{
return getRect();
}
protected final Vect mouse()
{
return getInput().getMousePos();
}
}

@ -8,9 +8,8 @@ import mightypork.gamecore.input.KeyBindingPool;
import mightypork.gamecore.input.KeyStroke;
import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@ -26,11 +25,6 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
private final KeyBindingPool keybindings = new KeyBindingPool();
/** Mouse position constraint */
protected final VectView cMousePos = getInput().getMousePos();
/** Screen size constraint */
protected final VectView cScreenSize = getDisplay().getSize();
/**
* @param screen parent screen
@ -67,7 +61,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
@Override
public RectView getRect()
public Rect getRect()
{
return screen.getRect();
}
@ -129,4 +123,16 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
*/
public abstract int getPriority();
protected final Rect bounds()
{
return screen.bounds();
}
protected final Vect mouse()
{
return screen.mouse();
}
}

@ -9,8 +9,8 @@ import mightypork.gamecore.control.bus.events.MouseMotionEvent;
import mightypork.gamecore.control.timing.Updateable;
import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVar;
import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard;
@ -29,7 +29,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
private final KeyBindingPool keybindings;
/** Current mouse position */
private final VectView mousePos = new VectView() {
private final Vect mousePos = new Vect() {
@Override
public double x()
@ -103,8 +103,8 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
}
// counters as fields to save memory.
private final VectMutable mouseMove = VectMutable.zero();
private final VectMutable mouseLastPos = VectMutable.zero();
private final VectVar mouseMove = VectVar.makeVar();
private final VectVar mouseLastPos = VectVar.makeVar();
@Override
@ -140,13 +140,13 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
}
private void onMouseEvent(VectMutable moveSum, VectMutable lastPos)
private void onMouseEvent(VectVar moveSum, VectVar lastPos)
{
final int button = Mouse.getEventButton();
final boolean down = Mouse.getEventButtonState();
final VectMutable pos = VectMutable.make(Mouse.getEventX(), Mouse.getEventY());
final VectMutable move = VectMutable.make(Mouse.getEventDX(), Mouse.getEventDY());
final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY());
final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY());
final int wheeld = Mouse.getEventDWheel();
@ -155,7 +155,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
move.mul(1, -1, 1);
if (button != -1 || wheeld != 0) {
getEventBus().send(new MouseButtonEvent(pos.copy(), button, down, wheeld));
getEventBus().send(new MouseButtonEvent(pos.freeze(), button, down, wheeld));
}
moveSum.add(move);
@ -178,7 +178,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
*
* @return mouse position
*/
public VectView getMousePos()
public Vect getMousePos()
{
return mousePos;
}

@ -11,9 +11,8 @@ import mightypork.gamecore.control.bus.events.ScreenChangeEvent;
import mightypork.gamecore.control.timing.FpsMeter;
import mightypork.utils.logging.Log;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectVal;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException;
@ -33,7 +32,7 @@ public class DisplaySystem extends AppModule implements RectBound {
private FpsMeter fpsMeter;
/** Current screen size */
private final VectView screenSize = new VectView() {
private final Vect screenSize = new Vect() {
@Override
public double y()
@ -49,6 +48,8 @@ public class DisplaySystem extends AppModule implements RectBound {
}
};
private final Rect rect = Rect.make(screenSize);
/**
* @param app app access
@ -189,7 +190,7 @@ public class DisplaySystem extends AppModule implements RectBound {
*
* @return size
*/
public VectView getSize()
public Vect getSize()
{
return screenSize;
}
@ -240,9 +241,9 @@ public class DisplaySystem extends AppModule implements RectBound {
@Override
public RectView getRect()
public Rect getRect()
{
return RectVal.make(getSize());
return rect;
}
@ -255,7 +256,7 @@ public class DisplaySystem extends AppModule implements RectBound {
}
public VectView getCenter()
public Vect getCenter()
{
return getSize().half();
}

@ -10,10 +10,8 @@ import mightypork.utils.files.FileUtils;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.vect.VectConst;
import org.lwjgl.opengl.GL11;
import org.newdawn.slick.opengl.Texture;
@ -29,9 +27,9 @@ import org.newdawn.slick.util.ResourceLoader;
*/
public class Render {
public static final VectView AXIS_X = VectVal.make(1, 0, 0);
public static final VectView AXIS_Y = VectVal.make(0, 1, 0);
public static final VectView AXIS_Z = VectVal.make(0, 0, 1);
public static final VectConst AXIS_X = Vect.make(1, 0, 0);
public static final VectConst AXIS_Y = Vect.make(0, 1, 0);
public static final VectConst AXIS_Z = Vect.make(0, 0, 1);
/**
@ -214,7 +212,7 @@ public class Render {
*/
public static void rotate(double angle, Vect axis)
{
final Vect vec = axis.view().norm(1);
final Vect vec = axis.norm(1);
glRotated(angle, vec.x(), vec.y(), vec.z());
}
@ -352,12 +350,10 @@ public class Render {
*/
public static void quad(Rect quad)
{
final RectView rv = quad.view();
final double x1 = rv.left().value();
final double y1 = rv.top().value();
final double x2 = rv.right().value();
final double y2 = rv.bottom().value();
final double x1 = quad.left().value();
final double y1 = quad.top().value();
final double x2 = quad.right().value();
final double y2 = quad.bottom().value();
// draw with color
unbindTexture();
@ -394,15 +390,15 @@ public class Render {
*/
public static void quadUV_nobound(Rect quad, Rect uvs)
{
final double x1 = quad.left();
final double y1 = quad.top();
final double x2 = quad.right();
final double y2 = quad.bottom();
final double x1 = quad.left().value();
final double y1 = quad.top().value();
final double x2 = quad.right().value();
final double y2 = quad.bottom().value();
final double tx1 = uvs.left();
final double ty1 = uvs.top();
final double tx2 = uvs.right();
final double ty2 = uvs.bottom();
final double tx1 = uvs.left().value();
final double ty1 = uvs.top().value();
final double tx2 = uvs.right().value();
final double ty2 = uvs.bottom().value();
// quad with texture
glTexCoord2d(tx1, ty2);
@ -440,10 +436,10 @@ public class Render {
*/
public static void quadColor(Rect quad, RGB colorHMinVMin, RGB colorHMaxVMin, RGB colorHMaxVMax, RGB colorHMinVMax)
{
final double x1 = quad.left();
final double y1 = quad.top();
final double x2 = quad.right();
final double y2 = quad.bottom();
final double x1 = quad.left().value();
final double y1 = quad.top().value();
final double x2 = quad.right().value();
final double y2 = quad.bottom().value();
// draw with color
unbindTexture();
@ -547,7 +543,7 @@ public class Render {
*
* @param size viewport size (screen size)
*/
public static void setupOrtho(VectView size)
public static void setupOrtho(Vect size)
{
// fix projection for changed size
glMatrixMode(GL_PROJECTION);

@ -5,8 +5,7 @@ import mightypork.gamecore.render.Render;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.vect.VectVar;
/**
@ -110,7 +109,7 @@ public class FontRenderer {
{
Render.pushMatrix();
Render.translate(pos.copy().round());
Render.translate(pos.freeze().round());
Render.scaleXY(getScale(height));
font.draw(text, color);
@ -144,7 +143,7 @@ public class FontRenderer {
*/
public void draw(String text, Rect bounds, Align align, RGB color)
{
VectView start;
Vect start;
switch (align) {
case LEFT:
@ -161,7 +160,7 @@ public class FontRenderer {
break;
}
draw(text, start, bounds.height(), align, color);
draw(text, start, bounds.height().value(), align, color);
}
@ -193,7 +192,7 @@ public class FontRenderer {
final double w = getWidth(text, height);
final VectMutable start = VectMutable.make(pos);
final VectVar start = Vect.makeVar(pos);
switch (align) {
case LEFT:

@ -2,7 +2,7 @@ package mightypork.gamecore.render.fonts;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.vect.Vect;
/**
@ -27,7 +27,7 @@ public interface GLFont {
* @param text string to check
* @return coord (width, height)
*/
VectView getNeededSpace(String text);
Vect getNeededSpace(String text);
/**

@ -23,7 +23,7 @@ import mightypork.gamecore.render.fonts.GLFont;
import mightypork.gamecore.render.textures.FilterMode;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectConst;
import org.lwjgl.BufferUtils;
import org.lwjgl.util.glu.GLU;
@ -294,8 +294,7 @@ public class CachedFont implements GLFont {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
} else {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder())
.put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
}
byteBuffer.flip();
@ -412,8 +411,7 @@ public class CachedFont implements GLFont {
chtx = chars.get(charCurrent);
if (chtx != null) {
drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY
+ chtx.height);
drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + chtx.height);
totalwidth += chtx.width;
}
}
@ -424,9 +422,9 @@ public class CachedFont implements GLFont {
@Override
public VectVal getNeededSpace(String text)
public VectConst getNeededSpace(String text)
{
return VectVal.make(getWidth(text), getLineHeight());
return VectConst.make(getWidth(text), getLineHeight());
}
}

@ -14,7 +14,6 @@ import mightypork.utils.annotations.Alias;
import mightypork.utils.files.FileUtils;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@ -130,7 +129,7 @@ public class DeferredFont extends DeferredResource implements GLFont {
*/
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);
@ -164,7 +163,7 @@ public class DeferredFont extends DeferredResource implements GLFont {
* @return coord (width, height)
*/
@Override
public VectView getNeededSpace(String text)
public Vect getNeededSpace(String text)
{
if (!ensureLoaded()) return Vect.ZERO;

@ -5,7 +5,6 @@ import mightypork.gamecore.render.fonts.GLFont;
import mightypork.utils.logging.Log;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/**
@ -23,7 +22,7 @@ public class NullFont implements GLFont {
@Override
public VectView getNeededSpace(String str)
public Vect getNeededSpace(String str)
{
return Vect.ZERO;
}

@ -2,7 +2,7 @@ package mightypork.gamecore.render.textures;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.rect.RectVal;
import mightypork.utils.math.rect.RectConst;
import org.newdawn.slick.opengl.Texture;
@ -65,7 +65,7 @@ public class TxQuad {
* @param y2 right bottom Y (0-1)
*/
public TxQuad(Texture tx, double x1, double y1, double x2, double y2) {
this(tx, RectVal.make(x1, y1, x2, y2));
this(tx, RectConst.make(x1, y1, x2, y2));
}

@ -38,7 +38,7 @@ public class LayerFps extends ScreenLayer {
final GLFont font = Res.getFont("default");
final RectBound constraint = box(add(topRight(this), -8, 8), 0, 32);
final RectBound constraint = bounds().topRight().add(-8, 8).expand(0, 0, 0, 32);
tp = new TextPainter(font, Align.RIGHT, RGB.WHITE, new StringProvider() {

@ -14,7 +14,7 @@ import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.rogue.Res;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectConst;
public class LayerBouncyBoxes extends ScreenLayer {
@ -57,7 +57,7 @@ public class LayerBouncyBoxes extends ScreenLayer {
final TextPainter tp = new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE);
tp.setText("Press \"C\" for \"Cat\" screen.");
tp.setShadow(RGB.RED, VectVal.make(2, 2));
tp.setShadow(RGB.RED, VectConst.make(2, 2));
layout.add(tp);
}

@ -17,15 +17,16 @@ import mightypork.rogue.Res;
import mightypork.utils.math.animation.AnimDouble;
import mightypork.utils.math.animation.Easing;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectAnimated;
import mightypork.utils.math.vect.VectVal;
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener {
private final AnimDouble size = new AnimDouble(400, Easing.SINE_BOTH);
private final VectAnimated pos = VectAnimated.make(Easing.ELASTIC_OUT);
private final VectAnimated pos = VectAnimated.makeVar(Easing.ELASTIC_OUT);
private final Random rand = new Random();
@ -42,22 +43,19 @@ public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButt
cat = new ImagePainter(Res.getTxQuad("test.kitten"));
// Bounds.box(size,size).centerTo(pos)
cat.setContext(centerTo(box(size, size), pos));
cat.setContext(Rect.make(size, size).centerTo(pos));
tp = new TextPainter(Res.getFont("default"));
tp.setAlign(Align.CENTER);
tp.setColor(RGB.YELLOW);
tp.setText("Meow!");
tp.setShadow(RGB.dark(0.8), VectVal.make(2, 2));
tp.setShadow(RGB.dark(0.8), Vect.make(2, 2));
// Bounds.box(64,64).centerTo(cMousePos)
tp.setContext(centerTo(box(64, 64), cMousePos));
tp.setContext(Rect.make(64, 64).centerTo(mouse()));
qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED);
// Bounds.wrap(cat).bottomLeft().expand(0,0,50,50)
qp.setContext(expand(bottomLeft(cat), 0, 0, 50, 50));
qp.setContext(cat.getRect().bottomLeft().expand(size.half(), Num.ZERO, Num.ZERO, size.half()));
/*
* Register keys

@ -7,8 +7,8 @@ import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.render.fonts.FontRenderer.Align;
import mightypork.rogue.Res;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.NumBound;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.rect.Rect;
public class ScreenTestFont extends Screen {
@ -22,9 +22,8 @@ public class ScreenTestFont extends Screen {
tp = new TextPainter(Res.getFont("default"), Align.CENTER, RGB.GREEN);
tp.setText("Hello World!");
final NumBound fontHeight = mul(getDisplay().getSize().yn(), 0.1);
final RectBound strbox = centerTo(box(fontHeight), this);
final Num h = bounds().height().mul(0.1);
final Rect strbox = Rect.make(Num.ZERO, h).centerTo(bounds());
tp.setContext(strbox);
}

@ -1,19 +1,15 @@
package mightypork.rogue.screens.test_render;
import mightypork.gamecore.control.timing.Poller;
import mightypork.gamecore.gui.screens.Screen;
import mightypork.gamecore.gui.screens.ScreenLayer;
import mightypork.gamecore.render.Render;
import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.vect.Vect;
public class LayerTestGradient extends ScreenLayer {
private final Poller p = new Poller();
private final RectBound pos1;
private final RectBound pos2;
@ -21,8 +17,8 @@ public class LayerTestGradient extends ScreenLayer {
public LayerTestGradient(Screen screen) {
super(screen);
pos1 = cached(p, growDown(edgeTop(this), 64));
pos2 = cached(p, shrinkTop(growRight(edgeLeft(this), 64), 64));
pos1 = bounds().topEdge().growDown(64);
pos2 = bounds().leftEdge().growUp(-64).growRight(64);
}
@ -41,11 +37,4 @@ public class LayerTestGradient extends ScreenLayer {
return 5;
}
@Override
protected void onSizeChanged(Vect size)
{
p.poll();
}
}

@ -3,14 +3,13 @@ package mightypork.test;
import java.util.Locale;
import mightypork.utils.math.num.NumMutable;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumVar;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.rect.RectVal;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.rect.RectConst;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.vect.VectConst;
import mightypork.utils.math.vect.VectVar;
public class TestConstr {
@ -22,52 +21,52 @@ public class TestConstr {
int cnt = -1;
{
final RectVal rect = RectVal.make(0, 0, 10, 10);
final VectVal point = VectVal.make(50, 50);
final RectConst rect = Rect.make(0, 0, 10, 10);
final VectConst point = Vect.make(50, 50);
System.out.println("Test " + ++cnt + ": rect = " + rect);
System.out.println("Test " + cnt + ": point = " + point);
System.out.println("Test " + cnt + ": centered rect = " + rect.view().centerTo(point));
System.out.println("Test " + cnt + ": centered rect = " + rect.centerTo(point));
}
{
final RectVal rect = RectVal.make(0, 0, 10, 10);
final RectView v = rect.view().view();
System.out.println("\nTest " + ++cnt + ": " + (v == rect.view()));
final RectConst rect = Rect.make(0, 0, 10, 10);
final Rect v = rect;
System.out.println("\nTest " + ++cnt + ": " + (v == rect));
}
{
final RectVal rect = RectVal.make(0, 0, 10, 10);
final RectView v = rect.view().view().view().view().view().view();
System.out.println("\nTest " + ++cnt + ": " + (v == rect.view()));
final RectConst rect = Rect.make(0, 0, 10, 10);
final Rect v = rect;
System.out.println("\nTest " + ++cnt + ": " + (v == rect));
}
{
final Vect a = VectVal.make(3, 3);
final VectVal v = a.copy().copy().copy();
System.out.println("\nTest " + ++cnt + ": " + (v == a.copy()));
final Vect a = Vect.make(3, 3);
final VectConst v = a.freeze().freeze().freeze();
System.out.println("\nTest " + ++cnt + ": " + (v == a.freeze()));
}
{
final Vect a = VectVal.make(3, 3);
final VectVal v = a.copy().copy().copy();
System.out.println("\nTest " + ++cnt + ": " + (v == a.copy()));
final Vect a = Vect.make(3, 3);
final VectConst v = a.freeze().freeze().freeze();
System.out.println("\nTest " + ++cnt + ": " + (v == a.freeze()));
}
{
final VectMutable a = VectMutable.make(10, 10);
final VectView view = a.view().mul(10).half().sub(1, 1);
System.out.println("\nTest " + ++cnt + ": " + (view.equals(VectVal.make(49, 49))));
final VectVar a = Vect.makeVar(10, 10);
final Vect view = a.mul(10).half().sub(1, 1);
System.out.println("\nTest " + ++cnt + ": " + (view.equals(Vect.make(49, 49))));
a.add(10, 0);
System.out.println("Test " + cnt + ": " + (view.equals(VectVal.make(99, 49))));
System.out.println("Test " + cnt + ": " + (view.equals(Vect.make(99, 49))));
a.setTo(900, 999);
System.out.println(view);
}
{
final NumMutable side = NumMutable.make(100);
final VectMutable center = VectMutable.make(0, 0);
final NumVar side = Num.makeVar(100);
final VectVar center = Vect.makeVar(0, 0);
final Rect box = side.view().box().centerTo(center);
final Rect box = Rect.make(side, side).centerTo(center);
System.out.println(box);
@ -82,17 +81,11 @@ public class TestConstr {
}
{
final NumMutable a = NumMutable.make(100);
final NumVar a = Num.makeVar(100);
a.setTo(a.mul(50).add(10).div(2));
a.assign(a.mul(50).add(10).div(2));
System.out.println(a);
Rect r;
System.out.println(r = a.box());
a.reset();
System.out.println(r);
}
}

@ -1,47 +1,50 @@
package mightypork.test;
import java.util.Locale;
import mightypork.utils.math.num.NumView;
import mightypork.utils.math.vect.VectMutable;
import mightypork.utils.math.vect.VectView;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumVar;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVar;
public class TestCoords {
public static void main(String[] args)
{
Locale.setDefault(Locale.ENGLISH);
// test
final VectMutable var = VectMutable.make(1, 2, 3);
final VectView cubicRoot = var.mul(var).mul(var);
final VectView half = var.half();
System.out.println("x, x^3, x/5");
System.out.println(var);
System.out.println(cubicRoot);
System.out.println(half);
var.setTo(var.mul(10));
System.out.println("x = x*10; x, x^3, x/5");
System.out.println(var);
System.out.println(cubicRoot);
System.out.println(half);
final NumView y = var.yn();
System.out.println("y: " + y.value());
var.setTo(var.add(100, 100));
System.out.println("x = x*100; x.y(), x, x^3, x/5");
System.out.println(y.value());
System.out.println(var);
System.out.println(cubicRoot);
System.out.println(half);
{
VectVar a = Vect.makeVar();
VectVar b = Vect.makeVar();
Vect cross = a.cross(b);
Num dot = a.dot(b);
Vect sum = a.add(b);
Num dist = a.dist(b);
a.setTo(0, 10, 0);
b.setTo(0, 6, 7);
System.out.println("a = " + a);
System.out.println("b = " + b);
System.out.println("axb = " + cross);
System.out.println("a.b = " + dot);
System.out.println("a+b = " + sum);
System.out.println("dist(a,b) = " + dist);
}
{
NumVar a = Num.makeVar();
Num end = a;
for (int i = 0; i < 100; i++) {
end = end.add(1);
}
System.out.println(end);
a.setTo(37);
System.out.println(end);
}
}
}

@ -0,0 +1,33 @@
package mightypork.test;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectConst;
import mightypork.utils.math.vect.VectVar;
public class TestVec {
public static void main(String[] args)
{
VectVar a = Vect.makeVar(-100, 12, 6);
VectConst b = a.freeze();
a.setTo(400, 400, 300);
System.out.println(a);
System.out.println(b);
Vect c = a.abs().neg();
System.out.println(c);
System.out.println("20,1");
a.setTo(20, 1);
System.out.println(a);
System.out.println(c);
}
}

@ -11,7 +11,7 @@ import java.util.TreeMap;
import mightypork.utils.math.Range;
import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal;
import mightypork.utils.math.vect.VectConst;
import mightypork.utils.objects.Convert;
@ -179,7 +179,7 @@ public class PropertyManager {
}
}
try(FileInputStream fis = new FileInputStream(file)) {
try (FileInputStream fis = new FileInputStream(file)) {
props.load(fis);
} catch (final IOException e) {
needsSave = true;
@ -362,7 +362,7 @@ public class PropertyManager {
* @param n key
* @return the coord found, or null
*/
public VectVal getCoord(String n)
public VectConst getCoord(String n)
{
return Convert.toVect(get(n).value);
}

@ -72,11 +72,9 @@ public class FileTreeDiff {
ck1.reset();
ck2.reset();
try(FileInputStream in1 = new FileInputStream(pair.a);
FileInputStream in2 = new FileInputStream(pair.b)) {
try (FileInputStream in1 = new FileInputStream(pair.a); FileInputStream in2 = new FileInputStream(pair.b)) {
try(CheckedInputStream cin1 = new CheckedInputStream(in1, ck1);
CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
try (CheckedInputStream cin1 = new CheckedInputStream(in1, ck1); CheckedInputStream cin2 = new CheckedInputStream(in2, ck2)) {
while (true) {
final int read1 = cin1.read(BUFFER);

@ -95,8 +95,7 @@ public class FileUtils {
public static void copyFile(File source, File target) throws IOException
{
try(InputStream in = new FileInputStream(source);
OutputStream out = new FileOutputStream(target)) {
try (InputStream in = new FileInputStream(source); OutputStream out = new FileOutputStream(target)) {
copyStream(in, out);
}
@ -161,7 +160,7 @@ public class FileUtils {
*/
public static String fileToString(File file) throws IOException
{
try(FileInputStream fin = new FileInputStream(file)) {
try (FileInputStream fin = new FileInputStream(file)) {
return streamToString(fin);
}
@ -361,7 +360,7 @@ public class FileUtils {
*/
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);
@ -482,8 +481,7 @@ public class FileUtils {
*/
public static void resourceToFile(String resname, File file) throws IOException
{
try(InputStream in = FileUtils.getResource(resname);
OutputStream out = new FileOutputStream(file)) {
try (InputStream in = FileUtils.getResource(resname); OutputStream out = new FileOutputStream(file)) {
FileUtils.copyStream(in, out);
}
@ -500,7 +498,7 @@ public class FileUtils {
*/
public static String resourceToString(String resname) throws IOException
{
try(InputStream in = FileUtils.getResource(resname)) {
try (InputStream in = FileUtils.getResource(resname)) {
return streamToString(in);
}
}

@ -74,7 +74,7 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path));
try(InputStream in = FileUtils.stringToStream(text)) {
try (InputStream in = FileUtils.stringToStream(text)) {
FileUtils.copyStream(in, out);
}
}
@ -95,7 +95,7 @@ public class ZipBuilder {
out.putNextEntry(new ZipEntry(path));
try(InputStream in = FileUtils.getResource(resPath)) {
try (InputStream in = FileUtils.getResource(resPath)) {
FileUtils.copyStream(in, out);
}
}

@ -33,7 +33,7 @@ public class ZipUtils {
*/
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);
}
}
@ -89,7 +89,7 @@ public class ZipUtils {
*/
public static List<String> listZip(File zipFile) throws IOException
{
try(ZipFile zip = new ZipFile(zipFile)) {
try (ZipFile zip = new ZipFile(zipFile)) {
return listZip(zip);
}
}
@ -133,10 +133,7 @@ public class ZipUtils {
{
if (!destFile.getParentFile().mkdirs()) throw new IOException("Could not create output directory.");
try(InputStream in = zip.getInputStream(entry);
BufferedInputStream is = new BufferedInputStream(in);
FileOutputStream fos = new FileOutputStream(destFile);
BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
try (InputStream in = zip.getInputStream(entry); BufferedInputStream is = new BufferedInputStream(in); FileOutputStream fos = new FileOutputStream(destFile); BufferedOutputStream dest = new BufferedOutputStream(fos, BUFFER_SIZE)) {
FileUtils.copyStream(is, dest);
}
@ -170,7 +167,7 @@ public class ZipUtils {
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;
} catch (final IOException | RuntimeException e) {
Log.w("Error reading zip.", e);

@ -67,7 +67,7 @@ public class Ion {
*/
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);
return obj;
@ -113,7 +113,7 @@ public class Ion {
*/
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 File dir = new File(f.substring(0, f.lastIndexOf(File.separator)));

@ -11,7 +11,7 @@
//import mightypork.utils.math.vect.Vect;
//import mightypork.utils.math.vect.VectAdapter;
//import mightypork.utils.math.vect.VectVal;
//import mightypork.utils.math.vect.VectView;
//import mightypork.utils.math.vect.Vect;
//
//
///**
@ -69,9 +69,9 @@
// * @param vectBound vect bound
// * @return contained vect
// */
// private static VectView eval(final VectBound vectBound)
// private static Vect eval(final VectBound vectBound)
// {
// return vectBound == null ? Vect.ZERO.view() : vectBound.getVect();
// return vectBound == null ? Vect.ZERO : vectBound.getVect();
// }
//
//
@ -83,7 +83,7 @@
// */
// private static RectView eval(final RectBound rectBound)
// {
// return rectBound == null ? Rect.ZERO.view() : rectBound.getRect();
// return rectBound == null ? Rect.ZERO : rectBound.getRect();
// }
//
//
@ -670,7 +670,7 @@
// final double b = eval(bottom);
// final double l = eval(left);
//
// final VectView v = eval(c);
// final Vect v = eval(c);
//
// return RectVal.make(v.x() - l, v.y() - t, l + r, t + b);
// }
@ -736,24 +736,24 @@
// }
//
//
// public static VectView neg(final VectBound c)
// public static Vect neg(final VectBound c)
// {
// return mul(c, -1);
// }
//
//
// public static VectView half(final VectBound c)
// public static Vect half(final VectBound c)
// {
// return mul(c, 0.5);
// }
//
//
// public static VectView add(final VectBound c1, final VectBound c2)
// public static Vect add(final VectBound c1, final VectBound c2)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(c1).add(eval(c2));
// }
@ -761,18 +761,18 @@
// }
//
//
// public static VectView add(final VectBound c, final Object x, final Object y)
// public static Vect add(final VectBound c, final Object x, final Object y)
// {
// return add(c, x, y, 0);
// }
//
//
// public static VectView add(final VectBound c, final Object x, final Object y, final Object z)
// public static Vect add(final VectBound c, final Object x, final Object y, final Object z)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(c).add(eval(x), eval(y), eval(z));
// }
@ -780,12 +780,12 @@
// }
//
//
// public static VectView sub(final VectBound c1, final VectBound c2)
// public static Vect sub(final VectBound c1, final VectBound c2)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(c1).sub(eval(c2));
// }
@ -793,18 +793,18 @@
// }
//
//
// public static VectView sub(final VectBound c, final Object x, final Object y)
// public static Vect sub(final VectBound c, final Object x, final Object y)
// {
// return sub(c, x, y, 0);
// }
//
//
// public static VectView sub(final VectBound c, final Object x, final Object y, final Object z)
// public static Vect sub(final VectBound c, final Object x, final Object y, final Object z)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(c).sub(eval(x), eval(y), eval(z));
// }
@ -813,12 +813,12 @@
// }
//
//
// public static VectView mul(final VectBound c, final Object mul)
// public static Vect mul(final VectBound c, final Object mul)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(c).mul(eval(mul));
// }
@ -827,12 +827,12 @@
// }
//
//
// public static VectView norm(final VectBound c, final Object norm)
// public static Vect norm(final VectBound c, final Object norm)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(c).norm(eval(norm));
// }
@ -841,12 +841,12 @@
// }
//
//
// public static VectView origin(final RectBound r)
// public static Vect origin(final RectBound r)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(r).origin();
// }
@ -854,12 +854,12 @@
// }
//
//
// public static VectView size(final RectBound r)
// public static Vect size(final RectBound r)
// {
// return new VectAdapter() {
//
// @Override
// public VectView getSource()
// public Vect getSource()
// {
// return eval(r).size();
// }
@ -879,55 +879,55 @@
// }
//
//
// public static VectView center(final RectBound r)
// public static Vect center(final RectBound r)
// {
// return add(origin(r), half(size(r)));
// }
//
//
// public static VectView topLeft(final RectBound r)
// public static Vect topLeft(final RectBound r)
// {
// return origin(r);
// }
//
//
// public static VectView topRight(final RectBound r)
// public static Vect topRight(final RectBound r)
// {
// return add(origin(r), width(r), 0);
// }
//
//
// public static VectView bottomLeft(final RectBound r)
// public static Vect bottomLeft(final RectBound r)
// {
// return add(origin(r), 0, width(r));
// }
//
//
// public static VectView bottomRight(final RectBound r)
// public static Vect bottomRight(final RectBound r)
// {
// return add(origin(r), size(r));
// }
//
//
// public static VectView topCenter(final RectBound r)
// public static Vect topCenter(final RectBound r)
// {
// return add(origin(r), half(width(r)), 0);
// }
//
//
// public static VectView bottomCenter(final RectBound r)
// public static Vect bottomCenter(final RectBound r)
// {
// return add(origin(r), half(width(r)), width(r));
// }
//
//
// public static VectView centerLeft(final RectBound r)
// public static Vect centerLeft(final RectBound r)
// {
// return add(origin(r), 0, half(width(r)));
// }
//
//
// public static VectView centerRight(final RectBound r)
// public static Vect centerRight(final RectBound r)
// {
// return add(origin(r), width(r), half(width(r)));
// }
@ -946,19 +946,19 @@
// @Override
// public RectView getRect()
// {
// VectView cv = eval(c);
// Vect cv = eval(c);
//
// return new RectView() {
//
// @Override
// public VectView size()
// public Vect size()
// {
// return Vect.ZERO.view();
// return Vect.ZERO;
// }
//
//
// @Override
// public VectView origin()
// public Vect origin()
// {
// return null;
// }

@ -21,7 +21,7 @@ public abstract class NumMutable extends Num {
*
* @param value new value
*/
public void setTo(Num value)
public void assign(Num value)
{
setTo(eval(value));
}

@ -30,6 +30,12 @@ public abstract class Rect implements RectBound {
}
public static Rect make(Vect size)
{
return Rect.make(size.xn(), size.yn());
}
@FactoryMethod
public static Rect make(Num x, Num y, Num width, Num height)
{
@ -122,6 +128,26 @@ public abstract class Rect implements RectBound {
return Rect.makeVar(Rect.ZERO);
}
private Vect p_bl;
private Vect p_bc;
private Vect p_br;
// p_t == origin
private Vect p_tc;
private Vect p_tr;
private Vect p_cl;
private Vect p_cc;
private Vect p_cr;
private Num p_x;
private Num p_y;
private Num p_w;
private Num p_h;
private Num p_l;
private Num p_r;
private Num p_t;
private Num p_b;
/**
* Get a copy of current value
@ -448,49 +474,49 @@ public abstract class Rect implements RectBound {
public Num x()
{
return origin().xn();
return p_x != null ? p_x : (p_x = origin().xn());
}
public Num y()
{
return origin().yn();
return p_y != null ? p_y : (p_y = origin().yn());
}
public Num width()
{
return size().xn();
return p_w != null ? p_w : (p_w = size().xn());
}
public Num height()
{
return size().yn();
return p_h != null ? p_h : (p_h = size().yn());
}
public Num left()
{
return origin().yn();
return p_l != null ? p_l : (p_l = origin().yn());
}
public Num right()
{
return origin().xn().add(size().xn());
return p_r != null ? p_r : (p_r = origin().xn().add(size().xn()));
}
public Num top()
{
return origin().yn();
return p_t != null ? p_t : (p_t = origin().yn());
}
public Num bottom()
{
return origin().yn().add(size().yn());
return p_b != null ? p_b : (p_b = origin().yn().add(size().yn()));
}
@ -502,49 +528,49 @@ public abstract class Rect implements RectBound {
public Vect topCenter()
{
return origin().add(size().xn().half(), Num.ZERO);
return p_tc != null ? p_tc : (p_tc = origin().add(size().xn().half(), Num.ZERO));
}
public Vect topRight()
{
return origin().add(size().xn(), Num.ZERO);
return p_tr != null ? p_tr : (p_tr = origin().add(size().xn(), Num.ZERO));
}
public Vect centerLeft()
{
return origin().add(Num.ZERO, size().yn().half());
return p_cl != null ? p_cl : (p_cl = origin().add(Num.ZERO, size().yn().half()));
}
public Vect center()
{
return origin().add(size().half());
return p_cc != null ? p_cc : (p_cc = origin().add(size().half()));
}
public Vect centerRight()
{
return origin().add(size().xn(), size().yn().half());
return p_cr != null ? p_cr : (p_cr = origin().add(size().xn(), size().yn().half()));
}
public Vect bottomLeft()
{
return origin().add(Num.ZERO, size().yn());
return p_bl != null ? p_bl : (p_bl = origin().add(Num.ZERO, size().yn()));
}
public Vect bottomCenter()
{
return origin().add(size().xn().half(), size().yn());
return p_bc != null ? p_bc : (p_bc = origin().add(size().xn().half(), size().yn()));
}
public Vect bottomRight()
{
return origin().add(size().xn(), size().yn());
return p_br != null ? p_br : (p_br = origin().add(size().xn(), size().yn()));
}
@ -595,4 +621,11 @@ public abstract class Rect implements RectBound {
return x >= x1 && y >= y1 && x <= x2 && y <= y2;
}
public Rect centerTo(Rect parent)
{
return centerTo(parent.center());
}
}

@ -16,6 +16,19 @@ public class RectConst extends Rect {
private final VectConst pos;
private final VectConst size;
// cached with lazy loading
private NumConst v_b;
private NumConst v_r;
private VectConst v_br;
private VectConst v_tc;
private VectConst v_tr;
private VectConst v_cl;
private VectConst v_c;
private VectConst v_cr;
private VectConst v_bl;
private VectConst v_bc;
private RectConst v_round;
/**
* Create at given origin, with given size.
@ -89,14 +102,14 @@ public class RectConst extends Rect {
@Override
public RectConst move(double x, double y)
{
return Rect.make(origin().add(x, y), size()).freeze();
return Rect.make(pos.add(x, y), size);
}
@Override
public RectConst shrink(double left, double right, double top, double bottom)
{
return Rect.make(origin().add(left, top), size().sub(left + right, top + bottom)).freeze();
return Rect.make(pos.add(left, top), size.sub(left + right, top + bottom)).freeze();
}
@ -104,136 +117,144 @@ public class RectConst extends Rect {
@Override
public RectConst grow(double left, double right, double top, double bottom)
{
return Rect.make(origin().sub(left, top), size().add(left + right, top + bottom)).freeze();
return Rect.make(pos.sub(left, top), size.add(left + right, top + bottom)).freeze();
}
@Override
public RectConst round()
{
final VectConst s = size();
final VectConst o = origin();
return Rect.make(o.round(), s.round()).freeze();
if (v_round == null) v_round = Rect.make(pos.round(), size.round());
return v_round;
}
@Override
public NumConst x()
{
return origin().xn();
return pos.xn();
}
@Override
public NumConst y()
{
return origin().yn();
return pos.yn();
}
@Override
public NumConst width()
{
return size().xn();
return size.xn();
}
@Override
public NumConst height()
{
return size().yn();
return size.yn();
}
@Override
public NumConst left()
{
return origin().xn();
return pos.xn();
}
@Override
public NumConst right()
{
return origin().xn().add(size().xn());
if (v_r == null) v_r = super.right().freeze();
return v_r;
}
@Override
public NumConst top()
{
return origin().yn();
return pos.yn();
}
@Override
public NumConst bottom()
{
return origin().yn().add(size().yn());
if (v_b == null) v_b = super.bottom().freeze();
return v_b;
}
@Override
public VectConst topLeft()
{
return origin();
return pos;
}
@Override
public VectConst topCenter()
{
return origin().add(size().x() / 2, 0);
if (v_tc == null) v_tc = super.topCenter().freeze();
return v_tc;
}
@Override
public VectConst topRight()
{
return origin().add(size().x(), 0);
if (v_tr == null) v_tr = super.topRight().freeze();
return v_tr;
}
@Override
public VectConst centerLeft()
{
return origin().add(0, size().y() / 2);
if (v_cl == null) v_cl = super.centerLeft().freeze();
return v_cl;
}
@Override
public VectConst center()
{
return origin().add(size().half()).freeze();
if (v_c == null) v_c = super.center().freeze();
return v_c;
}
@Override
public VectConst centerRight()
{
return origin().add(size().x(), size().y() / 2);
if (v_cr == null) v_cr = super.centerRight().freeze();
return v_cr;
}
@Override
public VectConst bottomLeft()
{
return origin().add(0, size().y());
if (v_bl == null) v_bl = super.bottomLeft().freeze();
return v_bl;
}
@Override
public VectConst bottomCenter()
{
return origin().add(size().x() / 2, size().y());
if (v_bc == null) v_bc = super.bottomCenter().freeze();
return v_bc;
}
@Override
public VectConst bottomRight()
{
return origin().add(size()).freeze();
if (v_br == null) v_br = super.bottomRight().freeze();
return v_br;
}
}

@ -5,7 +5,7 @@ import mightypork.utils.math.vect.Vect;
/**
* Rect made of two {@link VectView}s
* Rect made of two {@link Vect}s
*
* @author MightyPork
*/

@ -7,6 +7,7 @@ import mightypork.utils.math.Calc;
import mightypork.utils.math.constraints.VectBound;
import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumConst;
import mightypork.utils.math.rect.Rect;
/**
@ -1102,4 +1103,34 @@ public abstract class Vect implements VectBound {
return x() == other.x() && y() == other.y() && z() == other.z();
}
/**
* Expand to a rect, with given growth to each side.
*
* @param left
* @param right
* @param top
* @param bottom
* @return the rect
*/
public Rect expand(int left, int right, int top, int bottom)
{
return Rect.make(this, Vect.ZERO).grow(left, right, top, bottom);
}
/**
* Expand to a rect, with given growth to each side.
*
* @param left
* @param right
* @param top
* @param bottom
* @return the rect
*/
public Rect expand(Num left, Num right, Num top, Num bottom)
{
return Rect.make(this, Vect.ZERO).grow(left, right, top, bottom);
}
}

Loading…
Cancel
Save