Exemplo n.º 1
0
 def scale(self, factor):
     Validator.validatePositiveDouble(factor,
                                      "Scale Factor not a valid double")
     for point in self.points:
         dx = point.x - self.center.x
         dy = point.y - self.center.y
         point.x = dx * factor + self.center.x
         point.y = dy * factor + self.center.y
Exemplo n.º 2
0
    def testValidatePositiveDouble(self):
        Validator.validatePositiveDouble(123.456,
                                         "Double unexpectedly invalid")
        Validator.validatePositiveDouble(0, "Double unexpectedly invalid")

        self.assertRaises(ShapeException, Validator.validatePositiveDouble,
                          None, "None is not a valid positive double")
        self.assertRaises(ShapeException, Validator.validatePositiveDouble,
                          float('inf'), "Inf is not a valid positive double")
        self.assertRaises(ShapeException, Validator.validatePositiveDouble,
                          float('-inf'), "-Inf is not a valid positive double")
        self.assertRaises(ShapeException, Validator.validatePositiveDouble,
                          "foo",
                          "String \'foo\' is not a valid positive double")
        self.assertRaises(ShapeException, Validator.validatePositiveDouble,
                          -123.456, "-123.456 is not a valid positive double")
Exemplo n.º 3
0
 def scale(self, scaleFactor):
     Validator.validatePositiveDouble(scaleFactor,
                                      "Scale Factor not a valid double")
     f1_dx = self.foci1[0].x - self.__center.x
     f1_dy = self.foci1[0].y - self.__center.y
     f2_dx = self.foci2[0].x - self.__center.x
     f2_dy = self.foci2[0].y - self.__center.y
     a1_dx = self.axis1.point2.x - self.__center.x
     a1_dy = self.axis1.point2.y - self.__center.y
     a2_dx = self.axis2.point2.x - self.__center.x
     a2_dy = self.axis2.point2.y - self.__center.y
     self.foci1[0].x = f1_dx * scaleFactor + self.__center.x
     self.foci1[0].y = f1_dy * scaleFactor + self.__center.y
     self.foci1[1].x = f1_dx * scaleFactor + self.__center.x
     self.foci1[1].y = f1_dy * scaleFactor + self.__center.y
     self.foci2[0].x = f2_dx * scaleFactor + self.__center.x
     self.foci2[0].y = f2_dy * scaleFactor + self.__center.y
     self.foci2[1].x = f2_dx * scaleFactor + self.__center.x
     self.foci2[1].y = f2_dy * scaleFactor + self.__center.y
     self.axis1.point2.x = a1_dx * scaleFactor + self.__center.x
     self.axis1.point2.y = a1_dy * scaleFactor + self.__center.y
     self.axis2.point2.x = a2_dx * scaleFactor + self.__center.x
     self.axis2.point2.y = a2_dy * scaleFactor + self.__center.y