Skip to content

Commit

Permalink
Add atan2 and improve accuracy of atan (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
ZCG-coder authored Aug 11, 2024
2 parents cb31cd2 + 1ccb389 commit e8ef33d
Show file tree
Hide file tree
Showing 101 changed files with 1,718 additions and 1,094 deletions.
8 changes: 6 additions & 2 deletions .idea/editor.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 8 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

59 changes: 35 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -90,27 +92,36 @@ 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)
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})
Expand Down
24 changes: 12 additions & 12 deletions Steppable.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
9 changes: 8 additions & 1 deletion gui/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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()
163 changes: 163 additions & 0 deletions gui/impl/gui.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,163 @@
#include "gui.hpp"

#include "output.hpp"

#ifdef MACOSX
#include <CoreFoundation/CoreFoundation.h>
#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<CFStringRef>(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<LPBYTE>(&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
Loading

0 comments on commit e8ef33d

Please sign in to comment.