Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/scenic/core/object_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1081,7 +1081,11 @@ class Object(OrientedPoint):
"showVisibleRegion": False,
"color": None,
"render": True,
"velocity": PropertyDefault((), {"dynamic"}, lambda self: Vector(0, 0, 0)),
"velocity": PropertyDefault(
("speed", "orientation"),
{"dynamic"},
lambda self: Vector(0, self.speed, 0).rotatedBy(self.orientation),
),
"speed": PropertyDefault((), {"dynamic"}, lambda self: 0),
"angularVelocity": PropertyDefault((), {"dynamic"}, lambda self: Vector(0, 0, 0)),
"angularSpeed": PropertyDefault((), {"dynamic"}, lambda self: 0),
Expand Down
15 changes: 15 additions & 0 deletions tests/syntax/test_specifiers.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,21 @@ def test_lazy_value_in_requirement_2():
sampleScene(scenario, maxIterations=1)


def test_default_velocity_depends_on_speed_and_orientation():
# Heading convention in Scenic: 0 deg = +Y, 90 deg = -X
ego = sampleEgoFrom("ego = new Object with speed 10, facing 90 deg")
assert tuple(ego.velocity) == pytest.approx((-10, 0, 0))

# Order independence (dependency graph should resolve the same way)
ego = sampleEgoFrom("ego = new Object facing 90 deg, with speed 10")
assert tuple(ego.velocity) == pytest.approx((-10, 0, 0))

# Orientation derived from another specifier (not a literal heading)
ego = sampleEgoFrom("ego = new Object with speed 10, facing toward -1 @ 1")
s = 10 * math.sqrt(0.5)
assert tuple(ego.velocity) == pytest.approx((-s, s, 0))


## Value normalization


Expand Down
Loading