Search in sources :

Example 31 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class BlockAreaTest method textExtents.

@Test
public void textExtents() {
    BlockArea area = new BlockArea(2, 1, 10, 20).expand(3, 4);
    assertEquals(new Vector2i(-1, -3), area.getMin(new Vector2i()));
    assertEquals(new Vector2i(13, 24), area.getMax(new Vector2i()));
}
Also used : Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 32 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class BlockAreaTest method testIterator.

@Test
public void testIterator() {
    BlockArea a = new BlockArea(0, 0, 2, 2);
    // Make sure the iterator visits positions in the correct order, and that it works without calling hasNext() in between
    Iterator<Vector2ic> i = a.iterator();
    assertEquals(i.next(), new Vector2i(0, 0));
    assertEquals(i.next(), new Vector2i(1, 0));
    assertEquals(i.next(), new Vector2i(2, 0));
    assertEquals(i.next(), new Vector2i(0, 1));
    assertEquals(i.next(), new Vector2i(1, 1));
    assertEquals(i.next(), new Vector2i(2, 1));
    assertEquals(i.next(), new Vector2i(0, 2));
    assertEquals(i.next(), new Vector2i(1, 2));
    assertEquals(i.next(), new Vector2i(2, 2));
    assertFalse(i.hasNext());
}
Also used : Vector2ic(org.joml.Vector2ic) Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 33 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class SubSampledNoise method getSubset.

private float[] getSubset(float[] fullData, BlockAreac fullRegion, BlockAreac subRegion) {
    if (subRegion.getSizeX() != fullRegion.getSizeX() || subRegion.getSizeY() != fullRegion.getSizeY()) {
        float[] result = new float[subRegion.getSizeX() * subRegion.getSizeY()];
        Vector2i offset = new Vector2i(subRegion.minX() - fullRegion.minX(), subRegion.minY() - fullRegion.minY());
        for (int y = 0; y < subRegion.getSizeY(); ++y) {
            System.arraycopy(fullData, offset.x() + fullRegion.getSizeX() * (y + offset.y()), result, subRegion.getSizeX() * y, subRegion.getSizeX());
        }
        return result;
    } else {
        return fullData;
    }
}
Also used : Vector2i(org.joml.Vector2i)

Example 34 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class RowLayoutTest method setup.

@BeforeEach
public void setup() {
    rowLayout = new RowLayout();
    itemAt1x1 = mock(UIWidget.class);
    itemAt1x2 = mock(UIWidget.class);
    itemAt1x3 = mock(UIWidget.class);
    canvas = mock(Canvas.class);
    // +-----------------------------------+  +---+  +-------+
    // |                                   |  |1x2|  |       |
    // |               1x1                 |  +---+  |       |
    // |                                   |         |  1x3  |
    // +-----------------------------------+         |       |
    // |       |
    // +-------+
    when(canvas.calculateRestrictedSize(eq(itemAt1x1), any(Vector2i.class))).thenReturn(new Vector2i(50, 10));
    when(canvas.calculateRestrictedSize(eq(itemAt1x2), any(Vector2i.class))).thenReturn(new Vector2i(5, 5));
    when(canvas.calculateRestrictedSize(eq(itemAt1x3), any(Vector2i.class))).thenReturn(new Vector2i(10, 15));
    Vector2i availableSize = new Vector2i(CANVAS_WIDTH, CANVAS_HEIGHT);
    when(canvas.size()).thenReturn(availableSize);
    rowLayout.addWidget(itemAt1x1, null);
    rowLayout.addWidget(itemAt1x2, null);
    rowLayout.addWidget(itemAt1x3, null);
}
Also used : RowLayout(org.terasology.nui.layouts.RowLayout) Canvas(org.terasology.nui.Canvas) Vector2i(org.joml.Vector2i) UIWidget(org.terasology.nui.UIWidget) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 35 with Vector2i

use of org.joml.Vector2i in project Terasology by MovingBlocks.

the class RowLayoutTest method testSomeRelativeWidths.

@Test
public void testSomeRelativeWidths() throws Exception {
    // Sets relative width for first widget only
    rowLayout.setColumnRatios(0.5f);
    rowLayout.setHorizontalSpacing(0);
    Vector2i result = rowLayout.getPreferredContentSize(canvas, canvas.size());
    // Preferred width should be width of canvas
    assertEquals(CANVAS_WIDTH, result.x);
    // Preferred height should be the height of the tallest widget
    assertEquals(15, result.y);
    rowLayout.onDraw(canvas);
    // Width first determined for widget with relative width, then split equally among remaining widgets
    final int width1 = CANVAS_WIDTH / 2;
    final int width2 = (CANVAS_WIDTH - width1) / 2;
    final int width3 = (CANVAS_WIDTH - width1) / 2;
    verify(canvas).drawWidget(itemAt1x1, RectUtility.createFromMinAndSize(0, 0, width1, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x2, RectUtility.createFromMinAndSize(width1, 0, width2, CANVAS_HEIGHT));
    verify(canvas).drawWidget(itemAt1x3, RectUtility.createFromMinAndSize(width1 + width2, 0, width3, CANVAS_HEIGHT));
}
Also used : Vector2i(org.joml.Vector2i) Test(org.junit.jupiter.api.Test)

Aggregations

Vector2i (org.joml.Vector2i)41 Test (org.junit.jupiter.api.Test)12 Rectanglei (org.terasology.joml.geom.Rectanglei)9 Canvas (org.terasology.nui.Canvas)9 UILabel (org.terasology.nui.widgets.UILabel)6 List (java.util.List)5 Objects (java.util.Objects)5 ResourceUrn (org.terasology.gestalt.assets.ResourceUrn)5 Vector2f (org.joml.Vector2f)4 Vector2ic (org.joml.Vector2ic)4 Module (org.terasology.gestalt.module.Module)4 Name (org.terasology.gestalt.naming.Name)4 UIButton (org.terasology.nui.widgets.UIButton)4 DateFormat (java.text.DateFormat)3 SimpleDateFormat (java.text.SimpleDateFormat)3 Collection (java.util.Collection)3 Comparator (java.util.Comparator)3 Iterator (java.util.Iterator)3 Collectors (java.util.stream.Collectors)3 Stream (java.util.stream.Stream)3