From 413f603dcc166d2dd37d2de4f9a6a875b249bdc6 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 7 Sep 2024 17:41:51 +0200 Subject: [PATCH] Add another iteration config to Discovery --- MandelbrotDiscovery/mandelbrot_discovery.cpp | 36 +++- MandelbrotDiscovery/mandelbrot_discovery.h | 166 ++++++++++++++----- MandelbrotDiscovery/utility.h | 28 +--- 3 files changed, 156 insertions(+), 74 deletions(-) diff --git a/MandelbrotDiscovery/mandelbrot_discovery.cpp b/MandelbrotDiscovery/mandelbrot_discovery.cpp index 6b2191a..dd27697 100644 --- a/MandelbrotDiscovery/mandelbrot_discovery.cpp +++ b/MandelbrotDiscovery/mandelbrot_discovery.cpp @@ -45,23 +45,27 @@ template auto center_y() -> typename local::cfg_type using rectangle_from_digits_type = geometry::rectangle_type::mandelbrot_coord_pnt_type>>; -constexpr inline auto default_00_digits10() -> unsigned { return unsigned { UINT32_C( 44) }; } // For magnification <= 20 -constexpr inline auto default_01_digits10() -> unsigned { return unsigned { UINT32_C(104) }; } // For magnification <= 80 -constexpr inline auto default_02_digits10() -> unsigned { return unsigned { UINT32_C(536) }; } // For magnification <= 512 +constexpr inline auto default_00_digits10() -> unsigned { return unsigned { UINT32_C( 44) }; } // For magnification <= 20 +constexpr inline auto default_01_digits10() -> unsigned { return unsigned { UINT32_C( 64) }; } // For magnification <= 40 +constexpr inline auto default_02_digits10() -> unsigned { return unsigned { UINT32_C( 104) }; } // For magnification <= 80 +constexpr inline auto default_03_digits10() -> unsigned { return unsigned { UINT32_C(1560) }; } // For magnification <= 1536 (which we consider unlimited) using rectangle_00_type = rectangle_from_digits_type; using rectangle_01_type = rectangle_from_digits_type; using rectangle_02_type = rectangle_from_digits_type; +using rectangle_03_type = rectangle_from_digits_type; -using rectangle_tuple_type = std::tuple; +using rectangle_tuple_type = std::tuple; -using rectangle_ref_00_type = typename std::tuple_element<0, rectangle_tuple_type>::type; -using rectangle_ref_01_type = typename std::tuple_element<1, rectangle_tuple_type>::type; -using rectangle_ref_02_type = typename std::tuple_element<2, rectangle_tuple_type>::type; +using rectangle_ref_00_type = typename std::tuple_element<0x00, rectangle_tuple_type>::type; +using rectangle_ref_01_type = typename std::tuple_element<0x01, rectangle_tuple_type>::type; +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 local_window_type = mandelbrot_discovery(INT16_C(800)), static_cast(INT16_C(800)), @@ -117,9 +121,25 @@ auto rectangle_02() -> rectangle_02_type& return my_rect; } +auto rectangle_03() -> rectangle_03_type& +{ + static rectangle_03_type my_rect + { + point_03_type { center_x(), center_y() }, + dx_half(), + dy_half() + }; + + static const bool result_pixel_assoc_is_ok { my_rect.set_pixel_assoc(768, 768) }; + + static_cast(result_pixel_assoc_is_ok); + + return my_rect; +} + auto WINAPI WinMain(_In_ ::HINSTANCE h_wnd, _In_opt_ ::HINSTANCE, _In_ LPSTR, _In_ int) -> int { - rectangle_tuple_type rectangle_tuple(rectangle_00(), rectangle_01(), rectangle_02()); + rectangle_tuple_type rectangle_tuple(rectangle_00(), rectangle_01(), rectangle_02(), rectangle_03()); local_window_type::set_rectangle_tuple(rectangle_tuple); diff --git a/MandelbrotDiscovery/mandelbrot_discovery.h b/MandelbrotDiscovery/mandelbrot_discovery.h index 626f0f5..4b1de2d 100644 --- a/MandelbrotDiscovery/mandelbrot_discovery.h +++ b/MandelbrotDiscovery/mandelbrot_discovery.h @@ -29,14 +29,12 @@ #include #include #include - #include #include #include #include #include #include #include - #include namespace mandelbrot_discovery_detail { @@ -54,14 +52,17 @@ { public: 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_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; static constexpr int screen_coordinate_x = static_cast(ScreenCoordinateX); // Screen coordinate X static constexpr int screen_coordinate_y = static_cast(ScreenCoordinateY); // Screen coordinate Y @@ -76,6 +77,7 @@ 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; @@ -276,6 +278,7 @@ 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; @@ -285,6 +288,7 @@ static value_00_type my_mandelbrot_zoom_factor_00; static value_01_type my_mandelbrot_zoom_factor_01; static value_02_type my_mandelbrot_zoom_factor_02; + static value_03_type my_mandelbrot_zoom_factor_03; static std::uint_fast32_t my_mandelbrot_iterations; static constexpr auto window_title() noexcept -> const char* { return WindowTitle; } @@ -311,13 +315,19 @@ return my_thread_wait_for_new_set_click.load(); } - static auto zoom_factor_p10() -> int { return ilogb(my_mandelbrot_zoom_factor_02); }; + static auto zoom_factor_p10() -> int { using std::ilogb; return ilogb(my_mandelbrot_zoom_factor_03); }; static auto rectangle_tuple_index() -> int { const int zoom { zoom_factor_p10() }; - return ((zoom <= 20) ? 0 : (zoom <= 80) ? 1 : 2); + return + { + (zoom <= 20) ? 0 : + (zoom <= 40) ? 1 : + (zoom <= 80) ? 2 : + 3 + }; }; template @@ -374,7 +384,7 @@ static_cast(MANDELBROT_CALCULATION_PIXELS_X), static_cast(MANDELBROT_CALCULATION_PIXELS_Y)>; - const rectangle_00_type& local_rectangle_00_ref { std::get<0>(my_ref_to_rectangle_tuple.get()) }; + const rectangle_00_type& local_rectangle_00_ref { std::get<0x00>(my_ref_to_rectangle_tuple.get()) }; local_mandelbrot_config_00_type mandelbrot_config_object_00 @@ -405,7 +415,7 @@ static_cast(MANDELBROT_CALCULATION_PIXELS_X), static_cast(MANDELBROT_CALCULATION_PIXELS_Y)>; - const rectangle_01_type& local_rectangle_01_ref { std::get<1>(my_ref_to_rectangle_tuple.get()) }; + const rectangle_01_type& local_rectangle_01_ref { std::get<0x01>(my_ref_to_rectangle_tuple.get()) }; local_mandelbrot_config_01_type mandelbrot_config_object_01 @@ -428,10 +438,7 @@ constexpr auto MANDELBROT_CALCULATION_PIXELS_Y = static_cast(768); using mandelbrot_generator_02_type = - ckormanyos::mandelbrot::mandelbrot_generator_perturbative; - - ckormanyos::mandelbrot::color::color_stretch_histogram_method local_color_stretches; - const ckormanyos::mandelbrot::color::color_functions_bw local_color_functions; + ckormanyos::mandelbrot::mandelbrot_generator_trivial; using local_mandelbrot_config_02_type = ckormanyos::mandelbrot::mandelbrot_config(MANDELBROT_CALCULATION_PIXELS_X), static_cast(MANDELBROT_CALCULATION_PIXELS_Y)>; - const rectangle_02_type& local_rectangle_02_ref { std::get<2>(my_ref_to_rectangle_tuple.get()) }; + const rectangle_02_type& local_rectangle_02_ref { std::get<0x02>(my_ref_to_rectangle_tuple.get()) }; local_mandelbrot_config_02_type mandelbrot_config_object_02 @@ -456,6 +463,40 @@ mandelbrot_iterate_engine_worker(gen_02); } + static auto mandelbrot_iterate_engine_03() -> void + { + constexpr auto MANDELBROT_CALCULATION_PIXELS_X = static_cast(768); + constexpr auto MANDELBROT_CALCULATION_PIXELS_Y = static_cast(768); + + using mandelbrot_generator_03_type = + ckormanyos::mandelbrot::mandelbrot_generator_perturbative; + + ckormanyos::mandelbrot::color::color_stretch_histogram_method local_color_stretches; + const ckormanyos::mandelbrot::color::color_functions_bw local_color_functions; + + using local_mandelbrot_config_03_type = + ckormanyos::mandelbrot::mandelbrot_config(MANDELBROT_CALCULATION_PIXELS_X), + static_cast(MANDELBROT_CALCULATION_PIXELS_Y)>; + + const rectangle_03_type& local_rectangle_03_ref { std::get<0x03>(my_ref_to_rectangle_tuple.get()) }; + + local_mandelbrot_config_03_type + mandelbrot_config_object_03 + ( + local_rectangle_03_ref.center().get_x() - local_rectangle_03_ref.dx_half(), + local_rectangle_03_ref.center().get_x() + local_rectangle_03_ref.dx_half(), + local_rectangle_03_ref.center().get_y() - local_rectangle_03_ref.dy_half(), + local_rectangle_03_ref.center().get_y() + local_rectangle_03_ref.dy_half(), + my_mandelbrot_iterations + ); + + mandelbrot_generator_03_type gen_03 { mandelbrot_config_object_03 }; + + mandelbrot_iterate_engine_worker(gen_03); + } + static auto CALLBACK my_window_callback(::HWND handle_to_window, ::UINT message, ::WPARAM w_param, @@ -548,36 +589,42 @@ bool result_is_ok { true }; - result_is_ok = { std::get<0>(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<1>(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<2>(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<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 }; if(result_is_ok) { switch(rectangle_tuple_index()) { - case 0: - 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<0>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_is_ok); - result_is_ok = (write_string("\n") && result_is_ok); + 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 1: - 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<1>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_is_ok); - result_is_ok = (write_string("\n") && result_is_ok); + 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 2: + 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_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<2>(my_ref_to_rectangle_tuple.get()).dx_half(), 3) && result_is_ok); - result_is_ok = (write_string("\n") && result_is_ok); + 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; } + + result_is_ok = (write_string("\n") && result_is_ok); } const auto lresult = @@ -691,10 +738,12 @@ my_mandelbrot_zoom_factor_00 *= 10; my_mandelbrot_zoom_factor_01 *= 10; my_mandelbrot_zoom_factor_02 *= 10; + my_mandelbrot_zoom_factor_03 *= 10; - std::get<0>(my_ref_to_rectangle_tuple.get()).recenter(my_rectangle_center_00); - std::get<1>(my_ref_to_rectangle_tuple.get()).recenter(my_rectangle_center_01); - std::get<2>(my_ref_to_rectangle_tuple.get()).recenter(my_rectangle_center_02); + 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); // Set the flag to redraw the client window with the new JPEG. // The redrawing will occur below. @@ -716,6 +765,7 @@ my_mandelbrot_zoom_factor_00 /= 10; my_mandelbrot_zoom_factor_01 /= 10; my_mandelbrot_zoom_factor_02 /= 10; + my_mandelbrot_zoom_factor_03 /= 10; // Set the flag to redraw the client window with the new JPEG. // The redrawing will occur below. @@ -751,9 +801,10 @@ const int local_rectangle_tuple_index { rectangle_tuple_index() }; - if (local_rectangle_tuple_index == 0) { mandelbrot_iterate_engine_00(); } - else if(local_rectangle_tuple_index == 1) { mandelbrot_iterate_engine_01(); } - else { mandelbrot_iterate_engine_02(); } + if (local_rectangle_tuple_index == 0x00) { mandelbrot_iterate_engine_00(); } + else if(local_rectangle_tuple_index == 0x01) { mandelbrot_iterate_engine_01(); } + else if(local_rectangle_tuple_index == 0x02) { mandelbrot_iterate_engine_02(); } + else { mandelbrot_iterate_engine_03(); } // Redraw the client window with the new JPEG. using local_window_type = mandelbrot_discovery; @@ -984,7 +1035,26 @@ value_02_type { "+1.35" } }; - static rectangle_tuple_type my_default_rectangle_tuple(my_default_rect_00, my_default_rect_01, my_default_rect_02); + static rectangle_03_type + my_default_rect_03 + { + point_03_type + { + value_03_type { "-0.75" }, + value_03_type { "+0.00" } + }, + value_03_type { "+1.35" }, + value_03_type { "+1.35" } + }; + + static rectangle_tuple_type + my_default_rectangle_tuple + { + my_default_rect_00, + my_default_rect_01, + my_default_rect_02, + my_default_rect_03 + }; return my_default_rectangle_tuple; } @@ -1094,6 +1164,15 @@ const int ScreenCoordinateY> 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 typename mandelbrot_discovery::value_02_type mandelbrot_discovery::my_mandelbrot_zoom_factor_02 { 1 }; + template + typename mandelbrot_discovery::value_03_type mandelbrot_discovery::my_mandelbrot_zoom_factor_03 { 1 }; + template + typename input_iterator2> constexpr auto equal(input_iterator1 first1, input_iterator1 last1, input_iterator2 first2) -> bool { while((first1 != last1) && (*first1 == *first2)) @@ -83,32 +83,6 @@ for_each_in_tuple(tuple_pack, std::forward(func)); } } - - #if 0 - // Use-case example: - auto main() -> int - { - // Create a tuple of different class instances - std::tuple t { A { }, B { }, C { } }; - - // The parameter to pass to the method. - int param = 10; - - static_cast(index); - - // Call `some_method` with parameter `param` on each element of the tuple. - for_each_in_tuple - ( - t, - [param](auto& obj) - { - // Call the method with the parameter. - obj.operator*=(param); - } - ); - } - #endif - } // namespace util::caller #endif // UTILITY_2024_04_14_H