Search in sources :

Example 1 with Point

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

the class TriangleTest method testAcuteTriangleAreas.

/**
 * Tests area method using 4 triangles in each section
 * of pos & neg relations. It also tests the order of the points
 * when constructing the triangle to ensure there are no ordering
 * issues with how the math is handled
 */
public void testAcuteTriangleAreas() {
    final double expectedArea = 2;
    // Using zero zero
    Point zeroZero = new Point();
    Point p1 = null;
    Point p2 = null;
    Triangle a, b, c;
    for (int i = 0; i < 4; i++) {
        switch(i) {
            case 0:
                // UP
                p1 = new Point(1, 2);
                p2 = new Point(-1, 2);
                break;
            case 2:
                // DOWN
                p1 = new Point(1, -2);
                p2 = new Point(-1, -2);
                break;
            case 3:
                // RIGHT
                p1 = new Point(2, 1);
                p2 = new Point(2, -1);
                break;
            case 4:
                // LEFT
                p1 = new Point(-2, 1);
                p2 = new Point(-2, -1);
                break;
        }
        a = new Triangle(zeroZero, p1, p2);
        b = new Triangle(p1, p2, zeroZero);
        c = new Triangle(p2, zeroZero, p1);
        assertEquals("Failed area check for A" + i, expectedArea, a.getArea());
        assertEquals("Failed area check for B" + i, expectedArea, b.getArea());
        assertEquals("Failed area check for C" + i, expectedArea, c.getArea());
    }
}
Also used : Triangle(com.builtbroken.mc.lib.transform.region.Triangle) Point(com.builtbroken.mc.lib.transform.vector.Point) Point(com.builtbroken.mc.lib.transform.vector.Point)

Example 2 with Point

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

the class TriangleTest method testRightTriangleAreas.

/**
 * Tests area method using 4 triangles in each section
 * of pos & neg relations. It also tests the order of the points
 * when constructing the triangle to ensure there are no ordering
 * issues with how the math is handled
 */
public void testRightTriangleAreas() {
    final double expectedArea = 2;
    // Using zero zero
    Point zeroZero = new Point();
    Point p1 = null;
    Point p2 = null;
    Triangle a, b, c;
    for (int i = 0; i < 4; i++) {
        switch(i) {
            case 0:
                // positive positive
                p1 = new Point(0, 2);
                p2 = new Point(2, 0);
                break;
            case 2:
                // neg positive
                p1 = new Point(0, 2);
                p2 = new Point(-2, 0);
                break;
            case 3:
                // positive neg
                p1 = new Point(0, -2);
                p2 = new Point(2, 0);
                break;
            case 4:
                // neg neg
                p1 = new Point(0, -2);
                p2 = new Point(-2, 0);
                break;
        }
        a = new Triangle(zeroZero, p1, p2);
        b = new Triangle(p1, p2, zeroZero);
        c = new Triangle(p2, zeroZero, p1);
        assertEquals("Failed area check for A" + i, expectedArea, a.getArea());
        assertEquals("Failed area check for B" + i, expectedArea, b.getArea());
        assertEquals("Failed area check for C" + i, expectedArea, c.getArea());
    }
}
Also used : Triangle(com.builtbroken.mc.lib.transform.region.Triangle) Point(com.builtbroken.mc.lib.transform.vector.Point) Point(com.builtbroken.mc.lib.transform.vector.Point)

Example 3 with Point

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

the class TriangleTest method testObtuseTriangleAreas.

/**
 * Tests area method using 4 triangles in each section
 * of pos & neg relations. It also tests the order of the points
 * when constructing the triangle to ensure there are no ordering
 * issues with how the math is handled
 */
