fixed most compile errors caused by constraint system refactoring

v5stable
ondra 11 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.gamecore.control.timing.Updateable;
import mightypork.utils.math.Calc.Buffers; import mightypork.utils.math.Calc.Buffers;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectVar;
import mightypork.utils.math.vect.VectView;
import org.lwjgl.openal.AL; import org.lwjgl.openal.AL;
import org.lwjgl.openal.AL10; 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 Vect INITIAL_LISTENER_POS = Vect.ZERO;
private static final int MAX_SOURCES = 256; private static final int MAX_SOURCES = 256;
private static VectMutable listener = VectMutable.zero(); private static VectVar listener = Vect.makeVar();
private static boolean soundSystemInited = false; private static boolean soundSystemInited = false;
@ -60,9 +59,9 @@ public class SoundSystem extends RootBusNode implements Updateable {
/** /**
* @return listener coordinate * @return listener coordinate
*/ */
public static VectView getListener() public static Vect getListener()
{ {
return listener.view(); return listener;
} }
// -- instance -- // -- instance --

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

@ -2,7 +2,6 @@ package mightypork.gamecore.control.bus.events;
import mightypork.utils.math.vect.Vect; 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 * @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.AppAccess;
import mightypork.gamecore.control.AppSubModule; import mightypork.gamecore.control.AppSubModule;
import mightypork.utils.math.constraints.RectBound; 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 { public abstract class AbstractComponent extends AppSubModule implements PluggableRenderable {
@ -25,7 +25,7 @@ public abstract class AbstractComponent extends AppSubModule implements Pluggabl
@Override @Override
public RectView getRect() public Rect getRect()
{ {
return context.getRect(); return context.getRect();
} }

@ -3,7 +3,7 @@ package mightypork.gamecore.gui.components;
import mightypork.utils.math.constraints.PluggableRectBound; import mightypork.utils.math.constraints.PluggableRectBound;
import mightypork.utils.math.constraints.RectBound; 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 @Override
RectView getRect(); Rect getRect();
@Override @Override

@ -5,7 +5,7 @@ import mightypork.gamecore.gui.components.PluggableRenderable;
import mightypork.gamecore.gui.components.Renderable; import mightypork.gamecore.gui.components.Renderable;
import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.constraints.RectBoundAdapter; 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 @Override
public RectView getRect() public Rect getRect()
{ {
return super.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.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.rect.RectView; import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect; 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;
import mightypork.utils.string.StringProvider.StringWrapper; import mightypork.utils.string.StringProvider.StringWrapper;
@ -28,7 +28,7 @@ public class TextPainter extends AbstractPainter {
private boolean shadow; private boolean shadow;
private RGB shadowColor = RGB.BLACK; 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; if (text == null) return;
final String str = text.getString(); final String str = text.getString();
final RectView rect = getRect(); final Rect rect = getRect();
if (shadow) { if (shadow) {
font.draw(str, rect.move(shadowOffset), align, shadowColor); font.draw(str, rect.move(shadowOffset), align, shadowColor);

@ -11,7 +11,7 @@ import mightypork.gamecore.input.KeyStroke;
import mightypork.gamecore.render.Render; import mightypork.gamecore.render.Render;
import mightypork.utils.annotations.DefaultImpl; import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.math.constraints.RectBound; 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.Vect;
@ -104,7 +104,7 @@ public abstract class Screen extends AppSubModule implements Renderable, KeyBind
@Override @Override
public RectView getRect() public Rect getRect()
{ {
return getDisplay().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. * @return screen identifier to be used for requests.
*/ */
public abstract String getName(); 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.gamecore.input.KeyStroke;
import mightypork.utils.annotations.DefaultImpl; import mightypork.utils.annotations.DefaultImpl;
import mightypork.utils.math.constraints.RectBound; 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.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(); 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 * @param screen parent screen
@ -67,7 +61,7 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
@Override @Override
public RectView getRect() public Rect getRect()
{ {
return screen.getRect(); return screen.getRect();
} }
@ -129,4 +123,16 @@ public abstract class ScreenLayer extends AppSubModule implements Comparable<Scr
*/ */
public abstract int getPriority(); 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.gamecore.control.timing.Updateable;
import mightypork.rogue.events.ActionRequest; import mightypork.rogue.events.ActionRequest;
import mightypork.rogue.events.ActionRequest.RequestType; import mightypork.rogue.events.ActionRequest.RequestType;
import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView; import mightypork.utils.math.vect.VectVar;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
import org.lwjgl.input.Keyboard; import org.lwjgl.input.Keyboard;
@ -29,7 +29,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
private final KeyBindingPool keybindings; private final KeyBindingPool keybindings;
/** Current mouse position */ /** Current mouse position */
private final VectView mousePos = new VectView() { private final Vect mousePos = new Vect() {
@Override @Override
public double x() public double x()
@ -103,8 +103,8 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
} }
// counters as fields to save memory. // counters as fields to save memory.
private final VectMutable mouseMove = VectMutable.zero(); private final VectVar mouseMove = VectVar.makeVar();
private final VectMutable mouseLastPos = VectMutable.zero(); private final VectVar mouseLastPos = VectVar.makeVar();
@Override @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 int button = Mouse.getEventButton();
final boolean down = Mouse.getEventButtonState(); final boolean down = Mouse.getEventButtonState();
final VectMutable pos = VectMutable.make(Mouse.getEventX(), Mouse.getEventY()); final VectVar pos = Vect.makeVar(Mouse.getEventX(), Mouse.getEventY());
final VectMutable move = VectMutable.make(Mouse.getEventDX(), Mouse.getEventDY()); final VectVar move = Vect.makeVar(Mouse.getEventDX(), Mouse.getEventDY());
final int wheeld = Mouse.getEventDWheel(); final int wheeld = Mouse.getEventDWheel();
@ -155,7 +155,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
move.mul(1, -1, 1); move.mul(1, -1, 1);
if (button != -1 || wheeld != 0) { 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); moveSum.add(move);
@ -178,7 +178,7 @@ public class InputSystem extends RootBusNode implements Updateable, KeyBinder {
* *
* @return mouse position * @return mouse position
*/ */
public VectView getMousePos() public Vect getMousePos()
{ {
return mousePos; return mousePos;
} }

@ -11,9 +11,8 @@ 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.RectBound; import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.rect.RectVal; import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.rect.RectView; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.LWJGLException; import org.lwjgl.LWJGLException;
@ -33,7 +32,7 @@ public class DisplaySystem extends AppModule implements RectBound {
private FpsMeter fpsMeter; private FpsMeter fpsMeter;
/** Current screen size */ /** Current screen size */
private final VectView screenSize = new VectView() { private final Vect screenSize = new Vect() {
@Override @Override
public double y() 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 * @param app app access
@ -189,7 +190,7 @@ public class DisplaySystem extends AppModule implements RectBound {
* *
* @return size * @return size
*/ */
public VectView getSize() public Vect getSize()
{ {
return screenSize; return screenSize;
} }
@ -240,9 +241,9 @@ public class DisplaySystem extends AppModule implements RectBound {
@Override @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(); return getSize().half();
} }

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

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

@ -2,7 +2,7 @@ package mightypork.gamecore.render.fonts;
import mightypork.utils.math.color.RGB; 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 * @param text string to check
* @return coord (width, height) * @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.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.vect.VectVal; import mightypork.utils.math.vect.VectConst;
import org.lwjgl.BufferUtils; import org.lwjgl.BufferUtils;
import org.lwjgl.util.glu.GLU; 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); byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(newI);
} else { } else {
byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()) byteBuffer = ByteBuffer.allocateDirect(width * height * (bpp / 8)).order(ByteOrder.nativeOrder()).put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
.put(((DataBufferByte) (bufferedImage.getData().getDataBuffer())).getData());
} }
byteBuffer.flip(); byteBuffer.flip();
@ -412,8 +411,7 @@ public class CachedFont implements GLFont {
chtx = chars.get(charCurrent); chtx = chars.get(charCurrent);
if (chtx != null) { if (chtx != null) {
drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY drawQuad((totalwidth), 0, (totalwidth + chtx.width), (chtx.height), chtx.texPosX, chtx.texPosY, chtx.texPosX + chtx.width, chtx.texPosY + chtx.height);
+ chtx.height);
totalwidth += chtx.width; totalwidth += chtx.width;
} }
} }
@ -424,9 +422,9 @@ public class CachedFont implements GLFont {
@Override @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.files.FileUtils;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
import mightypork.utils.math.vect.Vect; 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 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);
@ -164,7 +163,7 @@ public class DeferredFont extends DeferredResource implements GLFont {
* @return coord (width, height) * @return coord (width, height)
*/ */
@Override @Override
public VectView getNeededSpace(String text) public Vect getNeededSpace(String text)
{ {
if (!ensureLoaded()) return Vect.ZERO; if (!ensureLoaded()) return Vect.ZERO;

@ -5,7 +5,6 @@ import mightypork.gamecore.render.fonts.GLFont;
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.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectView;
/** /**
@ -23,7 +22,7 @@ public class NullFont implements GLFont {
@Override @Override
public VectView getNeededSpace(String str) public Vect getNeededSpace(String str)
{ {
return Vect.ZERO; return Vect.ZERO;
} }

@ -2,7 +2,7 @@ package mightypork.gamecore.render.textures;
import mightypork.utils.math.rect.Rect; import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.rect.RectVal; import mightypork.utils.math.rect.RectConst;
import org.newdawn.slick.opengl.Texture; import org.newdawn.slick.opengl.Texture;
@ -65,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, 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 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() { 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.rogue.Res;
import mightypork.utils.math.color.RGB; import mightypork.utils.math.color.RGB;
import mightypork.utils.math.constraints.RectBound; import mightypork.utils.math.constraints.RectBound;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectConst;
public class LayerBouncyBoxes extends ScreenLayer { 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); final TextPainter tp = new TextPainter(Res.getFont("default"), Align.LEFT, RGB.WHITE);
tp.setText("Press \"C\" for \"Cat\" screen."); 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); layout.add(tp);
} }

@ -17,15 +17,16 @@ 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.num.Num;
import mightypork.utils.math.rect.Rect;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectAnimated; import mightypork.utils.math.vect.VectAnimated;
import mightypork.utils.math.vect.VectVal;
public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener { public class LayerFlyingCat extends ScreenLayer implements Updateable, MouseButtonEvent.Listener {
private final AnimDouble size = new AnimDouble(400, Easing.SINE_BOTH); 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(); 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")); cat = new ImagePainter(Res.getTxQuad("test.kitten"));
// Bounds.box(size,size).centerTo(pos) cat.setContext(Rect.make(size, size).centerTo(pos));
cat.setContext(centerTo(box(size, size), pos));
tp = new TextPainter(Res.getFont("default")); tp = new TextPainter(Res.getFont("default"));
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), VectVal.make(2, 2)); tp.setShadow(RGB.dark(0.8), Vect.make(2, 2));
// Bounds.box(64,64).centerTo(cMousePos) tp.setContext(Rect.make(64, 64).centerTo(mouse()));
tp.setContext(centerTo(box(64, 64), cMousePos));
qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED); qp = QuadPainter.gradV(RGB.YELLOW, RGB.RED);
// Bounds.wrap(cat).bottomLeft().expand(0,0,50,50) qp.setContext(cat.getRect().bottomLeft().expand(size.half(), Num.ZERO, Num.ZERO, size.half()));
qp.setContext(expand(bottomLeft(cat), 0, 0, 50, 50));
/* /*
* Register keys * Register keys

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

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

@ -3,14 +3,13 @@ package mightypork.test;
import java.util.Locale; 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.Rect;
import mightypork.utils.math.rect.RectVal; import mightypork.utils.math.rect.RectConst;
import mightypork.utils.math.rect.RectView;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectConst;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectVar;
import mightypork.utils.math.vect.VectView;
public class TestConstr { public class TestConstr {
@ -22,52 +21,52 @@ public class TestConstr {
int cnt = -1; int cnt = -1;
{ {
final RectVal rect = RectVal.make(0, 0, 10, 10); final RectConst rect = Rect.make(0, 0, 10, 10);
final VectVal point = VectVal.make(50, 50); final VectConst point = Vect.make(50, 50);
System.out.println("Test " + ++cnt + ": rect = " + rect); System.out.println("Test " + ++cnt + ": rect = " + rect);
System.out.println("Test " + cnt + ": point = " + point); 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 RectConst rect = Rect.make(0, 0, 10, 10);
final RectView v = rect.view().view(); final Rect v = rect;
System.out.println("\nTest " + ++cnt + ": " + (v == rect.view())); System.out.println("\nTest " + ++cnt + ": " + (v == rect));
} }
{ {
final RectVal rect = RectVal.make(0, 0, 10, 10); final RectConst rect = Rect.make(0, 0, 10, 10);
final RectView v = rect.view().view().view().view().view().view(); final Rect v = rect;
System.out.println("\nTest " + ++cnt + ": " + (v == rect.view())); System.out.println("\nTest " + ++cnt + ": " + (v == rect));
} }
{ {
final Vect a = VectVal.make(3, 3); final Vect a = Vect.make(3, 3);
final VectVal v = a.copy().copy().copy(); final VectConst v = a.freeze().freeze().freeze();
System.out.println("\nTest " + ++cnt + ": " + (v == a.copy())); System.out.println("\nTest " + ++cnt + ": " + (v == a.freeze()));
} }
{ {
final Vect a = VectVal.make(3, 3); final Vect a = Vect.make(3, 3);
final VectVal v = a.copy().copy().copy(); final VectConst v = a.freeze().freeze().freeze();
System.out.println("\nTest " + ++cnt + ": " + (v == a.copy())); System.out.println("\nTest " + ++cnt + ": " + (v == a.freeze()));
} }
{ {
final VectMutable a = VectMutable.make(10, 10); final VectVar a = Vect.makeVar(10, 10);
final VectView view = a.view().mul(10).half().sub(1, 1); final Vect view = a.mul(10).half().sub(1, 1);
System.out.println("\nTest " + ++cnt + ": " + (view.equals(VectVal.make(49, 49)))); System.out.println("\nTest " + ++cnt + ": " + (view.equals(Vect.make(49, 49))));
a.add(10, 0); 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); a.setTo(900, 999);
System.out.println(view); System.out.println(view);
} }
{ {
final NumMutable side = NumMutable.make(100); final NumVar side = Num.makeVar(100);
final VectMutable center = VectMutable.make(0, 0); 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); 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); 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; package mightypork.test;
import java.util.Locale; import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumVar;
import mightypork.utils.math.num.NumView; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectMutable; import mightypork.utils.math.vect.VectVar;
import mightypork.utils.math.vect.VectView;
public class TestCoords { public class TestCoords {
public static void main(String[] args) public static void main(String[] args)
{ {
Locale.setDefault(Locale.ENGLISH); {
VectVar a = Vect.makeVar();
// test VectVar b = Vect.makeVar();
final VectMutable var = VectMutable.make(1, 2, 3);
Vect cross = a.cross(b);
final VectView cubicRoot = var.mul(var).mul(var); Num dot = a.dot(b);
final VectView half = var.half(); Vect sum = a.add(b);
Num dist = a.dist(b);
System.out.println("x, x^3, x/5");
System.out.println(var); a.setTo(0, 10, 0);
System.out.println(cubicRoot); b.setTo(0, 6, 7);
System.out.println(half);
System.out.println("a = " + a);
var.setTo(var.mul(10)); System.out.println("b = " + b);
System.out.println("axb = " + cross);
System.out.println("x = x*10; x, x^3, x/5"); System.out.println("a.b = " + dot);
System.out.println(var); System.out.println("a+b = " + sum);
System.out.println(cubicRoot); System.out.println("dist(a,b) = " + dist);
System.out.println(half); }
final NumView y = var.yn(); {
System.out.println("y: " + y.value()); NumVar a = Num.makeVar();
var.setTo(var.add(100, 100)); Num end = a;
System.out.println("x = x*100; x.y(), x, x^3, x/5"); for (int i = 0; i < 100; i++) {
System.out.println(y.value()); end = end.add(1);
System.out.println(var); }
System.out.println(cubicRoot);
System.out.println(half); 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.Range;
import mightypork.utils.math.vect.Vect; import mightypork.utils.math.vect.Vect;
import mightypork.utils.math.vect.VectVal; import mightypork.utils.math.vect.VectConst;
import mightypork.utils.objects.Convert; 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); props.load(fis);
} catch (final IOException e) { } catch (final IOException e) {
needsSave = true; needsSave = true;
@ -362,7 +362,7 @@ public class PropertyManager {
* @param n key * @param n key
* @return the coord found, or null * @return the coord found, or null
*/ */
public VectVal getCoord(String n) public VectConst getCoord(String n)
{ {
return Convert.toVect(get(n).value); return Convert.toVect(get(n).value);
} }

@ -72,11 +72,9 @@ 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) {
final int read1 = cin1.read(BUFFER); final int read1 = cin1.read(BUFFER);

@ -95,8 +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 +160,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);
} }
@ -361,7 +360,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,8 +481,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 +498,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);
} }
} }

@ -74,7 +74,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);
} }
} }
@ -95,7 +95,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);
} }
} }

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

