From 881131898efa9ec8d07886c1e43a2339f8446d21 Mon Sep 17 00:00:00 2001 From: ckormanyos Date: Sat, 7 Sep 2024 10:24:34 +0200 Subject: [PATCH] Discovery start stronger template-rectangle basis --- .../MandelbrotDiscovery.vcxproj | 1 + .../MandelbrotDiscovery.vcxproj.filters | 3 + MandelbrotDiscovery/mandelbrot_discovery.cpp | 66 +++++++------- MandelbrotDiscovery/mandelbrot_discovery.h | 90 +++++++++---------- .../mandelbrot_discovery_type.h | 31 +++++++ MandelbrotDiscovery/utility.h | 80 ++++++++--------- 6 files changed, 148 insertions(+), 123 deletions(-) create mode 100644 MandelbrotDiscovery/mandelbrot_discovery_type.h diff --git a/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj b/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj index 3a6a2df..3f0f324 100644 --- a/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj +++ b/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj @@ -99,6 +99,7 @@ + diff --git a/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj.filters b/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj.filters index 52d7cba..9409048 100644 --- a/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj.filters +++ b/MandelbrotDiscovery/MandelbrotDiscovery.vcxproj.filters @@ -54,6 +54,9 @@ MandelbrotDiscovery + + MandelbrotDiscovery + diff --git a/MandelbrotDiscovery/mandelbrot_discovery.cpp b/MandelbrotDiscovery/mandelbrot_discovery.cpp index 8f2e553..439f3f8 100644 --- a/MandelbrotDiscovery/mandelbrot_discovery.cpp +++ b/MandelbrotDiscovery/mandelbrot_discovery.cpp @@ -6,57 +6,61 @@ // #include +#include #include #include -#include - -namespace local::cfg +namespace local { - constexpr int MANDELBROT_COORD_PNT_DIGITS10 = 132; - constexpr int MANDELBROT_ITERATION_DIGITS10 = 132; - constexpr int MANDELBROT_CALCULATION_PIXELS_X = 768; - constexpr int MANDELBROT_CALCULATION_PIXELS_Y = 768; + template + struct cfg_type + { + static constexpr auto my_digits10() noexcept -> unsigned { return Digits10; } + + using mandelbrot_coord_pnt_type = boost::multiprecision::number, boost::multiprecision::et_off>; + using mandelbrot_iteration_type = boost::multiprecision::number, boost::multiprecision::et_off>; + }; + + static constexpr char str_mandelbrot_point_dx_half [] = "+1.35"; + static constexpr char str_mandelbrot_point_dy_half [] = "+1.35"; + static constexpr char str_mandelbrot_point_center_x[] = "-0.75"; + static constexpr char str_mandelbrot_point_center_y[] = "+0.00"; +} // namespace local - constexpr char MANDELBROT_POINT_DX_HALF[] = "1.35"; - constexpr char MANDELBROT_POINT_DY_HALF[] = "1.35"; - constexpr char MANDELBROT_POINT_CENTER_X[] = "-0.75"; - constexpr char MANDELBROT_POINT_CENTER_Y[] = "+0.00"; -} // namespace local::cfg +//static_assert(local::mandelbrot_calculation_pixels_x == local::mandelbrot_calculation_pixels_y, +// "Error: This program is only compilable for square geometry"); -static_assert(local::cfg::MANDELBROT_CALCULATION_PIXELS_X == local::cfg::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"); -static_assert(util::utility::equal(local::cfg::MANDELBROT_POINT_DX_HALF, - local::cfg::MANDELBROT_POINT_DX_HALF + sizeof(local::cfg::MANDELBROT_POINT_DX_HALF), - local::cfg::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 }; } +template auto center_y() -> 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_y }; } -using mandelbrot_coord_pnt_type = boost::multiprecision::number, boost::multiprecision::et_off>; -using mandelbrot_iteration_type = boost::multiprecision::number, boost::multiprecision::et_off>; +template +using rectangle_from_digits_type = geometry::rectangle_type::mandelbrot_coord_pnt_type>>; -inline auto dx_half() -> mandelbrot_coord_pnt_type { return mandelbrot_coord_pnt_type(local::cfg::MANDELBROT_POINT_DX_HALF); } -inline auto dy_half() -> mandelbrot_coord_pnt_type { return mandelbrot_coord_pnt_type(local::cfg::MANDELBROT_POINT_DY_HALF); } -inline auto center_x() -> mandelbrot_coord_pnt_type { return mandelbrot_coord_pnt_type(local::cfg::MANDELBROT_POINT_CENTER_X); } -inline auto center_y() -> mandelbrot_coord_pnt_type { return mandelbrot_coord_pnt_type(local::cfg::MANDELBROT_POINT_CENTER_Y); } +constexpr inline auto default_digits10() -> unsigned { return 132U; } using local_window_type = mandelbrot_discovery(INT16_C(800)), static_cast(INT16_C(800)), - mandelbrot_coord_pnt_type, - mandelbrot_iteration_type, + rectangle_from_digits_type, mandelbrot_discovery_detail::WindowTitleDefault, IDI_MANDELBROT_DISCO>; -using point_type = typename local_window_type::point_type; -using rectangle_type = typename local_window_type::rectangle_type; +using rectangle_type = rectangle_from_digits_type; +using point_type = typename rectangle_type::point_type; auto rectangle() -> rectangle_type& { static rectangle_type my_rect { - point_type { center_x(), center_y() }, - dx_half(), - dy_half() + point_type { center_x(), center_y() }, + dx_half(), + dy_half() }; static const bool result_pixel_assoc_is_ok { my_rect.set_pixel_assoc(768, 768) }; diff --git a/MandelbrotDiscovery/mandelbrot_discovery.h b/MandelbrotDiscovery/mandelbrot_discovery.h index a12f6c1..ee2e372 100644 --- a/MandelbrotDiscovery/mandelbrot_discovery.h +++ b/MandelbrotDiscovery/mandelbrot_discovery.h @@ -8,9 +8,11 @@ #ifndef MANDELBROT_DISCOVERY_2024_04_12_H #define MANDELBROT_DISCOVERY_2024_04_12_H + #if (defined(_MSC_VER) && (_MSC_VER < 1930)) #if !defined(NOMINMAX) #define NOMINMAX #endif + #endif #include #include @@ -41,17 +43,19 @@ template(INT8_C(0)), const int ScreenCoordinateX = static_cast(UINT16_C(32)), const int ScreenCoordinateY = static_cast(UINT16_C(8))> class mandelbrot_discovery final { + public: + using rectangle_type = MandelbrotRectangleType; + private: - using my_coord_pnt_numeric_type = MandelbrotCoordPntType; - using my_iteration_numeric_type = MandelbrotIterationType; + using my_coord_pnt_numeric_type = typename rectangle_type::point_type::value_type; + using my_iteration_numeric_type = my_coord_pnt_numeric_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 @@ -63,7 +67,6 @@ static constexpr int window_height = static_cast(client_height + 42); // Total window height public: - using rectangle_type = geometry::rectangle_type>; using point_type = typename rectangle_type::point_type; using rectangle_ref_type = std::reference_wrapper; @@ -147,8 +150,8 @@ const bool create_window_result { - create_window_is_ok - && (handle_to_active_window != nullptr) + create_window_is_ok + && (handle_to_active_window != nullptr) && (my_handle_to_window == handle_to_active_window) }; @@ -181,9 +184,9 @@ constexpr ::UINT pos_x { - static_cast<::UINT> - ( - (screen_coordinate_x + client_width) + static_cast(INT8_C(24)) + static_cast<::UINT> + ( + (screen_coordinate_x + client_width) + static_cast(INT8_C(24)) ) }; @@ -231,7 +234,7 @@ if(get_message_is_ok) { - // Process Win32 API messages (via standard Windows message pump). + // Process all incoming Win32 API messages (via standard Windows message pump). const bool translate_message_is_ok { ::TranslateMessage(&message) == TRUE }; const bool dispatch_message_is_ok { ::DispatchMessage (&message) == TRUE }; @@ -389,6 +392,7 @@ SelectObject(hdcMem, hBitmap); ::BITMAP bitmap { }; + static_cast(::GetObject(hBitmap, static_cast(sizeof(bitmap)), &bitmap)); const auto result_stretch = @@ -712,7 +716,7 @@ char* input_buffer = new char[input_buffer_size]; - DWORD bytes_read { }; + ::DWORD bytes_read { }; const auto result_read = ::ReadConsole(console_input(), input_buffer, input_buffer_size, &bytes_read, nullptr); @@ -754,7 +758,7 @@ static auto write_string(const std::string& str_to_write) -> bool { - DWORD bytes_written { }; + ::DWORD bytes_written { }; const auto result_write = ::WriteConsole @@ -793,13 +797,12 @@ template - auto mandelbrot_discovery::default_rectangle() noexcept -> typename mandelbrot_discovery::rectangle_type& + auto mandelbrot_discovery::default_rectangle() noexcept -> typename mandelbrot_discovery::rectangle_type& { using local_value_type = typename point_type::value_type; @@ -820,13 +823,12 @@ template - auto mandelbrot_discovery::console_input() -> HANDLE& + auto mandelbrot_discovery::console_input() -> HANDLE& { static ::HANDLE my_handle { }; @@ -835,13 +837,12 @@ template - auto mandelbrot_discovery::console_output() -> HANDLE& + auto mandelbrot_discovery::console_output() -> HANDLE& { static ::HANDLE my_handle { }; @@ -850,13 +851,12 @@ template - auto mandelbrot_discovery::console_sync_mtx() -> std::mutex& + auto mandelbrot_discovery::console_sync_mtx() -> std::mutex& { static std::mutex my_mtx { }; @@ -865,82 +865,74 @@ template - std::thread mandelbrot_discovery::my_thread; + std::thread mandelbrot_discovery::my_thread; template - std::atomic mandelbrot_discovery::my_thread_wants_exit { false }; + std::atomic mandelbrot_discovery::my_thread_wants_exit { false }; template - std::atomic mandelbrot_discovery::my_thread_did_exit { false }; + std::atomic mandelbrot_discovery::my_thread_did_exit { false }; template - std::atomic mandelbrot_discovery::my_thread_wait_for_new_set_click; + std::atomic mandelbrot_discovery::my_thread_wait_for_new_set_click; template - typename mandelbrot_discovery::point_type mandelbrot_discovery::my_rectangle_center { }; + typename mandelbrot_discovery::point_type mandelbrot_discovery::my_rectangle_center { }; template - typename mandelbrot_discovery::rectangle_ref_type mandelbrot_discovery::my_ref_to_rectangle { default_rectangle() }; + typename mandelbrot_discovery::rectangle_ref_type mandelbrot_discovery::my_ref_to_rectangle { default_rectangle() }; template - typename mandelbrot_discovery::my_coord_pnt_numeric_type mandelbrot_discovery::my_mandelbrot_zoom_factor { 1 }; + typename mandelbrot_discovery::my_coord_pnt_numeric_type mandelbrot_discovery::my_mandelbrot_zoom_factor { 1 }; template - std::uint_fast32_t mandelbrot_discovery::my_mandelbrot_iterations { static_cast(UINT32_C(400)) }; + std::uint_fast32_t mandelbrot_discovery::my_mandelbrot_iterations { static_cast(UINT32_C(400)) }; #endif // MANDELBROT_DISCOVERY_2024_04_12_H diff --git a/MandelbrotDiscovery/mandelbrot_discovery_type.h b/MandelbrotDiscovery/mandelbrot_discovery_type.h new file mode 100644 index 0000000..56a6353 --- /dev/null +++ b/MandelbrotDiscovery/mandelbrot_discovery_type.h @@ -0,0 +1,31 @@ +/////////////////////////////////////////////////////////////////////////////// +// Copyright Christopher Kormanyos 2024. +// Distributed under the Boost Software License, +// Version 1.0. (See accompanying file LICENSE_1_0.txt +// or copy at http://www.boost.org/LICENSE_1_0.txt) +// + +#ifndef MANDELBROT_DISCOVERY_TYPE_2024_09_02_H + #define MANDELBROT_DISCOVERY_TYPE_2024_09_02_H + + #include + + #include + #include + + #include + + #include + + template + struct mandelbrot_discovery_type + { + // TBD: Use conditionals based on Digits10. + using mandelbrot_coord_pnt_type = boost::multiprecision::number, boost::multiprecision::et_off>; + using mandelbrot_iteration_type = boost::multiprecision::number, boost::multiprecision::et_off>; + + using rectangle_type = geometry::rectangle_type>; + using rectangle_point_type = typename rectangle_type::point_type; + }; + +#endif // MANDELBROT_DISCOVERY_TYPE_2024_09_02_H diff --git a/MandelbrotDiscovery/utility.h b/MandelbrotDiscovery/utility.h index fea5651..8f17b97 100644 --- a/MandelbrotDiscovery/utility.h +++ b/MandelbrotDiscovery/utility.h @@ -10,63 +10,57 @@ #include - #if(__cplusplus >= 201703L) - namespace util::utility { - #else - namespace util { namespace utility { // NOLINT(modernize-concat-nested-namespaces) - #endif + #include - template - constexpr auto equal(input_iterator1 first1, input_iterator1 last1, input_iterator2 first2) -> bool + namespace util::utility { - while((first1 != last1) && (*first1 == *first2)) + constexpr std::size_t strlen(const char* start) { - ++first1; - ++first2; + const char* end = start; + + while (*end != '\0') + { + ++end; + } + + return end - start; } - return { first1 == last1 }; - } + template + constexpr auto equal(input_iterator1 first1, input_iterator1 last1, input_iterator2 first2) -> bool + { + while((first1 != last1) && (*first1 == *first2)) + { + ++first1; + ++first2; + } - #if(__cplusplus >= 201703L) + return { first1 == last1 }; + } } // namespace util::utility - #else - } // namespace utility - } // namespace util - #endif - - #if(__cplusplus >= 201703L) - namespace util::text { - #else - namespace util { namespace text { // NOLINT(modernize-concat-nested-namespaces) - #endif - class text_output_alloc_console : public ckormanyos::mandelbrot::text_output_base // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) + namespace util::text { - public: - explicit text_output_alloc_console(callback_function_type cbk) : my_callback { cbk } { } - - text_output_alloc_console() = delete; + class text_output_alloc_console : public ckormanyos::mandelbrot::text_output_base // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) + { + public: + explicit text_output_alloc_console(callback_function_type cbk) : my_callback { cbk } { } - ~text_output_alloc_console() override = default; + text_output_alloc_console() = delete; - auto write(const std::string& str_to_write) -> bool override - { - my_callback(str_to_write); + ~text_output_alloc_console() override = default; - return true; - } + auto write(const std::string& str_to_write) -> bool override + { + my_callback(str_to_write); - private: - callback_function_type my_callback { nullptr }; - }; + return true; + } - #if(__cplusplus >= 201703L) + private: + callback_function_type my_callback { nullptr }; + }; } // namespace util::text - #else - } // namespace text - } // namespace util - #endif #endif // UTILITY_2024_04_14_H