From 0abd62e8c8a8648366ef12d024b821c6f55f2719 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 23 Jul 2025 15:01:09 +0300 Subject: chore: Update GCD algorithm from Euclids to the Euclidean Euclidean is faster --- src/LEDVideoWall.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/LEDVideoWall.cpp') diff --git a/src/LEDVideoWall.cpp b/src/LEDVideoWall.cpp index 5fb69ac..abdbcf0 100644 --- a/src/LEDVideoWall.cpp +++ b/src/LEDVideoWall.cpp @@ -18,9 +18,9 @@ LEDVideoWall* LEDVideoWall::Freeform(mm panel_width, mm panel_height, mm wall_ma // GCD is available in stl from C++17 onwards, but I'm still reimplementing it unsigned int gcd(unsigned int a, unsigned int b) { - if (a == b) return a; - if (a < b) return gcd(b, a); - return gcd(a - b, b); + // Eucledian algorithm https://en.wikipedia.org/wiki/Greatest_common_divisor#Euclidean_algorithm + if (b == 0) return a; + return gcd(b, a % b); } LEDVideoWall* LEDVideoWall::Aspect(mm panel_width, mm panel_height, unsigned int aspect_width, unsigned int aspect_height) { -- cgit v1.3.1-23-gd82d