Ejemplo n.º 1
0
    def round(self, precision):
        if not self.is_numeric():
            raise error.UncompatibleType(self, "numeric Value")
        elif (not (precision
                   in [UNIT, TENTH, HUNDREDTH, THOUSANDTH, TEN_THOUSANDTH] or
                   (type(precision) == int and 0 <= precision <= 4))):
            # __
            raise error.UncompatibleType(
                precision, "must be UNIT or" + "TENTH, " + "HUNDREDTH, " +
                "THOUSANDTH, " + "TEN_THOUSANDTH, " + "or 0, 1, 2, 3 or 4.")
        else:
            result_value = None

            if type(precision) == int:
                result_value = Value(
                    round(self.raw_value,
                          Decimal(PRECISION[precision]),
                          rounding=ROUND_HALF_UP))
            else:
                result_value = Value(
                    round(self.raw_value,
                          Decimal(precision),
                          rounding=ROUND_HALF_UP))

            if self.needs_to_get_rounded(precision):
                result_value.set_has_been_rounded(True)

            return result_value
Ejemplo n.º 2
0
    def label_into_euk(self):
        """Return the label correctly positionned along the Segment."""
        if self.label in [Value(''), Value('hidden')]:
            return ''
        else:
            result = ''
            x = self.real_length
            scale_factor = round(Decimal(str(1.6 * x)),
                                 Decimal('0.1'),
                                 rounding=ROUND_UP)
            if x <= 3:
                angle_correction = round(Decimal(str(-8 * x + 33)),
                                         Decimal('0.1'),
                                         rounding=ROUND_UP)
            else:
                angle_correction = \
                    round(
                        Decimal(
                            str(1.1 / (1 - 0.95 * math.exp(-0.027 * x)))),
                        Decimal('0.1'),
                        rounding=ROUND_UP)

            side_angle = Vector((self.points[0], self.points[1])).slope

            label_position_angle = round(side_angle,
                                         Decimal('1'),
                                         rounding=ROUND_HALF_EVEN)

            label_position_angle %= Decimal("360")

            rotate_box_angle = Decimal(label_position_angle)

            if (rotate_box_angle >= 90 and rotate_box_angle <= 270):
                rotate_box_angle -= Decimal("180")
            elif (rotate_box_angle <= -90 and rotate_box_angle >= -270):
                rotate_box_angle += Decimal("180")

            rotate_box_angle %= Decimal("360")

            result += "  $\\rotatebox{"
            result += str(rotate_box_angle)
            result += "}{\sffamily "
            result += self.label.into_str(display_unit=True,
                                          graphic_display=True)
            result += "}$ "
            result += self.points[0].name + " "
            result += str(label_position_angle)
            result += " - "
            result += str(angle_correction) + " deg "
            result += str(scale_factor)
            result += "\n"
            return result
Ejemplo n.º 3
0
 def label_display_angle(self, arg):
     if not is_.a_number(arg):
         raise error.WrongArgument(arg, ' a number ')
     else:
         self._label_display_angle = round(Decimal(str(arg)),
                                           Decimal('0.1'),
                                           rounding=ROUND_HALF_UP)
Ejemplo n.º 4
0
 def slope(self):
     """Return the slope of self."""
     theta = round(Decimal(str(math.degrees(
                               math.acos(self._x_exact / self.norm)))),
                   Decimal('0.1'),
                   rounding=ROUND_HALF_UP)
     return theta if self._y_exact > 0 else Decimal("360") - theta
Ejemplo n.º 5
0
 def digits_number(self):
     if not self.is_numeric():
         raise error.UncompatibleType(self, "numeric Value")
     else:
         temp_result = len(
             str((self.raw_value - round(
                 self.raw_value, Decimal(UNIT), rounding=ROUND_DOWN)))) - 2
         if temp_result < 0:
             return 0
         else:
             return temp_result
Ejemplo n.º 6
0
    def __init__(self, arg, **options):
        self._ray0 = None
        self._ray1 = None
        self._points = None
        self._measure = None
        self._mark = ""
        self._label = Value("")
        self._name = None

        if (isinstance(arg, tuple) and len(arg) == 3
            and isinstance(arg[0], Point)
            and isinstance(arg[1], Point)
            and isinstance(arg[2], Point)):
            # __
            self._ray0 = Ray((arg[1], arg[0]))
            self._ray1 = Ray((arg[1], arg[2]))
            self._points = [arg[0].clone(),
                            arg[1].clone(),
                            arg[2].clone()]

            # Let's determine the measure of the angle:
            aux_side0 = Segment((self._points[0], self._points[1]))
            aux_side1 = Segment((self._points[1], self._points[2]))
            aux_side2 = Segment((self._points[2], self._points[0]))
            aux_num = aux_side0.real_length * aux_side0.real_length \
                + aux_side1.real_length * aux_side1.real_length \
                - aux_side2.real_length * aux_side2.real_length
            aux_denom = 2 * aux_side0.real_length * aux_side1.real_length
            aux_cos = aux_num / aux_denom
            self._measure = Decimal(str(math.degrees(math.acos(aux_cos))))

            if 'label' in options and type(options['label']) == str:
                self._label = Value(options['label'])

            if 'mark' in options and type(options['mark']) == str:
                self._mark = options['mark']

            self._name = MARKUP['opening_widehat']
            self._name += arg[0].name + arg[1].name + arg[2].name
            self._name += MARKUP['closing_widehat']
        else:
            raise error.WrongArgument(' (Point, Point, Point) ',
                                      str(type(arg)))

        self._label_display_angle = round(Decimal(str(self._measure)),
                                          Decimal('0.1'),
                                          rounding=ROUND_HALF_UP) / 2
Ejemplo n.º 7
0
 def x(self):
     return round(Decimal(str(self._x)),
                  Decimal('0.01'),
                  rounding=ROUND_HALF_UP)