From 646b276a9ba766a7e2acfe2d35e83228afc0d1f7 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 9 Jun 2025 23:26:52 +0100 Subject: Handle edge cases ...where extending a network results in something that can be a straight or collapsed into a single arc from a bi-arc. --- lib/maths.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'lib/maths.cpp') diff --git a/lib/maths.cpp b/lib/maths.cpp index 000cea7..7dd313e 100644 --- a/lib/maths.cpp +++ b/lib/maths.cpp @@ -1,5 +1,6 @@ #include "maths.h" #include +#include #include #include #include @@ -32,6 +33,7 @@ static_assert(pow(3, 1) == 3); static_assert(pow(3, 2) == 9); static_assert(pow(pi, 3) == 31.006278991699219F); +#ifndef __clang__ static_assert(!linesIntersectAt({0, 10}, {10, 10}, {10, 0}, {0, 0}).has_value()); static_assert(*linesIntersectAt({0, 0}, {10, 10}, {10, 0}, {0, 10}) == GlobalPosition2D {5, 5}); static_assert(*linesIntersectAt({300'000'000, 400'000'00}, {300'010'000, 400'010'00}, {310'010'000, 410'000'00}, @@ -43,6 +45,13 @@ constexpr auto EAST2D = RelativePosition2D(east); static_assert(!linesIntersectAtDirs({0, 0}, NORTH2D, {10, 10}, NORTH2D).has_value()); static_assert(linesIntersectAtDirs({0, 0}, NORTH2D, {10, 10}, EAST2D) == GlobalPosition2D {0, 10}); static_assert(linesIntersectAtDirs({0, 0}, EAST2D, {10, 10}, NORTH2D) == GlobalPosition2D {10, 0}); + +static_assert(find_arc_centre({0, 0}, -NORTH2D, {10, 10}) == std::make_pair({10, 0}, 10.F)); +static_assert(find_arc_centre({20, 0}, -NORTH2D, {10, 10}) == std::make_pair({10, 0}, -10.F)); +static_assert(find_arc_centre({10, 0}, -NORTH2D, {10, 10}).second == 0.F); +static_assert(isWithinLimit(find_arc_centre({0, 0}, pi + quarter_pi, {1000, 1000}).second, 0.F, 0.1F)); +#endif + // NOLINTEND(readability-magic-numbers) float -- cgit v1.2.3