File tree Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Expand file tree Collapse file tree 2 files changed +18
-1
lines changed Original file line number Diff line number Diff line change @@ -1165,12 +1165,22 @@ chan_set_source_location(PyObject *self, PyObject *args)
1165
1165
{
1166
1166
int channelnum = pgChannel_AsInt (self );
1167
1167
Sint16 angle ;
1168
+ float angle_f ;
1168
1169
Uint8 distance ;
1170
+ float distance_f ;
1169
1171
PyThreadState * _save ;
1170
1172
1171
- if (!PyArg_ParseTuple (args , "hb " , & angle , & distance ))
1173
+ if (!PyArg_ParseTuple (args , "ff " , & angle_f , & distance_f ))
1172
1174
return NULL ;
1173
1175
1176
+ angle = (Sint16 )roundf (fmodf (angle_f , 360 ));
1177
+ distance_f = roundf (distance_f );
1178
+ if (0 > distance_f || 256 <= distance_f ) {
1179
+ return RAISE (PyExc_ValueError ,
1180
+ "distance out of range, expected (0, 255)" );
1181
+ }
1182
+ distance = (Uint8 )distance_f ;
1183
+
1174
1184
MIXER_INIT_CHECK ();
1175
1185
_save = PyEval_SaveThread ();
1176
1186
if (!Mix_SetPosition (channelnum , angle , distance )) {
Original file line number Diff line number Diff line change @@ -898,6 +898,13 @@ def todo_test_unpause(self):
898
898
899
899
self .fail ()
900
900
901
+ def test_set_source_location (self ):
902
+ ch = mixer .Channel (0 )
903
+ ch .set_source_location (- 3.14 , 6.25 )
904
+ self .assertRaises (ValueError , lambda : ch .set_source_location (0 , - 1 ))
905
+ self .assertRaises (ValueError , lambda : ch .set_source_location (0 , 256.0 ))
906
+ self .assertRaises (TypeError , lambda : ch .set_source_location ("" , 6.25 ))
907
+
901
908
902
909
class ChannelInteractiveTest (unittest .TestCase ):
903
910
__tags__ = ["interactive" ]
You can’t perform that action at this time.
0 commit comments