clean up some old leftovers

This commit is contained in:
Hartmut Seichter 2025-05-21 22:30:57 +02:00
parent 30cc534a37
commit b3686c1641
6 changed files with 94 additions and 86 deletions

View file

@ -40,8 +40,9 @@ template <typename Scalar, std::size_t N> struct aabb final {
constexpr auto dimension() const noexcept { return max - min; }
static constexpr auto make(
const std::vector<pw::vector<Scalar, N>>& vertices) -> aabb<Scalar, N> {
static constexpr auto
make(const std::vector<pw::vector<Scalar, N>>& vertices)
-> aabb<Scalar, N> {
return std::accumulate(
std::begin(vertices), std::end(vertices),
aabb{.min{vertices.front()}, .max{vertices.front()}},

View file

@ -8,8 +8,8 @@
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@ -26,8 +26,8 @@
#include <pw/core/globals.hpp>
#include <vector>
#include <functional>
#include <vector>
namespace pw {
@ -36,7 +36,6 @@ namespace pw {
*/
class debug {
public:
enum level {
none, //!< nothing will be logged, even no errors
error, //!< only errors will be logged
@ -52,17 +51,15 @@ public:
*/
class stream {
public:
stream(debug* log = nullptr);
~stream();
stream(const stream& other);
stream& operator<<(const bool& value);
stream& operator<<(const char* value);
stream& operator<<(const std::string& value); ///! log a string
stream& operator << (const std::string_view& value); ///! log a string_view
stream&
operator<<(const std::string_view& value); ///! log a string_view
stream& operator<<(const float& value); ///! log a float value
stream& operator<<(const double& value); ///! log a double value
@ -75,9 +72,7 @@ public:
stream& operator<<(const void* value); ///! pointer
protected:
debug* _log;
std::string _line;
};
@ -116,7 +111,6 @@ public:
~debug();
protected:
debug();
CallbackList _callbacks;
@ -156,7 +150,6 @@ protected:
// #define LOG_INFO() Log::s()
// #define LOG_FUNC() LOG_INFO() << __FUNCTION__ << " " << __LINE__ << " "
}
} // namespace pw
#endif

View file

@ -8,8 +8,8 @@
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
@ -23,54 +23,60 @@
#ifndef PW_CORE_MATH_HPP
#define PW_CORE_MATH_HPP
#include <cmath>
#include <algorithm>
#include <cmath>
#include <concepts>
#include <numbers>
namespace pw {
constexpr double __PW_PI = 3.1415926535897932384626433832795028841971693993751058209;
constexpr double __PW_PI_DOUBLE = 2.0 * __PW_PI;
static constexpr double __PW_PI{
3.1415926535897932384626433832795028841971693993751058209};
static constexpr double __PW_PI_DOUBLE{2 * __PW_PI};
template <typename T>
inline const T pi() { return static_cast<T>(__PW_PI); }
template <std::floating_point T> inline static constexpr T pi() {
return static_cast<T>(__PW_PI);
}
template <typename T>
inline const T one_over_pi() { return static_cast<T>(1 / __PW_PI); }
template <std::floating_point T> inline const T one_over_pi() {
return static_cast<T>(1 / __PW_PI);
}
template <typename T>
inline T rad_to_deg(const T& angle_in_radian) {
template <std::floating_point T> inline T rad_to_deg(const T& angle_in_radian) {
return angle_in_radian * static_cast<T>(180) * one_over_pi<T>();
}
template <typename T>
inline T deg_to_rad(const T& angle_in_degree) {
template <std::floating_point T> inline T deg_to_rad(const T& angle_in_degree) {
return angle_in_degree * pi<T>() / static_cast<T>(180);
}
template <typename T>
inline T repeat(const T& t, const T& length) {
return std::clamp(t - std::floor(t / length) * length, T(0), length);
template <typename T> inline T repeat(const T& t, const T& length) {
return std::clamp(t - std::floor(t / length) * length, T{}, length);
}
template <typename T>
inline T ping_pong(const T& t,const T& length) {
auto tn = repeat(t, length * T(2));
template <typename T> inline T ping_pong(const T& t, const T& length) {
auto tn = repeat(t, length * T{2});
return length - std::abs(tn - length);
}
template <typename T>
inline T wrap_angle(const T& angle_in_radian) {
template <std::floating_point T> inline T wrap_angle(const T& angle_in_radian) {
using std::floor;
return angle_in_radian - __PW_PI_DOUBLE * floor( angle_in_radian / __PW_PI_DOUBLE );
return angle_in_radian -
__PW_PI_DOUBLE * floor(angle_in_radian / __PW_PI_DOUBLE);
}
//void extractRotation(const matrix &A, Quaterniond &q,const unsigned int maxIter)
// void extractRotation(const matrix &A, Quaterniond &q,const unsigned int
// maxIter)
//{
// for (auto iter = 0; iter < maxIter; iter++){
// auto R = q.matrix();
// Vector3d omega = (R.col(0).cross(A.col(0)) + R.col(1).cross(A.col(1)) + R.col(2).cross(A.col(2)))*(1.0 / fabs(R.col(0).dot(A.col(0)) + R.col(1).dot(A.col(1)) + R.col(2).dot(A.col(2))) +1.0e-9);double w = omega.norm();if (w < 1.0e-9)break;q = Quaterniond(AngleAxisd(w, (1.0 / w)*omega))*q;q.normalize();}}
// Vector3d omega = (R.col(0).cross(A.col(0)) +
// R.col(1).cross(A.col(1)) + R.col(2).cross(A.col(2)))*(1.0 /
// fabs(R.col(0).dot(A.col(0)) + R.col(1).dot(A.col(1)) +
// R.col(2).dot(A.col(2))) +1.0e-9);double w = omega.norm();if (w
//< 1.0e-9)break;q = Quaterniond(AngleAxisd(w, (1.0 /
// w)*omega))*q;q.normalize();}}
}
} // namespace pw
#endif

View file

@ -23,7 +23,6 @@
#ifndef PW_CORE_MATRIX_HPP
#define PW_CORE_MATRIX_HPP
#include "vector.hpp"
#include <pw/core/globals.hpp>
#include <pw/core/math.hpp>
#include <pw/core/vector.hpp>

View file

@ -27,6 +27,7 @@
#include <pw/core/primitives.hpp>
#include <atomic>
#include <variant>
namespace pw {

View file

@ -2,17 +2,22 @@
#include <cstdint>
#include <map>
#include <print>
#include <pw/core/image.hpp>
#include <tuple>
#include <vector>
#include <pw/core/image.hpp>
namespace pw {
struct image_layout {
enum pixel_layout { RGB8, RGBA8, LUM8, DEPTH };
static constexpr auto bits_per_channel(pixel_layout layout) {
constexpr auto lut =
constexpr static auto lut =
std::array{std::make_tuple(RGB8, sizeof(std::uint8_t) << 3),
std::make_tuple(RGBA8, sizeof(std::uint8_t) << 3),
std::make_tuple(LUM8, sizeof(std::uint8_t) << 3),
std::make_tuple(DEPTH, sizeof(float) << 3)};
const auto iter = std::find_if(
@ -34,6 +39,9 @@ auto main() -> int {
std::print("DEPTH = {}bits per channel\n",
pw::image_layout::bits_per_channel(
pw::image_layout::pixel_layout::DEPTH));
std::print("LUM8 = {}bits per channel\n",
pw::image_layout::bits_per_channel(
pw::image_layout::pixel_layout::LUM8));
// pw::image
}