Skip to content

Commit

Permalink
Simplifying Discovery syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Sep 14, 2024
1 parent 97f4974 commit 81de30f
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 112 deletions.
3 changes: 2 additions & 1 deletion MandelbrotDiscovery/geometry.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@
auto dx_half() const noexcept -> value_type { return my_dx_half; }
auto dy_half() const noexcept -> value_type { return my_dy_half; }

auto center() const noexcept -> point_type { return my_center; }
auto center() const noexcept -> const point_type& { return my_center; }
auto center() noexcept -> point_type& { return my_center; }

auto recenter(const point_type& new_center) noexcept -> void
{
Expand Down
16 changes: 4 additions & 12 deletions MandelbrotDiscovery/mandelbrot_discovery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ namespace local
static constexpr char str_mandelbrot_point_center_y[] = "+0.00";
} // namespace local

//static_assert(local::mandelbrot_calculation_pixels_x == local::mandelbrot_calculation_pixels_y,
// "Error: This program is only compilable for square geometry");

//static_assert(util::utility::equal(local::mandelbrot_point_dx_half(),
// local::mandelbrot_point_dx_half() + util::utility::strlen(local::cfg_type_0::mandelbrot_point_dx_half()),
// local::mandelbrot_point_dy_half()),
// "Error: This program is only compilable for square geometry");

template<const unsigned Digits10> auto dx_half () -> typename local::cfg_type<Digits10>::mandelbrot_coord_pnt_type { using local_coord_pnt_type = typename local::cfg_type<Digits10>::mandelbrot_coord_pnt_type; return local_coord_pnt_type { local::str_mandelbrot_point_dx_half }; }
template<const unsigned Digits10> auto dy_half () -> typename local::cfg_type<Digits10>::mandelbrot_coord_pnt_type { using local_coord_pnt_type = typename local::cfg_type<Digits10>::mandelbrot_coord_pnt_type; return local_coord_pnt_type { local::str_mandelbrot_point_dy_half }; }
template<const unsigned Digits10> auto center_x() -> typename local::cfg_type<Digits10>::mandelbrot_coord_pnt_type { using local_coord_pnt_type = typename local::cfg_type<Digits10>::mandelbrot_coord_pnt_type; return local_coord_pnt_type { local::str_mandelbrot_point_center_x }; }
Expand All @@ -62,10 +54,10 @@ using rectangle_ref_01_type = typename std::tuple_element<0x01, rectangle_tuple
using rectangle_ref_02_type = typename std::tuple_element<0x02, rectangle_tuple_type>::type;
using rectangle_ref_03_type = typename std::tuple_element<0x03, rectangle_tuple_type>::type;

using point_00_type = typename rectangle_00_type::point_type;
using point_01_type = typename rectangle_01_type::point_type;
using point_02_type = typename rectangle_02_type::point_type;
using point_03_type = typename rectangle_03_type::point_type;
using point_00_type = typename rectangle_00_type::point_type;
using point_01_type = typename rectangle_01_type::point_type;
using point_02_type = typename rectangle_02_type::point_type;
using point_03_type = typename rectangle_03_type::point_type;

