// Copyright 2020 The Terasology Foundation
// SPDX-License-Identifier: Apache-2.0

package org.terasology.math;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.terasology.math.geom.Rect2i;
import org.terasology.math.geom.Vector2i;
import org.terasology.nui.Border;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class BorderTest {
    Border border;

    @BeforeEach
    public void initBorder() {
        border = new Border(10, 10, 10, 10);
    }

    @Test
    public void shrinkSameBorderAndRegionSize() {
        assertEquals(border.shrink(JomlUtil.from(Rect2i.createFromMinAndSize(10, 10, 10, 10))), JomlUtil.from(Rect2i.EMPTY));
    }

    @Test
    public void shrinkBorder() {
        assertEquals(border.shrink(JomlUtil.from(Rect2i.createFromMinAndSize(30, 30, 30, 30))),
                JomlUtil.from(Rect2i.createFromMinAndSize(40, 40, 10, 10)));
    }

    @Test
    public void shrinkVector() {
        assertEquals(border.shrink(JomlUtil.from(new Vector2i(10, 10))), JomlUtil.from(new Vector2i(-10, -10)));
    }

    @Test
    public void getTotals() {
        assertEquals(border.getTotals(), JomlUtil.from(new Vector2i(20, 20)));
    }

    @Test
    public void growVector() {
        assertEquals(border.grow(JomlUtil.from(new Vector2i(10, 10))), JomlUtil.from(new Vector2i(30, 30)));
    }

    @Test
    public void growVectorMax() {
        assertEquals(border.grow(JomlUtil.from(new Vector2i(Integer.MAX_VALUE, Integer.MAX_VALUE))), JomlUtil.from(new Vector2i(
            Integer.MAX_VALUE, Integer.MAX_VALUE)));
    }

    @Test
    public void growBorder() {
        assertEquals(border.grow(JomlUtil.from(Rect2i.createFromMinAndSize(30, 30, 30, 30))),
                JomlUtil.from(Rect2i.createFromMinAndSize(20, 20, 50, 50)));
    }

    @Test
    public void growBorderMax() {
        assertEquals(border.grow(JomlUtil.from(Rect2i.createFromMinAndSize(10, 10, Integer.MAX_VALUE,
            Integer.MAX_VALUE))), JomlUtil.from(Rect2i.createFromMinAndSize(0, 0, Integer.MAX_VALUE,
            Integer.MAX_VALUE)));
    }
}

@@ -107,16 +107,44 @@
 .math;%0A%0A
+import org.joml.Rectanglei;%0A
 import o
@@ -326,16 +326,60 @@
 .Border;
+%0Aimport org.terasology.nui.util.RectUtility;
 %0A%0Aimport
@@ -1962,40 +1962,36 @@
 als(
-border.grow(JomlUtil.from(Rect2i
+%0A                RectUtility
 .cre
@@ -2008,21 +2008,19 @@
 AndSize(
-1
 0, 
-1
 0, Integ
@@ -2028,36 +2028,24 @@
 r.MAX_VALUE,
-%0A           
  Integer.MAX
@@ -2055,32 +2055,49 @@
 LUE)
-)), JomlUtil.from
+,%0A                border.grow
 (Rect
-2i
+Utility
 .cre
@@ -2106,35 +2106,37 @@
 eFromMinAndSize(
+1
 0, 
+1
 0, Integer.MAX_V
@@ -2140,28 +2140,89 @@
 X_VALUE,
-%0A           
+ Integer.MAX_VALUE)),%0A                %22Growing border should be capped at
  Integer
@@ -2223,29 +2223,28 @@
 nteger.MAX_VALUE
-))
+%22
 );%0A    %7D%0A%7D%0A

fix `growBorderMax` test by removing JomlUtil conversion