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