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()));
}
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());
}
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;
}
}
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);
}
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));
}
Aggregations