From 81de30fb4b943735d1b34b0600b364a0ef6d0dc1 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 14 Sep 2024 15:59:51 +0200 Subject: [PATCH] Simplifying Discovery syntax --- MandelbrotDiscovery/geometry.h | 3 +- MandelbrotDiscovery/mandelbrot_discovery.cpp | 16 +- MandelbrotDiscovery/mandelbrot_discovery.h | 142 ++++++------------ MandelbrotDiscovery/readme.md | 8 +- .../mandelbrot_generator_perturbative.h | 1 - 5 files changed, 58 insertions(+), 112 deletions(-) diff --git a/MandelbrotDiscovery/geometry.h b/MandelbrotDiscovery/geometry.h index f73672d..dfc141a 100644 --- a/MandelbrotDiscovery/geometry.h +++ b/MandelbrotDiscovery/geometry.h @@ -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 { diff --git a/MandelbrotDiscovery/mandelbrot_discovery.cpp b/MandelbrotDiscovery/mandelbrot_discovery.cpp index dd27697..5ef83e0 100644 --- a/MandelbrotDiscovery/mandelbrot_discovery.cpp +++ b/MandelbrotDiscovery/mandelbrot_discovery.cpp @@ -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 auto dx_half () -> typename local::cfg_type::mandelbrot_coord_pnt_type { using local_coord_pnt_type = typename local::cfg_type::mandelbrot_coord_pnt_type; return local_coord_pnt_type { local::str_mandelbrot_point_dx_half }; } template auto dy_half () -> typename local::cfg_type::mandelbrot_coord_pnt_type { using local_coord_pnt_type = typename local::cfg_type::mandelbrot_coord_pnt_type; return local_coord_pnt_type { local::str_mandelbrot_point_dy_half }; } template auto center_x() -> typename local::cfg_type::mandelbrot_coord_pnt_type { using local_coord_pnt_type = typename local::cfg_type::mandelbrot_coord_pnt_type; return local_coord_pnt_type { local::str_mandelbrot_point_center_x }; } @@ -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(INT16_C(800)), static_cast(INT16_C(800)), diff --git a/MandelbrotDiscovery/mandelbrot_discovery.h b/MandelbrotDiscovery/mandelbrot_discovery.h index 4b1de2d..78fe69f 100644 --- a/MandelbrotDiscovery/mandelbrot_discovery.h +++ b/MandelbrotDiscovery/mandelbrot_discovery.h @@ -50,19 +50,28 @@ const int ScreenCoordinateY = static_cast(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::type>::type; - using rectangle_01_type = typename std::remove_reference::type>::type; - using rectangle_02_type = typename std::remove_reference::type>::type; - using rectangle_03_type = typename std::remove_reference::type>::type; + using rectangle_00_type = typename std::remove_reference::type>::type; + using rectangle_01_type = typename std::remove_reference::type>::type; + using rectangle_02_type = typename std::remove_reference::type>::type; + using rectangle_03_type = typename std::remove_reference::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; + + 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; + using value_tuple_type = std::tuple; static constexpr int screen_coordinate_x = static_cast(ScreenCoordinateX); // Screen coordinate X static constexpr int screen_coordinate_y = static_cast(ScreenCoordinateY); // Screen coordinate Y @@ -74,12 +83,6 @@ static constexpr int window_height = static_cast(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; - mandelbrot_discovery() = default; mandelbrot_discovery(const mandelbrot_discovery&) = delete; @@ -196,7 +199,7 @@ { static_cast<::UINT> ( - (screen_coordinate_x + client_width) + static_cast(INT8_C(24)) + (screen_coordinate_x + client_width) + static_cast(INT8_C(24)) ) }; @@ -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; @@ -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; } @@ -497,6 +496,18 @@ mandelbrot_iterate_engine_worker(gen_03); } + template + 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, @@ -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); } @@ -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. @@ -1137,42 +1127,6 @@ const int ScreenCoordinateY> std::atomic mandelbrot_discovery::my_thread_wait_for_new_set_click; - template - typename mandelbrot_discovery::point_00_type mandelbrot_discovery::my_rectangle_center_00 { }; - - template - typename mandelbrot_discovery::point_01_type mandelbrot_discovery::my_rectangle_center_01 { }; - - template - typename mandelbrot_discovery::point_02_type mandelbrot_discovery::my_rectangle_center_02 { }; - - template - typename mandelbrot_discovery::point_03_type mandelbrot_discovery::my_rectangle_center_03 { }; - template(UINT8_C(0)) }; my_coord_pnt_numeric_type zi2 { static_cast(UINT8_C(0)) }; - auto iteration_result = static_cast(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)