diff --git a/.idea/editor.xml b/.idea/editor.xml
index 3956cfa39..bde9249e6 100644
--- a/.idea/editor.xml
+++ b/.idea/editor.xml
@@ -19,7 +19,6 @@
-
@@ -116,8 +115,13 @@
+
-
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 494ec4521..7dd12dee6 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -8,9 +8,16 @@
+
+
+
+
+
+
+
-
+
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
index 4b3b22b08..148151638 100644
--- a/.idea/vcs.xml
+++ b/.idea/vcs.xml
@@ -9,6 +9,7 @@
+
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 21dd87a46..bce3af616 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -24,19 +24,21 @@ CMAKE_MINIMUM_REQUIRED(VERSION 3.20)
PROJECT(Steppable)
# Ensure that Python is available to run the development scripts, and build with bindings.
-set(Python_FIND_VIRTUALENV FIRST)
+SET(Python_FIND_VIRTUALENV FIRST)
-find_package(
-Python
-COMPONENTS Development Interpreter
-REQUIRED)
+FIND_PACKAGE(
+ Python
+ COMPONENTS Development Interpreter
+ REQUIRED
+)
-find_package(
-Python3
-COMPONENTS Development Interpreter
-REQUIRED)
+FIND_PACKAGE(
+ Python3
+ COMPONENTS Development Interpreter
+ REQUIRED
+)
-SET(CMAKE_CXX_STANDARD 20)
+SET(CMAKE_CXX_STANDARD 23)
SET(CMAKE_C_STANDARD 20)
SET(CMAKE_CXX_EXTENSIONS OFF)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
@@ -90,20 +92,23 @@ FUNCTION(capitalize IN OUT)
ENDFUNCTION()
SET(COMPONENTS
- abs
- add
- baseConvert
- subtract
- multiply
- decimalConvert
- comparison
- power
- division
- root
- factorial
- trig
- hyp
- log)
+ base::baseConvert
+ base::decimalConvert
+ calc::abs
+ calculus::nInt
+ calc::add
+ calc::atan2
+ calc::comparison
+ calc::division
+ calc::factorial
+ calc::hyp
+ calc::log
+ calc::multiply
+ calc::power
+ calc::root
+ calc::subtract
+ calc::trig
+)
# NEW_COMPONENT: PATCH Do NOT remove the previous comment.
SET(TARGETS ${COMPONENTS} util)
@@ -111,6 +116,12 @@ SET(TEST_TARGETS_TEMP util fraction number factors format ${COMPONENTS})
FOREACH(TEST_TARGET IN LISTS TEST_TARGETS_TEMP)
SET(TARGET_NAME "test")
+ STRING(REPLACE "::" ";" COMPONENT_PARTS ${TEST_TARGET})
+ LIST(LENGTH COMPONENT_PARTS LEN)
+ IF(LEN EQUAL 2)
+ LIST(GET COMPONENT_PARTS 1 TEST_TARGET)
+ ENDIF()
+
CAPITALIZE(${TEST_TARGET} FILE_NAME)
STRING(CONCAT TARGET_NAME ${TARGET_NAME} ${FILE_NAME})
LIST(APPEND TEST_TARGETS ${TARGET_NAME})
diff --git a/Steppable.sln b/Steppable.sln
index 818d01404..cdc2940e4 100644
--- a/Steppable.sln
+++ b/Steppable.sln
@@ -4,19 +4,19 @@ VisualStudioVersion = 17.11.35017.193
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "calc", "calc.vcxproj", "{0A900AAA-AC12-48CF-85CF-8BB0C0130512}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "add", "src\add\add.vcxproj", "{50F5EB82-9639-40D9-A6A1-62BE499E4528}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "add", "src\calc\add\add.vcxproj", "{50F5EB82-9639-40D9-A6A1-62BE499E4528}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "util", "util.vcxproj", "{F6AF63F8-9E0F-4DA2-89B3-3096B56BA251}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "subtract", "src\subtract\subtract.vcxproj", "{8F1DF35F-1D30-4703-8B94-B1A3753D60C4}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "subtract", "src\calc\subtract\subtract.vcxproj", "{8F1DF35F-1D30-4703-8B94-B1A3753D60C4}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "comparison", "src\comparison\comparison.vcxproj", "{7666B097-5666-4F12-863A-F7BAACFEDB4E}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "comparison", "src\calc\comparison\comparison.vcxproj", "{7666B097-5666-4F12-863A-F7BAACFEDB4E}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multiply", "src\multiply\multiply.vcxproj", "{D2D485AA-9E2E-4D6E-8D8A-0C82A6538BFA}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "multiply", "src\calc\multiply\multiply.vcxproj", "{D2D485AA-9E2E-4D6E-8D8A-0C82A6538BFA}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "division", "src\division\division.vcxproj", "{348481F3-C3A4-4D76-A801-54888CB569C4}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "division", "src\calc\division\division.vcxproj", "{348481F3-C3A4-4D76-A801-54888CB569C4}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "power", "src\power\power.vcxproj", "{0C2C224A-06F4-44F2-847F-B3870608F1EF}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "power", "src\calc\power\power.vcxproj", "{0C2C224A-06F4-44F2-847F-B3870608F1EF}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testAdd", "tests\testAdd.vcxproj", "{C11E7406-C105-44A5-91DD-71FD0ED96D2A}"
EndProject
@@ -51,7 +51,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
README.md = README.md
EndProjectSection
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "abs", "src\abs\abs.vcxproj", "{B0C1EC9C-06CC-47B2-9B93-CD046FC0EF34}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "abs", "src\calc\abs\abs.vcxproj", "{B0C1EC9C-06CC-47B2-9B93-CD046FC0EF34}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "base", "base.vcxproj", "{867A7B37-C961-4581-AE5B-067FD464CC7C}"
EndProject
@@ -67,15 +67,15 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testDecimalConvert", "tests
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "base Source", "base Source", "{254B33CA-1687-41C5-9060-FBF4EF09FECD}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "baseConvert", "src\baseConvert\baseConvert.vcxproj", "{00B3E92A-8C55-4D70-8A27-8F0AEBF5872D}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "baseConvert", "src\base\baseConvert\baseConvert.vcxproj", "{00B3E92A-8C55-4D70-8A27-8F0AEBF5872D}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "decimalConvert", "src\decimalConvert\decimalConvert.vcxproj", "{55A00CFD-37B4-4618-A8D3-445A05DA759A}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "decimalConvert", "src\base\decimalConvert\decimalConvert.vcxproj", "{55A00CFD-37B4-4618-A8D3-445A05DA759A}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "factorial", "src\factorial\factorial.vcxproj", "{C6B85BA3-8B2A-4778-BAB9-CF7BE46F12DB}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "factorial", "src\calc\factorial\factorial.vcxproj", "{C6B85BA3-8B2A-4778-BAB9-CF7BE46F12DB}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "root", "src\root\root.vcxproj", "{127594DF-529C-426F-AE9B-C46EC403CDBA}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "root", "src\calc\root\root.vcxproj", "{127594DF-529C-426F-AE9B-C46EC403CDBA}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "trig", "src\trig\trig.vcxproj", "{2B7A46CF-F3C3-4EAE-91EB-96B8DB2A2CD2}"
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "trig", "src\calc\trig\trig.vcxproj", "{2B7A46CF-F3C3-4EAE-91EB-96B8DB2A2CD2}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "testRoot", "tests\testRoot.vcxproj", "{09060239-6270-4BE5-BB4E-FDD22EA3C49D}"
EndProject
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt
index 986bd39ac..047c1e65a 100644
--- a/gui/CMakeLists.txt
+++ b/gui/CMakeLists.txt
@@ -9,7 +9,7 @@ FUNCTION(ADD_GUI SOURCE)
TARGET_INCLUDE_DIRECTORIES(${NAME} PRIVATE "${STP_BASE_DIRECTORY}/include/imgui")
# Link Steppable stuff
- TARGET_LINK_LIBRARIES(${NAME} PRIVATE calc util)
+ TARGET_LINK_LIBRARIES(${NAME} PRIVATE func impl)
TARGET_INCLUDE_DIRECTORIES(${NAME} PRIVATE ${STP_BASE_DIRECTORY}/include)
if(FREETYPE_FOUND)
@@ -24,5 +24,12 @@ IF (STP_BUILD_GUI EQUAL 1)
# Find and link SDL2 and OpenGL
FIND_PACKAGE(SDL2 REQUIRED)
FIND_PACKAGE(OpenGL REQUIRED)
+ ADD_LIBRARY(impl STATIC impl/gui.cpp impl/window.cpp)
+ TARGET_LINK_LIBRARIES(impl PRIVATE ${SDL2_LIBRARIES} ${OPENGL_LIBRARIES} imgui)
+ TARGET_INCLUDE_DIRECTORIES(impl PRIVATE
+ ${SDL2_INCLUDE_DIRS}
+ "${STP_BASE_DIRECTORY}/include/imgui"
+ "${STP_BASE_DIRECTORY}/include")
+
ADD_GUI(test.cpp)
ENDIF()
diff --git a/gui/impl/gui.cpp b/gui/impl/gui.cpp
new file mode 100644
index 000000000..a37db77ab
--- /dev/null
+++ b/gui/impl/gui.cpp
@@ -0,0 +1,163 @@
+#include "gui.hpp"
+
+#include "output.hpp"
+
+#ifdef MACOSX
+ #include
+#endif
+
+namespace steppable::gui::__internals
+{
+
+ bool isDarkModeEnabled()
+ {
+#ifdef MACOSX
+ bool isDarkMode = false;
+ CFPreferencesAppSynchronize(CFSTR("AppleInterfaceStyle"));
+ CFPropertyListRef value = CFPreferencesCopyAppValue(CFSTR("AppleInterfaceStyle"), kCFPreferencesAnyApplication);
+ if (value != nullptr)
+ {
+ const auto* interfaceStyle = static_cast(value);
+ if (CFStringCompare(interfaceStyle, CFSTR("Dark"), 0) == kCFCompareEqualTo)
+ isDarkMode = true;
+ CFRelease(value);
+ }
+ return isDarkMode;
+#elif defined(LINUX)
+ return std::filesystem::exists("/usr/share/themes/Adwaita-dark/gtk-3.0");
+#elif defined(WINDOWS)
+ HKEY key;
+ if (RegOpenKeyExA(HKEY_CURRENT_USER,
+ "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
+ 0,
+ KEY_QUERY_VALUE,
+ &key) == ERROR_SUCCESS)
+ {
+ DWORD value = 0;
+ DWORD size = sizeof(DWORD);
+ if (RegQueryValueExA(key, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast(&value), &size) ==
+ ERROR_SUCCESS)
+ return value == 0;
+ }
+ return false;
+#else
+ return false;
+#endif
+ }
+
+ void addFontIfExistent(const ImGuiIO* io,
+ const std::filesystem::path& path,
+ const ImFontConfig* config,
+ const ImWchar* ranges) noexcept
+ {
+ if (io->Fonts->Fonts.empty() and config->MergeMode)
+ config = nullptr;
+ if (std::filesystem::exists(path))
+ {
+#ifdef DEBUG
+ output::info("addIfExistent"s, "Added font {0}"s, { path });
+#endif
+ io->Fonts->AddFontFromFileTTF(path.c_str(), 15.0F, config, ranges);
+ }
+ }
+
+ void loadFonts(const ImGuiIO* io) noexcept
+ {
+ ImFontConfig config;
+ config.MergeMode = true;
+#ifdef WINDOWS
+ // WINDOWS fonts
+ // -------------
+ // Chinese -> Microsoft YaHei
+ // Cyrillic -> Segoe UI -----------------+
+ // Greek -> Segoe UI -----------------|
+ // Japanese -> Meiryo |
+ // Korean -> Malgun Gothic +--> Top-priority
+ // Thai -> Leelawadee |
+ // Vietnamese -> Segoe UI -----------------+
+
+ // Load top-priority fonts
+ addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesCyrillic());
+ addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesDefault());
+ addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesGreek());
+ addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesVietnamese());
+
+ // Load Chinese fonts
+ addIfExistent(io, "C:/Windows/Fonts/msyh.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
+
+ // Load Japanese fonts
+ addIfExistent(io, "C:/Windows/Fonts/meiryo.ttc", &config, io->Fonts->GetGlyphRangesJapanese());
+
+ // Load Korean fonts
+ addIfExistent(io, "C:/Windows/Fonts/malgun.ttf", &config, io->Fonts->GetGlyphRangesKorean());
+
+ // Load Thai fonts
+ addIfExistent(io, "C:/Windows/Fonts/leelawad.ttf", &config, io->Fonts->GetGlyphRangesThai());
+#elif defined(MACOSX)
+ // MACOS fonts
+ // -------------
+ // Chinese -> PingFang SC (*)
+ // Cyrillic -> SF Pro -----------------+
+ // Greek -> SF Pro -----------------|
+ // Japanese -> Hiragino Sans |
+ // Korean -> Apple SD Gothic Neo +--> Top-priority
+ // Thai -> Thonburi |
+ // Vietnamese -> SF Pro -----------------+
+ //
+ // (*) NOTE: PingFang may not be available on all systems, but STHeiti Medium is a good alternative.
+
+ // Load top-priority fonts
+ addFontIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesCyrillic());
+ addFontIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesDefault());
+ addFontIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesGreek());
+ addFontIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesVietnamese());
+
+ // Load Chinese fonts
+ addFontIfExistent(io, "/System/Library/Fonts/PingFang.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
+ addFontIfExistent(
+ io, "/System/Library/Fonts/STHeiti Medium.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
+
+ // Load Japanese fonts
+ addFontIfExistent(io, "/System/Library/Fonts/Hiragino.ttc", &config, io->Fonts->GetGlyphRangesJapanese());
+
+ // Load Korean fonts
+ addFontIfExistent(io, "/System/Library/Fonts/AppleSDGothicNeo.ttc", &config, io->Fonts->GetGlyphRangesKorean());
+
+ // Load Thai fonts
+ addFontIfExistent(io, "/System/Library/Fonts/Thonburi.ttf", &config, io->Fonts->GetGlyphRangesThai());
+ addFontIfExistent(
+ io, "/System/Library/Fonts/Supplemental/Ayuthaya.ttf", &config, io->Fonts->GetGlyphRangesThai());
+#elif defined(LINUX)
+ // LINUX fonts
+ // -------------
+ // Chinese -> WenQuanYi Zen Hei
+ // Cyrillic -> DejaVu Sans -----------------+
+ // Greek -> DejaVu Sans -----------------|
+ // Japanese -> Takao Gothic |
+ // Korean -> Nanum Gothic +--> Top-priority
+ // Thai -> Garuda |
+ // Vietnamese -> DejaVu Sans -----------------+
+
+ // Load top-priority fonts
+ addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesCyrillic());
+ addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesDefault());
+ addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesGreek());
+ addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesVietnamese());
+
+ // Load Chinese fonts
+ addIfExistent(io, "/usr/share/fonts/TTF/wqy-zenhei.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
+
+ // Load Japanese fonts
+ addIfExistent(io, "/usr/share/fonts/TTF/takao-mincho.ttf", &config, io->Fonts->GetGlyphRangesJapanese());
+
+ // Load Korean fonts
+ addIfExistent(io, "/usr/share/fonts/TTF/NanumGothic.ttf", &config, io->Fonts->GetGlyphRangesKorean());
+
+ // Load Thai fonts
+ addIfExistent(io, "/usr/share/fonts/TTF/garuda.ttf", &config, io->Fonts->GetGlyphRangesThai());
+#endif
+ // Add the default font as well.
+ io->Fonts->AddFontDefault(&config);
+ io->Fonts->Build();
+ }
+} // namespace steppable::gui::__internals
diff --git a/gui/impl/window.cpp b/gui/impl/window.cpp
new file mode 100644
index 000000000..389ca9ad1
--- /dev/null
+++ b/gui/impl/window.cpp
@@ -0,0 +1,143 @@
+#include "backends/imgui_impl_opengl3.h"
+#include "backends/imgui_impl_sdl2.h"
+#include "gui.hpp"
+#include "imgui.h"
+#include "output.hpp"
+#include "platform.hpp"
+
+#include
+#include
+#include
+
+using namespace steppable;
+using namespace steppable::gui::__internals;
+using namespace steppable::__internals::utils;
+
+namespace steppable::gui
+{
+ void runWindow(const std::string& name, const std::function& predicate)
+ {
+ // Setup SDL
+ if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
+ {
+ steppable::output::error("SDL_Init", std::string(SDL_GetError()));
+ programSafeExit(-1);
+ }
+
+ // Decide GL+GLSL versions
+#if defined(IMGUI_IMPL_OPENGL_ES2)
+ // GL ES 2.0 + GLSL 100
+ const char* glsl_version = "#version 100";
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+#elif defined(__APPLE__)
+ // GL 3.2 Core + GLSL 150
+ const char* glsl_version = "#version 150";
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
+#else
+ // GL 3.0 + GLSL 130
+ const char* glsl_version = "#version 130";
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
+ SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
+#endif
+
+ // From 2.0.18: Enable native IME.
+ SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
+
+ // Create window with graphics context
+ SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
+ SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
+ SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
+ auto window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
+ SDL_Window* window =
+ SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
+ if (window == nullptr)
+ {
+ steppable::output::error("SDL_CreateWindow"s, std::string(SDL_GetError()));
+ programSafeExit(-1);
+ }
+
+ SDL_GLContext gl_context = SDL_GL_CreateContext(window);
+ SDL_GL_MakeCurrent(window, gl_context);
+ SDL_GL_SetSwapInterval(1); // Enable vsync
+
+ // Setup Dear ImGui context
+ IMGUI_CHECKVERSION();
+ ImGui::CreateContext();
+ ImGuiIO& io = ImGui::GetIO();
+ io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
+ io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
+
+ // Setup Platform/Renderer backends
+ ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
+ ImGui_ImplOpenGL3_Init(glsl_version);
+
+ bool done = false;
+ ImVec4 clear_color = ImVec4(0.22, 0.22, 0.22, 1.00);
+ std::array buf{};
+ loadFonts(&io);
+
+ while (not done)
+ {
+ // Poll and handle events (inputs, window resize, etc.)
+ // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use
+ // your inputs.
+ // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or
+ // clear/overwrite your copy of the mouse data.
+ // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or
+ // clear/overwrite your copy of the keyboard data. Generally you may always pass all inputs to dear imgui,
+ // and hide them from your application based on those two flags.
+ SDL_Event event;
+ while (SDL_PollEvent(&event) != 0)
+ {
+ ImGui_ImplSDL2_ProcessEvent(&event);
+ if (event.type == SDL_QUIT)
+ done = true;
+ if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE &&
+ event.window.windowID == SDL_GetWindowID(window))
+ done = true;
+ }
+
+ // Start the Dear ImGui frame
+ ImGui_ImplOpenGL3_NewFrame();
+ ImGui_ImplSDL2_NewFrame();
+ ImGui::NewFrame();
+
+ predicate();
+
+ if (isDarkModeEnabled())
+ {
+ glClearColor(0.22, 0.22, 0.22, 1.0);
+ ImGui::StyleColorsDark();
+ }
+ else
+ {
+ glClearColor(0.95, 0.95, 0.95, 1.0);
+ ImGui::StyleColorsLight();
+ }
+
+ // Rendering
+ ImGui::Render();
+ glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
+ glClear(GL_COLOR_BUFFER_BIT);
+ ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
+ SDL_GL_SwapWindow(window);
+ }
+
+ // Cleanup
+ ImGui_ImplOpenGL3_Shutdown();
+ ImGui_ImplSDL2_Shutdown();
+ ImGui::DestroyContext();
+
+ SDL_GL_DeleteContext(gl_context);
+ SDL_DestroyWindow(window);
+ SDL_Quit();
+ }
+} // namespace steppable::gui
diff --git a/gui/test.cpp b/gui/test.cpp
index 756762ba6..8a816ba60 100644
--- a/gui/test.cpp
+++ b/gui/test.cpp
@@ -1,142 +1,21 @@
-#include "backends/imgui_impl_opengl3.h"
-#include "backends/imgui_impl_sdl2.h"
#include "gui.hpp"
#include "imgui.h"
-#include "output.hpp"
#include
#include
-#include
+
+// NOTE TO DEVELOPERS: This file is a test file for the GUI module of the Steppable library.
+// When building the GUI part for the first time, this can come in handy.
+// Run the executable to see if the GUI window works.
using namespace steppable;
using namespace steppable::gui::__internals;
-int main()
+void setUpContents()
{
- // Setup SDL
- if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_GAMECONTROLLER) != 0)
- {
- steppable::output::error("Error: {0}\n", std::string(SDL_GetError()));
- return -1;
- }
-
- // Decide GL+GLSL versions
-#if defined(IMGUI_IMPL_OPENGL_ES2)
- // GL ES 2.0 + GLSL 100
- const char* glsl_version = "#version 100";
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_ES);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 2);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
-#elif defined(__APPLE__)
- // GL 3.2 Core + GLSL 150
- const char* glsl_version = "#version 150";
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, SDL_GL_CONTEXT_FORWARD_COMPATIBLE_FLAG); // Always required on Mac
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 2);
-#else
- // GL 3.0 + GLSL 130
- const char* glsl_version = "#version 130";
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_FLAGS, 0);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
- SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 0);
-#endif
-
- // From 2.0.18: Enable native IME.
- SDL_SetHint(SDL_HINT_IME_SHOW_UI, "1");
-
- // Create window with graphics context
- SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
- SDL_GL_SetAttribute(SDL_GL_DEPTH_SIZE, 24);
- SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 8);
- auto window_flags = (SDL_WindowFlags)(SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
- SDL_Window* window = SDL_CreateWindow("", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 1280, 720, window_flags);
- if (window == nullptr)
- {
- printf("Error: SDL_CreateWindow(): %s\n", SDL_GetError());
- return -1;
- }
-
- SDL_GLContext gl_context = SDL_GL_CreateContext(window);
- SDL_GL_MakeCurrent(window, gl_context);
- SDL_GL_SetSwapInterval(1); // Enable vsync
-
- // Setup Dear ImGui context
- IMGUI_CHECKVERSION();
- ImGui::CreateContext();
- ImGuiIO& io = ImGui::GetIO();
- io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard; // Enable Keyboard Controls
- io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
-
- // Setup Platform/Renderer backends
- ImGui_ImplSDL2_InitForOpenGL(window, gl_context);
- ImGui_ImplOpenGL3_Init(glsl_version);
-
- bool done = false;
- ImVec4 clear_color = ImVec4(0.22, 0.22, 0.22, 1.00);
- std::array buf{};
- loadFonts(&io);
-
- while (not done)
- {
- // Poll and handle events (inputs, window resize, etc.)
- // You can read the io.WantCaptureMouse, io.WantCaptureKeyboard flags to tell if dear imgui wants to use your
- // inputs.
- // - When io.WantCaptureMouse is true, do not dispatch mouse input data to your main application, or
- // clear/overwrite your copy of the mouse data.
- // - When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application, or
- // clear/overwrite your copy of the keyboard data. Generally you may always pass all inputs to dear imgui, and
- // hide them from your application based on those two flags.
- SDL_Event event;
- while (SDL_PollEvent(&event) != 0)
- {
- ImGui_ImplSDL2_ProcessEvent(&event);
- if (event.type == SDL_QUIT)
- done = true;
- if (event.type == SDL_WINDOWEVENT && event.window.event == SDL_WINDOWEVENT_CLOSE &&
- event.window.windowID == SDL_GetWindowID(window))
- done = true;
- }
-
- // Start the Dear ImGui frame
- ImGui_ImplOpenGL3_NewFrame();
- ImGui_ImplSDL2_NewFrame();
- ImGui::NewFrame();
-
- ImGui::Begin("My Window");
- ImGui::Text("Testing!");
- ImGui::InputText("Input", buf.data(), buf.size());
- ImGui::End();
-
- if (isDarkModeEnabled())
- {
- glClearColor(0.22, 0.22, 0.22, 1.0);
- ImGui::StyleColorsDark();
- }
- else
- {
- glClearColor(0.95, 0.95, 0.95, 1.0);
- ImGui::StyleColorsLight();
- }
-
- // Rendering
- ImGui::Render();
- glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
- glClear(GL_COLOR_BUFFER_BIT);
- ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
- SDL_GL_SwapWindow(window);
- }
-
- // Cleanup
- ImGui_ImplOpenGL3_Shutdown();
- ImGui_ImplSDL2_Shutdown();
- ImGui::DestroyContext();
-
- SDL_GL_DeleteContext(gl_context);
- SDL_DestroyWindow(window);
- SDL_Quit();
-
- return 0;
+ ImGui::Begin("Hello, world!");
+ ImGui::Text("This is some useful text.");
+ ImGui::End();
}
+
+int main() { gui::runWindow("", &setUpContents); }
diff --git a/include/constants.hpp b/include/constants.hpp
index 2a194ac97..7d1af4d61 100644
--- a/include/constants.hpp
+++ b/include/constants.hpp
@@ -31,8 +31,7 @@
namespace steppable::constants
{
/// @brief 100 digits of pi.
- constexpr const std::string_view& PI =
- "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
+ extern const std::string_view& PI;
/// @brief Pi multiplied by 2.
// Generated using Python:
@@ -44,7 +43,7 @@ namespace steppable::constants
// 5 | 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
// 6 | ) * Decimal(2)
// -------------------------------------------------------
- constexpr const std::string_view& TWO_PI = "6.283185307179586231995926937088370323181152343750";
+ extern const std::string_view& TWO_PI;
/// @brief Pi divided by 2.
// Generated using Python:
@@ -56,8 +55,7 @@ namespace steppable::constants
// 5 | 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
// 6 | ) / Decimal(2)
// -------------------------------------------------------
- constexpr const std::string_view& PI_OVER_2 =
- "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412835292542";
+ extern const std::string_view& PI_OVER_2;
/// @brief Pi divided by 180 (to convert degrees to radians), correct to 100 decimal places.
// Generated using Python:
@@ -69,8 +67,7 @@ namespace steppable::constants
// 5 | 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
// 6 | ) / Decimal(180)
// -------------------------------------------------------
- constexpr const std::string_view& PI_OVER_180 =
- "0.01745329251994329508887757482524547311994764539930555555555555555555555555555555555555555555555555556";
+ extern const std::string_view& PI_OVER_180;
/// @brief Pi divided by 200 (to convert grads to radians), correct to 100 decimal places.
// Generated using Python:
@@ -82,8 +79,7 @@ namespace steppable::constants
// 5 | 3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679
// 6 | ) / Decimal(200)
// -------------------------------------------------------
- constexpr const std::string_view& PI_OVER_200 =
- "0.01570796326794896619231321691639716312084074699687552942986246296153903203140449499314017412671058534";
+ extern const std::string_view& PI_OVER_200;
- constexpr const std::string_view& E = "2.718281828459045090795598298427648842334747314453125";
+ extern const std::string_view& E;
} // namespace steppable::constants
diff --git a/include/fn/basicArithm.hpp b/include/fn/basicArithm.hpp
index 9bd20ba79..a82b78840 100644
--- a/include/fn/basicArithm.hpp
+++ b/include/fn/basicArithm.hpp
@@ -110,7 +110,7 @@ namespace steppable::__internals::arithmetic
* @brief Converts a string representation of a number from decimal to another one.
*
* @param[in] _number The string representation of the number.
- * @param[in] baseString The desired base.
+ * @param[in] baseStr The desired base.
* @param[in] steps The number of steps to perform the conversion.
* @return The converted number as a string.
*/
@@ -166,6 +166,15 @@ namespace steppable::__internals::arithmetic
*/
std::string power(const std::string& _number, const std::string& raiseTo, int steps = 2);
+ /**
+ * @brief Calculates e^x. Shorthand of power(x, E, 0);
+ *
+ * @param x The string representation of the number.
+ * @param decimals The number of decimals to output.
+ * @return The exponent of the number.
+ */
+ std::string exp(const std::string& x, size_t decimals = 10);
+
/**
* @brief Subtracts one string representation of a number from another string representation of a number.
*
diff --git a/include/fn/calculus.hpp b/include/fn/calculus.hpp
new file mode 100644
index 000000000..020063e76
--- /dev/null
+++ b/include/fn/calculus.hpp
@@ -0,0 +1,39 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+#pragma once
+
+#include
+#include
+
+/**
+ * @namespace steppable::__internals::calculus
+ * @brief Contains calculus functions.
+ */
+namespace steppable::__internals::calculus
+{
+ std::string romberg(const std::function& f,
+ const std::string& a,
+ const std::string& b,
+ int max_steps,
+ int decimals);
+}
diff --git a/include/getString.hpp b/include/getString.hpp
index 36e448980..d54677b50 100644
--- a/include/getString.hpp
+++ b/include/getString.hpp
@@ -25,6 +25,10 @@
#include
#include
+/**
+ * @namespace steppable::localization
+ * @brief The namespace for the localization utilities.
+ */
namespace steppable::localization
{
/**
diff --git a/include/gui.hpp b/include/gui.hpp
index 9b5d4d9d1..22d7cd9d8 100644
--- a/include/gui.hpp
+++ b/include/gui.hpp
@@ -22,170 +22,70 @@
#pragma once
-#include "output.hpp"
-
#include
#include
#include
+#include
#include
#include
using namespace std::literals;
+/**
+ * @brief The namespace for the internal components of the GUI module of the Steppable library.
+ * @details This namespace contains the internal components of the GUI module of the Steppable library.
+ * For example, methods that gets the system fonts, checks if the dark mode is enabled, and loads the fonts.
+ * @note This namespace is not intended for use by the end user.
+ */
namespace steppable::gui::__internals
{
-#ifdef MACOSX
- #include
-
- bool isDarkModeEnabled()
- {
- bool isDarkMode = false;
- CFPreferencesAppSynchronize(CFSTR("AppleInterfaceStyle"));
- CFPropertyListRef value = CFPreferencesCopyAppValue(CFSTR("AppleInterfaceStyle"), kCFPreferencesAnyApplication);
- if (value != nullptr)
- {
- const auto* interfaceStyle = static_cast(value);
- if (CFStringCompare(interfaceStyle, CFSTR("Dark"), 0) == kCFCompareEqualTo)
- isDarkMode = true;
- CFRelease(value);
- }
- return isDarkMode;
- }
-#elif defined(LINUX)
- bool isDarkModeEnabled() { return std::filesystem::exists("/usr/share/themes/Adwaita-dark/gtk-3.0"); }
-#elif defined(WINDOWS)
- bool isDarkModeEnabled()
- {
- HKEY key;
- if (RegOpenKeyExA(HKEY_CURRENT_USER,
- "Software\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize",
- 0,
- KEY_QUERY_VALUE,
- &key) == ERROR_SUCCESS)
- {
- DWORD value = 0;
- DWORD size = sizeof(DWORD);
- if (RegQueryValueExA(key, "AppsUseLightTheme", nullptr, nullptr, reinterpret_cast(&value), &size) ==
- ERROR_SUCCESS)
- return value == 0;
- }
- return false;
- }
-#else
- bool isDarkModeEnabled() { return false; }
-#endif
-
- inline void addIfExistent(const ImGuiIO* io,
- const std::filesystem::path& path,
- const ImFontConfig* config,
- const ImWchar* ranges) noexcept
- {
- if (io->Fonts->Fonts.empty() and config->MergeMode)
- config = nullptr;
- if (std::filesystem::exists(path))
- {
-#ifdef DEBUG
- output::info("addIfExistent"s, "Added font {0}"s, { path });
-#endif
- io->Fonts->AddFontFromFileTTF(path.c_str(), 15.0F, config, ranges);
- }
- }
-
- inline void loadFonts(const ImGuiIO* io) noexcept
- {
- ImFontConfig config;
- config.MergeMode = true;
-#ifdef WINDOWS
- // WINDOWS fonts
- // -------------
- // Chinese -> Microsoft YaHei
- // Cyrillic -> Segoe UI -----------------+
- // Greek -> Segoe UI -----------------|
- // Japanese -> Meiryo |
- // Korean -> Malgun Gothic +--> Top-priority
- // Thai -> Leelawadee |
- // Vietnamese -> Segoe UI -----------------+
-
- // Load top-priority fonts
- addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesCyrillic());
- addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesDefault());
- addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesGreek());
- addIfExistent(io, "C:/Windows/Fonts/segoeui.ttf", &config, io->Fonts->GetGlyphRangesVietnamese());
-
- // Load Chinese fonts
- addIfExistent(io, "C:/Windows/Fonts/msyh.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
-
- // Load Japanese fonts
- addIfExistent(io, "C:/Windows/Fonts/meiryo.ttc", &config, io->Fonts->GetGlyphRangesJapanese());
-
- // Load Korean fonts
- addIfExistent(io, "C:/Windows/Fonts/malgun.ttf", &config, io->Fonts->GetGlyphRangesKorean());
-
- // Load Thai fonts
- addIfExistent(io, "C:/Windows/Fonts/leelawad.ttf", &config, io->Fonts->GetGlyphRangesThai());
-#elif defined(MACOSX)
- // MACOS fonts
- // -------------
- // Chinese -> PingFang SC (*)
- // Cyrillic -> SF Pro -----------------+
- // Greek -> SF Pro -----------------|
- // Japanese -> Hiragino Sans |
- // Korean -> Apple SD Gothic Neo +--> Top-priority
- // Thai -> Thonburi |
- // Vietnamese -> SF Pro -----------------+
- //
- // (*) NOTE: PingFang may not be available on all systems, but STHeiti Medium is a good alternative.
-
- // Load top-priority fonts
- addIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesCyrillic());
- addIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesDefault());
- addIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesGreek());
- addIfExistent(io, "/Library/Fonts/SF-Pro.ttf", &config, io->Fonts->GetGlyphRangesVietnamese());
-
- // Load Chinese fonts
- addIfExistent(io, "/System/Library/Fonts/PingFang.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
- addIfExistent(io, "/System/Library/Fonts/STHeiti Medium.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
-
- // Load Japanese fonts
- addIfExistent(io, "/System/Library/Fonts/Hiragino.ttc", &config, io->Fonts->GetGlyphRangesJapanese());
-
- // Load Korean fonts
- addIfExistent(io, "/System/Library/Fonts/AppleSDGothicNeo.ttc", &config, io->Fonts->GetGlyphRangesKorean());
-
- // Load Thai fonts
- addIfExistent(io, "/System/Library/Fonts/Thonburi.ttf", &config, io->Fonts->GetGlyphRangesThai());
- addIfExistent(io, "/System/Library/Fonts/Supplemental/Ayuthaya.ttf", &config, io->Fonts->GetGlyphRangesThai());
-#elif defined(LINUX)
- // LINUX fonts
- // -------------
- // Chinese -> WenQuanYi Zen Hei
- // Cyrillic -> DejaVu Sans -----------------+
- // Greek -> DejaVu Sans -----------------|
- // Japanese -> Takao Gothic |
- // Korean -> Nanum Gothic +--> Top-priority
- // Thai -> Garuda |
- // Vietnamese -> DejaVu Sans -----------------+
-
- // Load top-priority fonts
- addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesCyrillic());
- addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesDefault());
- addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesGreek());
- addIfExistent(io, "/usr/share/fonts/TTF/DejaVuSans-Bold.ttf", &config, io->Fonts->GetGlyphRangesVietnamese());
-
- // Load Chinese fonts
- addIfExistent(io, "/usr/share/fonts/TTF/wqy-zenhei.ttc", &config, io->Fonts->GetGlyphRangesChineseFull());
-
- // Load Japanese fonts
- addIfExistent(io, "/usr/share/fonts/TTF/takao-mincho.ttf", &config, io->Fonts->GetGlyphRangesJapanese());
-
- // Load Korean fonts
- addIfExistent(io, "/usr/share/fonts/TTF/NanumGothic.ttf", &config, io->Fonts->GetGlyphRangesKorean());
-
- // Load Thai fonts
- addIfExistent(io, "/usr/share/fonts/TTF/garuda.ttf", &config, io->Fonts->GetGlyphRangesThai());
-#endif
- // Add the default font as well.
- io->Fonts->AddFontDefault(&config);
- io->Fonts->Build();
- }
+ /**
+ * @brief Checks if the dark mode is enabled.
+ * @return True if the dark mode is enabled, false otherwise.
+ */
+ bool isDarkModeEnabled();
+
+ /**
+ * Attempts to add a font to the application if it exists in the system.
+ *
+ * This method checks if a specified font is available on the system. If the font is found,
+ * it is added to the application's font resources, making it available for use within the application.
+ * If the font does not exist, the method will not perform any action or may log an error or warning,
+ * depending on implementation details.
+ *
+ * @param io A pointer to an ImGuiIO object to enable configuration.
+ * @param path The absolute path to the font file.
+ * @param config A pointer to an ImFontConfig object to enable font configuration.
+ * @param ranges A pointer to an array of ImWchar objects to enable character range configuration.
+ */
+ void addFontIfExistent(const ImGuiIO* io,
+ const std::filesystem::path& path,
+ const ImFontConfig* config,
+ const ImWchar* ranges) noexcept;
+
+ /**
+ * @brief Loads the fonts for the application.
+ * @details This method tries to find the system fonts that can display most character sets.
+ * @param io A pointer to an ImGuiIO object to enable configuration
+ */
+ void loadFonts(const ImGuiIO* io) noexcept;
} // namespace steppable::gui::__internals
+
+/**
+ * @brief The namespace for the GUI components of the Steppable library. This is the main namespace for the GUI
+ * components.
+ */
+namespace steppable::gui
+{
+ /**
+ * @brief Runs the main window of the application.
+ * @details This method replaces the long ininitalization process of the application with a simple
+ * call to the runWindow method. This method initializes the SDL2 and OpenGL backends for the application,
+ * then runs the main window loop. The main window loop is responsible for rendering the application's
+ * contents and handling user input.
+ *
+ * @param name The name of the window.
+ * @param predicate The function that will be called to render the window.
+ */
+ void runWindow(const std::string& name, const std::function& predicate);
+} // namespace steppable::gui
diff --git a/include/imgui b/include/imgui
index 469dfd15c..dad58f2f6 160000
--- a/include/imgui
+++ b/include/imgui
@@ -1 +1 @@
-Subproject commit 469dfd15c80884872acbf1f3942553e01948aca5
+Subproject commit dad58f2f6839e5fcadaf95b57cf6174ef0274e52
diff --git a/include/platform.hpp b/include/platform.hpp
index f370714fd..cfbe6d8ad 100644
--- a/include/platform.hpp
+++ b/include/platform.hpp
@@ -32,9 +32,11 @@
*/
#pragma once
+
#include
#include
#include
+#include
using namespace std::literals;
diff --git a/lib/CMakeLists.txt b/lib/CMakeLists.txt
index 29229660a..d72153c33 100644
--- a/lib/CMakeLists.txt
+++ b/lib/CMakeLists.txt
@@ -40,7 +40,7 @@ if(NOT ${STP_NO_BINDINGS}) # Only create the bindings if needed
target_link_options(steppyble PRIVATE -Bsymbolic)
endif()
set_target_properties(steppyble PROPERTIES POSITION_INDEPENDENT_CODE ON)
- target_link_libraries(steppyble PRIVATE calc steppable)
+ target_link_libraries(steppyble PRIVATE func steppable)
target_compile_definitions(steppyble PRIVATE NO_MAIN)
target_include_directories(steppyble PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/../include)
-endif()
\ No newline at end of file
+endif()
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 64330da66..59f4bc657 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -20,7 +20,19 @@
# SOFTWARE. #
#####################################################################################################
-ADD_LIBRARY(util STATIC argParse.cpp colors.cpp logging.cpp symbols.cpp testing.cpp util.cpp getString.cpp platform.cpp format.cpp)
+ADD_LIBRARY(
+ util STATIC
+ argParse.cpp
+ colors.cpp
+ logging.cpp
+ symbols.cpp
+ testing.cpp
+ util.cpp
+ getString.cpp
+ platform.cpp
+ format.cpp
+ constants.cpp
+)
SET_TARGET_PROPERTIES(util PROPERTIES POSITION_INDEPENDENT_CODE ON)
ADD_LIBRARY(steppable STATIC number.cpp fraction.cpp)
@@ -28,51 +40,36 @@ SET_TARGET_PROPERTIES(steppable PROPERTIES POSITION_INDEPENDENT_CODE ON)
SET(CALCULATOR_FILES)
-FUNCTION(COPY_TO_BIN TARGET_NAME)
- IF(DEFINED STP_BUILD_COMPONENT_EXECUTABLE)
- IF(WINDOWS)
- ADD_CUSTOM_COMMAND(
- TARGET ${TARGET_NAME}
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy $
- ${CMAKE_CURRENT_BINARY_DIR}/../bin/${TARGET_NAME}.exe
- )
- ELSE()
- ADD_CUSTOM_COMMAND(
- TARGET ${TARGET_NAME}
- POST_BUILD
- COMMAND ${CMAKE_COMMAND} -E copy $
- ${CMAKE_CURRENT_BINARY_DIR}/../bin/${TARGET_NAME}
- )
- ENDIF()
- ENDIF()
-ENDFUNCTION()
-
FOREACH(COMPONENT IN LISTS COMPONENTS)
- MESSAGE(TRACE "Adding component: ${COMPONENT}: ${COMPONENT}/${COMPONENT}.cpp, ${COMPONENT}/${COMPONENT}Report.cpp")
+ STRING(REPLACE "::" ";" COMPONENT_PARTS ${COMPONENT})
+ LIST(LENGTH COMPONENT_PARTS LEN)
+ IF(NOT LEN EQUAL 2)
+ MESSAGE(FATAL_ERROR "Incorrect format of target name.")
+ ENDIF()
+ LIST(GET COMPONENT_PARTS 0 ORIGIN)
+ LIST(GET COMPONENT_PARTS 1 NAME)
+ SET(TARGET_NAME ${ORIGIN}_${NAME})
+ MESSAGE(TRACE "Adding component: ${NAME}: ${ORIGIN}/${NAME}/${NAME}.cpp, ${ORIGIN}/${NAME}/${NAME}Report.cpp")
# No longer offering executables for each component automatically.
- IF(DEFINED STP_BUILD_COMPONENT_EXECUTABLE)
- ADD_EXECUTABLE(${COMPONENT} ${COMPONENT}/${COMPONENT}.cpp ${COMPONENT}/${COMPONENT}Report.cpp)
- TARGET_INCLUDE_DIRECTORIES(${COMPONENT} PRIVATE ${STP_BASE_DIRECTORY}/include/)
- TARGET_LINK_LIBRARIES(${COMPONENT} PRIVATE calc)
+ IF(STP_BUILD_COMPONENT_EXECUTABLE)
+ ADD_EXECUTABLE(${TARGET_NAME} ${ORIGIN}/${NAME}/${NAME}.cpp ${ORIGIN}/${NAME}/${NAME}Report.cpp)
+ TARGET_INCLUDE_DIRECTORIES(${TARGET_NAME} PRIVATE ${STP_BASE_DIRECTORY}/include/)
+ TARGET_LINK_LIBRARIES(${TARGET_NAME} PRIVATE func)
ENDIF()
- LIST(APPEND CALCULATOR_FILES ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/${COMPONENT}.cpp
- ${CMAKE_CURRENT_SOURCE_DIR}/${COMPONENT}/${COMPONENT}Report.cpp
- )
-
- COPY_TO_BIN(${COMPONENT})
+ LIST(APPEND CALCULATOR_FILES ${ORIGIN}/${NAME}/${NAME}.cpp ${ORIGIN}/${NAME}/${NAME}Report.cpp)
ENDFOREACH()
-ADD_LIBRARY(calc STATIC ${CALCULATOR_FILES} fraction.cpp rounding.cpp factors.cpp number.cpp)
-SET_TARGET_PROPERTIES(calc PROPERTIES POSITION_INDEPENDENT_CODE ON)
+# FUNC: Library containing all Steppable functions.
+ADD_LIBRARY(func STATIC ${CALCULATOR_FILES} fraction.cpp rounding.cpp factors.cpp number.cpp)
+SET_TARGET_PROPERTIES(func PROPERTIES POSITION_INDEPENDENT_CODE ON)
TARGET_INCLUDE_DIRECTORIES(steppable PRIVATE ${STP_BASE_DIRECTORY}/include/)
-TARGET_INCLUDE_DIRECTORIES(calc PRIVATE ${STP_BASE_DIRECTORY}/include/)
+TARGET_INCLUDE_DIRECTORIES(func PRIVATE ${STP_BASE_DIRECTORY}/include/)
TARGET_INCLUDE_DIRECTORIES(util PRIVATE ${STP_BASE_DIRECTORY}/include/)
TARGET_LINK_LIBRARIES(steppable PRIVATE util)
-TARGET_LINK_LIBRARIES(calc PRIVATE steppable)
-TARGET_COMPILE_DEFINITIONS(calc PRIVATE NO_MAIN)
+TARGET_LINK_LIBRARIES(func PRIVATE steppable)
+TARGET_COMPILE_DEFINITIONS(func PRIVATE NO_MAIN)
TARGET_COMPILE_DEFINITIONS(steppable PRIVATE NO_MAIN)
diff --git a/src/baseConvert/baseConvert.cpp b/src/base/baseConvert/baseConvert.cpp
similarity index 100%
rename from src/baseConvert/baseConvert.cpp
rename to src/base/baseConvert/baseConvert.cpp
diff --git a/src/baseConvert/baseConvert.vcxproj b/src/base/baseConvert/baseConvert.vcxproj
similarity index 98%
rename from src/baseConvert/baseConvert.vcxproj
rename to src/base/baseConvert/baseConvert.vcxproj
index d19c4660f..59383081c 100644
--- a/src/baseConvert/baseConvert.vcxproj
+++ b/src/base/baseConvert/baseConvert.vcxproj
@@ -1,177 +1,177 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 16.0
- Win32Proj
- {00B3E92A-8C55-4D70-8A27-8F0AEBF5872D}
- add
- 10.0
-
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
- false
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
- true
- $(SolutionDir)$(Configuration)\
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
- false
- $(SolutionDir)$(Configuration)\
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
-
- Level3
- true
- WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
- true
- true
-
-
-
-
- Level3
- true
- _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
- true
- true
-
-
-
-
-
-
-
-
- {0a900aaa-ac12-48cf-85cf-8bb0c0130512}
-
-
- {f6af63f8-9e0f-4da2-89b3-3096b56ba251}
-
-
-
-
-
-
-
-
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ Win32Proj
+ {00B3E92A-8C55-4D70-8A27-8F0AEBF5872D}
+ add
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+ false
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+ true
+ $(SolutionDir)$(Configuration)\
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+ false
+ $(SolutionDir)$(Configuration)\
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+ {0a900aaa-ac12-48cf-85cf-8bb0c0130512}
+
+
+ {f6af63f8-9e0f-4da2-89b3-3096b56ba251}
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/baseConvert/baseConvert.vcxproj.filters b/src/base/baseConvert/baseConvert.vcxproj.filters
similarity index 97%
rename from src/baseConvert/baseConvert.vcxproj.filters
rename to src/base/baseConvert/baseConvert.vcxproj.filters
index 6f4f7b4bb..bb2e27038 100644
--- a/src/baseConvert/baseConvert.vcxproj.filters
+++ b/src/base/baseConvert/baseConvert.vcxproj.filters
@@ -1,26 +1,26 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
-
-
- Source Files
-
-
- Source Files
-
-
-
-
- Header Files
-
-
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
\ No newline at end of file
diff --git a/src/baseConvert/baseConvertReport.cpp b/src/base/baseConvert/baseConvertReport.cpp
similarity index 100%
rename from src/baseConvert/baseConvertReport.cpp
rename to src/base/baseConvert/baseConvertReport.cpp
diff --git a/src/baseConvert/baseConvertReport.hpp b/src/base/baseConvert/baseConvertReport.hpp
similarity index 100%
rename from src/baseConvert/baseConvertReport.hpp
rename to src/base/baseConvert/baseConvertReport.hpp
diff --git a/src/decimalConvert/decimalConvert.cpp b/src/base/decimalConvert/decimalConvert.cpp
similarity index 100%
rename from src/decimalConvert/decimalConvert.cpp
rename to src/base/decimalConvert/decimalConvert.cpp
diff --git a/src/decimalConvert/decimalConvert.vcxproj b/src/base/decimalConvert/decimalConvert.vcxproj
similarity index 98%
rename from src/decimalConvert/decimalConvert.vcxproj
rename to src/base/decimalConvert/decimalConvert.vcxproj
index b91f363d0..97d9464a0 100644
--- a/src/decimalConvert/decimalConvert.vcxproj
+++ b/src/base/decimalConvert/decimalConvert.vcxproj
@@ -1,177 +1,177 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 16.0
- Win32Proj
- {55A00CFD-37B4-4618-A8D3-445A05DA759A}
- add
- 10.0
-
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
- false
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
- true
- $(SolutionDir)$(Configuration)\
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
- false
- $(SolutionDir)$(Configuration)\
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
-
- Level3
- true
- WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
- true
- true
-
-
-
-
- Level3
- true
- _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
- true
- true
-
-
-
-
- {0a900aaa-ac12-48cf-85cf-8bb0c0130512}
-
-
- {f6af63f8-9e0f-4da2-89b3-3096b56ba251}
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ Win32Proj
+ {55A00CFD-37B4-4618-A8D3-445A05DA759A}
+ add
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+ false
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+ true
+ $(SolutionDir)$(Configuration)\
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+ false
+ $(SolutionDir)$(Configuration)\
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ {0a900aaa-ac12-48cf-85cf-8bb0c0130512}
+
+
+ {f6af63f8-9e0f-4da2-89b3-3096b56ba251}
+
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/decimalConvert/decimalConvert.vcxproj.filters b/src/base/decimalConvert/decimalConvert.vcxproj.filters
similarity index 97%
rename from src/decimalConvert/decimalConvert.vcxproj.filters
rename to src/base/decimalConvert/decimalConvert.vcxproj.filters
index 063e28abb..767df5589 100644
--- a/src/decimalConvert/decimalConvert.vcxproj.filters
+++ b/src/base/decimalConvert/decimalConvert.vcxproj.filters
@@ -1,26 +1,26 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
-
-
- Source Files
-
-
- Source Files
-
-
-
-
- Header Files
-
-
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
\ No newline at end of file
diff --git a/src/decimalConvert/decimalConvertReport.cpp b/src/base/decimalConvert/decimalConvertReport.cpp
similarity index 100%
rename from src/decimalConvert/decimalConvertReport.cpp
rename to src/base/decimalConvert/decimalConvertReport.cpp
diff --git a/src/decimalConvert/decimalConvertReport.hpp b/src/base/decimalConvert/decimalConvertReport.hpp
similarity index 100%
rename from src/decimalConvert/decimalConvertReport.hpp
rename to src/base/decimalConvert/decimalConvertReport.hpp
diff --git a/src/abs/abs.cpp b/src/calc/abs/abs.cpp
similarity index 100%
rename from src/abs/abs.cpp
rename to src/calc/abs/abs.cpp
diff --git a/src/abs/abs.vcxproj b/src/calc/abs/abs.vcxproj
similarity index 98%
rename from src/abs/abs.vcxproj
rename to src/calc/abs/abs.vcxproj
index 3a523ef5e..1ad8f3569 100644
--- a/src/abs/abs.vcxproj
+++ b/src/calc/abs/abs.vcxproj
@@ -1,177 +1,177 @@
-
-
-
-
- Debug
- Win32
-
-
- Release
- Win32
-
-
- Debug
- x64
-
-
- Release
- x64
-
-
-
- 16.0
- Win32Proj
- {b0c1ec9c-06cc-47b2-9b93-cd046fc0ef34}
- abs
- 10.0
-
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
- Application
- true
- v143
- Unicode
-
-
- Application
- false
- v143
- true
- Unicode
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
- true
- $(SolutionDir)$(Configuration)\$(ProjectName).build
-
-
- false
- $(SolutionDir)$(Configuration)\$(ProjectName).build
-
-
- true
- $(SolutionDir)$(Configuration)\
- $(SolutionDir)$(Configuration)\$(ProjectName).build\
-
-
- false
- $(SolutionDir)$(Configuration)\
- $(SolutionDir)$(Configuration)\$(ProjectName).build
-
-
-
- Level3
- true
- WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
- true
- true
-
-
-
-
- Level3
- true
- _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
-
-
-
-
- Level3
- true
- true
- true
- NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
- true
- stdcpp20
- $(SolutionDir)\include
- /utf-8 %(AdditionalOptions)
-
-
- Console
- true
- true
- true
-
-
-
-
-
-
-
-
-
-
-
- {0a900aaa-ac12-48cf-85cf-8bb0c0130512}
-
-
- {f6af63f8-9e0f-4da2-89b3-3096b56ba251}
-
-
-
-
-
+
+
+
+
+ Debug
+ Win32
+
+
+ Release
+ Win32
+
+
+ Debug
+ x64
+
+
+ Release
+ x64
+
+
+
+ 16.0
+ Win32Proj
+ {b0c1ec9c-06cc-47b2-9b93-cd046fc0ef34}
+ abs
+ 10.0
+
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+ Application
+ true
+ v143
+ Unicode
+
+
+ Application
+ false
+ v143
+ true
+ Unicode
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ true
+ $(SolutionDir)$(Configuration)\$(ProjectName).build
+
+
+ false
+ $(SolutionDir)$(Configuration)\$(ProjectName).build
+
+
+ true
+ $(SolutionDir)$(Configuration)\
+ $(SolutionDir)$(Configuration)\$(ProjectName).build\
+
+
+ false
+ $(SolutionDir)$(Configuration)\
+ $(SolutionDir)$(Configuration)\$(ProjectName).build
+
+
+
+ Level3
+ true
+ WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+ Level3
+ true
+ _DEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+
+
+
+
+ Level3
+ true
+ true
+ true
+ NDEBUG;_CONSOLE;%(PreprocessorDefinitions)
+ true
+ stdcpp20
+ $(SolutionDir)\include
+ /utf-8 %(AdditionalOptions)
+
+
+ Console
+ true
+ true
+ true
+
+
+
+
+
+
+
+
+
+
+
+ {0a900aaa-ac12-48cf-85cf-8bb0c0130512}
+
+
+ {f6af63f8-9e0f-4da2-89b3-3096b56ba251}
+
+
+
+
+
\ No newline at end of file
diff --git a/src/abs/abs.vcxproj.filters b/src/calc/abs/abs.vcxproj.filters
similarity index 97%
rename from src/abs/abs.vcxproj.filters
rename to src/calc/abs/abs.vcxproj.filters
index baba94f49..8c7a52d20 100644
--- a/src/abs/abs.vcxproj.filters
+++ b/src/calc/abs/abs.vcxproj.filters
@@ -1,26 +1,26 @@
-
-
-
-
- {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
- cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
-
-
- {93995380-89BD-4b04-88EB-625FBE52EBFB}
- h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
-
-
-
-
- Source Files
-
-
- Source Files
-
-
-
-
- Header Files
-
-
+
+
+
+
+ {4FC737F1-C7A5-4376-A066-2A32D752A2FF}
+ cpp;c;cc;cxx;c++;cppm;ixx;def;odl;idl;hpj;bat;asm;asmx
+
+
+ {93995380-89BD-4b04-88EB-625FBE52EBFB}
+ h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd
+
+
+
+
+ Source Files
+
+
+ Source Files
+
+
+
+
+ Header Files
+
+
\ No newline at end of file
diff --git a/src/abs/absReport.cpp b/src/calc/abs/absReport.cpp
similarity index 100%
rename from src/abs/absReport.cpp
rename to src/calc/abs/absReport.cpp
diff --git a/src/abs/absReport.hpp b/src/calc/abs/absReport.hpp
similarity index 100%
rename from src/abs/absReport.hpp
rename to src/calc/abs/absReport.hpp
diff --git a/src/add/add.cpp b/src/calc/add/add.cpp
similarity index 100%
rename from src/add/add.cpp
rename to src/calc/add/add.cpp
diff --git a/src/add/add.vcxproj b/src/calc/add/add.vcxproj
similarity index 100%
rename from src/add/add.vcxproj
rename to src/calc/add/add.vcxproj
diff --git a/src/add/add.vcxproj.filters b/src/calc/add/add.vcxproj.filters
similarity index 100%
rename from src/add/add.vcxproj.filters
rename to src/calc/add/add.vcxproj.filters
diff --git a/src/add/addReport.cpp b/src/calc/add/addReport.cpp
similarity index 100%
rename from src/add/addReport.cpp
rename to src/calc/add/addReport.cpp
diff --git a/src/add/addReport.hpp b/src/calc/add/addReport.hpp
similarity index 100%
rename from src/add/addReport.hpp
rename to src/calc/add/addReport.hpp
diff --git a/src/calc/atan2/atan2.cpp b/src/calc/atan2/atan2.cpp
new file mode 100644
index 000000000..28500c436
--- /dev/null
+++ b/src/calc/atan2/atan2.cpp
@@ -0,0 +1,111 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+/**
+ * @file atan2.cpp
+ * @brief Desciption
+ *
+ * @author Andy Zhang
+ * @date 2nd August 2024
+ */
+
+#include "atan2Report.hpp"
+#include "constants.hpp"
+#include "fn/basicArithm.hpp"
+#include "output.hpp"
+#include "rounding.hpp"
+#include "util.hpp"
+
+#include
+#include
+
+using namespace std::literals;
+using namespace steppable::__internals::arithmetic;
+using namespace steppable::__internals::numUtils;
+using namespace steppable::output;
+
+namespace steppable::__internals::arithmetic
+{
+ std::string atan2(const std::string& y, const std::string& x, const size_t decimals = 10)
+ {
+ // /
+ // | y
+ // | arctan(---) if x > 0, (1)
+ // | x
+ // |
+ // | y
+ // | arctan(---) + pi if x < 0 and y >= 0, (2)
+ // | x
+ // |
+ // | y
+ // | arctan(---) - pi if x < 0 and y < 0, (3)
+ // | x
+ // |
+ // atan2(x, y) = <
+ // | pi
+ // | ----- if x = 0 and y > 0, (4)
+ // | 2
+ // |
+ // | pi
+ // | - ----- if x = 0 and y < 0, (5)
+ // | 2
+ // |
+ // | undefined if x = 0 and y = 0. (6)
+ // \
+
+ // (6)
+ if (isZeroString(x) and isZeroString(y)) [[unlikely]]
+ {
+ error("atan2"s, "atan2 is not defined here."s);
+ return "Undefined";
+ }
+
+ // (4)
+ if (isZeroString(x) and compare(y, "0", 0) == "1") [[unlikely]]
+ return roundOff(static_cast(constants::PI_OVER_2), decimals);
+
+ // (5)
+ if (isZeroString(x) and compare(y, "0", 0) == "0") [[unlikely]]
+ return "-" + roundOff(static_cast(constants::PI_OVER_2), decimals);
+
+ const auto& yOverX = divide(y, x, 0, static_cast(decimals + 2));
+ const auto& atanYOverX = atan(yOverX, static_cast(decimals + 2));
+
+ // (1)
+ if (compare(x, "0", 0) == "1") [[likely]]
+ return atanYOverX;
+ // (2)
+ if (compare(x, "0", 0) == "0" and compare(y, "0", 0) != "0") [[likely]]
+ return add(atanYOverX, static_cast(constants::PI), 0);
+ // (3)
+ if (compare(x, "0", 0) == "0" and compare(y, "0", 0) == "0") [[likely]]
+ return subtract(atanYOverX, static_cast(constants::PI), 0);
+
+ return "Impossible! How did you get here?";
+ }
+} // namespace steppable::__internals::arithmetic
+
+int main(int argc, const char* argv[])
+{
+ std::cout << atan2("12", "10", 5) << "\n";
+ return 0;
+}
diff --git a/src/calc/atan2/atan2Report.cpp b/src/calc/atan2/atan2Report.cpp
new file mode 100644
index 000000000..8ab4038bf
--- /dev/null
+++ b/src/calc/atan2/atan2Report.cpp
@@ -0,0 +1,39 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+/**
+ * @file atan2Report.cpp
+ * @brief Desciption
+ *
+ * @author Andy Zhang
+ * @date 2nd August 2024
+ */
+
+#include "atan2Report.hpp"
+
+#include
+
+std::string reportAtan2()
+{
+ // Intentionally not implemented.
+ return "";
+}
diff --git a/src/calc/atan2/atan2Report.hpp b/src/calc/atan2/atan2Report.hpp
new file mode 100644
index 000000000..0fb4aaa6d
--- /dev/null
+++ b/src/calc/atan2/atan2Report.hpp
@@ -0,0 +1,33 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+/**
+ * @file atan2Report.hpp
+ * @brief Desciption
+ *
+ * @author Andy Zhang
+ * @date 2nd August 2024
+ */
+
+#include
+
+std::string reportAtan2();
diff --git a/src/comparison/comparison.cpp b/src/calc/comparison/comparison.cpp
similarity index 100%
rename from src/comparison/comparison.cpp
rename to src/calc/comparison/comparison.cpp
diff --git a/src/comparison/comparison.vcxproj b/src/calc/comparison/comparison.vcxproj
similarity index 100%
rename from src/comparison/comparison.vcxproj
rename to src/calc/comparison/comparison.vcxproj
diff --git a/src/comparison/comparison.vcxproj.filters b/src/calc/comparison/comparison.vcxproj.filters
similarity index 100%
rename from src/comparison/comparison.vcxproj.filters
rename to src/calc/comparison/comparison.vcxproj.filters
diff --git a/src/comparison/comparisonReport.cpp b/src/calc/comparison/comparisonReport.cpp
similarity index 100%
rename from src/comparison/comparisonReport.cpp
rename to src/calc/comparison/comparisonReport.cpp
diff --git a/src/comparison/comparisonReport.hpp b/src/calc/comparison/comparisonReport.hpp
similarity index 100%
rename from src/comparison/comparisonReport.hpp
rename to src/calc/comparison/comparisonReport.hpp
diff --git a/src/division/division.cpp b/src/calc/division/division.cpp
similarity index 100%
rename from src/division/division.cpp
rename to src/calc/division/division.cpp
diff --git a/src/division/division.vcxproj b/src/calc/division/division.vcxproj
similarity index 100%
rename from src/division/division.vcxproj
rename to src/calc/division/division.vcxproj
diff --git a/src/division/division.vcxproj.filters b/src/calc/division/division.vcxproj.filters
similarity index 100%
rename from src/division/division.vcxproj.filters
rename to src/calc/division/division.vcxproj.filters
diff --git a/src/division/divisionReport.cpp b/src/calc/division/divisionReport.cpp
similarity index 100%
rename from src/division/divisionReport.cpp
rename to src/calc/division/divisionReport.cpp
diff --git a/src/division/divisionReport.hpp b/src/calc/division/divisionReport.hpp
similarity index 100%
rename from src/division/divisionReport.hpp
rename to src/calc/division/divisionReport.hpp
diff --git a/src/factorial/factorial.cpp b/src/calc/factorial/factorial.cpp
similarity index 100%
rename from src/factorial/factorial.cpp
rename to src/calc/factorial/factorial.cpp
diff --git a/src/factorial/factorial.vcxproj b/src/calc/factorial/factorial.vcxproj
similarity index 100%
rename from src/factorial/factorial.vcxproj
rename to src/calc/factorial/factorial.vcxproj
diff --git a/src/factorial/factorial.vcxproj.filters b/src/calc/factorial/factorial.vcxproj.filters
similarity index 100%
rename from src/factorial/factorial.vcxproj.filters
rename to src/calc/factorial/factorial.vcxproj.filters
diff --git a/src/factorial/factorialReport.cpp b/src/calc/factorial/factorialReport.cpp
similarity index 100%
rename from src/factorial/factorialReport.cpp
rename to src/calc/factorial/factorialReport.cpp
diff --git a/src/factorial/factorialReport.hpp b/src/calc/factorial/factorialReport.hpp
similarity index 100%
rename from src/factorial/factorialReport.hpp
rename to src/calc/factorial/factorialReport.hpp
diff --git a/src/hyp/hyp.cpp b/src/calc/hyp/hyp.cpp
similarity index 100%
rename from src/hyp/hyp.cpp
rename to src/calc/hyp/hyp.cpp
diff --git a/src/hyp/hypReport.cpp b/src/calc/hyp/hypReport.cpp
similarity index 100%
rename from src/hyp/hypReport.cpp
rename to src/calc/hyp/hypReport.cpp
diff --git a/src/hyp/hypReport.hpp b/src/calc/hyp/hypReport.hpp
similarity index 100%
rename from src/hyp/hypReport.hpp
rename to src/calc/hyp/hypReport.hpp
diff --git a/src/log/log.cpp b/src/calc/log/log.cpp
similarity index 74%
rename from src/log/log.cpp
rename to src/calc/log/log.cpp
index 5d8a678d1..ff5e15afa 100644
--- a/src/log/log.cpp
+++ b/src/calc/log/log.cpp
@@ -31,13 +31,11 @@
#include "argParse.hpp"
#include "fn/basicArithm.hpp"
#include "getString.hpp"
-#include "logReport.hpp"
#include "output.hpp"
#include "rounding.hpp"
#include "util.hpp"
#include
-#include
#include
using namespace steppable::__internals::arithmetic;
@@ -47,49 +45,60 @@ using namespace std::literals;
namespace steppable::__internals::arithmetic
{
- std::string _log(const std::string& _number, const size_t _decimals)
+ std::string _log(const std::string& x, const size_t _decimals)
{
+ const auto& decimals = _decimals + 2;
// Zero check
- if (numUtils::isZeroString(_number))
+ if (numUtils::isZeroString(x))
{
output::error("log::_log"s, "The number cannot be zero."s);
return "-Infinity";
}
- if (compare(_number, "1", 0) == "2")
+ if (compare(x, "1", 0) == "2")
return "0";
- // /-\ +--------------------------------------------+
- // / ! \ | WARNING: DO NOT CALL THIS METHOD DIRECTLY! |
- // /-----\ +--------------------------------------------+
- // TODO: Improve accuracy.
- // 4 3 2
- // (x - 1)(137x + 1762x + 3762x + 1762x + 137)
- // ln(x) = ------------------------------------------------
- // 5 4 3 2
- // 30(x + 25x + 100x + 100x + 25x + 1)
-
- auto x2 = power(_number, "2", 0);
- auto x3 = power(_number, "3", 0);
- auto x4 = multiply(x2, x2, 0);
- auto x5 = multiply(x2, x3, 0);
-
- auto xMinus1 = subtract(_number, "1", 0);
- auto numerator = multiply(x4, "137", 0);
- numerator = add(numerator, multiply(x3, "1762", 0), 0);
- numerator = add(numerator, multiply(x2, "3762", 0), 0);
- numerator = add(numerator, multiply(_number, "1762", 0), 0);
- numerator = add(numerator, "137", 0);
- numerator = multiply(xMinus1, numerator, 0);
-
- auto denominator = add(x5, multiply(x4, "25", 0), 0);
- denominator = add(denominator, multiply(x3, "100", 0), 0);
- denominator = add(denominator, multiply(x2, "100", 0), 0);
- denominator = add(denominator, multiply(_number, "25", 0), 0);
+ // ROUND 1 -- Padé approximant
+ // 2
+ // 3 * (x + 1) * (x - 1) 3 * (x - 1)
+ // ln(x) = ----------------------- = --------------
+ // 2 2
+ // x + 4x + 1 x + 4x + 1
+ const auto& x2 = power(x, "2", 0);
+ const auto& x2Minus1 = subtract(x2, "1", 0);
+ const auto& numerator = multiply("3", x2Minus1, 0);
+ const auto& fourX = multiply(x, "4", 0);
+
+ auto denominator = add(x2, fourX, 0);
denominator = add(denominator, "1", 0);
- denominator = multiply("30", denominator, 0);
- auto result = divide(numerator, denominator, 0, static_cast(_decimals));
- return result;
+ // ROUND 2 -- Newton's Method
+ // x - exp(y )
+ // n
+ // y = y + 2 * --------------
+ // n + 1 n x + exp(y )
+ // n
+
+ // ln(x) = y
+ // n + 1
+
+ const auto& epsilon = "0." + std::string(_decimals + 1, '0') + "1";
+ auto yn = divide(numerator, denominator, 0, static_cast(decimals));
+ auto yn1 = yn;
+
+ auto error = abs(subtract(yn, yn1, 0), 0);
+ do // NOLINT(cppcoreguidelines-avoid-do-while)
+ {
+ yn = yn1;
+ auto expYN = exp(yn, decimals);
+ auto xMinusExpYN = subtract(x, expYN, 0);
+ auto xPlusExpYN = add(x, expYN, 0);
+ auto fraction = divide(xMinusExpYN, xPlusExpYN, 0, static_cast(decimals));
+ auto twoXFraction = multiply(fraction, "2", 0);
+ yn1 = add(yn, twoXFraction, 0);
+ error = abs(subtract(yn, yn1, 0), 0);
+ } while (compare(error, epsilon, 0) == "1");
+
+ return numUtils::roundOff(yn1, _decimals);
}
// Common logarithms
diff --git a/src/log/logReport.cpp b/src/calc/log/logReport.cpp
similarity index 100%
rename from src/log/logReport.cpp
rename to src/calc/log/logReport.cpp
diff --git a/src/log/logReport.hpp b/src/calc/log/logReport.hpp
similarity index 100%
rename from src/log/logReport.hpp
rename to src/calc/log/logReport.hpp
diff --git a/src/multiply/multiply.cpp b/src/calc/multiply/multiply.cpp
similarity index 100%
rename from src/multiply/multiply.cpp
rename to src/calc/multiply/multiply.cpp
diff --git a/src/multiply/multiply.vcxproj b/src/calc/multiply/multiply.vcxproj
similarity index 100%
rename from src/multiply/multiply.vcxproj
rename to src/calc/multiply/multiply.vcxproj
diff --git a/src/multiply/multiply.vcxproj.filters b/src/calc/multiply/multiply.vcxproj.filters
similarity index 100%
rename from src/multiply/multiply.vcxproj.filters
rename to src/calc/multiply/multiply.vcxproj.filters
diff --git a/src/multiply/multiplyReport.cpp b/src/calc/multiply/multiplyReport.cpp
similarity index 100%
rename from src/multiply/multiplyReport.cpp
rename to src/calc/multiply/multiplyReport.cpp
diff --git a/src/multiply/multiplyReport.hpp b/src/calc/multiply/multiplyReport.hpp
similarity index 100%
rename from src/multiply/multiplyReport.hpp
rename to src/calc/multiply/multiplyReport.hpp
diff --git a/src/power/power.cpp b/src/calc/power/power.cpp
similarity index 93%
rename from src/power/power.cpp
rename to src/calc/power/power.cpp
index b14f546dd..b2aedd879 100644
--- a/src/power/power.cpp
+++ b/src/calc/power/power.cpp
@@ -28,10 +28,12 @@
* @date 8rd November 2023
*/
#include "argParse.hpp"
+#include "constants.hpp"
#include "fn/basicArithm.hpp"
#include "fraction.hpp"
#include "getString.hpp"
#include "powerReport.hpp"
+#include "rounding.hpp"
#include "symbols.hpp"
#include "util.hpp"
@@ -116,6 +118,21 @@ namespace steppable::__internals::arithmetic
}
return reportPower(number, raiseTo, numberTrailingZeros, negative, steps);
}
+
+ std::string exp(const std::string& x, const size_t decimals)
+ {
+ constexpr size_t iter = 200;
+ std::string sum = "1";
+ std::string term = "1";
+ for (size_t i = 1; i < iter; i++)
+ {
+ std::string frac = divide(x, std::to_string(i), 0, static_cast(decimals));
+ term = multiply(term, frac, 0);
+ sum = add(sum, term, 0);
+ }
+
+ return sum;
+ }
} // namespace steppable::__internals::arithmetic
#ifndef NO_MAIN
diff --git a/src/power/power.vcxproj b/src/calc/power/power.vcxproj
similarity index 100%
rename from src/power/power.vcxproj
rename to src/calc/power/power.vcxproj
diff --git a/src/power/power.vcxproj.filters b/src/calc/power/power.vcxproj.filters
similarity index 100%
rename from src/power/power.vcxproj.filters
rename to src/calc/power/power.vcxproj.filters
diff --git a/src/power/powerReport.cpp b/src/calc/power/powerReport.cpp
similarity index 100%
rename from src/power/powerReport.cpp
rename to src/calc/power/powerReport.cpp
diff --git a/src/power/powerReport.hpp b/src/calc/power/powerReport.hpp
similarity index 100%
rename from src/power/powerReport.hpp
rename to src/calc/power/powerReport.hpp
diff --git a/src/root/root.cpp b/src/calc/root/root.cpp
similarity index 99%
rename from src/root/root.cpp
rename to src/calc/root/root.cpp
index b3d265d33..4f9dc816a 100644
--- a/src/root/root.cpp
+++ b/src/calc/root/root.cpp
@@ -108,7 +108,7 @@ namespace steppable::__internals::arithmetic
auto test = power(radicand, base, 0);
if (compare(newAvg, "0", 0) == "2" or compare(test, number, 0) == "2")
- return roundDown(numUtils::roundOff(radicand, 1));
+ return roundDown(roundOff(radicand, 1));
if (compare(test, number, 0) == "1")
x = radicand;
else if (compare(test, number, 0) == "0")
diff --git a/src/root/root.vcxproj b/src/calc/root/root.vcxproj
similarity index 100%
rename from src/root/root.vcxproj
rename to src/calc/root/root.vcxproj
diff --git a/src/root/root.vcxproj.filters b/src/calc/root/root.vcxproj.filters
similarity index 100%
rename from src/root/root.vcxproj.filters
rename to src/calc/root/root.vcxproj.filters
diff --git a/src/root/rootReport.cpp b/src/calc/root/rootReport.cpp
similarity index 100%
rename from src/root/rootReport.cpp
rename to src/calc/root/rootReport.cpp
diff --git a/src/root/rootReport.hpp b/src/calc/root/rootReport.hpp
similarity index 100%
rename from src/root/rootReport.hpp
rename to src/calc/root/rootReport.hpp
diff --git a/src/subtract/subtract.cpp b/src/calc/subtract/subtract.cpp
similarity index 100%
rename from src/subtract/subtract.cpp
rename to src/calc/subtract/subtract.cpp
diff --git a/src/subtract/subtract.vcxproj b/src/calc/subtract/subtract.vcxproj
similarity index 100%
rename from src/subtract/subtract.vcxproj
rename to src/calc/subtract/subtract.vcxproj
diff --git a/src/subtract/subtract.vcxproj.filters b/src/calc/subtract/subtract.vcxproj.filters
similarity index 100%
rename from src/subtract/subtract.vcxproj.filters
rename to src/calc/subtract/subtract.vcxproj.filters
diff --git a/src/subtract/subtractReport.cpp b/src/calc/subtract/subtractReport.cpp
similarity index 100%
rename from src/subtract/subtractReport.cpp
rename to src/calc/subtract/subtractReport.cpp
diff --git a/src/subtract/subtractReport.hpp b/src/calc/subtract/subtractReport.hpp
similarity index 100%
rename from src/subtract/subtractReport.hpp
rename to src/calc/subtract/subtractReport.hpp
diff --git a/src/trig/trig.cpp b/src/calc/trig/trig.cpp
similarity index 85%
rename from src/trig/trig.cpp
rename to src/calc/trig/trig.cpp
index c4e52f3d9..7eb1203c7 100644
--- a/src/trig/trig.cpp
+++ b/src/calc/trig/trig.cpp
@@ -31,6 +31,7 @@
#include "argParse.hpp"
#include "constants.hpp"
#include "fn/basicArithm.hpp"
+#include "fn/calculus.hpp"
#include "getString.hpp"
#include "rounding.hpp"
#include "trigReport.hpp"
@@ -109,7 +110,7 @@ namespace steppable::__internals::arithmetic
// %@%&&&%%&&&. .&*@@@@@@@@& | Henri Padé |
// %&%&&&%&&&%&@&@@@@@@@@@@@ +------------+
- if (compare(abs(x, 0), "0.01", 0) == "0") // If small, use polynomial approximant
+ if (compare(abs(x, 0), "0.001", 0) == "0") // If small, use polynomial approximant
{
// double x2 = x * x;
auto x2 = multiply(x, x, 0);
@@ -304,27 +305,26 @@ namespace steppable::__internals::arithmetic
// Reduce x to a small number
x = divide("1", x, 0, decimals * 2);
}
- // Otherwise, use Padé series.
- // (https://journalofinequalitiesandapplications.springeropen.com/articles/10.1186/s13660-017-1310-6/tables/1)
- // 3
- // 55x + 105x
- // ------------------ ~= arctan(x)
- // 4 2
- // 9x + 90x + 105
- auto x2 = power(x, "2", 0);
- auto x3 = multiply(x2, x, 0); // Use multiply to reduce the number of operations.
- auto x4 = multiply(x3, x, 0);
- auto numerator = add(multiply("55", x3, 0), multiply("105", x, 0), 0);
- auto denominator = add(add(x4, multiply("90", x2, 0), 0), "105", 0);
- auto result = standardizeNumber(divide(numerator, denominator, 0, decimals * 2));
-
+ // Otherwise, use integration.
+ // 1 / x
+ // d --------- ==> | 1
+ // ---- arctan(x) = 2 arctan(x) = | ---------- dt
+ // dx x + 1 | 2
+ // / 0 t + 1
+ auto fx = [&](const std::string& y) {
+ const auto& y2 = power(y, "2", 0);
+ const auto& denominator = add(y2, "1", 0);
+ return divide("1", denominator, 0, decimals + 1);
+ };
+ auto result = calculus::romberg(fx, "0", x, 10, decimals + 1);
if (isReduced)
{
// If x was reduced, use the identity
- // arctan(1/x) = pi/2 - arctan(x)
+ // pi 1
+ // arctan(x) = ---- - arctan(---)
+ // 2 x
result = subtract(static_cast(constants::PI_OVER_2), result, 0);
}
- result = roundOff(result, decimals);
// Convert the result as needed.
switch (mode)
@@ -339,7 +339,9 @@ namespace steppable::__internals::arithmetic
break;
}
- return result;
+ if (_x.front() == '-')
+ result = "-" + result;
+ return roundOff(result, decimals);
}
std::string asin(const std::string& x, const int decimals, const int mode)
@@ -352,49 +354,21 @@ namespace steppable::__internals::arithmetic
if (compare(abs(x, 0), "0", 0) == "2")
return "0";
- auto x2 = power(x, "2", 0);
- auto x3 = multiply(x2, x, 0);
- auto x5 = multiply(x3, x2, 0);
- auto x7 = multiply(x5, x2, 0);
- std::string onePlusX;
- std::string oneMinusX;
- std::string sqrtOnePlusX;
- std::string sqrtOneMinusX;
- std::string result;
-
- // For x <= 0.5, use Taylor series.
- // 3 5 7
- // x 3x 5x
- // arcsin(x) = x + --- + ---- + -----
- // 6 40 112
- if (compare(abs(x, 0), "0.5", 0) != "1")
- {
- result = add(x, divide(x3, "6", 0), 0);
- result = add(result, divide(multiply(x5, "3", 0), "40", 0), 0);
- result = add(result, divide(multiply(x7, "5", 0), "112", 0), 0);
- goto out; // NOLINT(cppcoreguidelines-avoid-goto)
- }
+ // / x
+ // | 1
+ // | ---------------- dy
+ // | /------|
+ // | / 2
+ // | \/ 1 - y
+ // / 0
+ auto integrand = [&](const std::string& y) {
+ auto y2 = power(y, "2", 0);
+ auto oneMinusY2 = subtract("1", y2, 0);
+ auto denominator = root(oneMinusY2, "2", decimals + 1);
+ return divide("1", denominator, 0, decimals + 1);
+ };
+ auto result = calculus::romberg(integrand, "0", x, 10, decimals + 2);
- // Othman, S. B.; Bagul, Y. J. An Innovative Method for Approximating Arcsine Function. Preprints 2022,
- // 2022070388. https://doi.org/10.20944/preprints202207.0388.v1
- //
- // /-----| /-----| 5 3
- // arcsin(x) = 2 * 0.510774109 * (\/ 1 + x − \/ 1 − x ) + (0.239x − 0.138x + 0.005x)
- //
- // /-----| /-----| 5 3
- // = 1.021548218 * (\/ 1 + x − \/ 1 − x ) + (0.239x − 0.138x + 0.005x)
-
- onePlusX = add("1", x, 0);
- oneMinusX = subtract("1", x, 0);
- sqrtOnePlusX = root(onePlusX, "2", static_cast(decimals) * 2);
- sqrtOneMinusX = root(oneMinusX, "2", static_cast(decimals) * 2);
-
- result = multiply("1.021548218", subtract(sqrtOnePlusX, sqrtOneMinusX, 0), 0);
- result = add(result,
- add(multiply("0.239", x5, 0), subtract(multiply("0.138", x3, 0), multiply("0.005", x, 0), 0), 0),
- 0);
-
- out:
switch (mode)
{
case 1:
@@ -483,7 +457,7 @@ int main(int _argc, const char* _argv[])
Utf8CodePage _;
ProgramArgs program(_argc, _argv);
program.addPosArg('c', $("trig", "47dcf91b-847c-48f0-9889-f5ce1b6831e3"), false);
- program.addPosArg('n', $("trig", "bcd0a3e9-3d89-4921-94b3-d7533d60911f"), false);
+ program.addPosArg('n', $("trig", "bcd0a3e9-3d89-4921-94b3-d7533d60911f"));
program.addKeywordArg("mode", 0, $("trig", "03fdd1f2-6ea5-49d4-ac3f-27f01f04a518"));
program.addKeywordArg("decimals", 5, $("trig", "d1df3b60-dac1-496c-99bb-ba763dc551df"));
program.addSwitch("profile", false, $("trig", "162adb13-c4b2-4418-b3df-edb6f9355d64"));
diff --git a/src/trig/trig.vcxproj b/src/calc/trig/trig.vcxproj
similarity index 100%
rename from src/trig/trig.vcxproj
rename to src/calc/trig/trig.vcxproj
diff --git a/src/trig/trig.vcxproj.filters b/src/calc/trig/trig.vcxproj.filters
similarity index 100%
rename from src/trig/trig.vcxproj.filters
rename to src/calc/trig/trig.vcxproj.filters
diff --git a/src/trig/trigReport.cpp b/src/calc/trig/trigReport.cpp
similarity index 100%
rename from src/trig/trigReport.cpp
rename to src/calc/trig/trigReport.cpp
diff --git a/src/trig/trigReport.hpp b/src/calc/trig/trigReport.hpp
similarity index 100%
rename from src/trig/trigReport.hpp
rename to src/calc/trig/trigReport.hpp
diff --git a/src/calculus/nInt/nInt.cpp b/src/calculus/nInt/nInt.cpp
new file mode 100644
index 000000000..8982c5d44
--- /dev/null
+++ b/src/calculus/nInt/nInt.cpp
@@ -0,0 +1,89 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+#include "fn/basicArithm.hpp"
+#include "output.hpp"
+#include "rounding.hpp"
+
+#include
+#include
+#include
+#include
+
+using namespace steppable::__internals::arithmetic;
+using namespace steppable::__internals::numUtils;
+using namespace std::literals;
+
+namespace steppable::__internals::calculus
+{
+ std::string romberg(const std::function& f,
+ const std::string& a,
+ const std::string& b,
+ const int max_steps,
+ const int decimals)
+ {
+ auto acc = "0." + std::string(decimals - 1, '0') + "1";
+ auto previous = std::vector(max_steps, "0"s);
+ auto current = std::vector(max_steps, "0"s);
+
+ auto h = subtract(b, a, 0);
+ auto fAB = add(f(a), f(b), 0);
+ auto halfH = multiply(h, "0.5", 0);
+ previous.front() = multiply(halfH, fAB, 0);
+
+ for (int i = 1; i < max_steps; i++)
+ {
+ h = multiply(h, "0.5", 0);
+ auto c = "0"s;
+ long ep = 1 << (i - 1); // 2^(i - 1)
+ for (long j = 1; j < (ep + 1); j++)
+ {
+ auto d = multiply(std::to_string((2 * j) - 1), h, 0);
+ c = add(c, f(add(a, d, 0)), 0);
+ }
+ current.front() = add(multiply(h, c, 0), multiply("0.5", previous.front(), 0), 0);
+
+ for (int j = 1; j < (i + 1); j++)
+ {
+ long double n_k = pow(4, j);
+ auto one = multiply(std::to_string(n_k), current.at(j - 1), 0);
+ auto top = subtract(one, previous.at(j - 1), 0);
+ current.at(j) = divide(top, std::to_string(n_k - 1), 0, decimals + 1);
+
+ if (i > 1 and compare(abs(subtract(previous.at(i - 1), current.at(i), 0), 0), acc, 0) == "0")
+ return roundOff(current.at(i), decimals);
+ }
+
+ std::ranges::swap(previous, current);
+ }
+
+ return roundOff(previous.at(max_steps - 1), decimals);
+ }
+} // namespace steppable::__internals::calculus
+
+#ifndef NO_MAIN
+int main()
+{
+ steppable::output::error("calculus::nInt"s, "This program should not be run directly."s);
+ return 1;
+}
+#endif
diff --git a/src/calculus/nInt/nIntReport.cpp b/src/calculus/nInt/nIntReport.cpp
new file mode 100644
index 000000000..92b10dd07
--- /dev/null
+++ b/src/calculus/nInt/nIntReport.cpp
@@ -0,0 +1,31 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+#include "nIntReport.hpp"
+
+#include
+
+std::string reportNInt()
+{
+ // Intentionally not implemented.
+ return "";
+}
diff --git a/src/calculus/nInt/nIntReport.hpp b/src/calculus/nInt/nIntReport.hpp
new file mode 100644
index 000000000..aaeef0bf5
--- /dev/null
+++ b/src/calculus/nInt/nIntReport.hpp
@@ -0,0 +1,27 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+#pragma once
+
+#include
+
+std::string reportNInt();
diff --git a/src/constants.cpp b/src/constants.cpp
new file mode 100644
index 000000000..8e3e6e06c
--- /dev/null
+++ b/src/constants.cpp
@@ -0,0 +1,41 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+#include "constants.hpp"
+
+#include
+
+// NOLINTBEGIN(cert-err58-cpp)
+namespace steppable::constants
+{
+ const std::string_view& PI =
+ "3.1415926535897932384626433832795028841971693993751058209749445923078164062862089986280348253421170679";
+ const std::string_view& TWO_PI = "6.283185307179586231995926937088370323181152343750";
+ const std::string_view& PI_OVER_2 =
+ "1.570796326794896619231321691639751442098584699687552910487472296153908203143104499314017412835292542";
+ const std::string_view& PI_OVER_180 =
+ "0.01745329251994329508887757482524547311994764539930555555555555555555555555555555555555555555555555556";
+ const std::string_view& PI_OVER_200 =
+ "0.01570796326794896619231321691639716312084074699687552942986246296153903203140449499314017412671058534";
+ const std::string_view& E = "2.718281828459045090795598298427648842334747314453125";
+} // namespace steppable::constants
+// NOLINTEND(cert-err58-cpp)
diff --git a/src/getString.cpp b/src/getString.cpp
index 6fcc64391..991787ae7 100644
--- a/src/getString.cpp
+++ b/src/getString.cpp
@@ -59,8 +59,8 @@ namespace steppable::localization
else
return "en-US";
#else
- std::string langC = getenv("LANG"); // NOLINT(concurrency-mt-unsafe)
- if (not langC.empty())
+ char* langC = getenv("LANG"); // NOLINT(concurrency-mt-unsafe)
+ if (langC != nullptr)
lang = langC;
// If the language contains a period, remove everything after the period. Eg., en-US.UTF-8 -> en-US
diff --git a/src/symbols.cpp b/src/symbols.cpp
index bb3f2663f..d71b01539 100644
--- a/src/symbols.cpp
+++ b/src/symbols.cpp
@@ -128,7 +128,7 @@ namespace steppable::__internals::symbols
const std::array& SUPERSCRIPTS = { "\u2070", "\u00b9", "\u00b2", "\u00b3", "\u2074",
"\u2075", "\u2076", "\u2077", "\u2078", "\u2079" };
- std::string makeSubscript(const std::string& normal)
+ [[deprecated("Use steppable::prettyPrint instead")]] std::string makeSubscript(const std::string& normal)
{
std::string out;
for (const char c : normal)
@@ -136,9 +136,12 @@ namespace steppable::__internals::symbols
return out;
}
- std::string makeSubscript(const int normal) { return unicodeToUtf8(normal + SUB_MAGIC_NUMBER); }
+ [[deprecated("Use steppable::prettyPrint instead")]] std::string makeSubscript(const int normal)
+ {
+ return unicodeToUtf8(normal + SUB_MAGIC_NUMBER);
+ }
- std::string makeSuperscript(const std::string& normal)
+ [[deprecated("Use steppable::prettyPrint instead")]] std::string makeSuperscript(const std::string& normal)
{
std::stringstream ss;
for (const char c : normal)
@@ -150,7 +153,7 @@ namespace steppable::__internals::symbols
return string;
}
- std::string makeSuperscript(const char normal)
+ [[deprecated("Use steppable::prettyPrint instead")]] std::string makeSuperscript(const char normal)
{
if (normal == '-')
return "\u207B";
@@ -158,7 +161,7 @@ namespace steppable::__internals::symbols
return SUPERSCRIPTS.at(normal - '0');
}
- std::string makeSurd(const std::string& radicand)
+ [[deprecated("Use steppable::prettyPrint instead")]] std::string makeSurd(const std::string& radicand)
{
std::stringstream ss;
ss << SURD;
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index 94807f84f..c59da2df3 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -24,7 +24,7 @@ ENABLE_TESTING()
FOREACH(ITEM IN LISTS TEST_TARGETS)
ADD_EXECUTABLE(${ITEM} ${ITEM}.cpp)
- TARGET_LINK_LIBRARIES(${ITEM} PRIVATE calc)
+ TARGET_LINK_LIBRARIES(${ITEM} PRIVATE func)
ADD_TEST(NAME ${ITEM} COMMAND ${CMAKE_BINARY_DIR}/tests/${ITEM})
MESSAGE(TRACE "Added test case: ${ITEM}: ${ITEM}.cpp")
ENDFOREACH()
diff --git a/tests/testAtan2.cpp b/tests/testAtan2.cpp
new file mode 100644
index 000000000..31453bc05
--- /dev/null
+++ b/tests/testAtan2.cpp
@@ -0,0 +1,32 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+#include "colors.hpp"
+#include "output.hpp"
+#include "testing.hpp"
+#include "util.hpp"
+
+#include
+#include
+
+TEST_START()
+TEST_END()
diff --git a/tests/testHyp.cpp b/tests/testHyp.cpp
index c3b9cf660..28e16f14b 100644
--- a/tests/testHyp.cpp
+++ b/tests/testHyp.cpp
@@ -66,7 +66,7 @@ _.assertIsEqual(acosh("1.25", 4), "0.6931");
SECTION_END()
SECTION(Test inverse hyperbolic tangent)
-_.assertIsEqual(atanh("0.75", 4), "0.9725");
+_.assertIsEqual(atanh("0.75", 4), "0.9730");
SECTION_END()
SECTION(Test inverse hyperbolic cotangent)
@@ -79,7 +79,7 @@ _.assertIsEqual(asech("0.75", 4), "0.7953");
SECTION_END()
SECTION(Test inverse hyperbolic cosecant)
-_.assertIsEqual(acsch("0.25", 4), "2.0929");
+_.assertIsEqual(acsch("0.25", 4), "2.0947");
SECTION_END()
TEST_END()
diff --git a/tests/testLog.cpp b/tests/testLog.cpp
index b8a9d48f8..e8a36066f 100644
--- a/tests/testLog.cpp
+++ b/tests/testLog.cpp
@@ -33,7 +33,7 @@ TEST_START()
using namespace steppable::__internals::arithmetic;
SECTION(Test natural logarithm)
-_.assertIsEqual(ln("5.3", 4), "1.6675");
+_.assertIsEqual(ln("5.3", 4), "1.6677");
SECTION_END()
TEST_END()
diff --git a/tests/testNInt.cpp b/tests/testNInt.cpp
new file mode 100644
index 000000000..fb654a950
--- /dev/null
+++ b/tests/testNInt.cpp
@@ -0,0 +1,43 @@
+/**************************************************************************************************
+ * Copyright (c) 2023-2024 NWSOFT *
+ * *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy *
+ * of this software and associated documentation files (the "Software"), to deal *
+ * in the Software without restriction, including without limitation the rights *
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
+ * copies of the Software, and to permit persons to whom the Software is *
+ * furnished to do so, subject to the following conditions: *
+ * *
+ * The above copyright notice and this permission notice shall be included in all *
+ * copies or substantial portions of the Software. *
+ * *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
+ * SOFTWARE. *
+ **************************************************************************************************/
+
+#include "colors.hpp"
+#include "fn/basicArithm.hpp"
+#include "fn/calculus.hpp"
+#include "output.hpp"
+#include "testing.hpp"
+#include "util.hpp"
+
+#include
+#include
+
+using namespace steppable::__internals::calculus;
+using namespace steppable::__internals::arithmetic;
+
+TEST_START()
+
+SECTION(Test Numerical Integration)
+const auto& result = romberg([](const std::string& x) { return add("1", multiply(x, "2", 0), 0); }, "0", "1", 10, 3);
+_.assertIsEqual(result, "2.000");
+SECTION_END()
+
+TEST_END()
diff --git a/tests/testTrig.cpp b/tests/testTrig.cpp
index 800b2ef6c..46a8d3f11 100644
--- a/tests/testTrig.cpp
+++ b/tests/testTrig.cpp
@@ -45,19 +45,20 @@ _.assertIsEqual(tan("90", 2, 1), "Infinity");
SECTION_END()
SECTION(Test arc cosine)
-_.assertIsEqual(acos("0.5", 2, 1), "60");
+_.assertIsEqual(acos("0.5", 2, 1), "60.00");
// Zero check test
_.assertIsEqual(acos("1", 2, 1), "0");
SECTION_END()
SECTION(Test arc sine)
-_.assertIsEqual(asin("0.5", 2, 1), "30.00");
+_.assertIsEqual(asin("0.5", 0, 1), "30");
// Zero check test
_.assertIsEqual(asin("0", 2, 1), "0");
SECTION_END()
SECTION(Test arc tangent)
_.assertIsEqual(atan("0", 2, 1), "0");
+_.assertIsEqual(atan("1", 20, 0), "0.78539816339744830962");
SECTION_END()
TEST_END()
diff --git a/tools/add_copyright_header.py b/tools/add_copyright_header.py
index 4448b860f..2f7137a9f 100644
--- a/tools/add_copyright_header.py
+++ b/tools/add_copyright_header.py
@@ -158,6 +158,9 @@ def process(file: Path) -> None:
Process the file, adding or updating the header if necessary.
:param file: The file to process.
"""
+ if "imgui" in file.as_posix():
+ return
+
if (
file.suffix in (".cpp", ".hpp") # C++ Source / Header
or file.name == "cpp.hint" # C++ Hint file
diff --git a/tools/new_component.py b/tools/new_component.py
index 85839b9d9..94c873b56 100644
--- a/tools/new_component.py
+++ b/tools/new_component.py
@@ -139,7 +139,13 @@ def make_dir(name: str, date: str, author: str) -> None:
:param date: The date of creation.
:param author: The author of the component.
"""
- path: Path = SRC_DIR / name
+
+ parts = name.split("::")
+ if len(parts) != 2:
+ print("ERROR: Name format is incorrect. Should be a::b.")
+ origin = parts[0]
+ name = parts[1]
+ path: Path = SRC_DIR / origin / name
if not path.is_dir():
path.mkdir(exist_ok=False)
@@ -185,10 +191,13 @@ def make_dir(name: str, date: str, author: str) -> None:
#include "{name}Report.hpp"
#include
-std::string {name}(/* Arguments... */)
+namespace steppable::__internals::arithmetic
{BRACE}
- // Your code here...
-{END_BRACE}
+ std::string {name}(/* Arguments... */)
+ {BRACE}
+ // Your code here...
+ {END_BRACE}
+{END_BRACE} // namespace steppable::__internals::arithmetic
"""
)
print(f"- Added {name}.cpp")