Skip to content

Commit 1b72d31

Browse files
schroedtertOzaq
authored andcommitted
Rename e0 to desired_direction
1 parent f9a3e1d commit 1b72d31

File tree

3 files changed

+107
-16
lines changed

3 files changed

+107
-16
lines changed

python_bindings_jupedsim/generalized_centrifugal_force_model.cpp

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ void init_generalized_centrifugal_force_model(py::module_& m)
1717
m, "GeneralizedCentrifugalForceModelAgentParameters")
1818
.def(
1919
py::init([](double speed,
20-
std::tuple<double, double> e0,
20+
std::tuple<double, double> desired_direction,
2121
std::tuple<double, double> position,
2222
std::tuple<double, double> orientation,
2323
JPS_JourneyId journey_id,
@@ -31,7 +31,7 @@ void init_generalized_centrifugal_force_model(py::module_& m)
3131
double b_max) {
3232
return JPS_GeneralizedCentrifugalForceModelAgentParameters{
3333
speed,
34-
intoJPS_Point(e0),
34+
intoJPS_Point(desired_direction),
3535
intoJPS_Point(position),
3636
intoJPS_Point(orientation),
3737
journey_id,
@@ -46,7 +46,7 @@ void init_generalized_centrifugal_force_model(py::module_& m)
4646
}),
4747
py::kw_only(),
4848
py::arg("speed"),
49-
py::arg("e0"),
49+
py::arg("desired_direction"),
5050
py::arg("position"),
5151
py::arg("orientation"),
5252
py::arg("journey_id"),
@@ -60,7 +60,7 @@ void init_generalized_centrifugal_force_model(py::module_& m)
6060
py::arg("b_max"))
6161
.def("__repr__", [](const JPS_GeneralizedCentrifugalForceModelAgentParameters& p) {
6262
return fmt::format(
63-
"speed: {}, e0: {}, position: {}, orientation: {}, journey_id: {}, "
63+
"speed: {}, desired_direction: {}, position: {}, orientation: {}, journey_id: {}, "
6464
"stage_id: {}, mass: {}, desired_speed: {}, a_v: {}, a_min: {}, b_min: {}, b_max: "
6565
"{}",
6666
p.speed,
@@ -128,13 +128,14 @@ void init_generalized_centrifugal_force_model(py::module_& m)
128128
JPS_GeneralizedCentrifugalForceModelState_SetSpeed(w.handle, speed);
129129
})
130130
.def_property(
131-
"e0",
131+
"desired_direction",
132132
[](const JPS_GeneralizedCentrifugalForceModelState_Wrapper& w) {
133133
return intoTuple(JPS_GeneralizedCentrifugalForceModelState_GetE0(w.handle));
134134
},
135135
[](JPS_GeneralizedCentrifugalForceModelState_Wrapper& w,
136-
std::tuple<double, double> e0) {
137-
JPS_GeneralizedCentrifugalForceModelState_SetE0(w.handle, intoJPS_Point(e0));
136+
std::tuple<double, double> desired_direction) {
137+
JPS_GeneralizedCentrifugalForceModelState_SetE0(
138+
w.handle, intoJPS_Point(desired_direction));
138139
})
139140
.def_property(
140141
"mass",

python_modules/jupedsim/jupedsim/models/generalized_centrifugal_force.py

Lines changed: 39 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ class GeneralizedCentrifugalForceModelAgentParameters:
6363
6464
Attributes:
6565
speed: Speed of the agent.
66-
e0: Desired direction of the agent.
66+
desired_direction: Desired direction of the agent.
6767
position: Position of the agent.
6868
orientation: Orientation of the agent.
6969
journey_id: Id of the journey the agent follows.
@@ -78,7 +78,7 @@ class GeneralizedCentrifugalForceModelAgentParameters:
7878
"""
7979

8080
speed: float = 0.0
81-
e0: tuple[float, float] = (0.0, 0.0)
81+
desired_direction: tuple[float, float] = (0.0, 0.0)
8282
position: tuple[float, float] = (0.0, 0.0)
8383
orientation: tuple[float, float] = (1.0, 0.0)
8484
journey_id: int = -1
@@ -95,7 +95,7 @@ def __init__(
9595
self,
9696
*,
9797
speed: float = 0.0,
98-
e0: tuple[float, float] = (0.0, 0.0),
98+
desired_direction: tuple[float, float] = (0.0, 0.0),
9999
position: tuple[float, float] = (0.0, 0.0),
100100
orientation: tuple[float, float] = (1.0, 0.0),
101101
journey_id: int = -1,
@@ -108,10 +108,11 @@ def __init__(
108108
b_min: float = 0.2,
109109
b_max: float = 0.4,
110110
v0=None,
111+
e0=None,
111112
):
112113
"""Init dataclass to handle deprecated argument."""
113114
self.speed = speed
114-
self.e0 = e0
115+
self.desired_direction = desired_direction
115116
self.position = position
116117
self.orientation = orientation
117118
self.journey_id = journey_id
@@ -133,12 +134,32 @@ def __init__(
133134
else:
134135
self.desired_speed = desired_speed
135136

137+
if e0 is not None:
138+
warnings.warn(
139+
"'e0' is deprecated, use 'desired_direction' instead.",
140+
DeprecationWarning,
141+
stacklevel=2,
142+
)
143+
self.desired_direction = e0
144+
else:
145+
self.desired_direction = desired_direction
146+
147+
@property
148+
@deprecated("deprecated, use 'desired_direction' instead.")
149+
def e0(self) -> tuple[float, float]:
150+
return self.desired_direction
151+
152+
@e0.setter
153+
@deprecated("deprecated, use 'desired_direction' instead.")
154+
def e0(self, e0):
155+
self.desired_direction = e0
156+
136157
def as_native(
137158
self,
138159
) -> py_jps.GeneralizedCentrifugalForceModelAgentParameters:
139160
return py_jps.GeneralizedCentrifugalForceModelAgentParameters(
140161
speed=self.speed,
141-
e0=self.e0,
162+
desired_direction=self.desired_direction,
142163
position=self.position,
143164
orientation=self.orientation,
144165
journey_id=self.journey_id,
@@ -167,13 +188,24 @@ def speed(self, speed):
167188
self._obj.speed = speed
168189

169190
@property
191+
def desired_direction(self) -> float:
192+
"""desired direction of this agent."""
193+
return self._obj.desired_direction
194+
195+
@desired_direction.setter
196+
def desired_direction(self, desired_direction):
197+
self._obj.desired_direction = desired_direction
198+
199+
@property
200+
@deprecated("deprecated, use 'desired_direction' instead.")
170201
def e0(self) -> tuple[float, float]:
171202
"""Desired direction of this agent."""
172-
return self._obj.e0
203+
return self._obj.desired_speed
173204

174205
@e0.setter
206+
@deprecated("deprecated, use 'desired_direction' instead.")
175207
def e0(self, e0):
176-
self._obj.e0 = e0
208+
self._obj.desired_speed = e0
177209

178210
@property
179211
def tau(self) -> float:

systemtest/test_model_properties.py

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,8 @@ def test_set_model_parameters_generalized_centrifugal_force_model(
330330
sim.agent(agent_id).model.speed = 2.0
331331
assert sim.agent(agent_id).model.speed == 2.0
332332

333-
sim.agent(agent_id).model.e0 = (3.0, -3.0)
334-
assert sim.agent(agent_id).model.e0 == (3.0, -3.0)
333+
sim.agent(agent_id).model.desired_direction = (3.0, -3.0)
334+
assert sim.agent(agent_id).model.desired_direction == (3.0, -3.0)
335335

336336
sim.agent(agent_id).model.tau = 4.0
337337
assert sim.agent(agent_id).model.tau == 4.0
@@ -355,6 +355,64 @@ def test_set_model_parameters_generalized_centrifugal_force_model(
355355
assert sim.agent(agent_id).model.b_max == 9.0
356356

357357

358+
def test_generalized_centrifugal_force_model_agent_paramters_e0_constructor_deprecated(
359+
simulation_with_generalized_centrifugal_force_model,
360+
):
361+
sim = simulation_with_generalized_centrifugal_force_model
362+
wp = sim.add_waypoint_stage((10, 1), 0.5)
363+
journey_id = sim.add_journey(jps.JourneyDescription([wp]))
364+
365+
with pytest.warns(
366+
DeprecationWarning, match="deprecated, use 'desired_direction' instead"
367+
):
368+
agent = jps.GeneralizedCentrifugalForceModelAgentParameters(
369+
journey_id=journey_id, stage_id=wp, position=(1, 1), e0=(1, 2)
370+
)
371+
assert agent.desired_direction == (1, 2)
372+
373+
374+
def test_generalized_centrifugal_force_model_agent_paramters_e0_setter_deprecated(
375+
simulation_with_generalized_centrifugal_force_model,
376+
):
377+
sim = simulation_with_generalized_centrifugal_force_model
378+
wp = sim.add_waypoint_stage((10, 1), 0.5)
379+
journey_id = sim.add_journey(jps.JourneyDescription([wp]))
380+
381+
agent = jps.GeneralizedCentrifugalForceModelAgentParameters(
382+
journey_id=journey_id,
383+
stage_id=wp,
384+
position=(1, 1),
385+
desired_direction=(1, 2),
386+
)
387+
388+
with pytest.warns(
389+
DeprecationWarning, match="deprecated, use 'desired_direction' instead"
390+
):
391+
agent.e0 = (2, 1)
392+
assert agent.desired_direction == (2, 1)
393+
394+
395+
def test_generalized_centrifugal_force_model_agent_paramters_e0_getter_deprecated(
396+
simulation_with_generalized_centrifugal_force_model,
397+
):
398+
sim = simulation_with_generalized_centrifugal_force_model
399+
wp = sim.add_waypoint_stage((10, 1), 0.5)
400+
journey_id = sim.add_journey(jps.JourneyDescription([wp]))
401+
402+
agent = jps.GeneralizedCentrifugalForceModelAgentParameters(
403+
journey_id=journey_id,
404+
stage_id=wp,
405+
position=(1, 1),
406+
desired_direction=(1, 2),
407+
)
408+
409+
with pytest.warns(
410+
DeprecationWarning, match="deprecated, use 'desired_direction' instead"
411+
):
412+
desired_direction = agent.e0
413+
assert desired_direction == (1, 2)
414+
415+
358416
@pytest.fixture
359417
def simulation_with_social_force_model_body_force():
360418
with pytest.warns(

0 commit comments

Comments
 (0)