Browse Source

Add nodiscard attribute to math functions. Add more math constants. Improve debug log setup. Fix material pass comparator

master
C. J. Howard 1 year ago
parent
commit
3b3c5a1a31
48 changed files with 631 additions and 544 deletions
  1. +7
    -3
      CMakeLists.txt
  2. +1
    -1
      src/animation/spring.hpp
  3. +6
    -6
      src/debug/log.hpp
  4. +1
    -1
      src/game/ant/gene/loader/diet-loader.cpp
  5. +1
    -1
      src/game/ant/gene/loader/foraging-time-loader.cpp
  6. +1
    -1
      src/game/ant/gene/loader/founding-mode-loader.cpp
  7. +1
    -1
      src/game/ant/gene/loader/nest-site-loader.cpp
  8. +27
    -42
      src/game/state/boot.cpp
  9. +2
    -2
      src/game/system/astronomy.cpp
  10. +1
    -1
      src/geom/primitive/hypersphere.hpp
  11. +1
    -1
      src/geom/solid-angle.hpp
  12. +122
    -79
      src/main.cpp
  13. +16
    -27
      src/math/angles.hpp
  14. +3
    -5
      src/math/compile.hpp
  15. +0
    -69
      src/math/constants.hpp
  16. +16
    -16
      src/math/hash/pcg.hpp
  17. +9
    -18
      src/math/interpolation.hpp
  18. +32
    -0
      src/math/literals.hpp
  19. +1
    -1
      src/math/map.hpp
  20. +1
    -1
      src/math/math.hpp
  21. +63
    -63
      src/math/matrix.hpp
  22. +1
    -1
      src/math/noise/fbm.hpp
  23. +5
    -5
      src/math/noise/simplex.hpp
  24. +5
    -5
      src/math/noise/voronoi.hpp
  25. +122
    -0
      src/math/numbers.hpp
  26. +4
    -4
      src/math/polynomial.hpp
  27. +6
    -6
      src/math/projection.hpp
  28. +13
    -19
      src/math/quadrature.hpp
  29. +43
    -43
      src/math/quaternion.hpp
  30. +1
    -4
      src/math/random.hpp
  31. +6
    -6
      src/math/se3.hpp
  32. +4
    -4
      src/math/transform-functions.hpp
  33. +2
    -2
      src/math/transform-operators.hpp
  34. +89
    -89
      src/math/vector.hpp
  35. +1
    -1
      src/physics/gas/atmosphere.hpp
  36. +1
    -1
      src/physics/light/blackbody.hpp
  37. +1
    -1
      src/physics/light/phase.hpp
  38. +1
    -1
      src/physics/light/photometry.hpp
  39. +1
    -1
      src/physics/orbit/anomaly.hpp
  40. +1
    -1
      src/physics/orbit/elements.hpp
  41. +1
    -1
      src/physics/time/ut1.hpp
  42. +1
    -1
      src/physics/time/utc.hpp
  43. +1
    -1
      src/platform/windows/nvidia.cpp
  44. +6
    -4
      src/render/passes/material-pass.cpp
  45. +0
    -1
      src/render/passes/shadow-map-pass.cpp
  46. +1
    -1
      src/render/renderer.cpp
  47. +1
    -1
      src/resources/model-loader.cpp
  48. +1
    -1
      src/scene/camera.cpp

+ 7
- 3
CMakeLists.txt View File

