7ab69ab0f3
Naming pass: rename functions whose third+ segment is redundant or implementation-detail, sticking to the codebase's preferred ``noun_verb`` / ``verb_noun`` two-concept idiom. Renames are atomic across definitions, callers, and tests. is_penned_position → is_penned modulate_speed_near_sheep → modulate_speed mecanum_kinematics_step → mecanum_step policy_forward_mean → forward_mean Two-concept patterns like ``velocity_to_wheels`` / ``detections_from_scan`` / ``make_strombom_predictor`` are left alone — they're idiomatic converters / factories that read as a single concept, and the longer form aids grep-ability. Docstring polish: * ``herding/config.py`` header drops the "previously lived as a module-level literal" historical framing — we ship as a single thing, so the refactor anecdote no longer earns its keep. The usage examples now mention both ``HERDING_WEBOTS`` and ``HERDING_MEC_WEBOTS`` presets. 126 pytest cases still pass. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
76 lines
2.1 KiB
Python
76 lines
2.1 KiB
Python
"""Geometric predicates and constants."""
|
|
|
|
import math
|
|
|
|
from herding.world.geometry import (
|
|
FIELD_X, FIELD_Y, GATE_X, GATE_Y, MAX_SHEEP, PEN_ENTRY, PEN_X, PEN_Y,
|
|
distance_to_pen_entry, in_field, in_gate_corridor, in_pen,
|
|
is_penned,
|
|
)
|
|
|
|
|
|
def test_field_dimensions():
|
|
assert FIELD_X == (-15.0, 15.0)
|
|
assert FIELD_Y == (-15.0, 15.0)
|
|
|
|
|
|
def test_pen_geometry():
|
|
assert PEN_X == (10.0, 13.0)
|
|
assert PEN_Y == (-22.0, -15.0)
|
|
assert PEN_ENTRY == (11.5, -15.0)
|
|
assert GATE_X == PEN_X
|
|
assert GATE_Y == -15.0
|
|
|
|
|
|
def test_in_pen_strict_interior():
|
|
assert in_pen(11.5, -18.0)
|
|
assert not in_pen(10.0, -18.0) # boundary excluded
|
|
assert not in_pen(11.5, -15.0) # gate plane excluded
|
|
assert not in_pen(0.0, 0.0)
|
|
|
|
|
|
def test_in_field_with_margin():
|
|
assert in_field(0.0, 0.0)
|
|
assert in_field(14.0, 14.0)
|
|
assert not in_field(15.5, 0.0)
|
|
assert in_field(14.4, 0.0, margin=0.5)
|
|
assert not in_field(14.6, 0.0, margin=0.5)
|
|
|
|
|
|
def test_in_gate_corridor():
|
|
assert in_gate_corridor(11.5, -18.0)
|
|
assert in_gate_corridor(10.0, -15.0)
|
|
assert not in_gate_corridor(11.5, -10.0)
|
|
assert not in_gate_corridor(5.0, -18.0)
|
|
|
|
|
|
def test_is_penned_latches_below_gate():
|
|
# In the gate column and south of the gate plane → penned.
|
|
assert is_penned(11.5, -15.0)
|
|
assert is_penned(10.5, -18.0)
|
|
assert is_penned(12.5, -22.0)
|
|
# Above the gate plane → not yet.
|
|
assert not is_penned(11.5, -14.9)
|
|
# Outside the gate column → not penned even if south.
|
|
assert not is_penned(0.0, -16.0)
|
|
assert not is_penned(14.0, -16.0)
|
|
|
|
|
|
def test_is_penned_latch_margin():
|
|
# Slight tolerance on the gate column.
|
|
assert is_penned(9.9, -15.5)
|
|
assert is_penned(13.1, -15.5)
|
|
assert not is_penned(9.7, -15.5)
|
|
|
|
|
|
def test_distance_to_pen_entry():
|
|
assert distance_to_pen_entry(*PEN_ENTRY) == 0.0
|
|
assert math.isclose(distance_to_pen_entry(11.5, -10.0), 5.0)
|
|
assert math.isclose(distance_to_pen_entry(0.0, 0.0),
|
|
math.hypot(11.5, 15.0))
|
|
|
|
|
|
def test_max_sheep_positive_int():
|
|
assert isinstance(MAX_SHEEP, int)
|
|
assert MAX_SHEEP >= 1
|