This commit is contained in:
Ken Van Hoeylandt 2026-10-07 20:53:16 +02:00
parent ae0d002f36
commit 628f7b2b0c
2 changed files with 13 additions and 2 deletions

View File

@ -3,10 +3,13 @@
#include <algorithm>
#include <cmath>
#include <numbers>
constexpr double INV_SQRT2 = 1.0 / std::numbers::sqrt2;
// The part of a corner's square that a circle with the given radius cuts off along its diagonal
static int32_t corner_inset(int32_t radius) {
return static_cast<int32_t>(std::ceil(radius * (1.0 - M_SQRT1_2)));
return static_cast<int32_t>(std::ceil(radius * (1.0 - INV_SQRT2)));
}
// The horizontal distance between a circle's edge and its bounding box at the given distance from the circle's center row

View File

@ -5,6 +5,7 @@
#include <app/paths.h>
#include <charconv>
#include <cinttypes>
#include <cstdio>
#include <cstdlib>
@ -27,7 +28,14 @@ static std::optional<uint32_t> parseColor(const std::map<std::string, std::strin
if (entry == map.end() || entry->second.empty()) {
return std::nullopt;
}
return static_cast<uint32_t>(std::strtoul(entry->second.c_str(), nullptr, 16)) & 0xFFFFFF;
// An invalid value (e.g. from a hand-edited file) counts as unset, rather than as black
const std::string& text = entry->second;
uint32_t color = 0;
const auto [end, error] = std::from_chars(text.data(), text.data() + text.size(), color, 16);
if (error != std::errc {} || end != text.data() + text.size() || color > 0xFFFFFF) {
return std::nullopt;
}
return color;
}
// Saving only updates the keys that are written, so an unset colour is written as an empty value