@ -1,5 +1,4 @@
cmake_minimum_required(VERSION 3.7)
cmake_minimum_required(VERSION 3.25)
option(VERSION_STRING "Project version string" "0.0.0")
@ -69,6 +68,11 @@ set(EXECUTABLE_TARGET ${PROJECT_NAME}-executable)
add_executable(${EXECUTABLE_TARGET} ${SOURCE_FILES})
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES OUTPUT_NAME ${PROJECT_NAME})
if(MSVC)
# Select the static multithreaded MSVC runtime library
set_property(TARGET ${EXECUTABLE_TARGET} PROPERTY MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
endif()
# Add compile definitions
if(CMAKE_BUILD_TYPE STREQUAL "Debug")
target_compile_definitions(${EXECUTABLE_TARGET} PRIVATE DEBUG)
@ -78,7 +82,7 @@ endif()
# Set C++ standard
set_target_properties(${EXECUTABLE_TARGET} PROPERTIES
CXX_STANDARD 20
CXX_STANDARD 23
CXX_STANDARD_REQUIRED ON
CXX_EXTENSIONS OFF)

+ 1
- 1
src/animation/spring.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_SPRING_HPP
#define ANTKEEPER_SPRING_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
/**
* Contains the variables required for numeric springing.

+ 6
- 6
src/debug/log.hpp View File

@ -84,7 +84,7 @@ message(std::string_view, Args&&...) -> message;
/**
* Formats and logs a trace message.
*
* @param Args Types of arguments to be formatted.
* @tparam Args Types of arguments to be formatted.
*/
template <class... Args>
using trace = message<message_severity::trace, Args...>;
@ -97,7 +97,7 @@ message(std::string_view, Args&&...) -> message;
/**
* Formats and logs a debug message.
*
* @param Args Types of arguments to be formatted.
* @tparam Args Types of arguments to be formatted.
*/
template <class... Args>
using debug = message<message_severity::debug, Args...>;
@ -110,7 +110,7 @@ message(std::string_view, Args&&...) -> message;
/**
* Formats and logs an info message.
*
* @param Args Types of arguments to be formatted.
* @tparam Args Types of arguments to be formatted.
*/
template <class... Args>
using info = message<message_severity::info, Args...>;
@ -123,7 +123,7 @@ message(std::string_view, Args&&...) -> message;
/**
* Formats and logs a warning message.
*
* @param Args Types of arguments to be formatted.
* @tparam Args Types of arguments to be formatted.
*/
template <class... Args>
using warning = message<message_severity::warning, Args...>;
@ -136,7 +136,7 @@ message(std::string_view, Args&&...) -> message;
/**
* Formats and logs an error message.
*
* @param Args Types of arguments to be formatted.
* @tparam Args Types of arguments to be formatted.
*/
template <class... Args>
using error = message<message_severity::error, Args...>;
@ -149,7 +149,7 @@ message(std::string_view, Args&&...) -> message;
/**
* Formats and logs a fatal error message.
*
* @param Args Types of arguments to be formatted.
* @tparam Args Types of arguments to be formatted.
*/
template <class... Args>
using fatal = message<message_severity::fatal, Args...>;

+ 1
- 1
src/game/ant/gene/loader/diet-loader.cpp View File

@ -23,7 +23,7 @@
#include "resources/json.hpp"
#include "game/ant/gene/diet.hpp"
#include "math/angles.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <stdexcept>
using namespace game::ant;

+ 1
- 1
src/game/ant/gene/loader/foraging-time-loader.cpp View File

@ -23,7 +23,7 @@
#include "resources/json.hpp"
#include "game/ant/gene/foraging-time.hpp"
#include "math/angles.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <stdexcept>
using namespace game::ant;

+ 1
- 1
src/game/ant/gene/loader/founding-mode-loader.cpp View File

@ -23,7 +23,7 @@
#include "resources/json.hpp"
#include "game/ant/gene/founding-mode.hpp"
#include "math/angles.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <stdexcept>
using namespace game::ant;

+ 1
- 1
src/game/ant/gene/loader/nest-site-loader.cpp View File

@ -23,7 +23,7 @@
#include "resources/json.hpp"
#include "game/ant/gene/nest-site.hpp"
#include "math/angles.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <stdexcept>
using namespace game::ant;

+ 27
- 42
src/game/state/boot.cpp View File

@ -103,35 +103,28 @@ boot::boot(game::context& ctx, int argc, char** argv):
{
// Boot process
debug::log::trace("Booting up...");
try
{
// Allocate application
ctx.app = new application();
// Parse command line options
parse_options(argc, argv);
setup_resources();
load_config();
load_strings();
setup_window();
setup_rendering();
setup_audio();
setup_scenes();
setup_animation();
setup_entities();
setup_systems();
setup_controls();
setup_ui();
setup_debugging();
setup_loop();
ctx.active_ecoregion = nullptr;
}
catch (const std::exception& e)
{
debug::log::fatal("Boot up failed: unhandled exception: {}", e.what());
throw e;
}
// Allocate application
ctx.app = new application();
// Parse command line options
parse_options(argc, argv);
setup_resources();
load_config();
load_strings();
setup_window();
setup_rendering();
setup_audio();
setup_scenes();
setup_animation();
setup_entities();
setup_systems();
setup_controls();
setup_ui();
setup_debugging();
setup_loop();
ctx.active_ecoregion = nullptr;
debug::log::trace("Boot up complete");
@ -147,19 +140,11 @@ boot::~boot()
{
debug::log::trace("Booting down...");
try
{
shutdown_audio();
// Close application
delete ctx.app;
ctx.app = nullptr;
}
catch (const std::exception& e)
{
debug::log::fatal("Boot down failed: unhandled exception: {}", e.what());
throw e;
}
shutdown_audio();
// Close application
delete ctx.app;
ctx.app = nullptr;
debug::log::trace("Boot down complete");
}

+ 2
- 2
src/game/system/astronomy.cpp View File

@ -291,13 +291,13 @@ void astronomy::update(double t, double dt)
}
// Measure luminance of observer reference body as seen by reflector
const double3 reflector_observer_luminance = observer_blackbody_illuminance * reference_body->albedo * observer_reflector_transmittance * reflector_observer_phase_factor * math::inverse_pi<double>;
const double3 reflector_observer_luminance = observer_blackbody_illuminance * reference_body->albedo * observer_reflector_transmittance * reflector_observer_phase_factor * math::inv_pi<double>;
// Measure illuminance from observer reference body reaching reflector
const double3 reflector_observer_illuminance = reflector_observer_luminance * reflector_observer_solid_angle;
// Measure luminance of reflector as seen by observer
const double3 observer_reflector_luminance = (reflector_blackbody_illuminance * observer_reflector_phase_factor + reflector_observer_illuminance) * reflector.albedo * observer_reflector_transmittance * math::inverse_pi<double>;
const double3 observer_reflector_luminance = (reflector_blackbody_illuminance * observer_reflector_phase_factor + reflector_observer_illuminance) * reflector.albedo * observer_reflector_transmittance * math::inv_pi<double>;
// Measure illuminance from reflector reaching observer
const double3 observer_reflector_illuminance = observer_reflector_luminance * observer_reflector_solid_angle;

+ 1
- 1
src/geom/primitive/hypersphere.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_GEOM_PRIMITIVE_HYPERSPHERE_HPP
#define ANTKEEPER_GEOM_PRIMITIVE_HYPERSPHERE_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include "math/vector.hpp"
namespace geom {

+ 1
- 1
src/geom/solid-angle.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_GEOM_SOLID_ANGLE_HPP
#define ANTKEEPER_GEOM_SOLID_ANGLE_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <cmath>
namespace geom {

+ 122
- 79
src/main.cpp View File

@ -32,84 +32,105 @@
int main(int argc, char* argv[])
{
// Set up logging to standard output on debug builds
#if !defined(NDEBUG)
// Enable VT100 sequences for colored text
debug::console::enable_vt100();
// Subscribe log to cout function to message logged events
auto log_to_cout_subscription = debug::log::default_logger().get_message_logged_channel().subscribe
(
[&](const auto& event)
// Enable VT100 sequences in console for colored text
debug::console::enable_vt100();
// Subscribe log to cout function to message logged events
auto log_to_cout_subscription = debug::log::default_logger().get_message_logged_channel().subscribe
(
[&](const auto& event)
{
static const char* severities[] =
{
static const char* severities[] =
{
"trace",
"debug",
"info",
"warning",
"error",
"fatal"
};
static const std::string colors[] =
{
std::format("{}", ansi::fg_white),
std::format("{}", ansi::fg_bright_blue),
std::format("{}", ansi::fg_bright_green),
std::format("{}", ansi::fg_yellow),
std::format("{}", ansi::fg_red),
std::format("{}{}", ansi::fg_white, ansi::bg_bright_red)
};
std::osyncstream(std::cout) << std::format
(
"{}:{}:{}: {}{}: {}{}\n",
std::filesystem::path(event.location.file_name()).filename().string(),
event.location.line(),
event.location.column(),
colors[static_cast<int>(event.severity)],
severities[static_cast<int>(event.severity)],
event.message,
ansi::reset
);
}
);
#endif
"trace",
"debug",
"info",
"warning",
"error",
"fatal"
};
static const std::string colors[] =
{
std::format("{}", ansi::fg_white),
std::format("{}", ansi::fg_bright_blue),
std::format("{}", ansi::fg_bright_green),
std::format("{}", ansi::fg_yellow),
std::format("{}", ansi::fg_red),
std::format("{}{}", ansi::fg_white, ansi::bg_bright_red)
};
std::osyncstream(std::cout) << std::format
(
"{}:{}:{}: {}{}: {}{}\n",
std::filesystem::path(event.location.file_name()).filename().string(),
event.location.line(),
event.location.column(),
colors[static_cast<int>(event.severity)],
severities[static_cast<int>(event.severity)],
event.message,
ansi::reset
);
}
);
// Determine path to log archive, then construct path if it doesn't exist
// Determine path to log archive
const std::filesystem::path log_archive_path = get_config_path(config::application_name) / "logs";
const bool log_archive_created = std::filesystem::create_directories(log_archive_path);
// If log archive already existed
if (!log_archive_created)
// Set up log archive
bool log_archive_exists = false;
try
{
// Detect archived logs
std::set<std::filesystem::path> log_archive;
for (const auto& entry: std::filesystem::directory_iterator{log_archive_path})
// Create log archive if it doesn't exist
if (std::filesystem::create_directories(log_archive_path))
{
if (entry.is_regular_file() &&
entry.path().extension() == ".log")
{
log_archive.emplace(entry.path());
}
debug::log::debug("Created log archive \"{}\"", log_archive_path.string());
}
// Delete expired logs
if (!log_archive.empty())
else
{
for (std::size_t i = log_archive.size() + 1; i > config::debug_log_archive_capacity; --i)
// Clean pre-existing log archive
try
{
std::filesystem::remove(*log_archive.begin());
log_archive.erase(log_archive.begin());
// Detect and sort archived logs
std::set<std::filesystem::path> log_archive;
for (const auto& entry: std::filesystem::directory_iterator{log_archive_path})
{
if (entry.is_regular_file() &&
entry.path().extension() == ".log")
{
log_archive.emplace(entry.path());
}
}
debug::log::debug("Detected {} archived log{} at \"{}\"", log_archive.size(), log_archive.size() != 1 ? "s" : "", log_archive_path.string());
// Delete expired logs
if (!log_archive.empty())
{
for (std::size_t i = log_archive.size() + 1; i > config::debug_log_archive_capacity; --i)
{
std::filesystem::remove(*log_archive.begin());
debug::log::debug("Deleted expired log file \"{}\"", log_archive.begin()->string());
log_archive.erase(log_archive.begin());
}
}
}
catch (const std::filesystem::filesystem_error& e)
{
debug::log::error("An error occured while cleaning the log archive \"{}\": {}", log_archive_path.string(), e.what());
}
}
log_archive_exists = true;
}
catch (const std::filesystem::filesystem_error& e)
{
debug::log::error("Failed to create log archive at \"{}\": {}", log_archive_path.string(), e.what());
}
// Set up logging to file
std::shared_ptr<event::subscription> log_to_file_subscription;
if (config::debug_log_archive_capacity)
if (config::debug_log_archive_capacity && log_archive_exists)
{
// Determine log filename
const auto time = std::chrono::floor<std::chrono::seconds>(std::chrono::system_clock::now());
@ -117,28 +138,50 @@ int main(int argc, char* argv[])
// Open log file
std::filesystem::path log_filepath = log_archive_path / log_filename;
const std::string log_filepath_string = log_filepath.string();
auto log_filestream = std::make_shared<std::ofstream>(log_filepath);
// Write log file header
(*log_filestream) << "time\tfile\tline\tcolumn\tseverity\tmessage";
// Subscribe log to file function to message logged events
log_to_file_subscription = debug::log::default_logger().get_message_logged_channel().subscribe
(
[log_filestream](const auto& event)
if (log_filestream->is_open())
{
debug::log::debug("Opened log file \"{}\"", log_filepath_string);
// Write log file header
(*log_filestream) << "time\tfile\tline\tcolumn\tseverity\tmessage";
if (log_filestream->good())
{
std::osyncstream(*log_filestream) << std::format
// Subscribe log to file function to message logged events
log_to_file_subscription = debug::log::default_logger().get_message_logged_channel().subscribe
(
"\n{0:%Y%m%d}T{0:%H%M%S}Z\t{1}\t{2}\t{3}\t{4}\t{5}",
std::chrono::floor<std::chrono::milliseconds>(event.time),
std::filesystem::path(event.location.file_name()).filename().string(),
event.location.line(),
event.location.column(),
static_cast<int>(event.severity),
event.message
[log_filestream](const auto& event)
{
std::osyncstream(*log_filestream) << std::format
(
"\n{0:%Y%m%d}T{0:%H%M%S}Z\t{1}\t{2}\t{3}\t{4}\t{5}",
std::chrono::floor<std::chrono::milliseconds>(event.time),
std::filesystem::path(event.location.file_name()).filename().string(),
event.location.line(),
event.location.column(),
static_cast<int>(event.severity),
event.message
);
}
);
// Unsubscribe log to cout function from message logged events on release builds
#if defined(NDEBUG)
log_to_cout_subscription->unsubscribe();
#endif
}
else
{
debug::log::error("Failed to write to log file \"{}\"", log_filepath_string);
}
);
}
else
{
debug::log::error("Failed to open log file \"{}\"", log_filepath_string);
}
}
// Log application name and version string

+ 16
- 27
src/math/angles.hpp View File

@ -20,19 +20,23 @@
#ifndef ANTKEEPER_MATH_ANGLES_HPP
#define ANTKEEPER_MATH_ANGLES_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <cmath>
namespace math {
/**
* Converts an angle given in radians to degrees.
* Converts an angle from radians to degrees.
*
* @param radians Angle in radians.
*
* @return Angle in degrees.
*/
template <class T>
T degrees(T radians);
[[nodiscard]] inline constexpr T degrees(T radians) noexcept
{
return radians * rad2deg<T>;
}
/**
* Converts an angle given in degrees to radians.
@ -41,7 +45,10 @@ T degrees(T radians);
* @return Angle in degrees.
*/
template <class T>
T radians(T degrees);
[[nodiscard]] inline constexpr T radians(T degrees) noexcept
{
return degrees * deg2rad<T>;
}
/**
* Wraps an angle to [-180, 180].
@ -50,7 +57,10 @@ T radians(T degrees);
* @return Wrapped angle.
*/
template <class T>
T wrap_degrees(T degrees);
[[nodiscard]] inline constexpr T wrap_degrees(T degrees)
{
return std::remainder(degrees, T(360));
}
/**
* Wraps an angle to [-pi, pi].
@ -59,28 +69,7 @@ T wrap_degrees(T degrees);
* @return Wrapped angle.
*/
template <class T>
T wrap_radians(T radians);
template <class T>
inline T degrees(T radians)
{
return radians * T(180) / pi<T>;
}
template <class T>
inline T radians(T degrees)
{
return degrees * pi<T> / T(180);
}
template <class T>
inline T wrap_degrees(T degrees)
{
return std::remainder(degrees, T(360));
}
template <class T>
inline T wrap_radians(T radians)
[[nodiscard]] inline constexpr T wrap_radians(T radians)
{
return std::remainder(radians, two_pi<T>);
}

+ 3
- 5
src/math/compile.hpp View File

@ -27,8 +27,6 @@ namespace math {
/// Compile-time mathematical functions.
namespace compile {
/**
* Compile-time `ceil(log2(x))` for unsigned integrals.
*
@ -37,7 +35,7 @@ namespace compile {
* @return `ceil(log2(x))`.
*/
template <std::unsigned_integral T>
consteval T ceil_log2(T x) noexcept
[[nodiscard]] consteval T ceil_log2(T x) noexcept
{
return (x <= T(1)) ? T(0) : ceil_log2((x + T(1)) / T(2)) + T(1);
}
@ -50,7 +48,7 @@ consteval T ceil_log2(T x) noexcept
* @return `exp2(x)`.
*/
template <std::unsigned_integral T>
consteval T exp2(T x) noexcept
[[nodiscard]] consteval T exp2(T x) noexcept
{
return (x) ? T(2) << (x - 1) : T(1);
}
@ -64,7 +62,7 @@ consteval T exp2(T x) noexcept
* @return `x^e`.
*/
template <std::unsigned_integral T>
consteval T pow(T x, T e) noexcept
[[nodiscard]] consteval T pow(T x, T e) noexcept
{
return (e == 0) ? T(1) : (x * pow<T>(x, e - 1));
}

+ 0
- 69
src/math/constants.hpp View File

@ -1,69 +0,0 @@
/*
* Copyright (C) 2023 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MATH_CONSTANTS_HPP
#define ANTKEEPER_MATH_CONSTANTS_HPP
#include <limits>
namespace math {
/// Positive infinity.
template <class T>
constexpr T inf{std::numeric_limits<T>::infinity()};
/// Pi.
template <class T>
constexpr T pi = T{3.1415926535897932384626433832795};
/// Pi * 2.
template <class T>
constexpr T two_pi = pi<T> * T{2};
/// Pi * 4.
template <class T>
constexpr T four_pi = pi<T> * T{4};
/// Pi / 2.
template <class T>
constexpr T half_pi = pi<T> / T{2};
/// 1 / Pi.
template <class T>
constexpr T inverse_pi = T{1} / pi<T>;
/// sqrt(0.5)
template <class T>
constexpr T sqrt_half = T{0.70710678118654752440084436210485};
/// sqrt(2)
template <class T>
constexpr T sqrt_2 = T{1.4142135623730950488016887242097};
/// sqrt(3)
template <class T>
constexpr T sqrt_3 = T{1.7320508075688772935274463415059};
/// sqrt(5)
template <class T>
constexpr T sqrt_5 = T{2.2360679774997896964091736687313};
} // namespace math
#endif // ANTKEEPER_MATH_CONSTANTS_HPP

+ 16
- 16
src/math/hash/pcg.hpp View File

@ -66,7 +66,7 @@ constexpr std::uint64_t mcg_multiplier = 12605985483714917081ULL;
/// @private
template <class T>
constexpr T pcg_uint(T x) noexcept
[[nodiscard]] constexpr T pcg_uint(T x) noexcept
{
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value);
static_assert(sizeof(T) <= 8);
@ -78,7 +78,7 @@ constexpr T pcg_uint(T x) noexcept
/// @private
template <class T>
inline constexpr vector<T, 1> pcg_uvec1(vector<T, 1> x) noexcept
[[nodiscard]] inline constexpr vector<T, 1> pcg_uvec1(vector<T, 1> x) noexcept
{
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value);
static_assert(sizeof(T) <= 8);
@ -90,7 +90,7 @@ inline constexpr vector pcg_uvec1(vector x) noexcept
/// @private
template <class T>
constexpr vector<T, 2> pcg_uvec2(vector<T, 2> x) noexcept
[[nodiscard]] constexpr vector<T, 2> pcg_uvec2(vector<T, 2> x) noexcept
{
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value);
static_assert(sizeof(T) <= 8);
@ -114,7 +114,7 @@ constexpr vector pcg_uvec2(vector x) noexcept
/// @private
template <class T>
constexpr vector<T, 3> pcg_uvec3(vector<T, 3> x) noexcept
[[nodiscard]] constexpr vector<T, 3> pcg_uvec3(vector<T, 3> x) noexcept
{
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value);
static_assert(sizeof(T) <= 8);
@ -138,7 +138,7 @@ constexpr vector pcg_uvec3(vector x) noexcept
/// @private
template <class T>
constexpr vector<T, 4> pcg_uvec4(vector<T, 4> x) noexcept
[[nodiscard]] constexpr vector<T, 4> pcg_uvec4(vector<T, 4> x) noexcept
{
static_assert(std::is_integral<T>::value && std::is_unsigned<T>::value);
static_assert(sizeof(T) <= 8);
@ -178,58 +178,58 @@ constexpr vector pcg_uvec4(vector x) noexcept
* @see Mark Jarzynski and Marc Olano, Hash Functions for GPU Rendering, Journal of Computer Graphics Techniques (JCGT), vol. 9, no. 3, 21-38, 2020.
*/
/// @{
inline constexpr std::uint8_t pcg(std::uint8_t x) noexcept
[[nodiscard]] inline constexpr std::uint8_t pcg(std::uint8_t x) noexcept
{
return pcg_uint<std::uint8_t>(x);
}
inline constexpr std::uint16_t pcg(std::uint16_t x) noexcept
[[nodiscard]] inline constexpr std::uint16_t pcg(std::uint16_t x) noexcept
{
return pcg_uint<std::uint16_t>(x);
}
inline constexpr std::uint32_t pcg(std::uint32_t x) noexcept
[[nodiscard]] inline constexpr std::uint32_t pcg(std::uint32_t x) noexcept
{
return pcg_uint<std::uint32_t>(x);
}
inline constexpr std::uint64_t pcg(std::uint64_t x) noexcept
[[nodiscard]] inline constexpr std::uint64_t pcg(std::uint64_t x) noexcept
{
return pcg_uint<std::uint64_t>(x);
}
inline constexpr std::uint8_t pcg(std::int8_t x) noexcept
[[nodiscard]] inline constexpr std::uint8_t pcg(std::int8_t x) noexcept
{
return pcg_uint<std::uint8_t>(static_cast<std::uint8_t>(x));
}
inline constexpr std::uint16_t pcg(std::int16_t x) noexcept
[[nodiscard]] inline constexpr std::uint16_t pcg(std::int16_t x) noexcept
{
return pcg_uint<std::uint16_t>(static_cast<std::uint16_t>(x));
}
inline constexpr std::uint32_t pcg(std::int32_t x) noexcept
[[nodiscard]] inline constexpr std::uint32_t pcg(std::int32_t x) noexcept
{
return pcg_uint<std::uint32_t>(static_cast<std::uint32_t>(x));
}
inline constexpr std::uint64_t pcg(std::int64_t x) noexcept
[[nodiscard]] inline constexpr std::uint64_t pcg(std::int64_t x) noexcept
{
return pcg_uint<std::uint64_t>(static_cast<std::uint64_t>(x));
}
inline constexpr std::uint32_t pcg(float x) noexcept
[[nodiscard]] inline constexpr std::uint32_t pcg(float x) noexcept
{
return pcg_uint<std::uint32_t>(static_cast<std::uint32_t>(x));
}
inline constexpr std::uint64_t pcg(double x) noexcept
[[nodiscard]] inline constexpr std::uint64_t pcg(double x) noexcept
{
return pcg_uint<std::uint64_t>(static_cast<std::uint64_t>(x));
}
template <class T, std::size_t N>
inline constexpr vector<make_uint_t<T>, N> pcg(const vector<T, N>& x) noexcept
[[nodiscard]] inline constexpr vector<make_uint_t<T>, N> pcg(const vector<T, N>& x) noexcept
{
static_assert(N > 0 && N < 5, "PCG hash only supports vectors with 1-4 elements.");

+ 9
- 18
src/math/interpolation.hpp View File

@ -38,7 +38,10 @@ namespace math {
* @tparam S Scalar type.
*/
template <typename T, typename S = float>
T lerp(const T& x, const T& y, S a);
[[nodiscard]] constexpr T lerp(const T& x, const T& y, S a)
{
return x + (y - x) * a;
}
/**
* Linearly interpolates between two angles, @p x and @p y.
@ -50,7 +53,10 @@ T lerp(const T& x, const T& y, S a);
* @return Interpolated angle, in radians.
*/
template <typename T>
T lerp_angle(T x, T y, T a);
[[nodiscard]] constexpr T lerp_angle(T x, T y, T a)
{
return wrap_radians(x + wrap_radians(y - x) * a);
}
/**
* Logarithmically interpolates between @p x and @p y.
@ -61,22 +67,7 @@ T lerp_angle(T x, T y, T a);
* @tparam S Scalar type.
*/
template <typename T, typename S = float>
T log_lerp(const T& x, const T& y, S a);
template <typename T, typename S>
inline T lerp(const T& x, const T& y, S a)
{
return x + (y - x) * a;
}
template <typename T>
T lerp_angle(T x, T y, T a)
{
return wrap_radians(x + wrap_radians(y - x) * a);
}
template <typename T, typename S>
inline T log_lerp(const T& x, const T& y, S a)
[[nodiscard]] T log_lerp(const T& x, const T& y, S a)
{
//return std::exp(linear(std::log(x), std::log(y), a));
return x * std::pow(y / x, a);

+ 32
- 0
src/math/literals.hpp View File

@ -0,0 +1,32 @@
/*
* Copyright (C) 2023 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MATH_LITERALS_HPP
#define ANTKEEPER_MATH_LITERALS_HPP
namespace math {
/**
* User-defined math literals.
*/
namespace literals {}
} // namespace math
#endif // ANTKEEPER_MATH_LITERALS_HPP

+ 1
- 1
src/math/map.hpp View File

@ -34,7 +34,7 @@ namespace math {
* @return Unclamped remapped value.
*/
template <class T>
constexpr T map(T x, T from_min, T from_max, T to_min, T to_max) noexcept
[[nodiscard]] constexpr T map(T x, T from_min, T from_max, T to_min, T to_max) noexcept
{
return to_min + (x - from_min) * (to_max - to_min) / (from_max - from_min);
}

+ 1
- 1
src/math/math.hpp View File

@ -33,7 +33,7 @@ namespace math {}
#include "math/transform-operators.hpp"
#include "math/angles.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include "math/quadrature.hpp"
#include "math/interpolation.hpp"
#include "math/map.hpp"

+ 63
- 63
src/math/matrix.hpp View File

@ -68,7 +68,7 @@ struct matrix
/// @private
template <class U, std::size_t... I>
inline constexpr matrix<U, N, M> type_cast(std::index_sequence<I...>) const noexcept
[[nodiscard]] inline constexpr matrix<U, N, M> type_cast(std::index_sequence<I...>) const noexcept
{
return {vector<U, M>(columns[I])...};
}
@ -81,14 +81,14 @@ struct matrix
* @return Matrix containing the type-casted elements.
*/
template <class U>
inline constexpr explicit operator matrix<U, N, M>() const noexcept
[[nodiscard]] inline constexpr explicit operator matrix<U, N, M>() const noexcept
{
return type_cast<U>(std::make_index_sequence<N>{});
}
/// @private
template <std::size_t P, std::size_t O, std::size_t... I>
inline constexpr matrix<T, P, O> size_cast(std::index_sequence<I...>) const noexcept
[[nodiscard]] inline constexpr matrix<T, P, O> size_cast(std::index_sequence<I...>) const noexcept
{
if constexpr (O == M)
return {((I < N) ? columns[I] : matrix<T, P, O>::identity()[I]) ...};
@ -105,7 +105,7 @@ struct matrix
* @return *p* by *o* matrix.
*/
template <std::size_t P, std::size_t O>
inline constexpr explicit operator matrix<T, P, O>() const noexcept
[[nodiscard]] inline constexpr explicit operator matrix<T, P, O>() const noexcept
{
return size_cast<P, O>(std::make_index_sequence<P>{});
}
@ -123,19 +123,19 @@ struct matrix
* @return Reference to the column vector at index @p i.
*/
/// @{
inline constexpr column_vector_type& operator[](std::size_t i) noexcept
[[nodiscard]] inline constexpr column_vector_type& operator[](std::size_t i) noexcept
{
return columns[i];
}
inline constexpr const column_vector_type& operator[](std::size_t i) const noexcept
[[nodiscard]] inline constexpr const column_vector_type& operator[](std::size_t i) const noexcept
{
return columns[i];
}
inline constexpr column_vector_type& column(std::size_t i) noexcept
[[nodiscard]] inline constexpr column_vector_type& column(std::size_t i) noexcept
{
return columns[i];
}
inline constexpr const column_vector_type& column(std::size_t i) const noexcept
[[nodiscard]] inline constexpr const column_vector_type& column(std::size_t i) const noexcept
{
return columns[i];
}
@ -145,11 +145,11 @@ struct matrix
* Returns a reference to the first column vector.
*/
/// @{
inline constexpr column_vector_type& front() noexcept
[[nodiscard]] inline constexpr column_vector_type& front() noexcept
{
return columns[0];
}
inline constexpr const column_vector_type& front() const noexcept
[[nodiscard]] inline constexpr const column_vector_type& front() const noexcept
{
return columns[0];
}
@ -159,11 +159,11 @@ struct matrix
* Returns a reference to the last column vector.
*/
/// @{
inline constexpr column_vector_type& back() noexcept
[[nodiscard]] inline constexpr column_vector_type& back() noexcept
{
return columns[column_count - 1];
}
inline constexpr const column_vector_type& back() const noexcept
[[nodiscard]] inline constexpr const column_vector_type& back() const noexcept
{
return columns[column_count - 1];
}
@ -182,11 +182,11 @@ struct matrix
* @return Reference to the element at column-major index @p i.
*/
/// @{
inline constexpr T& element(std::size_t i) noexcept
[[nodiscard]] inline constexpr T& element(std::size_t i) noexcept
{
return columns[i / row_count][i % row_count];
}
inline constexpr const T& element(std::size_t i) const noexcept
[[nodiscard]] inline constexpr const T& element(std::size_t i) const noexcept
{
return columns[i / row_count][i % row_count];
}
@ -198,11 +198,11 @@ struct matrix
* @warning If matrix::element_type is not a POD type, elements may not be stored contiguously.
*/
/// @{
inline constexpr element_type* data() noexcept
[[nodiscard]] inline constexpr element_type* data() noexcept
{
return &columns[0][0];
};
inline constexpr const element_type* data() const noexcept
[[nodiscard]] inline constexpr const element_type* data() const noexcept
{
return &columns[0][0];
};
@ -217,15 +217,15 @@ struct matrix
* Returns an iterator to the first column vector.
*/
/// @{
inline constexpr column_vector_type* begin() noexcept
[[nodiscard]] inline constexpr column_vector_type* begin() noexcept
{
return columns;
}
inline constexpr const column_vector_type* begin() const noexcept
[[nodiscard]] inline constexpr const column_vector_type* begin() const noexcept
{
return columns;
}
inline constexpr const column_vector_type* cbegin() const noexcept
[[nodiscard]] inline constexpr const column_vector_type* cbegin() const noexcept
{
return columns;
}
@ -235,15 +235,15 @@ struct matrix
* Returns an iterator to the column vector following the last column vector.
*/
/// @{
inline constexpr column_vector_type* end() noexcept
[[nodiscard]] inline constexpr column_vector_type* end() noexcept
{
return columns + column_count;
}
inline constexpr const column_vector_type* end() const noexcept
[[nodiscard]] inline constexpr const column_vector_type* end() const noexcept
{
return columns + column_count;
}
inline constexpr const column_vector_type* cend() const noexcept
[[nodiscard]] inline constexpr const column_vector_type* cend() const noexcept
{
return columns + column_count;
}
@ -253,15 +253,15 @@ struct matrix
* Returns a reverse iterator to the first column vector of the reversed matrix.
*/
/// @{
inline constexpr std::reverse_iterator<column_vector_type*> rbegin() noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<column_vector_type*> rbegin() noexcept
{
return std::reverse_iterator<column_vector_type*>(columns + column_count);
}
inline constexpr std::reverse_iterator<const column_vector_type*> rbegin() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const column_vector_type*> rbegin() const noexcept
{
return std::reverse_iterator<const column_vector_type*>(columns + column_count);
}
inline constexpr std::reverse_iterator<const column_vector_type*> crbegin() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const column_vector_type*> crbegin() const noexcept
{
return std::reverse_iterator<const column_vector_type*>(columns + column_count);
}
@ -271,15 +271,15 @@ struct matrix
* Returns a reverse iterator to the column vector following the last column vector of the reversed matrix.
*/
/// @{
inline constexpr std::reverse_iterator<column_vector_type*> rend() noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<column_vector_type*> rend() noexcept
{
return std::reverse_iterator<column_vector_type*>(columns);
}
inline constexpr std::reverse_iterator<const column_vector_type*> rend() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const column_vector_type*> rend() const noexcept
{
return std::reverse_iterator<const column_vector_type*>(columns);
}
inline constexpr std::reverse_iterator<const column_vector_type*> crend() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const column_vector_type*> crend() const noexcept
{
return std::reverse_iterator<const column_vector_type*>(columns);
}
@ -293,7 +293,7 @@ struct matrix
/**
* Returns the number of elements in the matrix.
*/
inline constexpr std::size_t size() const noexcept
[[nodiscard]] inline constexpr std::size_t size() const noexcept
{
return element_count;
};
@ -306,14 +306,14 @@ struct matrix
/**
* Returns a zero matrix, where every element is equal to zero.
*/
static constexpr matrix zero() noexcept
[[nodiscard]] static constexpr matrix zero() noexcept
{
return {};
}
/// @private
template <std::size_t... I>
static inline constexpr matrix one(std::index_sequence<I...>) noexcept
[[nodiscard]] static inline constexpr matrix one(std::index_sequence<I...>) noexcept
{
//return {column_vector_type::one() ...};
@ -324,21 +324,21 @@ struct matrix
/**
* Returns a matrix of ones, where every element is equal to one.
*/
static constexpr matrix one() noexcept
[[nodiscard]] static constexpr matrix one() noexcept
{
return one(std::make_index_sequence<column_count>{});
}
/// @private
template <std::size_t... I>
static inline constexpr column_vector_type identity_column(std::size_t i, std::index_sequence<I...>) noexcept
[[nodiscard]] static inline constexpr column_vector_type identity_column(std::size_t i, std::index_sequence<I...>) noexcept
{
return {(I == i ? T{1} : T{0}) ...};
}
/// @private
template <std::size_t... I>
static inline constexpr matrix identity(std::index_sequence<I...>) noexcept
[[nodiscard]] static inline constexpr matrix identity(std::index_sequence<I...>) noexcept
{
return {identity_column(I, std::make_index_sequence<row_count>{}) ...};
}
@ -346,7 +346,7 @@ struct matrix
/**
* Returns an identity matrix, with ones on the main diagonal and zeros elsewhere.
*/
static constexpr matrix identity() noexcept
[[nodiscard]] static constexpr matrix identity() noexcept
{
return identity(std::make_index_sequence<column_count>{});
}
@ -387,7 +387,7 @@ using matrix4x4 = matrix;
* @return Sum of the two matrices.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> add(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> add(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
/**
* Adds a matrix and a scalar.
@ -398,7 +398,7 @@ constexpr matrix add(const matrix& a, const matrix& b
* @return Sum of the matrix and scalar.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> add(const matrix<T, N, M>& a, T b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> add(const matrix<T, N, M>& a, T b) noexcept;
/**
* Calculates the determinant of a square matrix.
@ -410,7 +410,7 @@ constexpr matrix add(const matrix& a, T b) noexcept;
* @warning Currently only implemented for 2x2, 3x3, and 4x4 matrices.
*/
template <class T, std::size_t N>
constexpr T determinant(const matrix<T, N, N>& m) noexcept;
[[nodiscard]] constexpr T determinant(const matrix<T, N, N>& m) noexcept;
/**
* Performs a component-wise multiplication of two matrices.
@ -421,7 +421,7 @@ constexpr T determinant(const matrix& m) noexcept;
* @return Product of the component-wise multiplcation.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> componentwise_mul(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> componentwise_mul(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
/**
* Divides a matrix by a matrix.
@ -432,7 +432,7 @@ constexpr matrix componentwise_mul(const matrix& a, const matr
* @return Result of the division.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> div(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> div(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
/**
* Divides a matrix by a scalar.
@ -443,7 +443,7 @@ constexpr matrix div(const matrix& a, const matrix& b
* @return Result of the division.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> div(const matrix<T, N, M>& a, T b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> div(const matrix<T, N, M>& a, T b) noexcept;
/**
* Divides a scalar by a matrix.
@ -454,7 +454,7 @@ constexpr matrix div(const matrix& a, T b) noexcept;
* @return Result of the division.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> div(T a, const matrix<T, N, M>& b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> div(T a, const matrix<T, N, M>& b) noexcept;
/**
* Extracts the Ith column from a matrix.
@ -470,13 +470,13 @@ constexpr matrix div(T a, const matrix& b) noexcept;
*/
/// @{
template<std::size_t I, class T, std::size_t N, std::size_t M>
constexpr typename matrix<T, N, M>::column_vector_type& get(math::matrix<T, N, M>& m) noexcept;
[[nodiscard]] constexpr typename matrix<T, N, M>::column_vector_type& get(math::matrix<T, N, M>& m) noexcept;
template<std::size_t I, class T, std::size_t N, std::size_t M>
constexpr typename matrix<T, N, M>::column_vector_type&& get(math::matrix<T, N, M>&& m) noexcept;
[[nodiscard]] constexpr typename matrix<T, N, M>::column_vector_type&& get(math::matrix<T, N, M>&& m) noexcept;
template<std::size_t I, class T, std::size_t N, std::size_t M>
constexpr const typename matrix<T, N, M>::column_vector_type& get(const math::matrix<T, N, M>& m) noexcept;
[[nodiscard]] constexpr const typename matrix<T, N, M>::column_vector_type& get(const math::matrix<T, N, M>& m) noexcept;
template<std::size_t I, class T, std::size_t N, std::size_t M>
constexpr const typename matrix<T, N, M>::column_vector_type&& get(const math::matrix<T, N, M>&& m) noexcept;
[[nodiscard]] constexpr const typename matrix<T, N, M>::column_vector_type&& get(const math::matrix<T, N, M>&& m) noexcept;
/// @}
/**
@ -489,7 +489,7 @@ constexpr const typename matrix::column_vector_type&& get(const math::m
* @warning Currently only implemented for 2x2, 3x3, and 4x4 matrices.
*/
template <class T, std::size_t N>
constexpr matrix<T, N, N> inverse(const matrix<T, N, N>& m) noexcept;
[[nodiscard]] constexpr matrix<T, N, N> inverse(const matrix<T, N, N>& m) noexcept;
/**
* Creates a viewing transformation matrix.
@ -501,7 +501,7 @@ constexpr matrix inverse(const matrix& m) noexcept;
* @return Viewing transformation matrix.
*/
template <class T>
constexpr matrix<T, 4, 4> look_at(const vector<T, 3>& position, const vector<T, 3>& target, vector<T, 3> up);
[[nodiscard]] constexpr matrix<T, 4, 4> look_at(const vector<T, 3>& position, const vector<T, 3>& target, vector<T, 3> up);
/**
* Multiplies two matrices
@ -517,7 +517,7 @@ constexpr matrix look_at(const vector& position, const vector
* @return Product of `a * b`.
*/
template <typename T, std::size_t N, std::size_t M, std::size_t P>
constexpr matrix<T, P, M> mul(const matrix<T, N, M>& a, const matrix<T, P, N>& b) noexcept;
[[nodiscard]] constexpr matrix<T, P, M> mul(const matrix<T, N, M>& a, const matrix<T, P, N>& b) noexcept;
/**
* Multiplies a matrix by a scalar.
@ -528,7 +528,7 @@ constexpr matrix mul(const matrix& a, const matrix& b
* @return Product of the matrix and the scalar.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> mul(const matrix<T, N, M>& a, T b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> mul(const matrix<T, N, M>& a, T b) noexcept;
/**
* Calculates the product of a matrix and a row vector.
@ -539,7 +539,7 @@ constexpr matrix mul(const matrix& a, T b) noexcept;
* @return Product of the matrix and the row vector.
*/
template <typename T, std::size_t N, std::size_t M>
constexpr typename matrix<T, N, M>::column_vector_type mul(const matrix<T, N, M>& a, const typename matrix<T, N, M>::row_vector_type& b) noexcept;
[[nodiscard]] constexpr typename matrix<T, N, M>::column_vector_type mul(const matrix<T, N, M>& a, const typename matrix<T, N, M>::row_vector_type& b) noexcept;
/**
* Calculates the product of a column vector and a matrix.
@ -550,7 +550,7 @@ constexpr typename matrix::column_vector_type mul(const matrix
* @return Product of the column vector and the matrix.
*/
template <typename T, std::size_t N, std::size_t M>
constexpr typename matrix<T, N, M>::row_vector_type mul(const typename matrix<T, N, M>::column_vector_type& a, const matrix<T, N, M>& b) noexcept;
[[nodiscard]] constexpr typename matrix<T, N, M>::row_vector_type mul(const typename matrix<T, N, M>::column_vector_type& a, const matrix<T, N, M>& b) noexcept;
/**
* Constructs a rotation matrix.
@ -561,7 +561,7 @@ constexpr typename matrix::row_vector_type mul(const typename matrix
* @return Rotation matrix.
*/
template <class T>
matrix<T, 3, 3> rotate(T angle, const vector<T, 3>& axis);
[[nodiscard]] matrix<T, 3, 3> rotate(T angle, const vector<T, 3>& axis);
/**
* Produces a matrix which rotates Cartesian coordinates about the x-axis by a given angle.
@ -571,7 +571,7 @@ matrix rotate(T angle, const vector& axis);
* @return Rotation matrix.
*/
template <class T>
matrix3<T> rotate_x(T angle);
[[nodiscard]] matrix3<T> rotate_x(T angle);
/**
* Produces a matrix which rotates Cartesian coordinates about the y-axis by a given angle.
@ -581,7 +581,7 @@ matrix3 rotate_x(T angle);
* @return Rotation matrix.
*/
template <class T>
matrix3<T> rotate_y(T angle);
[[nodiscard]] matrix3<T> rotate_y(T angle);
/**
* Produces a matrix which rotates Cartesian coordinates about the z-axis by a given angle.
@ -591,7 +591,7 @@ matrix3 rotate_y(T angle);
* @return Rotation matrix.
*/
template <class T>
matrix3<T> rotate_z(T angle);
[[nodiscard]] matrix3<T> rotate_z(T angle);
/**
* Scales a matrix.
@ -602,7 +602,7 @@ matrix3 rotate_z(T angle);
* @return Scaled matrix.
*/
template <class T>
constexpr matrix<T, 4, 4> scale(const matrix<T, 4, 4>& m, const vector<T, 3>& v);
[[nodiscard]] constexpr matrix<T, 4, 4> scale(const matrix<T, 4, 4>& m, const vector<T, 3>& v);
/**
* Subtracts a matrix from another matrix.
@ -613,7 +613,7 @@ constexpr matrix scale(const matrix& m, const vector& v)
* @return Difference between the two matrices.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> sub(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> sub(const matrix<T, N, M>& a, const matrix<T, N, M>& b) noexcept;
/**
* Subtracts a scalar from matrix.
@ -624,7 +624,7 @@ constexpr matrix sub(const matrix& a, const matrix& b
* @return Difference between the matrix and scalar.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> sub(const matrix<T, N, M>& a, T b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> sub(const matrix<T, N, M>& a, T b) noexcept;
/**
* Subtracts a matrix from a scalar.
@ -635,7 +635,7 @@ constexpr matrix sub(const matrix& a, T b) noexcept;
* @return Difference between the scalar and matrix.
*/
template <class T, std::size_t N, std::size_t M>
constexpr matrix<T, N, M> sub(T a, const matrix<T, N, M>& b) noexcept;
[[nodiscard]] constexpr matrix<T, N, M> sub(T a, const matrix<T, N, M>& b) noexcept;
/**
* Calculates the trace of a square matrix.
@ -645,7 +645,7 @@ constexpr matrix sub(T a, const matrix& b) noexcept;
* @return Sum of elements on the main diagonal.
*/
template <class T, std::size_t N>
constexpr T trace(const matrix<T, N, N>& m) noexcept;
[[nodiscard]] constexpr T trace(const matrix<T, N, N>& m) noexcept;
/**
* Translates a matrix.
@ -656,7 +656,7 @@ constexpr T trace(const matrix& m) noexcept;
* @return Translated matrix.
*/
template <class T>
constexpr matrix<T, 4, 4> translate(const matrix<T, 4, 4>& m, const vector<T, 3>& v);
[[nodiscard]] constexpr matrix<T, 4, 4> translate(const matrix<T, 4, 4>& m, const vector<T, 3>& v);
/**
* Calculates the transpose of a matrix.
@ -666,7 +666,7 @@ constexpr matrix translate(const matrix& m, const vector
* @return Transposed matrix.
*/
template <typename T, std::size_t N, std::size_t M>
constexpr matrix<T, M, N> transpose(const matrix<T, N, M>& m) noexcept;
[[nodiscard]] constexpr matrix<T, M, N> transpose(const matrix<T, N, M>& m) noexcept;
/// @private
template <class T, std::size_t N, std::size_t M, std::size_t... I>

+ 1
- 1
src/math/noise/fbm.hpp View File

@ -44,7 +44,7 @@ namespace noise {
*
*/
template <class T, std::size_t N>
T fbm
[[nodiscard]] T fbm
(
vector<T, N> position,
std::size_t octaves,

+ 5
- 5
src/math/noise/simplex.hpp View File

@ -51,7 +51,7 @@ constexpr std::size_t simplex_edge_count = (N > 1) ? N * simplex_corner_count
* @private
*/
template <class T, std::size_t N, std::size_t... I>
constexpr vector<T, N> make_simplex_corner(std::size_t i, std::index_sequence<I...>)
[[nodiscard]] constexpr vector<T, N> make_simplex_corner(std::size_t i, std::index_sequence<I...>)
{
return {((i >> I) % 2) * T{2} - T{1}...};
}
@ -62,7 +62,7 @@ constexpr vector make_simplex_corner(std::size_t i, std::index_sequence
* @private
*/
template <class T, std::size_t N, std::size_t... I>
constexpr std::array<vector<T, N>, simplex_corner_count<N>> make_simplex_corners(std::index_sequence<I...>)
[[nodiscard]] constexpr std::array<vector<T, N>, simplex_corner_count<N>> make_simplex_corners(std::index_sequence<I...>)
{
return {make_simplex_corner<T, N>(I, std::make_index_sequence<N>{})...};
}
@ -81,7 +81,7 @@ constexpr auto simplex_corners = make_simplex_corners(std::make_index_sequ
* @private
*/
template <class T, std::size_t N, std::size_t... I>
constexpr vector<T, N> make_simplex_edge(std::size_t i, std::index_sequence<I...>)
[[nodiscard]] constexpr vector<T, N> make_simplex_edge(std::size_t i, std::index_sequence<I...>)
{
std::size_t j = i / (simplex_edge_count<N> / N);
@ -104,7 +104,7 @@ constexpr vector make_simplex_edge(std::size_t i, std::index_sequence
* @private
*/
template <class T, std::size_t N, std::size_t... I>
constexpr std::array<vector<T, N>, simplex_edge_count<N>> make_simplex_edges(std::index_sequence<I...>)
[[nodiscard]] constexpr std::array<vector<T, N>, simplex_edge_count<N>> make_simplex_edges(std::index_sequence<I...>)
{
if constexpr (N == 1)
return std::array<vector<T, N>, simplex_edge_count<N>>{vector<T, N>{T{1}}, vector<T, N>{T{-1}}};
@ -138,7 +138,7 @@ constexpr auto simplex_edges = make_simplex_edges(std::make_index_sequence
* @see https://math.stackexchange.com/questions/474638/radius-and-amplitude-of-kernel-for-simplex-noise/1901116
*/
template <class T, std::size_t N>
T simplex
[[nodiscard]] T simplex
(
const vector<T, N>& position,
vector<hash::make_uint_t<T>, N> (*hash)(const vector<T, N>&) = &hash::pcg<T, N>

+ 5
- 5
src/math/noise/voronoi.hpp View File

@ -60,7 +60,7 @@ constexpr std::size_t kernel_size = 4 << std::max(0, (2 * (N - 1)))
* @private
*/
template <class T, std::size_t N, std::size_t... I>
constexpr vector<T, N> kernel_offset(std::size_t i, std::index_sequence<I...>)
[[nodiscard]] constexpr vector<T, N> kernel_offset(std::size_t i, std::index_sequence<I...>)
{
return {static_cast<T>((I ? (i / (2 << std::max<std::size_t>(0, 2 * I - 1))) : i) % 4)...};
}
@ -77,7 +77,7 @@ constexpr vector kernel_offset(std::size_t i, std::index_sequence)
* @private
*/
template <class T, std::size_t N, std::size_t... I>
constexpr std::array<vector<T, N>, kernel_size<N>> generate_kernel(std::index_sequence<I...>)
[[nodiscard]] constexpr std::array<vector<T, N>, kernel_size<N>> generate_kernel(std::index_sequence<I...>)
{
return {kernel_offset<T, N>(I, std::make_index_sequence<N>{})...};
}
@ -107,7 +107,7 @@ constexpr auto kernel = generate_kernel(std::make_index_sequence
* @return Tuple containing the square Euclidean distance from @p position to the F1 cell, the displacement vector from the input position to the F1 cell center, and a hash value indicating the ID of the F1 cell.
*/
template <class T, std::size_t N>
std::tuple
[[nodiscard]] std::tuple
<
// F1 square distance to center
T,
@ -197,7 +197,7 @@ f1
* @return Tuple containing the square Euclidean distance from @p position to the F1 cell center, the displacement vector from the input position to the F1 cell center, a hash value indicating the ID of the F1 cell, and the square Euclidean distance from @p position to the nearest edge.
*/
template <class T, std::size_t N>
std::tuple
[[nodiscard]] std::tuple
<
// F1 square distance to center
T,
@ -320,7 +320,7 @@ f1_edge
* @return Tuple containing the square Euclidean distances, displacement vectors from the input position to the cell centers, and hash values indicating the cell IDs, for both the F1 and F2 cells.
*/
template <class T, std::size_t N>
std::tuple
[[nodiscard]] std::tuple
<
// F1 square distance to center
T,

+ 122
- 0
src/math/numbers.hpp View File

@ -0,0 +1,122 @@
/*
* Copyright (C) 2023 Christopher J. Howard
*
* This file is part of Antkeeper source code.
*
* Antkeeper source code is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Antkeeper source code is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Antkeeper source code. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ANTKEEPER_MATH_NUMBERS_HPP
#define ANTKEEPER_MATH_NUMBERS_HPP
#include <limits>
#include <numbers>
namespace math {
/// Mathematical constants.
namespace numbers {
/// Positive infinity.
template <class T>
inline constexpr T inf = std::numeric_limits<T>::infinity();
/// e.
template <class T>
inline constexpr T e = std::numbers::e_v<T>;
/// log2(e).
template <class T>
inline constexpr T log2_e = std::numbers::log2e_v<T>;
/// log10(e).
template <class T>
inline constexpr T log10_e = std::numbers::log10e_v<T>;
/// Pi.
template <class T>
inline constexpr T pi = std::numbers::pi_v<T>;
/// Pi * 2.
template <class T>
inline constexpr T two_pi = pi<T> * T{2};
/// Pi * 4.
template <class T>
inline constexpr T four_pi = pi<T> * T{4};
/// Pi / 2.
template <class T>
inline constexpr T half_pi = pi<T> / T{2};
/// 1 / Pi.
template <class T>
inline constexpr T inv_pi = std::numbers::inv_pi_v<T>;
/// 1 / sqrt(Pi).
template <class T>
inline constexpr T inv_sqrt_pi = std::numbers::inv_sqrtpi_v<T>;
/// ln(2).
template <class T>
inline constexpr T ln_2 = std::numbers::ln2_v<T>;
/// ln(10).
template <class T>
inline constexpr T ln_10 = std::numbers::ln10_v<T>;
/// sqrt(0.5)
template <class T>
inline constexpr T sqrt_half = T{0.70710678118654752440084436210485};
/// sqrt(2)
template <class T>
inline constexpr T sqrt_2 = std::numbers::sqrt2_v<T>;
/// sqrt(3)
template <class T>
inline constexpr T sqrt_3 = std::numbers::sqrt3_v<T>;
/// 1 / sqrt(3)
template <class T>
inline constexpr T inv_sqrt_3 = std::numbers::inv_sqrt3_v<T>;
/// sqrt(5)
template <class T>
inline constexpr T sqrt_5 = T{2.2360679774997896964091736687313};
/// Euler–Mascheroni constant.
template <class T>
inline constexpr T egamma = std::numbers::egamma_v<T>;
/// Golden ratio constant.
template <class T>
inline constexpr T phi = std::numbers::phi_v<T>;
/// Degrees-to-radians conversion factor.
template <class T>
inline constexpr T deg2rad = pi<T> / T{180};
/// Radians-to-degrees conversion factor.
template <class T>
inline constexpr T rad2deg = T{180} / pi<T>;
} // namespace numbers
// Bring math::numbers into math namespace
using namespace numbers;
} // namespace math
#endif // ANTKEEPER_MATH_NUMBERS_HPP

+ 4
- 4
src/math/polynomial.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_MATH_POLYNOMIAL_HPP
#define ANTKEEPER_MATH_POLYNOMIAL_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include "math/map.hpp"
namespace math {
@ -38,7 +38,7 @@ namespace polynomial {
* @see https://en.wikipedia.org/wiki/Horner%27s_method
*/
template <class InputIt, class T>
T horner(InputIt first, InputIt last, T x)
[[nodiscard]] constexpr T horner(InputIt first, InputIt last, T x)
{
T y = *first;
for (++first; first != last; ++first)
@ -61,7 +61,7 @@ namespace chebyshev {
* @return Evaluated value.
*/
template <class InputIt, class T>
T evaluate(InputIt first, InputIt last, T x)
[[nodiscard]] T evaluate(InputIt first, InputIt last, T x)
{
T y = *(first++);
y += *(first++) * x;
@ -88,7 +88,7 @@ namespace chebyshev {
* @return Evaluated value.
*/
template <class InputIt, class T>
T evaluate(InputIt first, InputIt last, T min, T max, T x)
[[nodiscard]] T evaluate(InputIt first, InputIt last, T min, T max, T x)
{
return evaluate<InputIt, T>(first, last, math::map<T>(x, min, max, T(-1), T(1)));
}

+ 6
- 6
src/math/projection.hpp View File

@ -36,7 +36,7 @@ namespace math {
* @see https://en.wikipedia.org/wiki/Field_of_view_in_video_games
*/
template <class T>
T horizontal_fov(T v, T r)
[[nodiscard]] T horizontal_fov(T v, T r)
{
return T{2} * std::atan(std::tan(v * T{0.5}) * r);
}
@ -52,7 +52,7 @@ T horizontal_fov(T v, T r)
* @see https://en.wikipedia.org/wiki/Field_of_view_in_video_games
*/
template <class T>
T vertical_fov(T h, T r)
[[nodiscard]] T vertical_fov(T h, T r)
{
return T{2} * std::atan(std::tan(h * T{0.5}) / r);
}
@ -70,7 +70,7 @@ T vertical_fov(T h, T r)
* @return Orthographic projection matrix.
*/
template <class T>
constexpr matrix<T, 4, 4> ortho(T left, T right, T bottom, T top, T z_near, T z_far) noexcept
[[nodiscard]] constexpr matrix<T, 4, 4> ortho(T left, T right, T bottom, T top, T z_near, T z_far) noexcept
{
return
{{
@ -94,7 +94,7 @@ constexpr matrix ortho(T left, T right, T bottom, T top, T z_near, T z_
* @return Orthographic projection matrix.
*/
template <class T>
constexpr matrix<T, 4, 4> ortho_half_z(T left, T right, T bottom, T top, T z_near, T z_far) noexcept
[[nodiscard]] constexpr matrix<T, 4, 4> ortho_half_z(T left, T right, T bottom, T top, T z_near, T z_far) noexcept
{
return
{{
@ -116,7 +116,7 @@ constexpr matrix ortho_half_z(T left, T right, T bottom, T top, T z_nea
* @return Perspective projection matrix.
*/
template <class T>
matrix<T, 4, 4> perspective(T vertical_fov, T aspect_ratio, T z_near, T z_far)
[[nodiscard]] matrix<T, 4, 4> perspective(T vertical_fov, T aspect_ratio, T z_near, T z_far)
{
T half_fov = vertical_fov * T(0.5);
T f = std::cos(half_fov) / std::sin(half_fov);
@ -141,7 +141,7 @@ matrix perspective(T vertical_fov, T aspect_ratio, T z_near, T z_far)
* @return Perspective projection matrix.
*/
template <class T>
matrix<T, 4, 4> perspective_half_z(T vertical_fov, T aspect_ratio, T z_near, T z_far)
[[nodiscard]] matrix<T, 4, 4> perspective_half_z(T vertical_fov, T aspect_ratio, T z_near, T z_far)
{
T half_fov = vertical_fov * T(0.5);
T f = std::cos(half_fov) / std::sin(half_fov);

+ 13
- 19
src/math/quadrature.hpp View File

@ -33,29 +33,13 @@ namespace quadrature {
*
* @param f Unary function object to integrate.
* @param first,last Range of sample points on `[first, last)`.
* @return Approximated integral of @p f.
*
* @see https://en.wikipedia.org/wiki/Simpson%27s_rule
*/
template<class UnaryOp, class InputIt>
typename std::invoke_result<UnaryOp, typename std::iterator_traits<InputIt>::value_type>::type
simpson(UnaryOp f, InputIt first, InputIt last);
/**
* Approximates the definite integral of a function using the trapezoidal rule.
*
* @param f Unary function object to integrate.
* @param first,last Range of sample points on `[first, last)`.
* @return Approximated integral of @p f.
*
* @see https://en.wikipedia.org/wiki/Trapezoidal_rule
* @see https://en.wikipedia.org/wiki/Simpson%27s_rule
*/
template<class UnaryOp, class InputIt>
typename std::invoke_result<UnaryOp, typename std::iterator_traits<InputIt>::value_type>::type
trapezoid(UnaryOp f, InputIt first, InputIt last);
template<class UnaryOp, class InputIt>
typename std::invoke_result<UnaryOp, typename std::iterator_traits<InputIt>::value_type>::type
[[nodiscard]] typename std::invoke_result<UnaryOp, typename std::iterator_traits<InputIt>::value_type>::type
simpson(UnaryOp f, InputIt first, InputIt last)
{
typedef typename std::iterator_traits<InputIt>::value_type input_type;
@ -93,8 +77,18 @@ typename std::invoke_result::val
return sum / difference_type(6);
}
/**
* Approximates the definite integral of a function using the trapezoidal rule.
*
* @param f Unary function object to integrate.
* @param first,last Range of sample points on `[first, last)`.
*
* @return Approximated integral of @p f.
*
* @see https://en.wikipedia.org/wiki/Trapezoidal_rule
*/
template<class UnaryOp, class InputIt>
typename std::invoke_result<UnaryOp, typename std::iterator_traits<InputIt>::value_type>::type
[[nodiscard]] typename std::invoke_result<UnaryOp, typename std::iterator_traits<InputIt>::value_type>::type
trapezoid(UnaryOp f, InputIt first, InputIt last)
{
typedef typename std::iterator_traits<InputIt>::value_type input_type;

+ 43
- 43
src/math/quaternion.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_MATH_QUATERNION_HPP
#define ANTKEEPER_MATH_QUATERNION_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include "math/matrix.hpp"
#include "math/vector.hpp"
#include <cmath>
@ -54,11 +54,11 @@ struct quaternion
/// Returns a reference to the quaternion real part.
/// @{
inline constexpr scalar_type& w() noexcept
[[nodiscard]] inline constexpr scalar_type& w() noexcept
{
return r;
}
inline constexpr const scalar_type& w() const noexcept
[[nodiscard]] inline constexpr const scalar_type& w() const noexcept
{
return r;
}
@ -66,11 +66,11 @@ struct quaternion
/// Returns a reference to the first element of the quaternion imaginary part.
/// @{
inline constexpr scalar_type& x() noexcept
[[nodiscard]] inline constexpr scalar_type& x() noexcept
{
return i.x();
}
inline constexpr const scalar_type& x() const noexcept
[[nodiscard]] inline constexpr const scalar_type& x() const noexcept
{
return i.x();
}
@ -78,11 +78,11 @@ struct quaternion
/// Returns a reference to the second element of the quaternion imaginary part.
/// @{
inline constexpr scalar_type& y() noexcept
[[nodiscard]] inline constexpr scalar_type& y() noexcept
{
return i.y();
}
inline constexpr const scalar_type& y() const noexcept
[[nodiscard]] inline constexpr const scalar_type& y() const noexcept
{
return i.y();
}
@ -90,11 +90,11 @@ struct quaternion
/// Returns a reference to the third element of the quaternion imaginary part.
/// @{
inline constexpr scalar_type& z() noexcept
[[nodiscard]] inline constexpr scalar_type& z() noexcept
{
return i.z();
}
inline constexpr const scalar_type& z() const noexcept
[[nodiscard]] inline constexpr const scalar_type& z() const noexcept
{
return i.z();
}
@ -107,7 +107,7 @@ struct quaternion
*
* @return Quaternion representing an x-axis rotation.
*/
static quaternion rotate_x(scalar_type angle)
[[nodiscard]] static quaternion rotate_x(scalar_type angle)
{
return {std::cos(angle * T(0.5)), std::sin(angle * T(0.5)), T(0), T(0)};
}
@ -119,7 +119,7 @@ struct quaternion
*
* @return Quaternion representing an y-axis rotation.
*/
static quaternion rotate_y(scalar_type angle)
[[nodiscard]] static quaternion rotate_y(scalar_type angle)
{
return {std::cos(angle * T(0.5)), T(0), std::sin(angle * T(0.5)), T(0)};
}
@ -130,7 +130,7 @@ struct quaternion
* @param angle Angle of rotation, in radians.
* @return Quaternion representing an z-axis rotation.
*/
static quaternion rotate_z(scalar_type angle)
[[nodiscard]] static quaternion rotate_z(scalar_type angle)
{
return {std::cos(angle * T(0.5)), T(0), T(0), std::sin(angle * T(0.5))};
}
@ -143,7 +143,7 @@ struct quaternion
* @return Type-casted quaternion.
*/
template <class U>
inline constexpr explicit operator quaternion<U>() const noexcept
[[nodiscard]] inline constexpr explicit operator quaternion<U>() const noexcept
{
return {static_cast<U>(r), vector<U, 3>(i)};
}
@ -153,7 +153,7 @@ struct quaternion
*
* @return Rotation matrix.
*/
constexpr explicit operator matrix_type() const noexcept
[[nodiscard]] constexpr explicit operator matrix_type() const noexcept
{
const T xx = x() * x();
const T xy = x() * y();
@ -178,19 +178,19 @@ struct quaternion
*
* @return Vector containing the real and imaginary parts of the quaternion.
*/
inline constexpr explicit operator vector<T, 4>() const noexcept
[[nodiscard]] inline constexpr explicit operator vector<T, 4>() const noexcept
{
return {r, i[0], i[1], i[2]};
}
/// Returns a zero quaternion, where every scalar is equal to zero.
static constexpr quaternion zero() noexcept
[[nodiscard]] static constexpr quaternion zero() noexcept
{
return {};
}
/// Returns a rotation identity quaternion.
static constexpr quaternion identity() noexcept
[[nodiscard]] static constexpr quaternion identity() noexcept
{
return {T{1}, vector_type::zero()};
}
@ -205,7 +205,7 @@ struct quaternion
* @return Sum of the two quaternions.
*/
template <class T>
constexpr quaternion<T> add(const quaternion<T>& a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr quaternion<T> add(const quaternion<T>& a, const quaternion<T>& b) noexcept;
/**
* Adds a quaternion and a scalar.
@ -216,7 +216,7 @@ constexpr quaternion add(const quaternion& a, const quaternion& b) noex
* @return Sum of the quaternion and scalar.
*/
template <class T>
constexpr quaternion<T> add(const quaternion<T>& a, T b) noexcept;
[[nodiscard]] constexpr quaternion<T> add(const quaternion<T>& a, T b) noexcept;
/**
* Calculates the conjugate of a quaternion.
@ -226,7 +226,7 @@ constexpr quaternion add(const quaternion& a, T b) noexcept;
* @return Conjugate of the quaternion.
*/
template <class T>
constexpr quaternion<T> conjugate(const quaternion<T>& q) noexcept;
[[nodiscard]] constexpr quaternion<T> conjugate(const quaternion<T>& q) noexcept;
/**
* Calculates the dot product of two quaternions.
@ -237,7 +237,7 @@ constexpr quaternion conjugate(const quaternion& q) noexcept;
* @return Dot product of the two quaternions.
*/
template <class T>
constexpr T dot(const quaternion<T>& a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr T dot(const quaternion<T>& a, const quaternion<T>& b) noexcept;
/**
* Divides a quaternion by another quaternion.
@ -248,7 +248,7 @@ constexpr T dot(const quaternion& a, const quaternion& b) noexcept;
* @return Result of the division.
*/
template <class T>
constexpr quaternion<T> div(const quaternion<T>& a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr quaternion<T> div(const quaternion<T>& a, const quaternion<T>& b) noexcept;
/**
* Divides a quaternion by a scalar.
@ -259,7 +259,7 @@ constexpr quaternion div(const quaternion& a, const quaternion& b) noex
* @return Result of the division.
*/
template <class T>
constexpr quaternion<T> div(const quaternion<T>& a, T b) noexcept;
[[nodiscard]] constexpr quaternion<T> div(const quaternion<T>& a, T b) noexcept;
/**
* Divides a scalar by a quaternion.
@ -270,7 +270,7 @@ constexpr quaternion div(const quaternion& a, T b) noexcept;
* @return Result of the division.
*/
template <class T>
constexpr quaternion<T> div(T a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr quaternion<T> div(T a, const quaternion<T>& b) noexcept;
/**
* Calculates the inverse length of a quaternion.
@ -280,7 +280,7 @@ constexpr quaternion div(T a, const quaternion& b) noexcept;
* @return Inverse length of the quaternion.
*/
template <class T>
T inv_length(const quaternion<T>& q);
[[nodiscard]] T inv_length(const quaternion<T>& q);
/**
* Calculates the length of a quaternion.
@ -290,7 +290,7 @@ T inv_length(const quaternion& q);
* @return Length of the quaternion.
*/
template <class T>
T length(const quaternion<T>& q);
[[nodiscard]] T length(const quaternion<T>& q);
/**
* Performs linear interpolation between two quaternions.
@ -302,7 +302,7 @@ T length(const quaternion& q);
* @return Interpolated quaternion.
*/
template <class T>
constexpr quaternion<T> lerp(const quaternion<T>& a, const quaternion<T>& b, T t) noexcept;
[[nodiscard]] constexpr quaternion<T> lerp(const quaternion<T>& a, const quaternion<T>& b, T t) noexcept;
/**
* Creates a unit quaternion rotation using forward and up vectors.
@ -313,7 +313,7 @@ constexpr quaternion lerp(const quaternion& a, const quaternion& b, T t
* @return Unit rotation quaternion.
*/
template <class T>
quaternion<T> look_rotation(const vector<T, 3>& forward, vector<T, 3> up);
[[nodiscard]] quaternion<T> look_rotation(const vector<T, 3>& forward, vector<T, 3> up);
/**
* Multiplies two quaternions.
@ -324,7 +324,7 @@ quaternion look_rotation(const vector& forward, vector up);
* @return Product of the two quaternions.
*/
template <class T>
constexpr quaternion<T> mul(const quaternion<T>& a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr quaternion<T> mul(const quaternion<T>& a, const quaternion<T>& b) noexcept;
/**
* Multiplies a quaternion by a scalar.
@ -335,7 +335,7 @@ constexpr quaternion mul(const quaternion& a, const quaternion& b) noex
* @return Product of the quaternion and scalar.
*/
template <class T>
constexpr quaternion<T> mul(const quaternion<T>& a, T b) noexcept;
[[nodiscard]] constexpr quaternion<T> mul(const quaternion<T>& a, T b) noexcept;
/**
* Calculates the product of a quaternion and a vector.
@ -347,9 +347,9 @@ constexpr quaternion mul(const quaternion& a, T b) noexcept;
*/
/// @{
template <class T>
constexpr vector<T, 3> mul(const quaternion<T>& a, const vector<T, 3>& b) noexcept;
[[nodiscard]] constexpr vector<T, 3> mul(const quaternion<T>& a, const vector<T, 3>& b) noexcept;
template <class T>
constexpr vector<T, 3> mul(const vector<T, 3>& a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr vector<T, 3> mul(const vector<T, 3>& a, const quaternion<T>& b) noexcept;
/// @}
/**
@ -360,7 +360,7 @@ constexpr vector mul(const vector& a, const quaternion& b) noexce
* @return Negated quaternion.
*/
template <class T>
constexpr quaternion<T> negate(const quaternion<T>& q) noexcept;
[[nodiscard]] constexpr quaternion<T> negate(const quaternion<T>& q) noexcept;
/**
* Performs normalized linear interpolation between two quaternions.
@ -372,7 +372,7 @@ constexpr quaternion negate(const quaternion& q) noexcept;
* @return Interpolated quaternion.
*/
template <class T>
quaternion<T> nlerp(const quaternion<T>& a, const quaternion<T>& b, T t);
[[nodiscard]] quaternion<T> nlerp(const quaternion<T>& a, const quaternion<T>& b, T t);
/**
* Normalizes a quaternion.
@ -382,7 +382,7 @@ quaternion nlerp(const quaternion& a, const quaternion& b, T t);
* @return Normalized quaternion.
*/
template <class T>
quaternion<T> normalize(const quaternion<T>& q);
[[nodiscard]] quaternion<T> normalize(const quaternion<T>& q);
/**
* Creates a rotation from an angle and axis.
@ -393,7 +393,7 @@ quaternion normalize(const quaternion& q);
* @return Quaternion representing the rotation.
*/
template <class T>
quaternion<T> angle_axis(T angle, const vector<T, 3>& axis);
[[nodiscard]] quaternion<T> angle_axis(T angle, const vector<T, 3>& axis);
/**
* Calculates the minimum rotation between two normalized direction vectors.
@ -404,7 +404,7 @@ quaternion angle_axis(T angle, const vector& axis);
* @return Quaternion representing the minimum rotation between the source and destination vectors.
*/
template <class T>
quaternion<T> rotation(const vector<T, 3>& source, const vector<T, 3>& destination);
[[nodiscard]] quaternion<T> rotation(const vector<T, 3>& source, const vector<T, 3>& destination);
/**
* Performs spherical linear interpolation between two quaternions.
@ -416,7 +416,7 @@ quaternion rotation(const vector& source, const vector& destinati
* @return Interpolated quaternion.
*/
template <class T>
quaternion<T> slerp(const quaternion<T>& a, const quaternion<T>& b, T t, T error = T{1e-6});
[[nodiscard]] quaternion<T> slerp(const quaternion<T>& a, const quaternion<T>& b, T t, T error = T{1e-6});
/**
* Calculates the square length of a quaternion. The square length can be calculated faster than the length because a call to `std::sqrt` is saved.
@ -426,7 +426,7 @@ quaternion slerp(const quaternion& a, const quaternion& b, T t, T error
* @return Square length of the quaternion.
*/
template <class T>
constexpr T sqr_length(const quaternion<T>& q) noexcept;
[[nodiscard]] constexpr T sqr_length(const quaternion<T>& q) noexcept;
/**
* Subtracts a quaternion from another quaternion.
@ -437,7 +437,7 @@ constexpr T sqr_length(const quaternion& q) noexcept;
* @return Difference between the quaternions.
*/
template <class T>
constexpr quaternion<T> sub(const quaternion<T>& a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr quaternion<T> sub(const quaternion<T>& a, const quaternion<T>& b) noexcept;
/**
* Subtracts a quaternion and a scalar.
@ -449,9 +449,9 @@ constexpr quaternion sub(const quaternion& a, const quaternion& b) noex
*/
/// @{
template <class T>
constexpr quaternion<T> sub(const quaternion<T>& a, T b) noexcept;
[[nodiscard]] constexpr quaternion<T> sub(const quaternion<T>& a, T b) noexcept;
template <class T>
constexpr quaternion<T> sub(T a, const quaternion<T>& b) noexcept;
[[nodiscard]] constexpr quaternion<T> sub(T a, const quaternion<T>& b) noexcept;
/// @}
/**
@ -476,7 +476,7 @@ void swing_twist(const quaternion& q, const vector& a, quaternion& q
* @return Unit quaternion representing the rotation described by @p m.
*/
template <class T>
quaternion<T> quaternion_cast(const matrix<T, 3, 3>& m);
[[nodiscard]] quaternion<T> quaternion_cast(const matrix<T, 3, 3>& m);
template <class T>
inline constexpr quaternion<T> add(const quaternion<T>& a, const quaternion<T>& b) noexcept

+ 1
- 4
src/math/random.hpp View File

@ -35,10 +35,7 @@ namespace math {
* @return Pseudo-random floating point number.
*/
template <typename T = float>
T random(T start, T end);
template <typename T>
inline T random(T start, T end)
[[nodiscard]] T random(T start, T end)
{
static_assert(std::is_floating_point<T>::value);
constexpr T rand_max_inverse = T(1) / static_cast<T>(RAND_MAX);

+ 6
- 6
src/math/se3.hpp View File

@ -54,10 +54,10 @@ public:
quaternion_type r;
/// Returns the inverse of this SE(3) transformation.
se3 inverse() const;
[[nodiscard]] se3 inverse() const;
/// Returns a matrix representation of the SE(3) transformation.
matrix_type matrix() const;
[[nodiscard]] matrix_type matrix() const;
/**
* Transforms a vector by this SE(3) transformation.
@ -65,7 +65,7 @@ public:
* @param x Untransformed vector.
* @return Transformed vector.
*/
vector_type transform(const vector_type& x) const;
[[nodiscard]] vector_type transform(const vector_type& x) const;
/**
* Transforms an SE(3) transformation by this SE(3) transformation.
@ -73,13 +73,13 @@ public:
* @param x Other SE(3) transformation.
* @return Frame in this se3's space.
*/
se3 transform(const se3& x) const;
[[nodiscard]] se3 transform(const se3& x) const;
/// @copydoc se3::transform(const vector_type&) const
vector_type operator*(const vector_type& x) const;
[[nodiscard]] vector_type operator*(const vector_type& x) const;
/// @copydoc se3::transform(const se3&) const
se3 operator*(const se3& x) const;
[[nodiscard]] se3 operator*(const se3& x) const;
};
template <class T>

+ 4
- 4
src/math/transform-functions.hpp View File

@ -31,7 +31,7 @@ namespace math {
* @param t Transform of which to take the inverse.
*/
template <class T>
transform<T> inverse(const transform<T>& t);
[[nodiscard]] transform<T> inverse(const transform<T>& t);
/**
* Converts a transform to a transformation matrix.
@ -40,7 +40,7 @@ transform inverse(const transform& t);
* @return Matrix representing the transformation described by `t`.
*/
template <class T>
matrix<T, 4, 4> matrix_cast(const transform<T>& t);
[[nodiscard]] matrix<T, 4, 4> matrix_cast(const transform<T>& t);
/**
* Multiplies two transforms.
@ -50,7 +50,7 @@ matrix matrix_cast(const transform& t);
* @return Product of the two transforms.
*/
template <class T>
transform<T> mul(const transform<T>& x, const transform<T>& y);
[[nodiscard]] transform<T> mul(const transform<T>& x, const transform<T>& y);
/**
* Multiplies a vector by a transform.
@ -60,7 +60,7 @@ transform mul(const transform& x, const transform& y);
* @return Product of the transform and vector.
*/
template <class T>
vector<T, 3> mul(const transform<T>& t, const vector<T, 3>& v);
[[nodiscard]] vector<T, 3> mul(const transform<T>& t, const vector<T, 3>& v);
template <class T>
transform<T> inverse(const transform<T>& t)

+ 2
- 2
src/math/transform-operators.hpp View File

@ -25,11 +25,11 @@
/// @copydoc math::mul(const math::transform<T>&, const math::transform<T>&)
template <class T>
math::transform<T> operator*(const math::transform<T>& x, const math::transform<T>& y);
[[nodiscard]] math::transform<T> operator*(const math::transform<T>& x, const math::transform<T>& y);
/// @copydoc math::mul(const math::transform<T>&, const math::vector<T, 3>&)
template <class T>
math::vector<T, 3> operator*(const math::transform<T>& t, const math::vector<T, 3>& v);
[[nodiscard]] math::vector<T, 3> operator*(const math::transform<T>& t, const math::vector<T, 3>& v);
/**
* Multiplies two transforms and stores the result in the first transform.

+ 89
- 89
src/math/vector.hpp View File

@ -55,7 +55,7 @@ struct vector
/// @private
template <class U, std::size_t... I>
inline constexpr vector<U, N> type_cast(std::index_sequence<I...>) const noexcept
[[nodiscard]] inline constexpr vector<U, N> type_cast(std::index_sequence<I...>) const noexcept
{
return {static_cast<U>(elements[I])...};
}
@ -68,14 +68,14 @@ struct vector
* @return Vector containing the type-casted elements.
*/
template <class U>
inline constexpr explicit operator vector<U, N>() const noexcept
[[nodiscard]] inline constexpr explicit operator vector<U, N>() const noexcept
{
return type_cast<U>(std::make_index_sequence<N>{});
}
/// @private
template <std::size_t M, std::size_t... I>
inline constexpr vector<T, M> size_cast(std::index_sequence<I...>) const noexcept
[[nodiscard]] inline constexpr vector<T, M> size_cast(std::index_sequence<I...>) const noexcept
{
return {(I < N) ? elements[I] : T{0} ...};
}
@ -88,7 +88,7 @@ struct vector
* @return *m*-dimensional vector.
*/
template <std::size_t M>
inline constexpr explicit operator vector<T, M>() const noexcept
[[nodiscard]] inline constexpr explicit operator vector<T, M>() const noexcept
{
return size_cast<M>(std::make_index_sequence<M>{});
}
@ -106,11 +106,11 @@ struct vector
* @return Reference to the element at index @p i.
*/
/// @{
inline constexpr element_type& operator[](std::size_t i) noexcept
[[nodiscard]] inline constexpr element_type& operator[](std::size_t i) noexcept
{
return elements[i];
}
inline constexpr const element_type& operator[](std::size_t i) const noexcept
[[nodiscard]] inline constexpr const element_type& operator[](std::size_t i) const noexcept
{
return elements[i];
}
@ -120,11 +120,11 @@ struct vector
* Returns a reference to the first element.
*/
/// @{
inline constexpr element_type& front() noexcept
[[nodiscard]] inline constexpr element_type& front() noexcept
{
return elements[0];
}
inline constexpr const element_type& front() const noexcept
[[nodiscard]] inline constexpr const element_type& front() const noexcept
{
return elements[0];
}
@ -134,11 +134,11 @@ struct vector
* Returns a reference to the last element.
*/
/// @{
inline constexpr element_type& back() noexcept
[[nodiscard]] inline constexpr element_type& back() noexcept
{
return elements[N - 1];
}
inline constexpr const element_type& back() const noexcept
[[nodiscard]] inline constexpr const element_type& back() const noexcept
{
return elements[N - 1];
}
@ -148,11 +148,11 @@ struct vector
* Returns a pointer to the element array.
*/
/// @{
inline constexpr element_type* data() noexcept
[[nodiscard]] inline constexpr element_type* data() noexcept
{
return elements;
};
inline constexpr const element_type* data() const noexcept
[[nodiscard]] inline constexpr const element_type* data() const noexcept
{
return elements;
};
@ -160,12 +160,12 @@ struct vector
/// Returns a reference to the first element.
/// @{
inline constexpr element_type& x() noexcept
[[nodiscard]] inline constexpr element_type& x() noexcept
{
static_assert(N > 0, "Vector does not contain an x element.");
return elements[0];
}
inline constexpr const element_type& x() const noexcept
[[nodiscard]] inline constexpr const element_type& x() const noexcept
{
static_assert(N > 0, "Vector does not contain an x element.");
return elements[0];
@ -176,12 +176,12 @@ struct vector
* Returns a reference to the second element.
*/
/// @{
inline constexpr element_type& y() noexcept
[[nodiscard]] inline constexpr element_type& y() noexcept
{
static_assert(N > 1, "Vector does not contain a y element.");
return elements[1];
}
inline constexpr const element_type& y() const noexcept
[[nodiscard]] inline constexpr const element_type& y() const noexcept
{
static_assert(N > 1, "Vector does not contain a y element.");
return elements[1];
@ -192,12 +192,12 @@ struct vector
* Returns a reference to the third element.
*/
/// @{
inline constexpr element_type& z() noexcept
[[nodiscard]] inline constexpr element_type& z() noexcept
{
static_assert(N > 2, "Vector does not contain a z element.");
return elements[2];
}
inline constexpr const element_type& z() const noexcept
[[nodiscard]] inline constexpr const element_type& z() const noexcept
{
static_assert(N > 2, "Vector does not contain a z element.");
return elements[2];
@ -213,15 +213,15 @@ struct vector
* Returns an iterator to the first element.
*/
/// @{
inline constexpr element_type* begin() noexcept
[[nodiscard]] inline constexpr element_type* begin() noexcept
{
return elements;
}
inline constexpr const element_type* begin() const noexcept
[[nodiscard]] inline constexpr const element_type* begin() const noexcept
{
return elements;
}
inline constexpr const element_type* cbegin() const noexcept
[[nodiscard]] inline constexpr const element_type* cbegin() const noexcept
{
return elements;
}
@ -231,15 +231,15 @@ struct vector
* Returns an iterator to the element following the last element.
*/
/// @{
inline constexpr element_type* end() noexcept
[[nodiscard]] inline constexpr element_type* end() noexcept
{
return elements + N;
}
inline constexpr const element_type* end() const noexcept
[[nodiscard]] inline constexpr const element_type* end() const noexcept
{
return elements + N;
}
inline constexpr const element_type* cend() const noexcept
[[nodiscard]] inline constexpr const element_type* cend() const noexcept
{
return elements + N;
}
@ -249,15 +249,15 @@ struct vector
* Returns a reverse iterator to the first element of the reversed vector.
*/
/// @{
inline constexpr std::reverse_iterator<element_type*> rbegin() noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<element_type*> rbegin() noexcept
{
return std::reverse_iterator<element_type*>(elements + N);
}
inline constexpr std::reverse_iterator<const element_type*> rbegin() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const element_type*> rbegin() const noexcept
{
return std::reverse_iterator<const element_type*>(elements + N);
}
inline constexpr std::reverse_iterator<const element_type*> crbegin() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const element_type*> crbegin() const noexcept
{
return std::reverse_iterator<const element_type*>(elements + N);
}
@ -267,15 +267,15 @@ struct vector
* Returns a reverse iterator to the element following the last element of the reversed vector.
*/
/// @{
inline constexpr std::reverse_iterator<element_type*> rend() noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<element_type*> rend() noexcept
{
return std::reverse_iterator<element_type*>(elements);
}
inline constexpr std::reverse_iterator<const element_type*> rend() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const element_type*> rend() const noexcept
{
return std::reverse_iterator<const element_type*>(elements);
}
inline constexpr std::reverse_iterator<const element_type*> crend() const noexcept
[[nodiscard]] inline constexpr std::reverse_iterator<const element_type*> crend() const noexcept
{
return std::reverse_iterator<const element_type*>(elements);
}
@ -289,7 +289,7 @@ struct vector
/**
* Returns the number of elements in the vector.
*/
inline constexpr std::size_t size() const noexcept
[[nodiscard]] inline constexpr std::size_t size() const noexcept
{
return N;
};
@ -302,14 +302,14 @@ struct vector
/**
* Returns a zero vector, where every element is equal to zero.
*/
static constexpr vector zero() noexcept
[[nodiscard]] static constexpr vector zero() noexcept
{
return {};
}
/// @private
template <std::size_t... I>
static constexpr vector one(std::index_sequence<I...>) noexcept
[[nodiscard]] static constexpr vector one(std::index_sequence<I...>) noexcept
{
//return {T{1}...};
@ -320,7 +320,7 @@ struct vector
/**
* Returns a vector of ones, where every element is equal to one.
*/
static constexpr vector one() noexcept
[[nodiscard]] static constexpr vector one() noexcept
{
return one(std::make_index_sequence<N>{});
}
@ -348,7 +348,7 @@ using vector4 = vector;
* @return Absolute values of input vector elements.
*/
template <class T, std::size_t N>
constexpr vector<T, N> abs(const vector<T, N>& x);
[[nodiscard]] constexpr vector<T, N> abs(const vector<T, N>& x);
/**
* Adds two values.
@ -360,9 +360,9 @@ constexpr vector abs(const vector& x);
*/
/// @{
template <class T, std::size_t N>
constexpr vector<T, N> add(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<T, N> add(const vector<T, N>& x, const vector<T, N>& y) noexcept;
template <class T, std::size_t N>
constexpr vector<T, N> add(const vector<T, N>& x, T y) noexcept;
[[nodiscard]] constexpr vector<T, N> add(const vector<T, N>& x, T y) noexcept;
/// @}
/**
@ -373,7 +373,7 @@ constexpr vector add(const vector& x, T y) noexcept;
* @return `true` if all elements are `true`, `false` otherwise.
*/
template <std::size_t N>
constexpr bool all(const vector<bool, N>& x) noexcept;
[[nodiscard]] constexpr bool all(const vector<bool, N>& x) noexcept;
/**
* Checks if any elements of a boolean vector are `true`.
@ -383,7 +383,7 @@ constexpr bool all(const vector& x) noexcept;
* @return `true` if any elements are `true`, `false` otherwise.
*/
template <std::size_t N>
constexpr bool any(const vector<bool, N>& x) noexcept;
[[nodiscard]] constexpr bool any(const vector<bool, N>& x) noexcept;
/**
* Performs a element-wise ceil operation.
@ -393,7 +393,7 @@ constexpr bool any(const vector& x) noexcept;
* @return Component-wise ceil of input vector.
*/
template <class T, std::size_t N>
constexpr vector<T, N> ceil(const vector<T, N>& x);
[[nodiscard]] constexpr vector<T, N> ceil(const vector<T, N>& x);
/**
* Clamps the values of a vector's elements.
@ -406,9 +406,9 @@ constexpr vector ceil(const vector& x);
*/
/// @{
template <class T, std::size_t N>
constexpr vector<T, N> clamp(const vector<T, N>& x, const vector<T, N>& min, const vector<T, N>& max);
[[nodiscard]] constexpr vector<T, N> clamp(const vector<T, N>& x, const vector<T, N>& min, const vector<T, N>& max);
template <class T, std::size_t N>
constexpr vector<T, N> clamp(const vector<T, N>& x, T min, T max);
[[nodiscard]] constexpr vector<T, N> clamp(const vector<T, N>& x, T min, T max);
/// @}
/**
@ -420,7 +420,7 @@ constexpr vector clamp(const vector& x, T min, T max);
* @return Length-clamped vector.
*/
template <class T, std::size_t N>
vector<T, N> clamp_length(const vector<T, N>& x, T max_length);
[[nodiscard]] vector<T, N> clamp_length(const vector<T, N>& x, T max_length);
/**
* Calculate the cross product of two vectors.
@ -431,7 +431,7 @@ vector clamp_length(const vector& x, T max_length);
* @return Cross product of the two vectors.
*/
template <class T>
constexpr vector<T, 3> cross(const vector<T, 3>& x, const vector<T, 3>& y) noexcept;
[[nodiscard]] constexpr vector<T, 3> cross(const vector<T, 3>& x, const vector<T, 3>& y) noexcept;
/**
* Calculates the distance between two points.
@ -442,7 +442,7 @@ constexpr vector cross(const vector& x, const vector& y) noexc
* @return Distance between the two points.
*/
template <class T, std::size_t N>
T distance(const vector<T, N>& p0, const vector<T, N>& p1);
[[nodiscard]] T distance(const vector<T, N>& p0, const vector<T, N>& p1);
/**
* Divides a vector by a value.
@ -454,11 +454,11 @@ T distance(const vector& p0, const vector& p1);
*/
/// @{
template <class T, std::size_t N>
constexpr vector<T, N> div(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<T, N> div(const vector<T, N>& x, const vector<T, N>& y) noexcept;
template <class T, std::size_t N>
constexpr vector<T, N> div(const vector<T, N>& x, T y) noexcept;
[[nodiscard]] constexpr vector<T, N> div(const vector<T, N>& x, T y) noexcept;
template <class T, std::size_t N>
constexpr vector<T, N> div(T x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<T, N> div(T x, const vector<T, N>& y) noexcept;
/// @}
/**
@ -470,7 +470,7 @@ constexpr vector div(T x, const vector& y) noexcept;
* @return Dot product of the two vectors.
*/
template <class T, std::size_t N>
constexpr T dot(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr T dot(const vector<T, N>& x, const vector<T, N>& y) noexcept;
/**
* Compares two vectors for equality
@ -481,7 +481,7 @@ constexpr T dot(const vector& x, const vector& y) noexcept;
* @return Boolean vector containing the result of the element comparisons.
*/
template <class T, std::size_t N>
constexpr vector<bool, N> equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<bool, N> equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
/**
* Performs a element-wise floor operation.
@ -491,7 +491,7 @@ constexpr vector equal(const vector& x, const vector& y) no
* @return Component-wise floor of input vector.
*/
template <class T, std::size_t N>
constexpr vector<T, N> floor(const vector<T, N>& x);
[[nodiscard]] constexpr vector<T, N> floor(const vector<T, N>& x);
/**
* Performs a multiply-add operation.
@ -504,9 +504,9 @@ constexpr vector floor(const vector& x);
*/
/// @{
template <class T, std::size_t N>
constexpr vector<T, N> fma(const vector<T, N>& x, const vector<T, N>& y, const vector<T, N>& z);
[[nodiscard]] constexpr vector<T, N> fma(const vector<T, N>& x, const vector<T, N>& y, const vector<T, N>& z);
template <class T, std::size_t N>
constexpr vector<T, N> fma(const vector<T, N>& x, T y, T z);
[[nodiscard]] constexpr vector<T, N> fma(const vector<T, N>& x, T y, T z);
/// @}
/**
@ -517,7 +517,7 @@ constexpr vector fma(const vector& x, T y, T z);
* @return Fractional parts of input vector.
*/
template <class T, std::size_t N>
constexpr vector<T, N> fract(const vector<T, N>& x);
[[nodiscard]] constexpr vector<T, N> fract(const vector<T, N>& x);
/**
* Extracts the Ith element from a vector.
@ -532,13 +532,13 @@ constexpr vector fract(const vector& x);
*/
/// @{
template<std::size_t I, class T, std::size_t N>
constexpr T& get(math::vector<T, N>& v) noexcept;
[[nodiscard]] constexpr T& get(math::vector<T, N>& v) noexcept;
template<std::size_t I, class T, std::size_t N>
constexpr T&& get(math::vector<T, N>&& v) noexcept;
[[nodiscard]] constexpr T&& get(math::vector<T, N>&& v) noexcept;
template<std::size_t I, class T, std::size_t N>
constexpr const T& get(const math::vector<T, N>& v) noexcept;
[[nodiscard]] constexpr const T& get(const math::vector<T, N>& v) noexcept;
template<std::size_t I, class T, std::size_t N>
constexpr const T&& get(const math::vector<T, N>&& v) noexcept;
[[nodiscard]] constexpr const T&& get(const math::vector<T, N>&& v) noexcept;
/// @}
/**
@ -550,7 +550,7 @@ constexpr const T&& get(const math::vector&& v) noexcept;
* @return Boolean vector containing the result of the element comparisons.
*/
template <class T, std::size_t N>
constexpr vector<bool, N> greater_than(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<bool, N> greater_than(const vector<T, N>& x, const vector<T, N>& y) noexcept;
/**
* Performs a element-wise greater-than or equal-to comparison of two vectors.
@ -561,7 +561,7 @@ constexpr vector greater_than(const vector& x, const vector
* @return Boolean vector containing the result of the element comparisons.
*/
template <class T, std::size_t N>
constexpr vector<bool, N> greater_than_equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<bool, N> greater_than_equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
/**
* Calculates the inverse length of a vector.
@ -571,7 +571,7 @@ constexpr vector greater_than_equal(const vector& x, const vector
* @return Inverse length of the vector.
*/
template <class T, std::size_t N>
T inv_length(const vector<T, N>& x);
[[nodiscard]] T inv_length(const vector<T, N>& x);
/**
* Calculates the length of a vector.
@ -581,7 +581,7 @@ T inv_length(const vector& x);
* @return Length of the vector.
*/
template <class T, std::size_t N>
T length(const vector<T, N>& x);
[[nodiscard]] T length(const vector<T, N>& x);
/**
* Performs a element-wise less-than comparison of two vectors.
@ -592,7 +592,7 @@ T length(const vector& x);
* @return Boolean vector containing the result of the element comparisons.
*/
template <class T, std::size_t N>
constexpr vector<bool, N> less_than(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<bool, N> less_than(const vector<T, N>& x, const vector<T, N>& y) noexcept;
/**
* Performs a element-wise less-than or equal-to comparison of two vectors.
@ -603,7 +603,7 @@ constexpr vector less_than(const vector& x, const vector& y
* @return Boolean vector containing the result of the element comparisons.
*/
template <class T, std::size_t N>
constexpr vector<bool, N> less_than_equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<bool, N> less_than_equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
/**
* Returns a vector containing the maximum elements of two vectors.
@ -614,7 +614,7 @@ constexpr vector less_than_equal(const vector& x, const vector
* @return Maximum elements of the two vectors.
*/
template <class T, std::size_t N>
constexpr vector<T, N> max(const vector<T, N>& x, const vector<T, N>& y);
[[nodiscard]] constexpr vector<T, N> max(const vector<T, N>& x, const vector<T, N>& y);
/**
* Returns the value of the greatest element in a vector.
@ -624,7 +624,7 @@ constexpr vector max(const vector& x, const vector& y);
* @return Value of the greatest element in the input vector.
*/
template <class T, std::size_t N>
constexpr T max(const vector<T, N>& x);
[[nodiscard]] constexpr T max(const vector<T, N>& x);
/**
* Returns a vector containing the minimum elements of two vectors.
@ -635,7 +635,7 @@ constexpr T max(const vector& x);
* @return Minimum elements of the two vectors.
*/
template <class T, std::size_t N>
constexpr vector<T, N> min(const vector<T, N>& x, const vector<T, N>& y);
[[nodiscard]] constexpr vector<T, N> min(const vector<T, N>& x, const vector<T, N>& y);
/**
* Returns the value of the smallest element in a vector.
@ -645,7 +645,7 @@ constexpr vector min(const vector& x, const vector& y);
* @return Value of the smallest element in the input vector.
*/
template <class T, std::size_t N>
constexpr T min(const vector<T, N>& x);
[[nodiscard]] constexpr T min(const vector<T, N>& x);
/**
* Calculates the element-wise remainder of the division operation `x / y`.
@ -657,9 +657,9 @@ constexpr T min(const vector& x);
*/
/// @{
template <class T, std::size_t N>
constexpr vector<T, N> mod(const vector<T, N>& x, const vector<T, N>& y);
[[nodiscard]] constexpr vector<T, N> mod(const vector<T, N>& x, const vector<T, N>& y);
template <class T, std::size_t N>
constexpr vector<T, N> mod(const vector<T, N>& x, T y);
[[nodiscard]] constexpr vector<T, N> mod(const vector<T, N>& x, T y);
/// @}
/**
@ -672,9 +672,9 @@ constexpr vector mod(const vector& x, T y);
*/
/// @{
template <class T, std::size_t N>
constexpr vector<T, N> mul(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<T, N> mul(const vector<T, N>& x, const vector<T, N>& y) noexcept;
template <class T, std::size_t N>
constexpr vector<T, N> mul(const vector<T, N>& x, T y) noexcept;
[[nodiscard]] constexpr vector<T, N> mul(const vector<T, N>& x, T y) noexcept;
/// @}
/**
@ -685,7 +685,7 @@ constexpr vector mul(const vector& x, T y) noexcept;
* @return Negated vector.
*/
template <class T, std::size_t N>
constexpr vector<T, N> negate(const vector<T, N>& x) noexcept;
[[nodiscard]] constexpr vector<T, N> negate(const vector<T, N>& x) noexcept;
/**
* Calculates the unit vector in the same direction as the original vector.
@ -695,7 +695,7 @@ constexpr vector negate(const vector& x) noexcept;
* @return Normalized vector.
*/
template <class T, std::size_t N>
vector<T, N> normalize(const vector<T, N>& x);
[[nodiscard]] vector<T, N> normalize(const vector<T, N>& x);
/**
* Logically inverts a boolean vector.
@ -705,7 +705,7 @@ vector normalize(const vector& x);
* @return Logically inverted vector.
*/
template <class T, std::size_t N>
constexpr vector<bool, N> logical_not(const vector<T, N>& x) noexcept;
[[nodiscard]] constexpr vector<bool, N> logical_not(const vector<T, N>& x) noexcept;
/**
* Compares two vectors for inequality
@ -716,7 +716,7 @@ constexpr vector logical_not(const vector& x) noexcept;
* @return Boolean vector containing the result of the element comparisons.
*/
template <class T, std::size_t N>
constexpr vector<bool, N> not_equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<bool, N> not_equal(const vector<T, N>& x, const vector<T, N>& y) noexcept;
/**
* Raises each element to a power.
@ -728,9 +728,9 @@ constexpr vector not_equal(const vector& x, const vector& y
*/
/// @{
template <class T, std::size_t N>
vector<T, N> pow(const vector<T, N>& x, const vector<T, N>& y);
[[nodiscard]] vector<T, N> pow(const vector<T, N>& x, const vector<T, N>& y);
template <class T, std::size_t N>
vector<T, N> pow(const vector<T, N>& x, T y);
[[nodiscard]] vector<T, N> pow(const vector<T, N>& x, T y);
/// @}
/**
@ -741,7 +741,7 @@ vector pow(const vector& x, T y);
* @return Component-wise round of input vector.
*/
template <class T, std::size_t N>
constexpr vector<T, N> round(const vector<T, N>& x);
[[nodiscard]] constexpr vector<T, N> round(const vector<T, N>& x);
/**
* Returns a vector containing the signs of each element.
@ -750,7 +750,7 @@ constexpr vector round(const vector& x);
* @return Signs of input vector elements.
*/
template <class T, std::size_t N>
constexpr vector<T, N> sign(const vector<T, N>& x);
[[nodiscard]] constexpr vector<T, N> sign(const vector<T, N>& x);
/**
* Calculates the square distance between two points. The square distance can be calculated faster than the distance because a call to `std::sqrt` is saved.
@ -761,7 +761,7 @@ constexpr vector sign(const vector& x);
* @return Square distance between the two points.
*/
template <class T, std::size_t N>
constexpr T sqr_distance(const vector<T, N>& p0, const vector<T, N>& p1) noexcept;
[[nodiscard]] constexpr T sqr_distance(const vector<T, N>& p0, const vector<T, N>& p1) noexcept;
/**
* Calculates the square length of a vector. The square length can be calculated faster than the length because a call to `std::sqrt` is saved.
@ -771,7 +771,7 @@ constexpr T sqr_distance(const vector& p0, const vector& p1) noexcep
* @return Square length of the vector.
*/
template <class T, std::size_t N>
constexpr T sqr_length(const vector<T, N>& x) noexcept;
[[nodiscard]] constexpr T sqr_length(const vector<T, N>& x) noexcept;
/**
* Takes the square root of each element.
@ -781,7 +781,7 @@ constexpr T sqr_length(const vector& x) noexcept;
* @return Square roots of the input vector elements.
*/
template <class T, std::size_t N>
vector<T, N> sqrt(const vector<T, N>& x);
[[nodiscard]] vector<T, N> sqrt(const vector<T, N>& x);
/**
* Subtracts a value by another value.
@ -793,11 +793,11 @@ vector sqrt(const vector& x);
*/
/// @{
template <class T, std::size_t N>
constexpr vector<T, N> sub(const vector<T, N>& x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<T, N> sub(const vector<T, N>& x, const vector<T, N>& y) noexcept;
template <class T, std::size_t N>
constexpr vector<T, N> sub(const vector<T, N>& x, T y) noexcept;
[[nodiscard]] constexpr vector<T, N> sub(const vector<T, N>& x, T y) noexcept;
template <class T, std::size_t N>
constexpr vector<T, N> sub(T x, const vector<T, N>& y) noexcept;
[[nodiscard]] constexpr vector<T, N> sub(T x, const vector<T, N>& y) noexcept;
/// @}
/**
@ -807,7 +807,7 @@ constexpr vector sub(T x, const vector& y) noexcept;
* @return Sum of the vector's elements.
*/
template <class T, std::size_t N>
constexpr T sum(const vector<T, N>& x) noexcept;
[[nodiscard]] constexpr T sum(const vector<T, N>& x) noexcept;
/**
* Makes an *m*-dimensional vector by rearranging and/or duplicating elements of an *n*-dimensional vector.
@ -821,7 +821,7 @@ constexpr T sum(const vector& x) noexcept;
* @return Vector containing elements from @p x in the order specified by @p Indices. The size of the returned vector is equivalent to the number of indices in @p Indices.
*/
template <std::size_t... Indices, class T, std::size_t N>
constexpr vector<T, sizeof...(Indices)> swizzle(const vector<T, N>& x) noexcept;
[[nodiscard]] constexpr vector<T, sizeof...(Indices)> swizzle(const vector<T, N>& x) noexcept;
/**
* Performs a element-wise trunc operation.
@ -830,7 +830,7 @@ constexpr vector swizzle(const vector& x) noexcept;
* @return Component-wise trunc of input vector.
*/
template <class T, std::size_t N>
constexpr vector<T, N> trunc(const vector<T, N>& x);
[[nodiscard]] constexpr vector<T, N> trunc(const vector<T, N>& x);
/// @private
template <class T, std::size_t N, std::size_t... I>

+ 1
- 1
src/physics/gas/atmosphere.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_PHYSICS_GAS_ATMOSPHERE_HPP
#include "physics/constants.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <algorithm>
#include <cmath>

+ 1
- 1
src/physics/light/blackbody.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_PHYSICS_LIGHT_BLACKBODY_HPP
#define ANTKEEPER_PHYSICS_LIGHT_BLACKBODY_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include "physics/constants.hpp"
namespace physics {

+ 1
- 1
src/physics/light/phase.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_PHYSICS_LIGHT_PHASE_HPP
#define ANTKEEPER_PHYSICS_LIGHT_PHASE_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <cmath>
namespace physics {

+ 1
- 1
src/physics/light/photometry.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP
#define ANTKEEPER_PHYSICS_LIGHT_PHOTOMETRY_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include "math/quadrature.hpp"
namespace physics {

+ 1
- 1
src/physics/orbit/anomaly.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_PHYSICS_ORBIT_ANOMALY_HPP
#define ANTKEEPER_PHYSICS_ORBIT_ANOMALY_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <cmath>
namespace physics {

+ 1
- 1
src/physics/orbit/elements.hpp View File

@ -21,7 +21,7 @@
#define ANTKEEPER_PHYSICS_ORBIT_ELEMENTS_HPP
#include "utility/fundamental-types.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <cmath>
namespace physics {

+ 1
- 1
src/physics/time/ut1.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_PHYSICS_TIME_UT1_HPP
#define ANTKEEPER_PHYSICS_TIME_UT1_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
namespace physics {
namespace time {

+ 1
- 1
src/physics/time/utc.hpp View File

@ -20,7 +20,7 @@
#ifndef ANTKEEPER_PHYSICS_TIME_UTC_HPP
#define ANTKEEPER_PHYSICS_TIME_UTC_HPP
#include "math/constants.hpp"
#include "math/numbers.hpp"
namespace physics {
namespace time {

+ 1
- 1
src/platform/windows/nvidia.cpp View File

@ -22,6 +22,6 @@
extern "C"
{
// Direct Nvidia Optimus to use high-performance graphics
/// Direct Nvidia Optimus to use high-performance graphics
_declspec(dllexport) DWORD NvOptimusEnablement = 0x00000001;
}

+ 6
- 4
src/render/passes/material-pass.cpp View File

@ -269,7 +269,7 @@ void material_pass::render(const render::context& ctx, render::queue& queue) con
// Sort render queue
queue.sort(operation_compare);
for (const render::operation& operation: queue)
{
// Get operation material
@ -591,6 +591,8 @@ const material_pass::parameter_set* material_pass::load_parameter_set(const gl::
bool operation_compare(const render::operation& a, const render::operation& b)
{
/// @TODO: something is wrong with this compare op, assertion fails
if (!a.material)
return false;
else if (!b.material)
@ -607,7 +609,7 @@ bool operation_compare(const render::operation& a, const render::operation& b)
if (xray_b)
{
// A and B are both xray, render back to front
return (a.depth >= b.depth);
return (a.depth > b.depth);
}
else
{
@ -641,7 +643,7 @@ bool operation_compare(const render::operation& a, const render::operation& b)
if (decal_b)
{
// A and B are both transparent decals, render back to front
return (a.depth >= b.depth);
return (a.depth > b.depth);
}
else
{
@ -659,7 +661,7 @@ bool operation_compare(const render::operation& a, const render::operation& b)
else
{
// A and B are both transparent, but not decals, render back to front
return (a.depth <= b.depth);
return (a.depth < b.depth);
}
}
}

+ 0
- 1
src/render/passes/shadow-map-pass.cpp View File

@ -173,7 +173,6 @@ void shadow_map_pass::render_csm(const scene::directional_light& light, const re
float4x4 light_projection = math::ortho(-1.0f, 1.0f, -1.0f, 1.0f, -1.0f, 1.0f);
float4x4 light_view_projection = light_projection * light_view;
float4x4 crop_matrix;
float4x4 cropped_view_projection;
float4x4 model_view_projection;

+ 1
- 1
src/render/renderer.cpp View File

@ -32,7 +32,7 @@
#include "geom/projection.hpp"
#include "config.hpp"
#include "math/quaternion.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <functional>
#include <set>

+ 1
- 1
src/resources/model-loader.cpp View File

@ -24,7 +24,7 @@
#include "gl/vertex-attribute.hpp"
#include "gl/drawing-mode.hpp"
#include "utility/fundamental-types.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include <sstream>
#include <stdexcept>
#include <limits>

+ 1
- 1
src/scene/camera.cpp View File

@ -19,7 +19,7 @@
#include "scene/camera.hpp"
#include "config.hpp"
#include "math/constants.hpp"
#include "math/numbers.hpp"
#include "math/interpolation.hpp"
#include "math/quaternion.hpp"
#include "math/projection.hpp"

Loading…
Cancel
Save