Search in sources :

Example 26 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class SpongeAABBTest method testExpandVector3d.

@Test
void testExpandVector3d() {
    final AABB aabb1 = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    final AABB aabb2 = new SpongeAABB(new Vector3d(-4, 3, 2.5), new Vector3d(12, 9, 13.5));
    Assertions.assertEquals(aabb2, aabb1.expand(new Vector3d(10, -2, 1)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 27 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class SpongeAABBTest method testSize.

@Test
void testSize() {
    final AABB aabb = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    Assertions.assertEquals(new Vector3d(6, 8, 10), aabb.size());
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 28 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class SpongeAABBTest method newIntersectingAABB.

private static AABB newIntersectingAABB(AABB with) {
    final Vector3d wMin = with.min();
    final Vector3d wSize = with.size();
    final double iSizeX = RANDOM.nextDouble() * wSize.x();
    final double iSizeY = RANDOM.nextDouble() * wSize.y();
    final double iSizeZ = RANDOM.nextDouble() * wSize.z();
    final double eSizeX = RANDOM.nextDouble() * 4 + 4;
    final double eSizeY = RANDOM.nextDouble() * 4 + 4;
    final double eSizeZ = RANDOM.nextDouble() * 4 + 4;
    final Vector3d min = wMin.sub(eSizeX, eSizeY, eSizeZ);
    final Vector3d max = wMin.add(iSizeX, iSizeY, iSizeZ);
    return new SpongeAABB(min, max);
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d)

Example 29 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class SpongeAABBTest method testConstructor.

@Test
void testConstructor() {
    final AABB aabb1 = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    Assertions.assertEquals(new Vector3d(1, 2, 3), aabb1.min());
    Assertions.assertEquals(new Vector3d(7, 10, 13), aabb1.max());
    final AABB aabb2 = new SpongeAABB(new Vector3d(11, 2, 3), new Vector3d(7, -10, 13));
    Assertions.assertEquals(new Vector3d(7, -10, 3), aabb2.min());
    Assertions.assertEquals(new Vector3d(11, 2, 13), aabb2.max());
    try {
        new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(1, 10, 13));
        Assertions.fail();
    } catch (IllegalArgumentException ignored) {
    // pass
    }
    try {
        new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 2, 13));
        Assertions.fail();
    } catch (IllegalArgumentException ignored) {
    // pass
    }
    try {
        new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 3));
        Assertions.fail();
    } catch (IllegalArgumentException ignored) {
    // pass
    }
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 30 with Vector3d

use of org.spongepowered.math.vector.Vector3d in project SpongeCommon by SpongePowered.

the class SpongeAABBTest method testExpandVector3i.

@Test
void testExpandVector3i() {
    final AABB aabb1 = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    final AABB aabb2 = new SpongeAABB(new Vector3d(-4, 3, 2.5), new Vector3d(12, 9, 13.5));
    Assertions.assertEquals(aabb2, aabb1.expand(new Vector3i(10, -2, 1)));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) Vector3i(org.spongepowered.math.vector.Vector3i) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Aggregations

Vector3d (org.spongepowered.math.vector.Vector3d)71 Vector3i (org.spongepowered.math.vector.Vector3i)16 CauseStackManager (org.spongepowered.api.event.CauseStackManager)14 AABB (org.spongepowered.api.util.AABB)14 Test (org.junit.jupiter.api.Test)13 ServerWorld (org.spongepowered.api.world.server.ServerWorld)13 BlockPos (net.minecraft.core.BlockPos)8 ServerLevel (net.minecraft.server.level.ServerLevel)7 BlockState (org.spongepowered.api.block.BlockState)7 Transformation (org.spongepowered.api.util.transformation.Transformation)7 Function (java.util.function.Function)6 IntStream (java.util.stream.IntStream)6 Stream (java.util.stream.Stream)6 Entity (org.spongepowered.api.entity.Entity)6 MoveEntityEvent (org.spongepowered.api.event.entity.MoveEntityEvent)6 ServerLocation (org.spongepowered.api.world.server.ServerLocation)6 Nullable (org.checkerframework.checker.nullness.qual.Nullable)5 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 MethodSource (org.junit.jupiter.params.provider.MethodSource)5 BlockType (org.spongepowered.api.block.BlockType)5