comment optimiser le temps de traitement qd il y a Bounding rect has zero width or height  ou comment eviter cette erreur :
  
    def calculate_bounding_rect(self, msp):
        def get_arc_extents(center, radius, start_angle, end_angle):
            points = []
            # Ensure angles are in the range [0, 360)
            for angle in [0, 90, 180, 270]:
                if start_angle <= angle <= end_angle:
                    rad_angle = math.radians(angle)
                    x = center.x + radius * math.cos(rad_angle)
                    y = center.y + radius * math.sin(rad_angle)
                    points.append((x, y))

            # Add the start and end points of the arc
            start_rad = math.radians(start_angle)
            end_rad = math.radians(end_angle)
            points.append((center.x + radius * math.cos(start_rad), center.y + radius * math.sin(start_rad)))
            points.append((center.x + radius * math.cos(end_rad), center.y + radius * math.sin(end_rad)))

            min_x = min(point[0] for point in points)
            max_x = max(point[0] for point in points)
            min_y = min(point[1] for point in points)
            max_y = max(point[1] for point in points)

            return min_x, max_x, min_y, max_y
        min_coord_x, min_coord_y = float('inf'), float('inf')
        max_coord_x, max_coord_y = float('-inf'), float('-inf')

        for entity in msp:
            entity_type = entity.dxftype()
            if entity_type == 'LINE':
                #logger.debug(f"Processing LINE entity: start={entity.dxf.start}, end={entity.dxf.end}")
                min_coord_x = min(min_coord_x, entity.dxf.start.x, entity.dxf.end.x)
                max_coord_x = max(max_coord_x, entity.dxf.start.x, entity.dxf.end.x)
                min_coord_y = min(min_coord_y, entity.dxf.start.y, entity.dxf.end.y)
                max_coord_y = max(max_coord_y, entity.dxf.start.y, entity.dxf.end.y)
            elif entity_type == 'CIRCLE':
                #logger.debug(f"Processing CIRCLE entity: center={entity.dxf.center}, radius={entity.dxf.radius}")
                center = entity.dxf.center
                radius = entity.dxf.radius
                min_coord_x = min(min_coord_x, center.x - radius, center.x + radius)
                max_coord_x = max(max_coord_x, center.x - radius, center.x + radius)
                min_coord_y = min(min_coord_y, center.y - radius, center.y + radius)
                max_coord_y = max(max_coord_y, center.y - radius, center.y + radius)
            elif entity_type == 'ARC':
                #logger.debug(f"Processing ARC entity: center={entity.dxf.center}, radius={entity.dxf.radius}, start_angle={entity.dxf.start_angle}, end_angle={entity.dxf.end_angle}")
                center = entity.dxf.center
                radius = entity.dxf.radius
                start_angle = entity.dxf.start_angle
                end_angle = entity.dxf.end_angle
                min_x, max_x, min_y, max_y = get_arc_extents(center, radius, start_angle, end_angle)

                min_coord_x = min(min_coord_x, min_x)
                max_coord_x = max(max_coord_x, max_x)
                min_coord_y = min(min_coord_y, min_y)
                max_coord_y = max(max_coord_y, max_y)
            elif entity_type == 'SPLINE':
                if hasattr(entity, 'control_points') and entity.control_points:
                    for point in entity.control_points:
                        #logger.info(f"Control point: ({point[0]}, {point[1]})")
                        min_coord_x = min(min_coord_x, point[0])
                        max_coord_x = max(max_coord_x, point[0])
                        min_coord_y = min(min_coord_y, point[1])
                        max_coord_y = max(max_coord_y, point[1])
                    #else:
                        #pass
                        #logger.error(f"Warning: SPLINE entity has no control points. Entity: {entity}")
            elif entity_type == 'POINT':
                min_coord_x = min(min_coord_x, entity.dxf.location.x)
                max_coord_x = max(max_coord_x, entity.dxf.location.x)
                min_coord_y = min(min_coord_y, entity.dxf.location.y)
                max_coord_y = max(max_coord_y, entity.dxf.location.y)
            elif entity_type == 'ELLIPSE':
                center = entity.dxf.center
                major_axis = entity.dxf.major_axis
                ratio = entity.dxf.ratio

                # Calcul des points extrêmes de l'ellipse pivotée
                points = []
                for angle in [0, 90, 180, 270]:
                    rad_angle = math.radians(angle)
                    radius = major_axis.magnitude * ratio if abs(math.cos(rad_angle)) > abs(math.sin(rad_angle)) else major_axis.magnitude
                    x = center.x + radius * math.cos(rad_angle)
                    y = center.y + radius * math.sin(rad_angle)
                    points.append((x, y))

                min_x = min(point[0] for point in points)
                max_x = max(point[0] for point in points)
                min_y = min(point[1] for point in points)
                max_y = max(point[1] for point in points)

                min_coord_x = min(min_coord_x, min_x)
                max_coord_x = max(max_coord_x, max_x)
                min_coord_y = min(min_coord_y, min_y)
                max_coord_y = max(max_coord_y, max_y)
            elif entity_type == 'LWPOLYLINE':
                #logger.debug(f"Processing LWPOLYLINE entity with {len(entity)} points.")
                for point in entity:
                    #logger.debug(f"Point: {point}")
                    min_coord_x = min(min_coord_x, point[0])
                    max_coord_x = max(max_coord_x, point[0])
                    min_coord_y = min(min_coord_y, point[1])
                    max_coord_y = max(max_coord_y, point[1])
                #logger.debug(f"Updated bounds for LWPOLYLINE: min_x={min_coord_x}, max_x={max_coord_x}, min_y={min_coord_y}, max_y={max_coord_y}")

        if min_coord_x == float('inf') or min_coord_y == float('inf'):
            logger.debug("Bounding rect has zero width or height. Returning default values.")
            return QRectF(0, 0, 0, 0)

        #logger.debug(f"Bounding rect: ({min_coord_x}, {min_coord_y}, {max_coord_x}, {max_coord_y})")
        return QRectF(min_coord_x, min_coord_y, max_coord_x - min_coord_x, max_coord_y - min_coord_y)

    def calculate_scale_factor_and_offset(self, bounding_rect, frame_width, frame_height):
        if bounding_rect.width() == 0 or bounding_rect.height() == 0:
            logger.warning("Bounding rect has zero width or height. Returning default values to avoid division by zero.")
            return 1, 0, 0  # Return default values to avoid division by zero
        drawing_width = bounding_rect.height()
        drawing_height = bounding_rect.width()
        drawing_center_x = (bounding_rect.left() + bounding_rect.right()) / 2
        drawing_center_y = (bounding_rect.top() + bounding_rect.bottom()) / 2
        scale_factor_width = frame_width / drawing_width
        scale_factor_height = frame_height / drawing_height
        scale_factor = min(scale_factor_width, scale_factor_height)
        offset_x = (frame_width / 2) - (drawing_center_y * scale_factor)
        offset_y = (frame_height / 2) - (drawing_center_x * scale_factor)
        #logger.debug(f"Scale factor: {scale_factor}, Offset X: {offset_x}, Offset Y: {offset_y}")
        return scale_factor, offset_x, offset_y