using local_window_type = mandelbrot_discovery<static_cast<int>(INT16_C(800)),
static_cast<int>(INT16_C(800)),
Expand Down
142 changes: 48 additions & 94 deletions MandelbrotDiscovery/mandelbrot_discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,19 +50,28 @@
const int ScreenCoordinateY = static_cast<int>(UINT16_C(8))>
class mandelbrot_discovery final
{
public:
using rectangle_tuple_type = MandelbrotRectangleTupleType;
private:
using rectangle_tuple_type = MandelbrotRectangleTupleType;

using rectangle_00_type = typename std::remove_reference<typename std::tuple_element<0x00, rectangle_tuple_type>::type>::type;
using rectangle_01_type = typename std::remove_reference<typename std::tuple_element<0x01, rectangle_tuple_type>::type>::type;
using rectangle_02_type = typename std::remove_reference<typename std::tuple_element<0x02, rectangle_tuple_type>::type>::type;
using rectangle_03_type = typename std::remove_reference<typename std::tuple_element<0x03, rectangle_tuple_type>::type>::type;
using rectangle_00_type = typename std::remove_reference<typename std::tuple_element<0x00, rectangle_tuple_type>::type>::type;
using rectangle_01_type = typename std::remove_reference<typename std::tuple_element<0x01, rectangle_tuple_type>::type>::type;
using rectangle_02_type = typename std::remove_reference<typename std::tuple_element<0x02, rectangle_tuple_type>::type>::type;
using rectangle_03_type = typename std::remove_reference<typename std::tuple_element<0x03, rectangle_tuple_type>::type>::type;

private:
using value_00_type = typename rectangle_00_type::point_type::value_type;
using value_01_type = typename rectangle_01_type::point_type::value_type;
using value_02_type = typename rectangle_02_type::point_type::value_type;
using value_03_type = typename rectangle_03_type::point_type::value_type;
using rectangle_tuple_ref_type = std::reference_wrapper<rectangle_tuple_type>;

using point_00_type = typename rectangle_00_type::point_type;
using point_01_type = typename rectangle_01_type::point_type;
using point_02_type = typename rectangle_02_type::point_type;
using point_03_type = typename rectangle_03_type::point_type;

using value_00_type = typename rectangle_00_type::point_type::value_type;
using value_01_type = typename rectangle_01_type::point_type::value_type;
using value_02_type = typename rectangle_02_type::point_type::value_type;
using value_03_type = typename rectangle_03_type::point_type::value_type;

using point_tuple_type = std::tuple<point_00_type, point_01_type, point_02_type, point_03_type>;
using value_tuple_type = std::tuple<value_00_type, value_01_type, value_02_type, value_03_type>;

static constexpr int screen_coordinate_x = static_cast<int>(ScreenCoordinateX); // Screen coordinate X
static constexpr int screen_coordinate_y = static_cast<int>(ScreenCoordinateY); // Screen coordinate Y
Expand All @@ -74,12 +83,6 @@
static constexpr int window_height = static_cast<int>(client_height + 42); // Total window height

public:
using point_00_type = typename rectangle_00_type::point_type;
using point_01_type = typename rectangle_01_type::point_type;
using point_02_type = typename rectangle_02_type::point_type;
using point_03_type = typename rectangle_03_type::point_type;
using rectangle_tuple_ref_type = std::reference_wrapper<rectangle_tuple_type>;

mandelbrot_discovery() = default;

mandelbrot_discovery(const mandelbrot_discovery&) = delete;
Expand Down Expand Up @@ -196,7 +199,7 @@
{
static_cast<::UINT>
(
(screen_coordinate_x + client_width) + static_cast<int>(INT8_C(24))
(screen_coordinate_x + client_width) + static_cast<int>(INT8_C(24))
)
};

Expand Down Expand Up @@ -275,10 +278,6 @@
::HWND my_handle_to_window { nullptr };
::HINSTANCE my_handle_to_instance { nullptr };

static point_00_type my_rectangle_center_00;
static point_01_type my_rectangle_center_01;
static point_02_type my_rectangle_center_02;
static point_03_type my_rectangle_center_03;
static rectangle_tuple_ref_type my_ref_to_rectangle_tuple;

static std::thread my_thread;
Expand All @@ -292,7 +291,7 @@
static std::uint_fast32_t my_mandelbrot_iterations;

static constexpr auto window_title() noexcept -> const char* { return WindowTitle; }
static constexpr auto icon_id() noexcept -> int { return IconId; }
static constexpr auto icon_id () noexcept -> int { return IconId; }

auto get_handle_to_instance() const noexcept -> const ::HINSTANCE { return my_handle_to_instance; }

Expand Down Expand Up @@ -497,6 +496,18 @@
mandelbrot_iterate_engine_worker(gen_03);
}

