Search in sources :

Example 66 with Vector3d

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

the class SpongeAABBTest method testExpandCoordinates.

@Test
void testExpandCoordinates() {
    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(10, -2, 1));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 67 with Vector3d

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

the class SpongeAABBTest method testOffsetCoordinates.

@Test
void testOffsetCoordinates() {
    final AABB aabb1 = new SpongeAABB(new Vector3d(1, 2, 3), new Vector3d(7, 10, 13));
    final AABB aabb2 = new SpongeAABB(new Vector3d(11, 0, 4), new Vector3d(17, 8, 14));
    Assertions.assertEquals(aabb2, aabb1.offset(10, -2, 1));
}
Also used : Vector3d(org.spongepowered.math.vector.Vector3d) AABB(org.spongepowered.api.util.AABB) Test(org.junit.jupiter.api.Test)

Example 68 with Vector3d

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

the class TransformationTest method testRotatingAroundOrigin180DegreesAroundYAxisWithTwoSteps.

@ParameterizedTest
@MethodSource("testRotatingAroundOrigin180DegreesAroundYAxis")
void testRotatingAroundOrigin180DegreesAroundYAxisWithTwoSteps(final Vector3d original, final Vector3d expected) {
    // and this rotation
    final Rotation mockRotation = Mockito.mock(Rotation.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
    Mockito.when(mockRotation.angle()).thenReturn(Angle.fromDegrees(90));
    Mockito.when(mockRotation.and(Mockito.any(Rotation.class))).thenAnswer((Answer<Rotation>) invocation -> {
        final Rotation rotation = invocation.getArgument(0);
        final Rotation newMock = Mockito.mock(Rotation.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
        Mockito.when(newMock.angle()).thenAnswer((Answer<Angle>) x -> Angle.fromDegrees(rotation.angle().degrees() + 90));
        return newMock;
    });
    final Transformation transformation = this.performRotationTest(mockRotation, original, expected, Vector3d.ZERO, 2);
    Assertions.assertEquals(180, transformation.rotation().angle().degrees(), "Did not get expected angle.");
}
Also used : Transformation(org.spongepowered.api.util.transformation.Transformation) Mockito(org.mockito.Mockito) Answer(org.mockito.stubbing.Answer) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Rotation(org.spongepowered.api.util.rotation.Rotation) Stream(java.util.stream.Stream) Vector3d(org.spongepowered.math.vector.Vector3d) Assertions(org.junit.jupiter.api.Assertions) Axis(org.spongepowered.api.util.Axis) Arguments(org.junit.jupiter.params.provider.Arguments) MethodSource(org.junit.jupiter.params.provider.MethodSource) Angle(org.spongepowered.api.util.Angle) Answer(org.mockito.stubbing.Answer) Transformation(org.spongepowered.api.util.transformation.Transformation) Rotation(org.spongepowered.api.util.rotation.Rotation) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 69 with Vector3d

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

the class TransformationTest method testRotationThenTranslation.

@ParameterizedTest
@MethodSource
void testRotationThenTranslation(final Vector3d original, final Vector3d expected) {
    // given this builder
    final SpongeTransformationBuilder transformationBuilder = new SpongeTransformationBuilder();
    // and this rotation
    final Rotation mockRotation = Mockito.mock(Rotation.class, Mockito.withSettings().defaultAnswer(Mockito.CALLS_REAL_METHODS));
    Mockito.when(mockRotation.angle()).thenReturn(Angle.fromDegrees(90));
    // when rotating by 90 degrees with this translation
    final Transformation transformation = transformationBuilder.rotate(mockRotation).translate(Vector3d.ONE).build();
    // then perform the transformation
    final Vector3d result = transformation.transformPosition(original);
    Assertions.assertEquals(expected, result, "Did not get expected result.");
}
Also used : Transformation(org.spongepowered.api.util.transformation.Transformation) Vector3d(org.spongepowered.math.vector.Vector3d) Rotation(org.spongepowered.api.util.rotation.Rotation) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) MethodSource(org.junit.jupiter.params.provider.MethodSource)

Example 70 with Vector3d

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

the class TransformationTest method performRotationTest.

private Transformation performRotationTest(final Rotation rotation, final Vector3d original, final Vector3d expected, final Vector3d origin, final int rotateTimes) {
    // given this builder
    final SpongeTransformationBuilder transformationBuilder = new SpongeTransformationBuilder();
    // when rotating
    for (int i = 0; i < rotateTimes; ++i) {
        transformationBuilder.rotate(rotation);
    }
    final Transformation transformation = transformationBuilder.origin(origin).build();
    // then perform the transformation
    final Vector3d result = transformation.transformPosition(original);
    Assertions.assertEquals(expected, result, "Did not get expected rotation.");
    return transformation;
}
Also used : Transformation(org.spongepowered.api.util.transformation.Transformation) Vector3d(org.spongepowered.math.vector.Vector3d)

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