All pastes #339922 Raw Edit

Miscellany

public java v1 · immutable
·published 2007-02-04 12:16 UTC
rendered paste body
public int getCompass() throws InterruptedException {        RGB redDot = new RGB(159, 12, 14);        XY t1 = null, t2 = null, t3 = null;        t1 = findXYspiral(                getColorArray2d(),                redDot,                Areas.COMPASS,                new Rectangle[] { Areas.COMPASSEXCLUDE, Areas.COMPASSEXCLUDE2 },                10, 10, 10);        if (t1 != null) {            t2 = findXYspiral(getColorArray2d(), redDot, Areas.COMPASS,                    new Rectangle[] { Areas.COMPASSEXCLUDE,                            Areas.COMPASSEXCLUDE2,                            new Rectangle(t1.x - 3, t1.y - 3, 6, 6) }, 10, 10,                    10);            if (t2 != null) {                t3 = findXYspiral(getColorArray2d(), redDot, Areas.COMPASS,                        new Rectangle[] { Areas.COMPASSEXCLUDE,                                Areas.COMPASSEXCLUDE2,                                new Rectangle(t1.x - 3, t1.y - 3, 6, 6),                                new Rectangle(t2.x - 3, t2.y - 3, 6, 6) }, 10,                        10, 10);                if (t3 != null) {                    return compassbullshitRuler(t1, t2, t3);                }            }        }        log("getCompass() :(");        return -1;    }    public double distanceDouble(XY xy1, XY xy2) {        double dx = xy1.x - xy2.x;        double dy = xy1.y - xy2.y;        if (dx == 0) {            return dy;        }        if (dy == 0) {            return dx;        }        return Math.sqrt((dx * dx) + (dy * dy));    }    private int compassbullshitRuler(XY xy1, XY xy2, XY xy3)            throws InterruptedException {        XY CompassCenter = new XY(566, 20);        xy1 = new XY(xy1.x - CompassCenter.x, CompassCenter.y - xy1.y);        xy2 = new XY(xy2.x - CompassCenter.x, CompassCenter.y - xy2.y);        xy3 = new XY(xy3.x - CompassCenter.x, CompassCenter.y - xy3.y);        XY reversePoint = null;        if (distanceDouble(xy1, xy3) > distanceDouble(xy2, xy3)                && distanceDouble(xy1, xy3) > distanceDouble(xy1, xy2)) {            reversePoint = xy2;        } else if (distanceDouble(xy2, xy3) > distanceDouble(xy2, xy1)                && distanceDouble(xy2, xy3) > distanceDouble(xy1, xy3)) {            reversePoint = xy1;        } else if (distanceDouble(xy1, xy2) > distanceDouble(xy2, xy3)                && distanceDouble(xy1, xy2) > distanceDouble(xy1, xy3)) {            reversePoint = xy3;        }        if (reversePoint != null) {            int degrees = (int) Math.toDegrees(Math.atan2(reversePoint.y,                    reversePoint.x));            if (degrees < 0) {                degrees = 180 + degrees;            } else {                degrees = degrees - 180;            }            if (degrees < 0) {                degrees = 360 + degrees;            }            degrees %= 360;            return degrees % 360;        } else {            log("compassbullshitRuler() :(");            return -1;        }    }