Compare commits

..

No commits in common. "master" and "v1.0.1" have entirely different histories.

12 changed files with 23 additions and 249 deletions

View File

@ -7,9 +7,6 @@
<option name="FUNCTION_BRACE_PLACEMENT" value="2" /> <option name="FUNCTION_BRACE_PLACEMENT" value="2" />
<option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="2" /> <option name="FUNCTION_TOP_AFTER_RETURN_TYPE_WRAP" value="2" />
</Objective-C> </Objective-C>
<clangFormatSettings>
<option name="ENABLED" value="true" />
</clangFormatSettings>
<files> <files>
<extensions> <extensions>
<pair source="cc" header="h" fileNamingConvention="PASCAL_CASE" /> <pair source="cc" header="h" fileNamingConvention="PASCAL_CASE" />

View File

@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.22) cmake_minimum_required(VERSION 3.22)
project(scsl LANGUAGES CXX project(scsl LANGUAGES CXX
VERSION 1.1.4 VERSION 1.0.0
DESCRIPTION "Shimmering Clarity Standard Library") DESCRIPTION "Shimmering Clarity Standard Library")
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)
@ -154,7 +154,7 @@ add_custom_target(deploy-docs
configure_file(scsl.pc.in scsl.pc @ONLY) configure_file(scsl.pc.in scsl.pc @ONLY)
install(TARGETS scsl LIBRARY DESTINATION lib) install(TARGETS scsl LIBRARY DESTINATION lib)
install(TARGETS phonebook RUNTIME DESTINATION bin) install(TARGETS phonebook RUNTIME DESTINATION bin)
install(DIRECTORY include/ DESTINATION include) install(FILES ${HEADER_FILES} DESTINATION include/scsl)
install(FILES scslConfig.cmake DESTINATION share/scsl/cmake) install(FILES scslConfig.cmake DESTINATION share/scsl/cmake)
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/scsl.pc DESTINATION lib/pkgconfig) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/scsl.pc DESTINATION lib/pkgconfig)

View File

@ -20,9 +20,9 @@ set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS ON)
set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT) set(CPACK_DEBIAN_FILE_NAME DEB-DEFAULT)
if(LINUX) if(LINUX)
set(CPACK_GENERATOR "DEB;RPM;STGZ;TGZ") set(CPACK_GENERATOR "DEB;STGZ;TGZ")
elseif(APPLE) elseif(APPLE)
set(CPACK_GENERATOR "STGZ;TGZ") set(CPACK_GENERATOR "productbuild")
elseif(MSVC OR MSYS OR MINGW) elseif(MSVC OR MSYS OR MINGW)
set(CPACK_GENERATOR "NSIS;ZIP") set(CPACK_GENERATOR "NSIS;ZIP")
else() else()

View File

@ -115,13 +115,6 @@ WithinTolerance(T a, T b, T epsilon)
} }
/// \brief Integer square-root.
///
/// \param n A max-value integer whose square root should be returned.
/// \return The square root of $n$.
size_t ISqrt(size_t n);
} // namespace scmp } // namespace scmp

View File

