Beispiel #1
0
 def test_add_points_to_line(self):
     model = LineModel.create_line_from_2points(0, 0, 100, 100)
     test_point1 = Point(1, 0)
     test_point2 = Point(2, 0)
     model.points.append(test_point1)
     model.points.append(test_point2)
     self.assertTrue(test_point1 in model.points)
     self.assertTrue(test_point2 in model.points)
     self.assertTrue(len(model.points) == 2)
Beispiel #2
0
 def test_create_line_from_start_and_end_vertical_line(self):
     start_x = 1
     start_y = 5
     end_x = 1
     end_y = 25
     model = LineModel.create_line_from_2points(start_x, start_y, end_x,
                                                end_y)
     expected_B = 0
     expected_x_intercept = start_x
     self.assertAlmostEqual(model.B, 0)
     self.assertAlmostEqual(model.C / model.A, -expected_x_intercept)
Beispiel #3
0
 def test_create_line_from_start_and_end_horizontal_line(self):
     start_x = 0
     start_y = 1
     end_x = 1
     end_y = 2
     model = LineModel.create_line_from_2points(start_x, start_y, end_x,
                                                end_y)
     #equation ax+by+c=0
     #slope=-a/b
     #yinter=-c/b
     expected_slope = 1
     expected_y_intercept = 1
     self.assertAlmostEqual(model.A / model.B, -expected_slope)
     self.assertAlmostEqual(model.C / model.B, -expected_y_intercept)
Beispiel #4
0
 def test_generate_points_at_regular_intervals_stline(self):
     start_x = 0
     start_y = 1
     end_x = 10
     end_y = 11
     model = LineModel.create_line_from_2points(start_x, start_y, end_x,
                                                end_y)
     slope = -model.A / model.B
     yintercept = -model.C / model.B
     gap = 5
     new_points = LineModel.generate_points_at_regular_intervals_stline(
         start_x, start_y, end_x, end_y, gap)
     count_of_new_points = len(new_points)
     self.assertTrue(count_of_new_points > 0)
     self.assertTrue(count_of_new_points < 4)
     for new_point in new_points:
         new_x = new_point.X
         new_y = new_point.Y
         expected_y = slope * new_x + yintercept
         self.assertAlmostEqual(new_y, expected_y)