@ -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)));

@ -11,7 +11,7 @@
//import mightypork.utils.math.vect.Vect; //import mightypork.utils.math.vect.Vect;
//import mightypork.utils.math.vect.VectAdapter; //import mightypork.utils.math.vect.VectAdapter;
//import mightypork.utils.math.vect.VectVal; //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 // * @param vectBound vect bound
// * @return contained vect // * @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) // 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 b = eval(bottom);
// final double l = eval(left); // 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); // 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); // return mul(c, -1);
// } // }
// //
// //
// public static VectView half(final VectBound c) // public static Vect half(final VectBound c)
// { // {
// return mul(c, 0.5); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(c1).add(eval(c2)); // 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); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(c).add(eval(x), eval(y), eval(z)); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(c1).sub(eval(c2)); // 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); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(c).sub(eval(x), eval(y), eval(z)); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(c).mul(eval(mul)); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(c).norm(eval(norm)); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(r).origin(); // 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() { // return new VectAdapter() {
// //
// @Override // @Override
// public VectView getSource() // public Vect getSource()
// { // {
// return eval(r).size(); // 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))); // return add(origin(r), half(size(r)));
// } // }
// //
// //
// public static VectView topLeft(final RectBound r) // public static Vect topLeft(final RectBound r)
// { // {
// return origin(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); // 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)); // 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)); // 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); // 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)); // 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))); // 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))); // return add(origin(r), width(r), half(width(r)));
// } // }
@ -946,19 +946,19 @@
// @Override // @Override
// public RectView getRect() // public RectView getRect()
// { // {
// VectView cv = eval(c); // Vect cv = eval(c);
// //
// return new RectView() { // return new RectView() {
// //
// @Override // @Override
// public VectView size() // public Vect size()
// { // {
// return Vect.ZERO.view(); // return Vect.ZERO;
// } // }
// //
// //
// @Override // @Override
// public VectView origin() // public Vect origin()
// { // {
// return null; // return null;
// } // }

