fix(humanize): preserve gaussian magnitude in jitter_point; unify swipe return shape
This commit is contained in:
@@ -27,6 +27,28 @@ def test_jitter_point_centered_on_input():
|
||||
assert abs(sum(xs) / len(xs)) < 0.3
|
||||
|
||||
|
||||
def test_jitter_point_concentrated_near_target():
|
||||
"""Regression: jitter must be polar-Gaussian (concentrated near target),
|
||||
not uniform-on-circle (all points at exactly ``radius``).
|
||||
|
||||
For a folded Gaussian with sigma=radius/2, the expected mean distance is
|
||||
~0.8*sigma ~= 0.4*radius. Using ``< 0.7*radius`` gives a safe margin that
|
||||
fails the previous reprojection bug (mean distance == radius exactly).
|
||||
"""
|
||||
rng = random.Random(1234)
|
||||
radius = 5.0
|
||||
n = 5000
|
||||
distances = [
|
||||
math.hypot(x - 0.0, y - 0.0)
|
||||
for x, y in (jitter_point(0.0, 0.0, radius=radius, rng=rng) for _ in range(n))
|
||||
]
|
||||
mean_distance = sum(distances) / n
|
||||
assert mean_distance < radius * 0.7, (
|
||||
f"mean distance {mean_distance:.3f} is too large; jitter looks like "
|
||||
"uniform-on-circle rather than polar-Gaussian"
|
||||
)
|
||||
|
||||
|
||||
def test_jitter_duration_within_spread():
|
||||
rng = random.Random(3)
|
||||
for _ in range(200):
|
||||
|
||||
Reference in New Issue
Block a user