2020
2121using namespace libscratchcpp ;
2222
23- static const double pi = std::acos(-1 ); // TODO: Use std::numbers::pi in C++20
24-
2523std::string MotionBlocks::name () const
2624{
2725 return " Motion" ;
@@ -357,7 +355,7 @@ CompilerValue *MotionBlocks::compileDirection(Compiler *compiler)
357355BLOCK_EXPORT void motion_movesteps (Sprite *sprite, double steps)
358356{
359357 double dir = sprite->direction ();
360- sprite->setPosition (sprite->x () + std::sin (dir * pi / 180 ) * steps, sprite->y () + std::cos (dir * pi / 180 ) * steps);
358+ sprite->setPosition (sprite->x () + std::sin (dir * std::numbers:: pi / 180 ) * steps, sprite->y () + std::cos (dir * std::numbers:: pi / 180 ) * steps);
361359}
362360
363361BLOCK_EXPORT void motion_turnright (Sprite *sprite, double degrees)
@@ -387,9 +385,9 @@ inline void motion_point_towards_pos(Sprite *sprite, double x, double y)
387385 else
388386 sprite->setDirection (90 );
389387 } else if (deltaY < 0 )
390- sprite->setDirection (180 + (180 / pi) * std::atan (deltaX / deltaY));
388+ sprite->setDirection (180 + (180 / std::numbers:: pi) * std::atan (deltaX / deltaY));
391389 else
392- sprite->setDirection ((180 / pi) * std::atan (deltaX / deltaY));
390+ sprite->setDirection ((180 / std::numbers:: pi) * std::atan (deltaX / deltaY));
393391}
394392
395393BLOCK_EXPORT void motion_point_towards_mouse (Sprite *sprite)
@@ -678,7 +676,7 @@ BLOCK_EXPORT void motion_ifonedgebounce(Sprite *sprite)
678676 assert (nearestEdge != 0 );
679677
680678 // Point away from the nearest edge
681- double radians = (90 - sprite->direction ()) * pi / 180 ;
679+ double radians = (90 - sprite->direction ()) * std::numbers:: pi / 180 ;
682680 double dx = std::cos (radians);
683681 double dy = -std::sin (radians);
684682
@@ -704,7 +702,7 @@ BLOCK_EXPORT void motion_ifonedgebounce(Sprite *sprite)
704702 break ;
705703 }
706704
707- double newDirection = (180 / pi) * (std::atan2 (dy, dx)) + 90 ;
705+ double newDirection = (180 / std::numbers:: pi) * (std::atan2 (dy, dx)) + 90 ;
708706 sprite->setDirection (newDirection);
709707
710708 // Keep within the stage
0 commit comments