File tree Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Expand file tree Collapse file tree 2 files changed +31
-1
lines changed Original file line number Diff line number Diff line change @@ -197,7 +197,13 @@ double Sprite::direction() const
197197/* ! Sets the direction. */
198198void Sprite::setDirection (double newDirection)
199199{
200- impl->direction = newDirection;
200+ if (newDirection >= -180 && newDirection <= 180 )
201+ impl->direction = newDirection;
202+ else if (newDirection < -180 )
203+ impl->direction = std::fmod (newDirection - 180 , 360 ) + 180 ;
204+ else
205+ impl->direction = std::fmod (newDirection + 180 , 360 ) - 180 ;
206+
201207 if (impl->iface )
202208 impl->iface ->onDirectionChanged (impl->direction );
203209}
Original file line number Diff line number Diff line change @@ -225,6 +225,30 @@ TEST(SpriteTest, Direction)
225225
226226 sprite.setDirection (145.2 );
227227 ASSERT_EQ (sprite.direction (), 145.2 );
228+
229+ sprite.setDirection (182.5 );
230+ ASSERT_EQ (sprite.direction (), -177.5 );
231+
232+ sprite.setDirection (270 );
233+ ASSERT_EQ (sprite.direction (), -90 );
234+
235+ sprite.setDirection (360 );
236+ ASSERT_EQ (sprite.direction (), 0 );
237+
238+ sprite.setDirection (500 );
239+ ASSERT_EQ (sprite.direction (), 140 );
240+
241+ sprite.setDirection (-182.5 );
242+ ASSERT_EQ (sprite.direction (), 177.5 );
243+
244+ sprite.setDirection (-270 );
245+ ASSERT_EQ (sprite.direction (), 90 );
246+
247+ sprite.setDirection (-360 );
248+ ASSERT_EQ (sprite.direction (), 0 );
249+
250+ sprite.setDirection (-500 );
251+ ASSERT_EQ (sprite.direction (), -140 );
228252}
229253
230254TEST (SpriteTest, Draggable)
You can’t perform that action at this time.
0 commit comments