class TestBeamForce(unittest.TestCase): def setUp(self) -> None: self.v1 = Vertex(0, 0, 0, 0) self.v2 = Vertex(1, 2, 0, 0) self.edge = Edge(0, self.v1, self.v2, EDGE_BOUNDARY) def test_is_zero_if_position_did_not_change(self): set_all_beam_forces([self.edge]) self.assertEqual(self.v1.total_force(), Vector3(0, 0, 0)) def test_creates_shrinking_force(self): self.v2.x = 4 set_all_beam_forces([self.edge]) self.assertTrue( same_direction_vec(self.v1.total_force(), Vector3(1, 0, 0))) self.assertTrue( same_direction_vec(self.v2.total_force(), Vector3(-1, 0, 0))) def test_creates_expanding_force(self): self.v2.x = 1 set_all_beam_forces([self.edge]) self.assertTrue( same_direction_vec(self.v1.total_force(), Vector3(-1, 0, 0))) self.assertTrue( same_direction_vec(self.v2.total_force(), Vector3(1, 0, 0)))
class TestVertexForces(unittest.TestCase): def setUp(self) -> None: self.v = Vertex(0, 0, 0, 0) def test_forces_manipulation(self): self.v.set_force(ForceName.BEAM, Vector3(1, 1, 0)) self.v.set_force(ForceName.DAMPING, Vector3(1, 1, 0)) self.v.set_force(ForceName.CREASE, Vector3(1, 1, 0)) self.v.set_force(ForceName.FACE, Vector3(1, 1, -1)) self.assertEqual(self.v.total_force(), Vector3(4, 4, -1)) self.v.reset_forces() self.assertEqual(self.v.total_force(), Vector3(0, 0, 0))
class TestFaceForce(unittest.TestCase): def setUp(self) -> None: self.v1 = Vertex(0, 1, 0, 0) self.v2 = Vertex(1, -1, 0, 0) self.v3 = Vertex(2, 0, 2, 0) self.face = Face(0, self.v1, self.v2, self.v3) def test_is_zero_if_no_position_changed(self): set_all_face_forces([self.face]) self.assertEqual(self.v1.total_force(), Vector3(0, 0, 0)) self.assertEqual(self.v2.total_force(), Vector3(0, 0, 0)) self.assertEqual(self.v3.total_force(), Vector3(0, 0, 0)) def test_creates_pulling_force_if_face_is_squished(self): self.v3.y = 1 set_all_face_forces([self.face]) self.assertTrue(same_direction_vec(self.v3.total_force(), Vector3(0, 1, 0))) def test_creates_pushing_force_if_face_is_expanded(self): self.v3.y = 3 set_all_face_forces([self.face]) self.assertTrue(same_direction_vec(self.v3.total_force(), Vector3(0, -1, 0)))
class TestDampingForce(unittest.TestCase): def setUp(self) -> None: self.v1 = Vertex(0, 0, 0, 0) self.v2 = Vertex(1, 1, 1, 0) self.edge = Edge(0, self.v1, self.v2, EDGE_FLAT) def test_is_zero_if_velocity_is_zero(self): set_all_damping_forces([self.edge]) self.assertEqual(self.v1.total_force(), Vector3(0, 0, 0)) self.assertEqual(self.v2.total_force(), Vector3(0, 0, 0)) def test_creates_equal_forces_when_velocity_changes(self): self.v1.velocity = Vector3(-1, 0, 0) self.v2.velocity = Vector3(1, 0, 0) set_all_damping_forces([self.edge]) self.assertEqual(self.v1.total_force(), -self.v2.total_force()) self.assertTrue( same_direction_vec(self.v1.total_force(), Vector3(1, 0, 0))) self.assertTrue( same_direction_vec(self.v2.total_force(), Vector3(-1, 0, 0)))
class TestCreaseForce(unittest.TestCase): def setUp(self) -> None: self.v1 = Vertex(0, 1, -1, 0) self.v2 = Vertex(1, 1, 1, 0) self.v3 = Vertex(2, -1, 1, 0) self.v4 = Vertex(3, -1, -1, 0) self.face1 = Face(0, self.v1, self.v2, self.v4) self.face2 = Face(1, self.v2, self.v3, self.v4) self.edge = Edge(2, self.v4, self.v2, EDGE_UNKNOWN) self.edge.face_right = self.face1 self.edge.face_left = self.face2 def test_is_zero_if_is_not_being_folded(self): set_all_crease_forces([self.edge]) self.assertEqual(self.v1.total_force(), Vector3(0, 0, 0)) self.assertEqual(self.v2.total_force(), Vector3(0, 0, 0)) self.assertEqual(self.v3.total_force(), Vector3(0, 0, 0)) self.assertEqual(self.v4.total_force(), Vector3(0, 0, 0)) def test_creates_upward_force_for_valley_assignment(self): self.edge.assignment = EDGE_VALLEY self.edge.target_angle = angle_from_assignment(self.edge.assignment) set_all_crease_forces([self.edge]) self.assertTrue( same_direction_vec(self.v1.total_force(), Vector3(0, 0, 1))) self.assertTrue( same_direction_vec(self.v2.total_force(), Vector3(0, 0, -1))) self.assertTrue( same_direction_vec(self.v3.total_force(), Vector3(0, 0, 1))) self.assertTrue( same_direction_vec(self.v4.total_force(), Vector3(0, 0, -1))) def test_creates_downwards_force_for_mountain_assignment(self): self.edge.assignment = EDGE_MOUNTAIN self.edge.target_angle = angle_from_assignment(self.edge.assignment) set_all_crease_forces([self.edge]) self.assertTrue( same_direction_vec(self.v1.total_force(), Vector3(0, 0, -1))) self.assertTrue( same_direction_vec(self.v2.total_force(), Vector3(0, 0, 1))) self.assertTrue( same_direction_vec(self.v3.total_force(), Vector3(0, 0, -1))) self.assertTrue( same_direction_vec(self.v4.total_force(), Vector3(0, 0, 1)))