@ -21,7 +21,7 @@ public abstract class NumMutable extends Num {
* *
* @param value new value * @param value new value
*/ */
public void setTo(Num value) public void assign(Num value)
{ {
setTo(eval(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 @FactoryMethod
public static Rect make(Num x, Num y, Num width, Num height) 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); 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 * Get a copy of current value
@ -448,49 +474,49 @@ public abstract class Rect implements RectBound {
public Num x() public Num x()
{ {
return origin().xn(); return p_x != null ? p_x : (p_x = origin().xn());
} }
public Num y() public Num y()
{ {
return origin().yn(); return p_y != null ? p_y : (p_y = origin().yn());
} }
public Num width() public Num width()
{ {
return size().xn(); return p_w != null ? p_w : (p_w = size().xn());
} }
public Num height() public Num height()
{ {
return size().yn(); return p_h != null ? p_h : (p_h = size().yn());
} }
public Num left() public Num left()
{ {
return origin().yn(); return p_l != null ? p_l : (p_l = origin().yn());
} }
public Num right() 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() public Num top()
{ {
return origin().yn(); return p_t != null ? p_t : (p_t = origin().yn());
} }
public Num bottom() 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() 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() 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() 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() public Vect center()
{ {
return origin().add(size().half()); return p_cc != null ? p_cc : (p_cc = origin().add(size().half()));
} }
public Vect centerRight() 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() 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() 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() 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; 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 pos;
private final VectConst size; 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. * Create at given origin, with given size.
@ -89,14 +102,14 @@ public class RectConst extends Rect {
@Override @Override
public RectConst move(double x, double y) 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 @Override
public RectConst shrink(double left, double right, double top, double bottom) 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 @Override
public RectConst grow(double left, double right, double top, double bottom) 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 @Override
public RectConst round() public RectConst round()
{ {
final VectConst s = size(); if (v_round == null) v_round = Rect.make(pos.round(), size.round());
final VectConst o = origin(); return v_round;
return Rect.make(o.round(), s.round()).freeze();
} }
@Override @Override
public NumConst x() public NumConst x()
{ {
return origin().xn(); return pos.xn();
} }
@Override @Override
public NumConst y() public NumConst y()
{ {
return origin().yn(); return pos.yn();
} }
@Override @Override
public NumConst width() public NumConst width()
{ {
return size().xn(); return size.xn();
} }
@Override @Override
public NumConst height() public NumConst height()
{ {
return size().yn(); return size.yn();
} }
@Override @Override
public NumConst left() public NumConst left()
{ {
return origin().xn(); return pos.xn();
} }
@Override @Override
public NumConst right() public NumConst right()
{ {
return origin().xn().add(size().xn()); if (v_r == null) v_r = super.right().freeze();
return v_r;
} }
@Override @Override
public NumConst top() public NumConst top()
{ {
return origin().yn(); return pos.yn();
} }
@Override @Override
public NumConst bottom() public NumConst bottom()
{ {
return origin().yn().add(size().yn()); if (v_b == null) v_b = super.bottom().freeze();
return v_b;
} }
@Override @Override
public VectConst topLeft() public VectConst topLeft()
{ {
return origin(); return pos;
} }
@Override @Override
public VectConst topCenter() public VectConst topCenter()
{ {
return origin().add(size().x() / 2, 0); if (v_tc == null) v_tc = super.topCenter().freeze();
return v_tc;
} }
@Override @Override
public VectConst topRight() public VectConst topRight()
{ {
return origin().add(size().x(), 0); if (v_tr == null) v_tr = super.topRight().freeze();
return v_tr;
} }
@Override @Override
public VectConst centerLeft() public VectConst centerLeft()
{ {
return origin().add(0, size().y() / 2); if (v_cl == null) v_cl = super.centerLeft().freeze();
return v_cl;
} }
@Override @Override
public VectConst center() public VectConst center()
{ {
return origin().add(size().half()).freeze(); if (v_c == null) v_c = super.center().freeze();
return v_c;
} }
@Override @Override
public VectConst centerRight() public VectConst centerRight()
{ {
return origin().add(size().x(), size().y() / 2); if (v_cr == null) v_cr = super.centerRight().freeze();
return v_cr;
} }
@Override @Override
public VectConst bottomLeft() public VectConst bottomLeft()
{ {
return origin().add(0, size().y()); if (v_bl == null) v_bl = super.bottomLeft().freeze();
return v_bl;
} }
@Override @Override
public VectConst bottomCenter() public VectConst bottomCenter()
{ {
return origin().add(size().x() / 2, size().y()); if (v_bc == null) v_bc = super.bottomCenter().freeze();
return v_bc;
} }
@Override @Override
public VectConst bottomRight() 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 * @author MightyPork
*/ */

@ -7,6 +7,7 @@ import mightypork.utils.math.Calc;
import mightypork.utils.math.constraints.VectBound; import mightypork.utils.math.constraints.VectBound;
import mightypork.utils.math.num.Num; import mightypork.utils.math.num.Num;
import mightypork.utils.math.num.NumConst; 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(); 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