def test_clone_and_convert_to_float_using_floatify(self):
     a = Point(int(35), int(44))
     b = a.floatify()
     self.assertTrue(isinstance(a.x, int))
     self.assertEqual(b.x, float(35))
     self.assertTrue(isinstance(b.x, float))
     self.assertEqual(b.y, float(44))
     self.assertTrue(isinstance(b.y, float))
Esempio n. 2
0
 def from_array(corner_array):
     """ Creates a new Rectangle from an array in the format [ax, ay, bx, by] when a and b are two co-ordinates.
     This method will raise an ValueError if the length of the array is not 4. """
     if len(corner_array) != 4:
         raise ValueError(
             "Attempt to construct Rectangle with wrong number of co-ordinate values - "
             "correct format is [ax, ay, bx, by].")
     return Rectangle(Point(corner_array[0], corner_array[1]),
                      Point(corner_array[2], corner_array[3]))
Esempio n. 3
0
 def test_crystal_stage_disabled_by_changing_perform_poi_analysis_option(self):
     cmd_line = "{resources}/A10_1.jpg {resources}/[email protected] 123,123 456,456 " \
                "--config {resources}/configs/config_disable_poi_stage"
     test_name = self.test_crystal_stage_disabled_by_changing_perform_poi_analysis_option.__name__
     self.run_crystal_matching_test(test_name, cmd_line)
     self.failUnlessPoiAlmostEqual([[Point(113, 113), Point(0, 0), 2, 0],
                                    [Point(446, 446), Point(0, 0), 2, 0]],
                                   [0.5, 0, 0])
     self.failUnlessStdOutContains("2, DISABLED")
 def test_scaled_point_calculation(self):
     a = Point(35, 27)
     b = a.scale(0.2)
     c = a.scale(5)
     self.assertEqual(a.x, 35)
     self.assertEqual(a.y, 27)
     self.assertEqual(b.x, 7)
     self.assertEqual(b.y, 5.4)
     self.assertEqual(c.x, 175)
     self.assertEqual(c.y, 135)
Esempio n. 5
0
 def test_equality(self):
     self.failUnless(
         Rectangle(Point(2, 3), Point(12, 16)) == self.basic_rectangle)
     self.failIf(
         Rectangle(Point(1, 3), Point(12, 16)) == self.basic_rectangle)
     self.failIf(
         Rectangle(Point(2, 1), Point(12, 16)) == self.basic_rectangle)
     self.failIf(
         Rectangle(Point(2, 3), Point(1, 16)) == self.basic_rectangle)
     self.failIf(
         Rectangle(Point(2, 3), Point(12, 1)) == self.basic_rectangle)
 def test_equality(self):
     self.assertTrue(
         Rectangle(Point(2, 3), Point(12, 16)) == self.basic_rectangle)
     self.assertFalse(
         Rectangle(Point(1, 3), Point(12, 16)) == self.basic_rectangle)
     self.assertFalse(
         Rectangle(Point(2, 1), Point(12, 16)) == self.basic_rectangle)
     self.assertFalse(
         Rectangle(Point(2, 3), Point(1, 16)) == self.basic_rectangle)
     self.assertFalse(
         Rectangle(Point(2, 3), Point(12, 1)) == self.basic_rectangle)
Esempio n. 7
0
    def intersection(self, rect_b):
        """ Returns a new Rectangle which is the region of overlap between the two Rectangles. """
        if not self.intersects(rect_b):
            return Rectangle(Point(0, 0), Point(0, 0))

        x1 = max(self.x1, rect_b.x1)
        y1 = max(self.y1, rect_b.y1)
        x2 = min(self.x2, rect_b.x2)
        y2 = min(self.y2, rect_b.y2)

        return Rectangle(Point(x1, y1), Point(x2, y2))
Esempio n. 8
0
 def test_intersect_test_returns_true_for_intersecting_rectangles(self):
     self.failUnless(
         Rectangle(Point(-1, -1), Point(2, 2)).intersects(
             Rectangle(Point(-2, -2), Point(1, 1))))
     self.failUnless(
         Rectangle(Point(-0.99, -0.99), Point(-2, -2)).intersects(
             Rectangle(Point(-1.01, -1.01), Point(1, 1))))
Esempio n. 9
0
 def test_scale_transform_returns_correct_result(self):
     rectangle = Rectangle(Point(-1, -1), Point(1, 1))
     self.failUnlessEqual(Rectangle(Point(-0.5, -0.5), Point(0.5, 0.5)),
                          rectangle.scale(0.5))
     self.failUnlessEqual(Rectangle(Point(-3, -3), Point(3, 3)),
                          rectangle.scale(3))
     self.failUnlessEqual(Rectangle(Point(3.5, 3.5), Point(-3.5, -3.5)),
                          rectangle.scale(-3.5))
Esempio n. 10
0
 def from_corner(top_left, width, height):
     """ Create a new Rectangle of the specified dimensions, with the specified top-left corner. """
     if not isinstance(top_left, Point):
         raise ValueError(
             "Attempt to create Rectangle with invalid corner Point: " +
             repr(top_left))
     bottom_right = top_left + Point(width, height)
     return Rectangle(top_left, bottom_right)
Esempio n. 11
0
 def from_center(center, width, height):
     """ Create a new Rectangle of the specified dimensions, centered around the specified point. """
     if not isinstance(center, Point):
         raise ValueError(
             "Attempt to create Rectangle with invalid centre Point: " +
             repr(center))
     dimensions = Point(width, height) / 2.0
     return Rectangle(center - dimensions, center + dimensions)