Search in sources :

Example 6 with Point

use of com.builtbroken.mc.lib.transform.vector.Point in project Engine by VoltzEngine-Project.

the class RectangleTest method testIsWithin.

/**
 * Checks if the basic version of the point bounding box check is working
 */
public void testIsWithin() {
    Rectangle rect = new Rectangle(new Point(0, 0), new Point(2, 2));
    List<Point> points_inside = new LinkedList();
    points_inside.add(rect.cornerA());
    points_inside.add(rect.cornerB());
    points_inside.add(rect.cornerC());
    points_inside.add(rect.cornerD());
    points_inside.add(new Point(1, 1));
    List<Point> points_outside = new LinkedList();
    points_outside.add(new Point(-1, -1));
    points_outside.add(new Point(0, -1));
    points_outside.add(new Point(-1, 0));
    points_outside.add(new Point(3, 0));
    points_outside.add(new Point(0, 3));
    for (int i = 0; i < 4; i++) {
        // First two runs are inside checks
        boolean inside = i <= 1;
        boolean rotated = (i == 1 || i == 3);
        List<Point> l = inside ? points_inside : points_outside;
        for (Point vec : l) {
            boolean flag = !rotated ? rect.isWithin(vec) : rect.isWithin_rotated(vec);
            // Debug for when the checks fail and we need to know why
            if (flag != inside) {
                System.out.println("===   Debug   ===");
                if (!rotated) {
                    System.out.println("isWithinX: " + (vec.x() >= rect.min().x() && vec.x() <= rect.max().x()));
                    System.out.println("isWithinY: " + (vec.y() >= rect.min().y() && vec.y() <= rect.max().y()));
                } else {
                    double ab = new Triangle(rect.cornerA(), rect.cornerB(), vec).getArea();
                    double bc = new Triangle(rect.cornerB(), rect.cornerC(), vec).getArea();
                    double cd = new Triangle(rect.cornerC(), rect.cornerD(), vec).getArea();
                    double da = new Triangle(rect.cornerD(), rect.cornerA(), vec).getArea();
                    System.out.println("TriABP Area: " + ab);
                    System.out.println("TriBCP Area: " + bc);
                    System.out.println("TriCBP Area: " + cd);
                    System.out.println("TriDAP Area: " + da);
                    System.out.println("Total Area:  " + (ab + bc + cd + da));
                    System.out.println("Rect Area:   " + rect.getArea());
                }
                System.out.println("==================");
                // Failure message
                String msg = "Failed for ";
                msg += (!rotated ? "Normal Test " : "Rotated Test ");
                msg += vec + " ";
                msg += (inside ? " should be inside the rect!" : " should be outside the rect!");
                fail(msg);
            }
        }
    }
}
Also used : Rectangle(com.builtbroken.mc.lib.transform.region.Rectangle) Triangle(com.builtbroken.mc.lib.transform.region.Triangle) Point(com.builtbroken.mc.lib.transform.vector.Point) LinkedList(java.util.LinkedList) Point(com.builtbroken.mc.lib.transform.vector.Point)

Example 7 with Point

use of com.builtbroken.mc.lib.transform.vector.Point in project Engine by VoltzEngine-Project.

the class GuiContainerBase method drawTextWithTooltip.

// TODO update and docs
protected void drawTextWithTooltip(String textName, String format, int x, int y, int mouseX, int mouseY, int color) {
    String name = LanguageUtility.getLocal("gui." + textName + ".name");
    String text = format.replaceAll("%1", name);
    fontRendererObj.drawString(text, x, y, color);
    String tooltip = LanguageUtility.getLocal("gui." + textName + ".tooltip");
    if (tooltip != null && tooltip != "") {
        if (new Rectangle(x, y, (int) (text.length() * 4.8), 12).isWithin(new Point(mouseX, mouseY))) {
            this.tooltip = tooltip;
        }
    }
}
Also used : Rectangle(com.builtbroken.mc.lib.transform.region.Rectangle) Point(com.builtbroken.mc.lib.transform.vector.Point)

Example 8 with Point

use of com.builtbroken.mc.lib.transform.vector.Point in project Engine by VoltzEngine-Project.

the class GuiContainerBase method renderUniversalDisplay.

// TODO update and docs
public void renderUniversalDisplay(int x, int y, double energy, double maxEnergy, int mouseX, int mouseY, Unit unit, boolean symbol) {
    String displaySuffix = "";
    if (unit == Unit.WATT) {
        displaySuffix = "/s";
    }
    String display = new UnitDisplay(unit, energy).symbol(symbol) + "/" + new UnitDisplay(unit, maxEnergy).symbol(symbol);
    // TODO: Check if this rect works.
    if (new Rectangle(x, y, x + display.length() * 5, y + 9).isWithin(new Point(mouseX, mouseY))) {
        if (Mouse.isButtonDown(0) && this.lastChangeFrameTime <= 0) {
            energyType = (energyType + 1) % 4;
            this.lastChangeFrameTime = 60;
        } else {
            this.drawTooltip(mouseX - this.guiLeft, mouseY - this.guiTop + 10, "Click to change unit.");
        }
    }
    this.lastChangeFrameTime--;
    fontRendererObj.drawString(display, x, y, 4210752);
}
Also used : Rectangle(com.builtbroken.mc.lib.transform.region.Rectangle) UnitDisplay(com.builtbroken.jlib.data.science.units.UnitDisplay) Point(com.builtbroken.mc.lib.transform.vector.Point)

Aggregations

Point (com.builtbroken.mc.lib.transform.vector.Point)8 Triangle (com.builtbroken.mc.lib.transform.region.Triangle)5 Rectangle (com.builtbroken.mc.lib.transform.region.Rectangle)4 UnitDisplay (com.builtbroken.jlib.data.science.units.UnitDisplay)1 LinkedList (java.util.LinkedList)1