shooting works

This commit is contained in:
nora 2020-12-11 20:29:03 +01:00
parent 0d5397dbe3
commit e2483b30ff
8 changed files with 45 additions and 23 deletions

View file

@ -41,20 +41,33 @@ class Vector2DTest {
}
@Test
void rotateAroundTest(){
void rotateAroundTestSimple(){
Vector2D cent = new Vector2D(0, 0);
Vector2D a = new Vector2D(1, 0);
Vector2D exceptedA = new Vector2D(6.123233995736766E-17 ,-1); //floating point precision probably
Vector2D centB = new Vector2D(1, 1);
Vector2D b = new Vector2D(2, 1);
Vector2D exceptedB = new Vector2D(1 ,2);
Vector2D excepted = new Vector2D(0 ,-1); //floating point precision probably
Vector2D rotated = Vector2D.rotateAround(cent, a, Math.toRadians(90), Vector2D.CLOCKWISE);
Vector2D rotatedb = Vector2D.rotateAround(centB, b, Math.toRadians(90), Vector2D.COUNTERCLOCKWISE);
assertEquals(round(excepted), round(rotated));
}
assertEquals(exceptedA, rotated);
assertEquals(exceptedB, rotatedb);
@Test
void rotateAroundTestMovedCenter(){
Vector2D cent = new Vector2D(1, 1);
Vector2D a = new Vector2D(2, 1);
Vector2D excepted = new Vector2D(1 ,2);
Vector2D rotated = Vector2D.rotateAround(cent, a, Math.toRadians(90), Vector2D.COUNTERCLOCKWISE);
assertEquals(round(excepted), round(rotated));
}
@Test
void rotateAroundTestExact(){
Vector2D cent = new Vector2D();
Vector2D a = new Vector2D(5, 6);
Vector2D rotated = Vector2D.rotateAround(cent, a, Math.toRadians(120), Vector2D.COUNTERCLOCKWISE);
Vector2D expected = new Vector2D(-7.6962, 1.3301);
assertEquals(round(expected), round(rotated));
}
public static Vector2D round(Vector2D a){
return new Vector2D(Math.round(a.x*10000d)/10000d, Math.round(a.y*10000d)/10000d);
}
}