From 1402ca7d6c2bb0cea2cf52a4ecce7b809ebf31b1 Mon Sep 17 00:00:00 2001 From: "Danilo M." Date: Wed, 28 Oct 2026 10:31:32 +0100 Subject: Reject malformed spline counts and unsorted knots Co-Authored-By: Claude Haiku 5.5 --- generat3d/formula.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'generat3d') diff --git a/generat3d/formula.py b/generat3d/formula.py index 2165e16..2434d89 100644 --- a/generat3d/formula.py +++ b/generat3d/formula.py @@ -123,7 +123,10 @@ class Graph: def _spline_op(name, stack): - n = int(stack.pop()) + n = stack.pop() + if isinstance(n, bool) or not isinstance(n, (int, float)) or n != int(n): + raise ValueError + n = int(n) if n < 1 or n > len(stack) - 1: raise IndexError knots = stack[-n:] @@ -135,6 +138,8 @@ def spline(kind, x, knots): """Evaluate a DSON spline at x. Knots are [x, y] or [x, y, t, c, b], sorted by x.""" xs = [k[0] for k in knots] ys = [k[1] for k in knots] + if any(a > b for a, b in zip(xs, xs[1:])): + raise ValueError("spline knots not sorted by x") if x <= xs[0]: return ys[0] if x >= xs[-1]: @@ -147,6 +152,7 @@ def spline(kind, x, knots): return ys[i] + s * (ys[i + 1] - ys[i]) # ponytail: Kochanek-Bartels with uniform segment parameterization; # if the corpus shows Daz scales tangents by knot spacing, add that here. + # end tangents use a one-sided difference (halved), check endpoints against the corpus too. m0 = _tcb_tangent(knots, ys, i, outgoing=True) m1 = _tcb_tangent(knots, ys, i + 1, outgoing=False) s2, s3 = s * s, s * s * s -- cgit v1.2.3