From fca729da24c8ee569446e5e32b16f907a72c55ca Mon Sep 17 00:00:00 2001 From: Steven Ewald Date: Sat, 23 Nov 2024 23:20:12 -0600 Subject: [PATCH 1/3] arbitrary --- source/main.cpp | 16 ++++++++-------- source/units.hpp | 13 ++++++++++++- 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/source/main.cpp b/source/main.cpp index 433ed62..013fb53 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -13,16 +13,16 @@ namespace fractal { -constexpr complex_underlying DIVERGENCE_NORM = 4; -constexpr display_domain DISPLAY_DOMAIN{ - {0, 0 }, - {799, 599} +const complex_underlying DIVERGENCE_NORM = 4; +const display_domain DISPLAY_DOMAIN{ + {0, 0 }, + {WINDOW_WIDTH - 1, WINDOW_HEIGHT - 1} }; -constexpr complex_domain COMPLEX_DOMAIN{ - {-2, -1.5}, - {1, 1.5 } +const complex_domain COMPLEX_DOMAIN{ + {complex_underlying{-2}, complex_underlying{-1.5}}, + {complex_underlying{1}, complex_underlying{1.5} } }; -constexpr std::size_t MAX_ITERATIONS = 50; +constexpr std::size_t MAX_ITERATIONS = 512; // https://en.wikipedia.org/wiki/Mandelbrot_set#Formal_definition std::complex diff --git a/source/units.hpp b/source/units.hpp index 889d7d7..325ef90 100644 --- a/source/units.hpp +++ b/source/units.hpp @@ -1,5 +1,16 @@ #pragma once +#include +#include +#include +#include + +#include + namespace fractal { -using complex_underlying = double; +using small_float = boost::multiprecision::cpp_bin_float< + 128, boost::multiprecision::digit_base_2, void, int32_t, + (std::numeric_limits::min() + 1024), 32>; +using complex_underlying = boost::multiprecision::number; +using complex = boost::multiprecision::complex_adaptor; } // namespace fractal From 43b462dd9725af32c40a063ecbdb6160a0ffa85c Mon Sep 17 00:00:00 2001 From: Steven Ewald Date: Sun, 24 Nov 2024 10:49:26 -0600 Subject: [PATCH 2/3] Remove old lib.c/hpp --- CMakeLists.txt | 1 - source/coordinates.hpp | 58 ++++++++++++++++++++------ source/lib.cpp | 5 --- source/lib.hpp | 20 --------- source/main.cpp | 6 ++- source/units.hpp | 5 ++- test/source/fractal-generator_test.cpp | 5 +-- 7 files changed, 55 insertions(+), 45 deletions(-) delete mode 100644 source/lib.cpp delete mode 100644 source/lib.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 0837226..e8764ee 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,7 +17,6 @@ include(cmake/variables.cmake) add_library( fractal-generator_lib OBJECT - source/lib.cpp source/graphics/basic_display.cpp source/graphics/color_conversions.cpp ) diff --git a/source/coordinates.hpp b/source/coordinates.hpp index d3bcc40..397aca2 100644 --- a/source/coordinates.hpp +++ b/source/coordinates.hpp @@ -4,6 +4,8 @@ #include +#include + namespace fractal { using display_coordinate = std::pair; using complex_coordinate = std::complex; @@ -13,26 +15,58 @@ struct display_domain { display_coordinate end_coordinate; class DisplayCoordinateIterator { - display_coordinate current_coordinate_; - display_coordinate end_coordinate_; + uint32_t grid_width_; + uint32_t current_coordinate_; + uint32_t end_coordinate_; + + uint32_t decay_coordinate_(const display_coordinate& coordinate) const + { + return static_cast(coordinate.first) + + static_cast(coordinate.second) * grid_width_; + } public: + using iterator_category = std::bidirectional_iterator_tag; + using value_type = display_coordinate; + using difference_type = std::uint32_t; + using pointer = display_coordinate*; + using reference = display_coordinate&; + explicit DisplayCoordinateIterator(const display_domain& domain) : - current_coordinate_{domain.start_coordinate}, - end_coordinate_{domain.end_coordinate} + grid_width_{domain.end_coordinate.first}, + current_coordinate_{decay_coordinate_(domain.start_coordinate)}, + end_coordinate_{decay_coordinate_(domain.end_coordinate)} {} - const display_coordinate& operator*() const { return current_coordinate_; } + value_type operator*() const + { + return { + current_coordinate_ % grid_width_, + (current_coordinate_ - current_coordinate_ % grid_width_) / grid_width_ + }; + } DisplayCoordinateIterator& operator++() { - if (current_coordinate_.first == end_coordinate_.first) [[unlikely]] { - current_coordinate_.first = 0; - current_coordinate_.second++; - } - else { - current_coordinate_.first++; - } + ++current_coordinate_; + return *this; + } + + DisplayCoordinateIterator& operator--() + { + --current_coordinate_; + return *this; + } + + DisplayCoordinateIterator& operator-(difference_type other) + { + current_coordinate_ -= other; + return *this; + } + + DisplayCoordinateIterator& operator+(difference_type other) + { + current_coordinate_ += other; return *this; } diff --git a/source/lib.cpp b/source/lib.cpp deleted file mode 100644 index dabbccc..0000000 --- a/source/lib.cpp +++ /dev/null @@ -1,5 +0,0 @@ -#include "lib.hpp" - -#include - -library::library() : name{fmt::format("{}", "fractal-generator")} {} diff --git a/source/lib.hpp b/source/lib.hpp deleted file mode 100644 index 970482b..0000000 --- a/source/lib.hpp +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -#include - -/** - * @brief The core implementation of the executable - * - * This class makes up the library part of the executable, which means that the - * main logic is implemented here. This kind of separation makes it easy to - * test the implementation for the executable, because the logic is nicely - * separated from the command-line logic implemented in the main function. - */ -struct library { - /** - * @brief Simply initializes the name member to the name of the project - */ - library(); - - std::string name; -}; diff --git a/source/main.cpp b/source/main.cpp index 013fb53..9703843 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -9,6 +9,7 @@ #include #include +#include #include namespace fractal { @@ -78,7 +79,10 @@ void display_mandelbrot() ); }; - std::for_each(DISPLAY_DOMAIN.begin(), DISPLAY_DOMAIN.end(), process_coordinate); + std::for_each( + std::execution::par_unseq, DISPLAY_DOMAIN.begin(), DISPLAY_DOMAIN.end(), + process_coordinate + ); display.display_window(); } diff --git a/source/units.hpp b/source/units.hpp index 325ef90..07af578 100644 --- a/source/units.hpp +++ b/source/units.hpp @@ -11,6 +11,7 @@ namespace fractal { using small_float = boost::multiprecision::cpp_bin_float< 128, boost::multiprecision::digit_base_2, void, int32_t, (std::numeric_limits::min() + 1024), 32>; -using complex_underlying = boost::multiprecision::number; -using complex = boost::multiprecision::complex_adaptor; +// using complex_underlying = boost::multiprecision::number; +// using complex = boost::multiprecision::complex_adaptor; +using complex_underlying = double; } // namespace fractal diff --git a/test/source/fractal-generator_test.cpp b/test/source/fractal-generator_test.cpp index 6fb15b7..4a003fc 100644 --- a/test/source/fractal-generator_test.cpp +++ b/test/source/fractal-generator_test.cpp @@ -1,9 +1,6 @@ -#include "lib.hpp" - #include TEST_CASE("Name is fractal-generator", "[library]") { - auto const lib = library{}; - REQUIRE(lib.name == "fractal-generator"); + REQUIRE(true); } From 3fd6600525e96781e39016d53eef2abd16d2e23e Mon Sep 17 00:00:00 2001 From: Steven Ewald Date: Sun, 24 Nov 2024 10:52:14 -0600 Subject: [PATCH 3/3] Update workflow to llvm 18 --- .github/workflows/ci.yml | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 47253a0..23e3220 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -19,11 +19,18 @@ jobs: - uses: actions/setup-python@v5 with: { python-version: "3.12" } + - name: Install LLVM 18 + run: | + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" + sudo apt update + sudo apt install llvm-18 llvm-18-dev llvm-18-tools clang-18 clang-tidy-18 clang-format-18 clang-tools-18 libclang-18-dev -y + - name: Install codespell run: pip3 install codespell - name: Lint - run: cmake -D FORMAT_COMMAND=clang-format-14 -P cmake/lint.cmake + run: cmake -D FORMAT_COMMAND=clang-format-18 -P cmake/lint.cmake - name: Spell check if: always() @@ -34,7 +41,7 @@ jobs: runs-on: ubuntu-22.04 - env: { CXX: clang++-14 } + env: { CXX: clang++-18 } steps: - uses: actions/checkout@v4 @@ -43,6 +50,13 @@ jobs: uses: actions/setup-python@v5 with: { python-version: "3.12" } + - name: Install LLVM 18 + run: | + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" + sudo apt update + sudo apt install llvm-18 llvm-18-dev llvm-18-tools clang-18 clang-tidy-18 clang-format-18 clang-tools-18 libclang-18-dev -y + - name: Conan cache uses: actions/cache@v4 with: @@ -76,21 +90,28 @@ jobs: strategy: matrix: - os: [macos-14, ubuntu-22.04] + os: [ubuntu-22.04] runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + - name: Install LLVM 18 + run: | + wget -qO- https://apt.llvm.org/llvm-snapshot.gpg.key | sudo tee /etc/apt/trusted.gpg.d/apt.llvm.org.asc + sudo apt-add-repository "deb http://apt.llvm.org/jammy/ llvm-toolchain-jammy-18 main" + sudo apt update + sudo apt install llvm-18 llvm-18-dev llvm-18-tools clang-18 clang-tidy-18 clang-format-18 clang-tools-18 libclang-18-dev -y + - name: Install static analyzers if: matrix.os == 'ubuntu-22.04' run: >- - sudo apt-get install clang-tidy-14 cppcheck -y -q + sudo apt-get install clang-tidy-18 cppcheck -y -q sudo update-alternatives --install /usr/bin/clang-tidy clang-tidy - /usr/bin/clang-tidy-14 140 + /usr/bin/clang-tidy-18 140 - name: Install Python uses: actions/setup-python@v5