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
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ cmake_minimum_required(VERSION 3.14)
project(libscratchcpp VERSION 0.15.0 LANGUAGES C CXX)

set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

option(LIBSCRATCHCPP_BUILD_UNIT_TESTS "Build unit tests" ON)
Expand Down
12 changes: 5 additions & 7 deletions src/blocks/motionblocks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@

using namespace libscratchcpp;

static const double pi = std::acos(-1); // TODO: Use std::numbers::pi in C++20

std::string MotionBlocks::name() const
{
return "Motion";
Expand Down Expand Up @@ -357,7 +355,7 @@ CompilerValue *MotionBlocks::compileDirection(Compiler *compiler)
BLOCK_EXPORT void motion_movesteps(Sprite *sprite, double steps)
{
double dir = sprite->direction();
sprite->setPosition(sprite->x() + std::sin(dir * pi / 180) * steps, sprite->y() + std::cos(dir * pi / 180) * steps);
sprite->setPosition(sprite->x() + std::sin(dir * std::numbers::pi / 180) * steps, sprite->y() + std::cos(dir * std::numbers::pi / 180) * steps);
}

BLOCK_EXPORT void motion_turnright(Sprite *sprite, double degrees)
Expand Down Expand Up @@ -387,9 +385,9 @@ inline void motion_point_towards_pos(Sprite *sprite, double x, double y)
else
sprite->setDirection(90);
} else if (deltaY < 0)
sprite->setDirection(180 + (180 / pi) * std::atan(deltaX / deltaY));
sprite->setDirection(180 + (180 / std::numbers::pi) * std::atan(deltaX / deltaY));
else
sprite->setDirection((180 / pi) * std::atan(deltaX / deltaY));
sprite->setDirection((180 / std::numbers::pi) * std::atan(deltaX / deltaY));
}

BLOCK_EXPORT void motion_point_towards_mouse(Sprite *sprite)
Expand Down Expand Up @@ -678,7 +676,7 @@ BLOCK_EXPORT void motion_ifonedgebounce(Sprite *sprite)
assert(nearestEdge != 0);

// Point away from the nearest edge
double radians = (90 - sprite->direction()) * pi / 180;
double radians = (90 - sprite->direction()) * std::numbers::pi / 180;
double dx = std::cos(radians);
double dy = -std::sin(radians);

Expand All @@ -704,7 +702,7 @@ BLOCK_EXPORT void motion_ifonedgebounce(Sprite *sprite)
break;
}

double newDirection = (180 / pi) * (std::atan2(dy, dx)) + 90;
double newDirection = (180 / std::numbers::pi) * (std::atan2(dy, dx)) + 90;
sprite->setDirection(newDirection);

// Keep within the stage
Expand Down
1 change: 0 additions & 1 deletion src/scratch/sprite_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@

using namespace libscratchcpp;

static const double pi = std::acos(-1); // TODO: Use std::numbers::pi in C++20
static const double FENCE_WIDTH = 15;

SpritePrivate::SpritePrivate(Sprite *sprite) :
Expand Down
3 changes: 1 addition & 2 deletions src/scratch/string_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ extern "C"
size++; // null terminator

if (str->allocatedSize < size) {
// TODO: Use std::bit_ceil() in C++20
const size_t newSize = std::pow(2, std::ceil(std::log2(size)));
const size_t newSize = std::bit_ceil(size);
assert((str->data && str->allocatedSize > 0) || (!str->data && str->allocatedSize == 0));

if (str->data)
Expand Down
Loading