예제 #1
0
def test_from_ellipse():
    from ezdxf.entities import Ellipse
    spline = Spline.from_arc(
        Ellipse.new(
            dxfattribs={
                'center': (1, 1),
                'major_axis': (2, 0),
                'ratio': 0.5,
                'start_param': 0.5,  # radians
                'end_param': 3,
                'layer': 'ellipse',
            }))
    assert spline.dxf.layer == 'ellipse'
    assert spline.dxf.degree == 2
    assert len(spline.control_points) > 2
    assert len(spline.weights) > 2
    assert len(spline.fit_points) == 0
    assert len(spline.knots) == required_knot_values(
        len(spline.control_points), spline.dxf.degree + 1)
예제 #2
0
파일: spline.py 프로젝트: mhenr18/ezdxf
    def _audit_control_points(self, auditor: 'Auditor'):
        name = str(self)
        order = self.dxf.degree + 1
        n_control_points = len(self.control_points)

        # Splines with to few control points can't be processed:
        n_control_points_required = required_control_points(order)
        if n_control_points < n_control_points_required:
            auditor.fixed_error(
                code=AuditError.INVALID_SPLINE_CONTROL_POINT_COUNT,
                message=f"Removed {name} with invalid control point count: "
                        f"{n_control_points} < {n_control_points_required}"
            )
            auditor.trash(self)
            return

        n_weights = len(self.weights)
        n_knots = len(self.knots)
        n_knots_required = required_knot_values(
            n_control_points, order)

        if n_knots < n_knots_required:
            # Can not fix entity: because the knot values are basic
            # values which define the geometry of SPLINE.
            auditor.fixed_error(
                code=AuditError.INVALID_SPLINE_KNOT_VALUE_COUNT,
                message=f"Removed {name} with invalid knot value count: "
                        f"{n_knots} < {n_knots_required}"
            )
            auditor.trash(self)
            return

        if n_weights and n_weights != n_control_points:
            # Can not fix entity: because the weights are basic
            # values which define the geometry of SPLINE.
            auditor.fixed_error(
                code=AuditError.INVALID_SPLINE_WEIGHT_COUNT,
                message=f"Removed {name} with invalid weight count: "
                        f"{n_weights} != {n_control_points}"
            )
            auditor.trash(self)
            return
예제 #3
0
def test_from_ellipse():
    from ezdxf.entities import Ellipse

    spline = Spline.from_arc(
        Ellipse.new(
            dxfattribs={
                "center": (1, 1),
                "major_axis": (2, 0),
                "ratio": 0.5,
                "start_param": 0.5,  # radians
                "end_param": 3,
                "layer": "ellipse",
            }))
    assert spline.dxf.layer == "ellipse"
    assert spline.dxf.degree == 2
    assert len(spline.control_points) > 2
    assert len(spline.weights) > 2
    assert len(spline.fit_points) == 0
    assert len(spline.knots) == required_knot_values(
        len(spline.control_points), spline.dxf.degree + 1)