template<const int TupleIndex>
static auto write_coords() -> bool
{
bool result_write_coords_is_ok { true };

result_write_coords_is_ok = (write_number("x_val : ", std::get<0x00>(my_ref_to_rectangle_tuple.get()).center().get_x()) && result_write_coords_is_ok);
result_write_coords_is_ok = (write_number("y_val : ", std::get<0x00>(my_ref_to_rectangle_tuple.get()).center().get_y()) && result_write_coords_is_ok);
result_write_coords_is_ok = (write_number("dx_half: ", std::get<0x00>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_write_coords_is_ok);

return result_write_coords_is_ok;
}

static auto CALLBACK my_window_callback(::HWND handle_to_window,
::UINT message,
::WPARAM w_param,
Expand Down Expand Up @@ -589,40 +600,19 @@

bool result_is_ok { true };

result_is_ok = { std::get<0x00>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, my_rectangle_center_00) && result_is_ok };
result_is_ok = { std::get<0x01>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, my_rectangle_center_01) && result_is_ok };
result_is_ok = { std::get<0x02>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, my_rectangle_center_02) && result_is_ok };
result_is_ok = { std::get<0x03>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, my_rectangle_center_03) && result_is_ok };
result_is_ok = { std::get<0x00>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, std::get<0x00>(my_ref_to_rectangle_tuple.get()).center()) && result_is_ok };
result_is_ok = { std::get<0x01>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, std::get<0x01>(my_ref_to_rectangle_tuple.get()).center()) && result_is_ok };
result_is_ok = { std::get<0x02>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, std::get<0x02>(my_ref_to_rectangle_tuple.get()).center()) && result_is_ok };
result_is_ok = { std::get<0x03>(my_ref_to_rectangle_tuple.get()).pixel_to_point(pixel_x, pixel_y, std::get<0x03>(my_ref_to_rectangle_tuple.get()).center()) && result_is_ok };

