Пример #1
0
    def center(self):
        """Returns the center of this rectangle, calculated to be the point of intersection of its diagonals."""
        v = self.vertices
        x, y = 0, 0

        for pt in v:
            x += pt.x
            y += pt.y
        if TwoDPoint.midpoint(v[0], v[2]) == TwoDPoint.midpoint(v[1], v[3]):
            return TwoDPoint.midpoint(v[0], v[2])
        else:
            return TwoDPoint(x/4, y/4)
Пример #2
0
 def test_midpoint(self):
     self.assertEqual(TwoDPoint.midpoint(self.point1, self.point3),
                      TwoDPoint(2.5, 0))
     self.assertEqual(TwoDPoint.midpoint(self.point1, self.point2),
                      TwoDPoint(.5, 1))