public void testObtuseTriangleAreas() {
    final double expectedArea = 4;
    // Using zero zero
    Point zeroZero = new Point();
    Point p1 = null;
    Point p2 = null;
    Triangle a, b, c;
    for (int i = 0; i < 4; i++) {
        switch(i) {
            case 0:
                // UP
                p1 = new Point(2, 2);
                p2 = new Point(-2, 2);
                break;
            case 2:
                // DOWN
                p1 = new Point(2, -2);
                p2 = new Point(-2, -2);
                break;
            case 3:
                // RIGHT
                p1 = new Point(2, 2);
                p2 = new Point(2, -2);
                break;
            case 4:
                // LEFT
                p1 = new Point(-2, 2);
                p2 = new Point(-2, -2);
                break;
        }
        a = new Triangle(zeroZero, p1, p2);
        b = new Triangle(p1, p2, zeroZero);
        c = new Triangle(p2, zeroZero, p1);
        assertEquals("Failed area check for A" + i, expectedArea, a.getArea());
        assertEquals("Failed area check for B" + i, expectedArea, b.getArea());
        assertEquals("Failed area check for C" + i, expectedArea, c.getArea());
    }
}
Also used : Triangle(com.builtbroken.mc.lib.transform.region.Triangle) Point(com.builtbroken.mc.lib.transform.vector.Point) Point(com.builtbroken.mc.lib.transform.vector.Point)

Example 4 with Point

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

the class TriangleTest method testTriangleAreas.

// TODO include a performance test to see how fast these method calls run on average
public void testTriangleAreas() {
    // Dummy checks for the hell of it
    Triangle t = new Triangle(new Point(), new Point(), new Point());
    assertEquals("Expected zero due to all 3 points being zero zero", 0.0, t.getArea());
    t = new Triangle(new Point(0, 1), new Point(0, 2), new Point(0, 3));
    assertEquals("Expected zero due to all 3 points being in a line", 0.0, t.getArea());
    // http://www.mathopenref.com/coordtrianglearea.html
    t = new Triangle(new Point(0, 0), new Point(-1, 2), new Point(13, 5));
    assertEquals("Expected an exact match for area check one", 15.5, t.getArea());
    t = new Triangle(new Point(0, 0), new Point(-12, 27), new Point(37, 25));
    assertEquals("Expected an exact match for area check two", 649.5, t.getArea());
    t = new Triangle(new Point(0, 0), new Point(-12, 27), new Point(14, -10));
    assertEquals("Expected an exact match for area check three", 129.0, t.getArea());
    t = new Triangle(new Point(15, 15), new Point(23, 30), new Point(25, 8));
    assertEquals("Expected an exact match for area check four", 103.0, t.getArea());
    t = new Triangle(new Point(10, -6), new Point(42, -6), new Point(25, -12));
    assertEquals("Expected an exact match for area check five", 96.0, t.getArea());
}
Also used : Triangle(com.builtbroken.mc.lib.transform.region.Triangle) Point(com.builtbroken.mc.lib.transform.vector.Point)

Example 5 with Point

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

the class RectangleTest method testArea.

/**
 * Checks too see if the area math is working :P
 */
public void testArea() {
    // For the hell of it
    Rectangle rect = new Rectangle(new Point(), new Point());
    assertEquals("Expected zero as both corners are zero zero", 0.0, rect.getArea());
    rect = new Rectangle(new Point(0, 1), new Point(0, 2));
    assertEquals("Expected zero as both corners are in a strait line", 0.0, rect.getArea());
    // Random are checks
    rect = new Rectangle(new Point(0, 0), new Point(2, 2));
    assertEquals("Expected an exact match for area check one", 4.0, rect.getArea());
    rect = new Rectangle(new Point(0, 0), new Point(-2, -2));
    assertEquals("Expected an exact match for area check two", 4.0, rect.getArea());
    rect = new Rectangle(new Point(-2, -2), new Point(2, 2));
    assertEquals("Expected an exact match for area check three", 16.0, rect.getArea());
    rect = new Rectangle(new Point(10, 20), new Point(-20, -10));
    assertEquals("Expected an exact match for area check four", 900.0, rect.getArea());
}
Also used : Rectangle(com.builtbroken.mc.lib.transform.region.Rectangle) 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