def test_auditing_control_point_count(self, auditor, spline, degree): order = degree + 1 spline.dxf.degree = degree add_n_control_points(spline, required_control_points(order) - 1) spline.audit(auditor) assert len(auditor.fixes) == 1 assert auditor.fixes[0].code == \ AuditError.INVALID_SPLINE_CONTROL_POINT_COUNT # Test if invalid spline will be destroyed: auditor.empty_trashcan() assert spline.is_alive is False
def test_auditing_weight_count(self, auditor, spline, degree): order = degree + 1 spline.dxf.degree = degree count = required_control_points(order) add_n_control_points(spline, count) spline.knots = uniform_knot_vector(count, order) spline.weights = range(count - 1) spline.audit(auditor) assert len(auditor.fixes) == 1 assert auditor.fixes[0].code == AuditError.INVALID_SPLINE_WEIGHT_COUNT # Test if invalid spline will be destroyed: auditor.empty_trashcan() assert spline.is_alive is False
def test_auditing_knot_value_count(self, auditor, spline, degree): order = degree + 1 spline.dxf.degree = degree add_n_control_points(spline, required_control_points(order)) spline.knots = [1, 2, 3] spline.audit(auditor) assert len(auditor.fixes) == 1 assert ( auditor.fixes[0].code == AuditError.INVALID_SPLINE_KNOT_VALUE_COUNT ) # Test if invalid spline will be destroyed: auditor.empty_trashcan() assert spline.is_alive is False
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
def test_required_control_points_calculation(order, expected): assert required_control_points(order) == expected