Skip to content

Commit 77724df

Browse files
committed
Improved display_coordinate type
1 parent edf6ced commit 77724df

19 files changed

+180
-123
lines changed

CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ include(cmake/project-is-top-level.cmake)
1414
include(cmake/variables.cmake)
1515

1616
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION ON)
17-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=x86-64 -mavx512f -mavx512dq -mavx512vl -mavx512bf16")
17+
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native -mavx512f -mavx512dq -mavx512vl -mavx512bf16")
1818
# add_compile_options(-fno-inline -fno-omit-frame-pointer)
1919

2020

@@ -29,6 +29,7 @@ add_library(
2929
source/graphics/aspect_ratio/aspect_ratio.cpp
3030
source/mandelbrot/equations_simd.cpp
3131
source/mandelbrot/equations.cpp
32+
source/units/coordinates.cpp
3233
)
3334

3435
target_include_directories(

CMakePresets.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
"description": "These flags are supported by both GCC and Clang",
6060
"hidden": true,
6161
"cacheVariables": {
62-
"CMAKE_CXX_FLAGS": "-D_GLIBCXX_ASSERTIONS=1 -fstack-protector-strong -fcf-protection=full -fstack-clash-protection -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast",
62+
"CMAKE_CXX_FLAGS": "-D_GLIBCXX_ASSERTIONS=1 -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast",
6363
"CMAKE_EXE_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now,-z,nodlopen",
6464
"CMAKE_SHARED_LINKER_FLAGS": "-Wl,--allow-shlib-undefined,--as-needed,-z,noexecstack,-z,relro,-z,now,-z,nodlopen"
6565
}
@@ -68,7 +68,7 @@
6868
"name": "flags-appleclang",
6969
"hidden": true,
7070
"cacheVariables": {
71-
"CMAKE_CXX_FLAGS": "-fstack-protector-strong -Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast"
71+
"CMAKE_CXX_FLAGS": "-Wall -Wextra -Wpedantic -Wconversion -Wsign-conversion -Wcast-qual -Wformat=2 -Wundef -Werror=float-equal -Wshadow -Wcast-align -Wunused -Wnull-dereference -Wdouble-promotion -Wimplicit-fallthrough -Wextra-semi -Woverloaded-virtual -Wnon-virtual-dtor -Wold-style-cast"
7272
}
7373
},
7474
{

Taskfile.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ version: '3'
22

33
vars:
44
NAME: fractal-generator
5-
RELEASE_BUILD: "true"
5+
RELEASE_BUILD: "false"
66
RELEASE_PRESET: "ci-ubuntu"
77

88
tasks:
@@ -60,7 +60,7 @@ tasks:
6060
dir: .
6161
cmds:
6262
- task: build
63-
- ./build/benchmark/fractal_benchmarks
63+
- taskset -c 0 ./build/benchmark/fractal_benchmarks --benchmark_repetitions=5 --benchmark_min_warmup_time=0.5 --benchmark_report_aggregates_only=true
6464

6565
fmt:
6666
dir: .

benchmark/source/bench.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#include "config.hpp"
2-
#include "coordinates.hpp"
2+
#include "units/coordinates.hpp"
33
#include "graphics/display_to_complex.hpp"
44
#include "mandelbrot/equations.hpp"
55
#include "mandelbrot/equations_simd.hpp"
@@ -11,7 +11,7 @@ using namespace fractal;
1111

1212
static void BM_GenerateMandelbrot(benchmark::State& state)
1313
{
14-
display_domain display = {
14+
DisplayDomain display = {
1515
{0, 0 },
1616
{800, 800}
1717
};
@@ -32,7 +32,7 @@ static void BM_GenerateMandelbrot(benchmark::State& state)
3232

3333
static void BM_GenerateMandelbrotSimd(benchmark::State& state)
3434
{
35-
display_domain display = {
35+
DisplayDomain display = {
3636
{0, 0 },
3737
{800, 800}
3838
};

source/config.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#pragma once
22

3-
#include "coordinates.hpp"
3+
#include "units/coordinates.hpp"
44
#include "units/units.hpp"
55

66
#include <cstddef>

source/graphics/aspect_ratio/aspect_ratio.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ display_coordinate calculate_rectangle_end_point(
66
display_coordinate start, display_coordinate current, float target_aspect_ratio
77
)
88
{
9-
auto width = static_cast<float>(std::abs(current.first - start.first));
10-
auto height = static_cast<float>(std::abs(current.second - start.second));
9+
auto width = static_cast<float>(std::abs(current.x - start.x));
10+
auto height = static_cast<float>(std::abs(current.y - start.y));
1111

1212
// Adjust the dimensions to maintain the target aspect ratio
1313
if (width / height > target_aspect_ratio) {
@@ -19,15 +19,15 @@ display_coordinate calculate_rectangle_end_point(
1919
height = width / target_aspect_ratio;
2020
}
2121

22-
auto new_x = static_cast<float>(std::min(current.first, start.first));
23-
auto new_y = static_cast<float>(std::min(current.second, start.second));
22+
auto new_x = static_cast<float>(std::min(current.x, start.x));
23+
auto new_y = static_cast<float>(std::min(current.y, start.y));
2424

2525
// Adjust the top-left corner based on new dimensions
26-
if (current.first < start.first) {
27-
new_x = static_cast<float>(start.first) - width;
26+
if (current.x < start.x) {
27+
new_x = static_cast<float>(start.x) - width;
2828
}
29-
if (current.second < start.second) {
30-
new_y = static_cast<float>(start.second) - height;
29+
if (current.y < start.y) {
30+
new_y = static_cast<float>(start.y) - height;
3131
}
3232

3333
// Return the top-left and bottom-right corners as a pair of sf::Vector2f

source/graphics/aspect_ratio/aspect_ratio.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#pragma once
22

33
#include "config.hpp"
4-
#include "coordinates.hpp"
4+
#include "units/coordinates.hpp"
55

66
namespace fractal {
77
display_coordinate calculate_rectangle_end_point(

source/graphics/display/display.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void PixelDisplay::handle_event_(const sf::Event& event)
4141
}
4242
}
4343

44-
void PixelDisplay::add_observer(std::unique_ptr<DisplayEventObserver> observer)
44+
void PixelDisplay::add_drawable(std::unique_ptr<DisplayEventObserver> observer)
4545
{
4646
observers_.push_back(std::move(observer));
4747
}

source/graphics/display/display.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PixelDisplay {
2121
public:
2222
explicit PixelDisplay();
2323

24-
void add_observer(std::unique_ptr<DisplayEventObserver> observer);
24+
void add_drawable(std::unique_ptr<DisplayEventObserver> observer);
2525

2626
void poll_window_events();
2727
void display_window();

source/graphics/display_to_complex.hpp

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
#pragma once
22

3-
#include "coordinates.hpp"
3+
#include "units/display_domain.hpp"
44
#include "units/units.hpp"
55
#include "units/units_avx.hpp"
66

77
#include <complex>
88

99
namespace fractal {
1010
class DisplayToComplexCoordinates {
11-
const display_domain DISPLAY_DOMAIN;
11+
const DisplayDomain DISPLAY_DOMAIN;
1212
complex_underlying real_scaling_factor_;
1313
complex_underlying imaginary_scaling_factor_;
1414
complex_coordinate complex_domain_start_;
@@ -19,7 +19,7 @@ class DisplayToComplexCoordinates {
1919
)
2020
{
2121
complex_underlying real_d_size = real_domain_size(complex_domain);
22-
return real_d_size / static_cast<complex_underlying>(display_top_right.first);
22+
return real_d_size / static_cast<complex_underlying>(display_top_right.x);
2323
}
2424

2525
static complex_underlying imaginary_scaling_factor(
@@ -28,43 +28,45 @@ class DisplayToComplexCoordinates {
2828
)
2929
{
3030
complex_underlying imaginary_d_size = imaginary_domain_size(complex_domain);
31-
return imaginary_d_size
32-
/ static_cast<complex_underlying>(display_top_right.second);
31+
return imaginary_d_size / static_cast<complex_underlying>(display_top_right.y);
3332
}
3433

3534
static complex_coordinate to_complex(display_coordinate coordinate)
3635
{
3736
return {
38-
static_cast<complex_underlying>(coordinate.first),
39-
static_cast<complex_underlying>(coordinate.second)
37+
static_cast<complex_underlying>(coordinate.x),
38+
static_cast<complex_underlying>(coordinate.y)
4039
};
4140
}
4241

4342
public:
4443
DisplayToComplexCoordinates(
45-
display_domain display_domain, const complex_domain& complex_domain
44+
const DisplayDomain& display_domain, const complex_domain& complex_domain
4645
) :
47-
DISPLAY_DOMAIN{std::move(display_domain)},
46+
DISPLAY_DOMAIN{display_domain},
4847
real_scaling_factor_(
49-
real_scaling_factor(display_domain.end_coordinate, complex_domain)
50-
),
51-
imaginary_scaling_factor_(
52-
imaginary_scaling_factor(display_domain.end_coordinate, complex_domain)
48+
real_scaling_factor(display_domain.get_end_coordinate(), complex_domain)
5349
),
50+
imaginary_scaling_factor_(imaginary_scaling_factor(
51+
display_domain.get_end_coordinate(), complex_domain
52+
)),
5453
complex_domain_start_(complex_domain.start_coordinate)
5554
{}
5655

57-
void update_display_domain(display_domain new_domain)
56+
void update_display_domain(const DisplayDomain& new_domain)
5857
{
5958
complex_coordinate new_start =
60-
to_complex_projection(new_domain.start_coordinate);
61-
complex_coordinate new_end = to_complex_projection(new_domain.end_coordinate);
59+
to_complex_projection(new_domain.get_start_coordinate());
60+
complex_coordinate new_end =
61+
to_complex_projection(new_domain.get_end_coordinate());
6262
complex_domain new_complex_domain = {new_start, new_end};
6363

64-
real_scaling_factor_ =
65-
real_scaling_factor(DISPLAY_DOMAIN.end_coordinate, new_complex_domain);
66-
imaginary_scaling_factor_ =
67-
imaginary_scaling_factor(DISPLAY_DOMAIN.end_coordinate, new_complex_domain);
64+
real_scaling_factor_ = real_scaling_factor(
65+
DISPLAY_DOMAIN.get_end_coordinate(), new_complex_domain
66+
);
67+
imaginary_scaling_factor_ = imaginary_scaling_factor(
68+
DISPLAY_DOMAIN.get_end_coordinate(), new_complex_domain
69+
);
6870
complex_domain_start_ = new_complex_domain.start_coordinate;
6971
}
7072

0 commit comments

Comments
 (0)