X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=src%2Forg%2Fibex%2Fgraphics%2FAffine.java;h=83b2d18b0d409744aeb6005acc8a4a528f665b70;hb=05d23fde131a7d19b378c632c6cc6b7924d8ab4d;hp=027f0486e0c1863efa60fec7abdc658ac478551b;hpb=76b21655a0710caf4f972c107a3ab991032d7e10;p=org.ibex.core.git diff --git a/src/org/ibex/graphics/Affine.java b/src/org/ibex/graphics/Affine.java index 027f048..83b2d18 100644 --- a/src/org/ibex/graphics/Affine.java +++ b/src/org/ibex/graphics/Affine.java @@ -25,7 +25,19 @@ public final class Affine { public static Affine flip(boolean horiz, boolean vert) { return new Affine(horiz ? -1 : 1, 0, 0, vert ? -1 : 1, 0, 0); } public float multiply_px(float x, float y) { return x * a + y * c + e; } public float multiply_py(float x, float y) { return x * b + y * d + f; } + public float sign(float x) { return x >= 0 ? 1 : -1; } + public float divide_boundingbox_x(float bx, float by, float aspect) { + return (float)Math.min(Math.abs(bx * (sign(a) * sign(c)) / (aspect * a + c)), + Math.abs(by * (sign(b) * sign(d)) / (aspect * b + d))); + } + public float multiply_boundingbox_x(float x, float y) { + return (float)Math.max((int)Math.abs(multiply_px(x, y) - multiply_px(0, 0)), + (int)Math.abs(multiply_px(x, 0) - multiply_px(0, y))); } + public float multiply_boundingbox_y(float x, float y) { + return (float)Math.max((int)Math.abs(multiply_py(x, y) - multiply_py(0, 0)), + (int)Math.abs(multiply_py(x, 0) - multiply_py(0, y))); } public boolean equalsIgnoringTranslation(Affine x) { return a == x.a && b == x.b && c == x.c && d == x.d; } + public Affine clearTranslation() { e = (float)0.0; f = (float)0.0; return this; } public boolean equals(Object o) { if (!(o instanceof Affine)) return false; @@ -63,7 +75,7 @@ public final class Affine { return this; } - public void invert() { + public Affine invert() { float det = 1 / (a * d - b * c); float _a = d * det; float _b = -1 * b * det; @@ -72,6 +84,7 @@ public final class Affine { float _e = -1 * e * a - f * c; float _f = -1 * e * b - f * d; a = _a; b = _b; c = _c; d = _d; e = _e; f = _f; + return this; } public static Affine parse(String t) {