def test_basic_central_rotate_45(self): before = self.create_simple_line_seg((0, 0), (1, 1)) after = self.create_simple_line_seg((0, 0), (math.sqrt(2), 0)) self.assertTrue( get_rotated_line_segment(before, -45).almost_equals(after)) self.assertTrue( get_rotated_line_segment(after, 45).almost_equals(before))
def test_rotate_by_30(self): before = self.create_simple_line_seg((1, math.sqrt(3.0)), (math.sqrt(3.0), 1)) after = self.create_simple_line_seg((math.sqrt(3.0), 1), (2, 0)) self.assertTrue( get_rotated_line_segment(before, -30).almost_equals(after)) self.assertTrue( get_rotated_line_segment(after, 30).almost_equals(before))
def test_get_rotated_line_segment_right_hemisphere(self): before = self.create_simple_line_seg((0, 1), (1, 2)) after = self.create_simple_line_seg((1 / math.sqrt(2.0), 1 / math.sqrt(2.0)), \ (math.sqrt(2.0) + 1 / math.sqrt(2.0), 1 / math.sqrt(2.0))) self.assertTrue( get_rotated_line_segment(before, -45).almost_equals(after)) self.assertTrue( get_rotated_line_segment(after, 45).almost_equals(before))
def get_representative_line_from_trajectory_line_segments(trajectory_line_segments, min_vertical_lines, min_prev_dist): average_trajectory_vector = get_average_vector(line_segment_list=map(lambda x: x.line_segment, trajectory_line_segments)) for traj_line_seg in trajectory_line_segments: traj_line_seg.line_segment = get_rotated_line_segment(traj_line_seg.line_segment, \ - average_trajectory_vector.angle) representative_points = get_representative_line_from_rotated_line_segments(trajectory_line_segments=trajectory_line_segments, \ min_vertical_lines=min_vertical_lines, \ min_prev_dist=min_prev_dist) return map(lambda x: x.rotated(angle=average_trajectory_vector.angle), representative_points)
def test_rotate_by_30(self): before = self.create_simple_line_seg((1, math.sqrt(3.0)), (math.sqrt(3.0), 1)) after = self.create_simple_line_seg((math.sqrt(3.0), 1), (2, 0)) self.assertTrue(get_rotated_line_segment(before, -30).almost_equals(after)) self.assertTrue(get_rotated_line_segment(after, 30).almost_equals(before))
def test_rotate_by_zero(self): test_ob = self.create_simple_line_seg((0, 1), (1, 2)) self.assertEquals(get_rotated_line_segment(test_ob, 0.0), test_ob)
def test_basic_centrial_rotate_90_left_hemi(self): before = self.create_simple_line_seg((0, 0), (-1, 0)) after = self.create_simple_line_seg((0, 0), (0, -1)) self.assertEquals(get_rotated_line_segment(before, 90), after) self.assertEquals(get_rotated_line_segment(after, -90), before)
def test_basic_central_rotate_90(self): before = self.create_simple_line_seg((0, 0), (0, 1)) after = self.create_simple_line_seg((0, 0), (1, 0)) self.assertEquals(get_rotated_line_segment(before, -90), after) self.assertEquals(get_rotated_line_segment(after, 90), before)
def test_basic_central_rotate_45(self): before = self.create_simple_line_seg((0, 0), (1, 1)) after = self.create_simple_line_seg((0, 0), (math.sqrt(2), 0)) self.assertTrue(get_rotated_line_segment(before, -45).almost_equals(after)) self.assertTrue(get_rotated_line_segment(after, 45).almost_equals(before))
def test_get_rotated_line_segment_right_hemisphere(self): before = self.create_simple_line_seg((0, 1), (1, 2)) after = self.create_simple_line_seg((1 / math.sqrt(2.0), 1 / math.sqrt(2.0)), \ (math.sqrt(2.0) + 1 / math.sqrt(2.0), 1 / math.sqrt(2.0))) self.assertTrue(get_rotated_line_segment(before, -45).almost_equals(after)) self.assertTrue(get_rotated_line_segment(after, 45).almost_equals(before))
def test_rotate_by_zero(self): test_ob = self.create_simple_line_seg((0, 1), (1, 2)) self.assertEquals(get_rotated_line_segment(test_ob, 0.0), test_ob)
def test_basic_centrial_rotate_90_left_hemi(self): before = self.create_simple_line_seg((0, 0), (-1, 0)) after = self.create_simple_line_seg((0, 0), (0, -1)) self.assertEquals(get_rotated_line_segment(before, 90), after) self.assertEquals(get_rotated_line_segment(after, -90), before)
def test_basic_central_rotate_90(self): before = self.create_simple_line_seg((0, 0), (0, 1)) after = self.create_simple_line_seg((0, 0), (1, 0)) self.assertEquals(get_rotated_line_segment(before, -90), after) self.assertEquals(get_rotated_line_segment(after, 90), before)