@ -42,7 +42,7 @@ namespace geom {
/// and rotations in three dimensions. /// and rotations in three dimensions.
/// ///
/// Quaternions encode rotations in three-dimensional space. While /// Quaternions encode rotations in three-dimensional space. While
/// technically a Quaternion is comprised of a real element and a /// technically a MakeQuaternion is comprised of a real element and a
/// complex vector<3>, for the purposes of this library, it is modeled /// complex vector<3>, for the purposes of this library, it is modeled
/// as a floating point 4D vector of the form <w, x, y, z>, where x, y, /// as a floating point 4D vector of the form <w, x, y, z>, where x, y,
/// and z represent an Axis of rotation in R3 and w the Angle, in /// and z represent an Axis of rotation in R3 and w the Angle, in

View File

@ -193,8 +193,8 @@ public:
T T
Angle(const Vector<T, N> &other) const Angle(const Vector<T, N> &other) const
{ {
auto unitA = this->UnitVector(); Vector<T, N> unitA = this->UnitVector();
auto unitB = other.UnitVector(); Vector<T, N> unitB = other.UnitVector();
// Can't compute angles with a zero vector. // Can't compute angles with a zero vector.
assert(!this->IsZero()); assert(!this->IsZero());
@ -214,24 +214,12 @@ public:
return true; return true;
} }
// If the two unit vectors are equal, the two vectors T angle = this->Angle(other);
// lie on the same path. if (scmp::WithinTolerance(angle, (T) 0.0, this->epsilon)) {
// return true;
// Context: this used to use Vector::Angle to check for }
// a zero angle between the two. However, the vagaries
// of floating point math meant that while this worked
// fine on Linux amd64 builds, it failed on Linux arm64
// and MacOS builds. Parallel float vectors would have
// an angle of ~0.0003 radians, while double vectors
// would have an angle of +NaN. I suspect this is due to
// tiny variations in floating point math, such that a dot
// product of unit vectors would be just a hair over 1,
// e.g. 1.000000001 - which would still fall outside the
// domain of acos.
auto unitA = this->UnitVector();
auto unitB = other.UnitVector();
return unitA == unitB; return false;
} }

View File

@ -110,27 +110,6 @@ public:
/// \return The value stored under the key, or an empty string. /// \return The value stored under the key, or an empty string.
static std::string GetGlobal(std::string &key); static std::string GetGlobal(std::string &key);
/// \brief Get the value stored for the key from the config.
///
/// \note This operates on the global config.
///
/// \param key The key to look up. See the class documentation
/// for information on how this is used.
/// \return The value stored under the key, or an empty string.
static std::string GetGlobal(const char *key);
/// \brief Get the value stored for the key from the config.
///
/// \note This operates on the global config.
///
/// \param key The key to look up. See the class documentation
/// for information on how this is used.
/// \param defaultValue A default value to cache and use if no
/// value is stored under the key.
/// \return The value stored under the key, or the default
/// value.
static std::string GetGlobal(const char *key, const std::string &defaultValue);
/// \brief Get the value stored for the key from the config. /// \brief Get the value stored for the key from the config.
/// ///
/// \note This operates on the global config. /// \note This operates on the global config.
@ -142,14 +121,6 @@ public:
/// \return The value stored under the key, or the default /// \return The value stored under the key, or the default
/// value. /// value.
static std::string GetGlobal(std::string &key, const std::string &defaultValue); static std::string GetGlobal(std::string &key, const std::string &defaultValue);
/// \brief Set a configuration value. This will override any
/// value set.
static void PutGlobal(std::string &key, const std::string &value);
/// \brief Set a configuration value. This will override any
/// value set.
static void PutGlobal(const char *key, const std::string &value);
#endif #endif
/// \brief The constructor doesn't need any initialisation. /// \brief The constructor doesn't need any initialisation.
@ -192,13 +163,6 @@ public:
/// \return The value stored under the key, or an empty string. /// \return The value stored under the key, or an empty string.
std::string Get(std::string &key); std::string Get(std::string &key);
/// \brief Get the value stored for the key from the config.
///
/// \param key The key to look up. See the class documentation
/// for information on how this is used.
/// \return The value stored under the key, or an empty string.
std::string Get(const char *key);
/// \brief Get the value stored for the key from the config. /// \brief Get the value stored for the key from the config.
/// ///
/// \param key The key to look up. See the class documentation /// \param key The key to look up. See the class documentation
@ -209,31 +173,6 @@ public:
/// value. /// value.
std::string Get(std::string &key, std::string defaultValue); std::string Get(std::string &key, std::string defaultValue);
/// \brief Get the value stored for the key from the config.
///
/// \param key The key to look up. See the class documentation
/// for information on how this is used.
/// \param defaultValue A default value to cache and use if no
/// value is stored under the key.
/// \return The value stored under the key, or the default
/// value.
std::string Get(const char *key, std::string defaultValue);
/// \brief Set a configuration value. This will override any
/// value set.
///
/// \param key The key to look up. See the class documentation
/// for information on how this is used.
/// \param value The value to set.
void Put(std::string &key, const std::string value);
/// \brief Set a configuration value. This will override any
/// value set.
///
/// \param key The key to look up. See the class documentation
/// for information on how this is used.
/// \param value The value to set.
void Put(const char *key, const std::string value);
private: private:
std::string envPrefix; std::string envPrefix;
std::map<std::string, std::string> vars; std::map<std::string, std::string> vars;

