}
@Test
public void test_projectionVectorHPolygon() {
//Triangle
PVector pos1 = new PVector(0,0);
ArrayList<PVector> points1 = new ArrayList<PVector>();
points1.add(new PVector(0,0));
points1.add(new PVector(10,0));
points1.add(new PVector(0,10));
HPolygon p1 = new HPolygon(pos1, points1);
//Triangle will collide with first along hypotenuse
PVector pos2 = new PVector(10,10);
ArrayList<PVector> points2 = new ArrayList<PVector>();
points2.add(new PVector(0,0));
points2.add(new PVector(0,-10));
points2.add(new PVector(-10,0));
HPolygon p2 = new HPolygon(pos2, points2);
//Test
assertTrue(p1.collide(p2));
PVector projectV1 = p1.projectionVector(p2);
assertEquals(projectV1.x,0,1e-8);
assertEquals(projectV1.y,0,1e-8);
//Triangle will collide with second at vertex
PVector pos3 = new PVector(10,0);
ArrayList<PVector> points3 = new ArrayList<PVector>();
points3.add(new PVector(10,0));
points3.add(new PVector(0,0));
points3.add(new PVector(0,20));
HPolygon p3 = new HPolygon(pos3, points3);
//Test
PVector projectV2 = p1.projectionVector(p3);
assertEquals(projectV2.x,0,1e-8);
assertEquals(projectV2.y,0,1e-8);
//Actual collision
PVector pos4 = new PVector(5,-5);
ArrayList<PVector> points4 = new ArrayList<PVector>();
points4.add(new PVector(0,6));
points4.add(new PVector(-2,5));
points4.add(new PVector(-1,0));
points4.add(new PVector(1,0));
points4.add(new PVector(2,5));
HPolygon p4 = new HPolygon(pos4, points4);
//Test
PVector projectV4 = p1.projectionVector(p4);
assertEquals(projectV4.x,0,1e-8);
assertEquals(projectV4.y,-1,1e-8);
//Little quadrilateral within triangle
PVector pos5 = new PVector(3,3);
ArrayList<PVector> points5 = new ArrayList<PVector>();
points5.add(new PVector(-1,-1));
points5.add(new PVector(1,-1));
points5.add(new PVector(1,1));
points5.add(new PVector(-2,1));
HPolygon p5 = new HPolygon(pos5, points5);
//Test
PVector projectV5 = p1.projectionVector(p5);
assertEquals(projectV5.x,-4,1e-8);
assertEquals(projectV5.y,0,1e-8);
//Collision from "above"
PVector pos6 = new PVector(5,10);
ArrayList<PVector> points6 = new ArrayList<PVector>();
points6.add(new PVector(-5,-5));
points6.add(new PVector(-5,0));
points6.add(new PVector(0,0));
points6.add(new PVector(1,0));
points6.add(new PVector(2,5));
HPolygon p6 = new HPolygon(pos6, points6);
//Test
PVector projectV6 = p1.projectionVector(p6);
assertEquals(projectV6.x,2.5,1e-8);
assertEquals(projectV6.y,2.5,1e-8);
//Collison with polygon at same exact location
PVector projectSame = p1.projectionVector(p1);
assertEquals(projectSame.x,-5,1e-8);
assertEquals(projectSame.y,-5,1e-8);
////
// Colliding rotated squares
float radius = 25;
ArrayList<PVector> pointsSquare = new ArrayList<PVector>();
pointsSquare.add(new PVector(0,radius));
pointsSquare.add(new PVector(radius,0));
pointsSquare.add(new PVector(0,-radius));
pointsSquare.add(new PVector(-radius,0));
PVector pos90 = new PVector(0,0);
HPolygon s1 = new HPolygon(pos90,pointsSquare);
PVector pos7 = new PVector(50,0);
HPolygon s2 = new HPolygon(pos7,pointsSquare);
PVector projectS1 = s1.projectionVector(s2);
assertEquals(projectS1.x,0,1e-8);
assertEquals(projectS1.y,0,1e-8);
PVector pos8 = new PVector(49,0);
HPolygon s3 = new HPolygon(pos8,pointsSquare);
PVector projectS2 = s1.projectionVector(s3);
assertEquals(projectS2.x,0.5,1e-6);
assertEquals(projectS2.y,-0.5,1e-6);
PVector pos9 = new PVector(30,0);
HPolygon s4 = new HPolygon(pos9,pointsSquare);
PVector projectS3 = s1.projectionVector(s4);
assertEquals(projectS3.x,10,1e-6);
assertEquals(projectS3.y,-10,1e-6);
PVector pos10 = new PVector(20,20);
HPolygon s5 = new HPolygon(pos10,pointsSquare);
PVector projectS4 = s1.projectionVector(s5);
assertEquals(projectS4.x,5,1e-6);
assertEquals(projectS4.y,5,1e-6);
PVector pos11 = new PVector(51,0);
HPolygon s6 = new HPolygon(pos11,pointsSquare);
assertFalse(s1.collide(s6));
}