[bezier] validate weights

This commit is contained in:
Jan Petykiewicz 2026-04-01 21:16:03 -07:00
commit 75a9114709
2 changed files with 23 additions and 0 deletions

View file

@ -3,9 +3,12 @@ from pathlib import Path
import numpy
from numpy.testing import assert_equal, assert_allclose
from numpy import pi
import pytest
from ..utils import remove_duplicate_vertices, remove_colinear_vertices, poly_contains_points, rotation_matrix_2d, apply_transforms, DeferredDict
from ..file.utils import tmpfile
from ..utils.curves import bezier
from ..error import PatternError
def test_remove_duplicate_vertices() -> None:
@ -91,6 +94,19 @@ def test_apply_transforms_advanced() -> None:
assert_allclose(combined[0], [0, 10, pi / 2, 1, 1], atol=1e-10)
def test_bezier_validates_weight_length() -> None:
with pytest.raises(PatternError, match='one entry per control point'):
bezier([[0, 0], [1, 1]], [0, 0.5, 1], weights=[1])
with pytest.raises(PatternError, match='one entry per control point'):
bezier([[0, 0], [1, 1]], [0, 0.5, 1], weights=[1, 2, 3])
def test_bezier_accepts_exact_weight_count() -> None:
samples = bezier([[0, 0], [1, 1]], [0, 0.5, 1], weights=[1, 2])
assert_allclose(samples, [[0, 0], [2 / 3, 2 / 3], [1, 1]], atol=1e-10)
def test_deferred_dict_accessors_resolve_values_once() -> None:
calls = 0