View File

@ -72,12 +72,6 @@ namespace scsl {
/// working on a graphical editor. For this, I needed some data structures to /// working on a graphical editor. For this, I needed some data structures to
/// manage memory in the editor. Thus, Buffer was born. /// manage memory in the editor. Thus, Buffer was born.
/// ///
/// \subsection finally Finally
///
/// I'd been writing Go professionally for a while, but C was my first love. I
/// recently started a job that is mostly in C++, and the best way for me to
/// learn is to build a bunch of stuff with it. So, I took a bunch of micro-
/// controller stuff I'd been writing and started building out some other stuff.
} }

View File

@ -151,37 +151,5 @@ DefaultEpsilon(int& epsilon)
} }
size_t
ISqrt(size_t n)
{
if (n < 2) {
return n;
}
size_t start = 0;
size_t end = n / 2;
size_t result = 0;
while (start <= end) {
auto middle = (start + end) >> 1;
result = middle * middle;
if (result == n) {
return middle;
}
if (result < n) {
start = middle + 1;
result = middle;
} else {
end = middle - 1;
result = middle;
}
}
return result;
}
} // namespace scmp } // namespace scmp

View File

@ -25,9 +25,9 @@
#include <regex> #include <regex>
#include <utility> #include <utility>
#include <vector>
#include <scsl/Flags.h> #include <scsl/Flags.h>
#include <scsl/StringUtil.h> #include <scsl/StringUtil.h>
#include <vector>
namespace scsl { namespace scsl {
@ -300,6 +300,7 @@ Flags::Parse(int argc, char **argv, bool skipFirst)
throw std::runtime_error("unhandled parse state"); throw std::runtime_error("unhandled parse state");
#endif #endif
} }
} }
return ParseStatus::OK; return ParseStatus::OK;
@ -312,44 +313,26 @@ Flags::Usage(std::ostream &os, int exitCode)
os << this->name << ":\t"; os << this->name << ":\t";
auto indent = this->name.size() + 7; auto indent = this->name.size() + 7;
scstring::WriteTabIndented(os, this->description, 72 - indent, scstring::WriteTabIndented(os, description, 72 - indent, indent / 8, false);
indent / 8, false);
os << "\n\n"; os << "\n\n";
for (const auto &pair : this->flags) { for (const auto &pair : this->flags) {
auto argDesc = pair.second->Description;
if (!argDesc.empty()) {
argDesc += ' ';
}
auto argLine = "\t" + pair.first; auto argLine = "\t" + pair.first;
switch (pair.second->Type) { switch (pair.second->Type) {
case FlagType::Boolean: case FlagType::Boolean:
argLine += "\t\t"; argLine += "\t\t";
argDesc += "(default=false)";
break; break;
case FlagType::Integer: case FlagType::Integer:
argLine += " int\t\t"; argLine += " int\t\t";
if (pair.second->Value.i != 0) {
argDesc += "(default=" + std::to_string(pair.second->Value.i) + ")";
}
break; break;
case FlagType::UnsignedInteger: case FlagType::UnsignedInteger:
argLine += " uint\t\t"; argLine += " uint\t\t";
if (pair.second->Value.u != 0) {
argDesc += "(default=" + std::to_string(pair.second->Value.u) + ")";
}
break; break;
case FlagType::SizeT: case FlagType::SizeT:
argLine += " size_t\t"; argLine += " size_t\t";
if (pair.second->Value.size != 0) {
argDesc += "(default=" + std::to_string(pair.second->Value.size) + ")";
}
break; break;
case FlagType::String: case FlagType::String:
argLine += " string\t"; argLine += " string\t";
if (pair.second->Value.s != nullptr && !(pair.second->Value.s->empty())) {
argDesc += "(default=" + *(pair.second->Value.s) + ")";
}
break; break;
case FlagType::Unknown: case FlagType::Unknown:
// fallthrough // fallthrough
@ -364,8 +347,8 @@ Flags::Usage(std::ostream &os, int exitCode)
os << argLine; os << argLine;
indent = argLine.size(); indent = argLine.size();
scstring::WriteTabIndented(os, argDesc, 72 - indent, scstring::WriteTabIndented(os, pair.second->Description,
(indent / 8) + 2, false); 72-indent, (indent/8)+2, false);
} }
os << "\n"; os << "\n";
@ -473,3 +456,4 @@ Flags::GetString(std::string fName, std::string &flagValue)
} // namespace scsl } // namespace scsl

View File

@ -83,13 +83,6 @@ SimpleConfig::GetGlobal(std::string &key)
} }
std::string
SimpleConfig::GetGlobal(const char *key)
{
return globalConfig.Get(key);
}
std::string std::string
SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue) SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue)
{ {
@ -97,27 +90,6 @@ SimpleConfig::GetGlobal(std::string &key, const std::string &defaultValue)
} }
std::string
SimpleConfig::GetGlobal(const char *key, const std::string &defaultValue)
{
return globalConfig.Get(key, defaultValue);
}
void
SimpleConfig::PutGlobal(std::string &key, const std::string &value)
{
return globalConfig.Put(key, value);
}
void
SimpleConfig::PutGlobal(const char *key, const std::string &value)
{
return globalConfig.Put(key, value);
}
SimpleConfig::SimpleConfig() SimpleConfig::SimpleConfig()
{ {
} }
@ -181,14 +153,6 @@ SimpleConfig::Get(std::string &key)
} }
std::string
SimpleConfig::Get(const char *key)
{
auto keyStr = std::string(key);
return this->Get(keyStr, "");
}
std::string std::string
SimpleConfig::Get(std::string &key, std::string defaultValue) SimpleConfig::Get(std::string &key, std::string defaultValue)
{ {
@ -209,29 +173,6 @@ SimpleConfig::Get(std::string &key, std::string defaultValue)
} }
std::string
SimpleConfig::Get(const char *key, std::string defaultValue)
{
auto keyStr = std::string(key);
return this->Get(keyStr, std::move(defaultValue));
}
void
SimpleConfig::Put(std::string &key, const std::string value)
{
this->vars[key] = std::move(value);
}
void
SimpleConfig::Put(const char *key, const std::string value)
{
auto keyStr = std::string(key);
this->vars[std::move(keyStr)] = std::move(value);
}
std::vector<std::string> std::vector<std::string>
SimpleConfig::KeyList() SimpleConfig::KeyList()
{ {

View File

@ -116,35 +116,6 @@ RotateRadians()
} }
bool
IntegerSquareRoot()
{
static std::vector<size_t> ns{
// standard integer roots
4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144,
// a few float cases
42, 90, 92
};
static std::vector<size_t> expected{
// standard integer roots
2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,
// a few float cases
6, 9, 10
};
SCTEST_CHECK_EQ(ns.size(), expected.size());
for (size_t i = 0; i < ns.size(); i++) {
auto root = scmp::ISqrt(ns.at(i));
SCTEST_CHECK_EQ(root, expected.at(i));
}
return true;
}
} // anonymous namespace } // anonymous namespace
@ -177,7 +148,6 @@ main(int argc, char *argv[])
suite.AddTest("WithinToleranceFloat", WithinToleranceFloat); suite.AddTest("WithinToleranceFloat", WithinToleranceFloat);
suite.AddTest("WithinToleranceDouble", WithinToleranceDouble); suite.AddTest("WithinToleranceDouble", WithinToleranceDouble);
suite.AddTest("RotateRadians", RotateRadians); suite.AddTest("RotateRadians", RotateRadians);
suite.AddTest("IntegerSquareRoot", IntegerSquareRoot);
delete flags; delete flags;
auto result = suite.Run(); auto result = suite.Run();