Skip to content

Commit

Permalink
Merge pull request #6 from stevenewald/arbitrary-zoom
Browse files Browse the repository at this point in the history
Add arbitrary zoom
  • Loading branch information
stevenewald authored Nov 24, 2024
2 parents af56647 + 3fd6600 commit 2bb27f3
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 56 deletions.
31 changes: 26 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -34,7 +41,7 @@ jobs:

runs-on: ubuntu-22.04

env: { CXX: clang++-14 }
env: { CXX: clang++-18 }

steps:
- uses: actions/checkout@v4
Expand All @@ -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:
Expand Down Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
58 changes: 46 additions & 12 deletions source/coordinates.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

#include <complex>

#include <iterator>

namespace fractal {
using display_coordinate = std::pair<uint16_t, uint16_t>;
using complex_coordinate = std::complex<complex_underlying>;
Expand All @@ -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<uint32_t>(coordinate.first)
+ static_cast<uint32_t>(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;
}

Expand Down
5 changes: 0 additions & 5 deletions source/lib.cpp

This file was deleted.

20 changes: 0 additions & 20 deletions source/lib.hpp

This file was deleted.

22 changes: 13 additions & 9 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,21 @@
#include <complex>

#include <algorithm>
#include <execution>
#include <limits>

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<complex_underlying>
Expand Down Expand Up @@ -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();
}
Expand Down
12 changes: 12 additions & 0 deletions source/units.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
#pragma once

#include <boost/multiprecision/cpp_bin_float.hpp>
#include <boost/multiprecision/cpp_complex.hpp>
#include <boost/multiprecision/fwd.hpp>
#include <boost/multiprecision/number.hpp>

#include <limits>

namespace fractal {
using small_float = boost::multiprecision::cpp_bin_float<
128, boost::multiprecision::digit_base_2, void, int32_t,
(std::numeric_limits<int32_t>::min() + 1024), 32>;
// using complex_underlying = boost::multiprecision::number<small_float>;
// using complex = boost::multiprecision::complex_adaptor<small_float>;
using complex_underlying = double;
} // namespace fractal
5 changes: 1 addition & 4 deletions test/source/fractal-generator_test.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include "lib.hpp"

#include <catch2/catch_test_macros.hpp>

TEST_CASE("Name is fractal-generator", "[library]")
{
auto const lib = library{};
REQUIRE(lib.name == "fractal-generator");
REQUIRE(true);
}

0 comments on commit 2bb27f3

Please sign in to comment.