if(result_is_ok)
{
switch(rectangle_tuple_index())
{
case 0x00:
result_is_ok = (write_number("x_val : ", my_rectangle_center_00.get_x()) && result_is_ok);
result_is_ok = (write_number("y_val : ", my_rectangle_center_00.get_y()) && result_is_ok);
result_is_ok = (write_number("dx_half: ", std::get<0x00>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_is_ok);
break;

case 0x01:
result_is_ok = (write_number("x_val : ", my_rectangle_center_01.get_x()) && result_is_ok);
result_is_ok = (write_number("y_val : ", my_rectangle_center_01.get_y()) && result_is_ok);
result_is_ok = (write_number("dx_half: ", std::get<0x01>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_is_ok);
break;

case 0x02:
result_is_ok = (write_number("x_val : ", my_rectangle_center_02.get_x()) && result_is_ok);
result_is_ok = (write_number("y_val : ", my_rectangle_center_02.get_y()) && result_is_ok);
result_is_ok = (write_number("dx_half: ", std::get<0x02>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_is_ok);
break;

case 0x03:
default:
result_is_ok = (write_number("x_val : ", my_rectangle_center_03.get_x()) && result_is_ok);
result_is_ok = (write_number("y_val : ", my_rectangle_center_03.get_y()) && result_is_ok);
result_is_ok = (write_number("dx_half: ", std::get<0x03>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_is_ok);
break;
}
const int tuple_index { rectangle_tuple_index() };

if (tuple_index == 0) { result_is_ok = (write_coords<0x00>() && result_is_ok); }
else if(tuple_index == 1) { result_is_ok = (write_coords<0x01>() && result_is_ok); }
else if(tuple_index == 2) { result_is_ok = (write_coords<0x02>() && result_is_ok); }
else { result_is_ok = (write_coords<0x03>() && result_is_ok); }

result_is_ok = (write_string("\n") && result_is_ok);
}
Expand Down Expand Up @@ -740,10 +730,10 @@
my_mandelbrot_zoom_factor_02 *= 10;
my_mandelbrot_zoom_factor_03 *= 10;

std::get<0x00>(my_ref_to_rectangle_tuple.get()).recenter(my_rectangle_center_00);
std::get<0x01>(my_ref_to_rectangle_tuple.get()).recenter(my_rectangle_center_01);
std::get<0x02>(my_ref_to_rectangle_tuple.get()).recenter(my_rectangle_center_02);
std::get<0x03>(my_ref_to_rectangle_tuple.get()).recenter(my_rectangle_center_03);
std::get<0x00>(my_ref_to_rectangle_tuple.get()).recenter(std::get<0x00>(my_ref_to_rectangle_tuple.get()).center());
std::get<0x01>(my_ref_to_rectangle_tuple.get()).recenter(std::get<0x01>(my_ref_to_rectangle_tuple.get()).center());
std::get<0x02>(my_ref_to_rectangle_tuple.get()).recenter(std::get<0x02>(my_ref_to_rectangle_tuple.get()).center());
std::get<0x03>(my_ref_to_rectangle_tuple.get()).recenter(std::get<0x03>(my_ref_to_rectangle_tuple.get()).center());

// Set the flag to redraw the client window with the new JPEG.
// The redrawing will occur below.
Expand Down Expand Up @@ -1137,42 +1127,6 @@
const int ScreenCoordinateY>
std::atomic<bool> mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::my_thread_wait_for_new_set_click;

template<const int WindowWidth,
const int WindowHeight,
typename MandelbrotRectangleTupleType,
const char* WindowTitle,
const int IconId,
const int ScreenCoordinateX,
const int ScreenCoordinateY>
typename mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::point_00_type mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::my_rectangle_center_00 { };

template<const int WindowWidth,
const int WindowHeight,
typename MandelbrotRectangleTupleType,
const char* WindowTitle,
const int IconId,
const int ScreenCoordinateX,
const int ScreenCoordinateY>
typename mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::point_01_type mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::my_rectangle_center_01 { };

template<const int WindowWidth,
const int WindowHeight,
typename MandelbrotRectangleTupleType,
const char* WindowTitle,
const int IconId,
const int ScreenCoordinateX,
const int ScreenCoordinateY>
typename mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::point_02_type mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::my_rectangle_center_02 { };

template<const int WindowWidth,
const int WindowHeight,
typename MandelbrotRectangleTupleType,
const char* WindowTitle,
const int IconId,
const int ScreenCoordinateX,
const int ScreenCoordinateY>
typename mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::point_03_type mandelbrot_discovery<WindowWidth, WindowHeight, MandelbrotRectangleTupleType, WindowTitle, IconId, ScreenCoordinateX, ScreenCoordinateY>::my_rectangle_center_03 { };

template<const int WindowWidth,
const int WindowHeight,
typename MandelbrotRectangleTupleType,
Expand Down
8 changes: 4 additions & 4 deletions MandelbrotDiscovery/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ The result of this dive ended up being:

![](https://github.com/ckormanyos/mandelbrot/blob/main/images/discovery/mandelbrot_discovery_dive_example.jpg)

## Additional Program Dynamic Behavior

The following features (and probably a few more) are TODO both in docs as well as in the program.

### Changing the Resolution

This feature is TODO both in docs as well as in the program.

### Saving and Restoring Previous Work

These features are TODO both in docs as well as in the program.

## Program Defaults and Dynamic Behavior

This feature is TODO both in docs as well as in the program.
1 change: 0 additions & 1 deletion mandelbrot/mandelbrot_generator_perturbative.h
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,6 @@
my_coord_pnt_numeric_type zr2 { static_cast<my_coord_pnt_numeric_type>(UINT8_C(0)) };
my_coord_pnt_numeric_type zi2 { static_cast<my_coord_pnt_numeric_type>(UINT8_C(0)) };


auto iteration_result = static_cast<std::uint_fast32_t>(UINT8_C(0));

while ((iteration_result < base_class_type::get_iterations()) && ((zr2 + zi2) < base_class_type::four_coord_pnt())) // NOLINT(altera-id-dependent-backward-branch)
Expand Down

0 comments on commit 81de30f

Please sign in to comment.