From f4fc8bc72bffe1107c6adb8a526a56ac5215999e Mon Sep 17 00:00:00 2001 From: Jonathan Date: Tue, 5 Oct 2021 22:35:30 -0400 Subject: [PATCH] Remove unused functions, fix math issues MacOSX potential fix for __VA_ARGS__ --- include/common/cmdlib.hh | 16 +++++++++++----- include/common/log.hh | 6 ++++++ include/common/mathlib.hh | 21 --------------------- include/common/qvec.hh | 7 ++++++- light/test_light.cc | 11 ----------- 5 files changed, 23 insertions(+), 38 deletions(-) diff --git a/include/common/cmdlib.hh b/include/common/cmdlib.hh index ce80e58f..338c72fb 100644 --- a/include/common/cmdlib.hh +++ b/include/common/cmdlib.hh @@ -119,7 +119,13 @@ template Error(formatted.c_str()); } +#ifdef _MSC_VER #define FError(fmt, ...) Error("{}: " fmt, __func__, __VA_ARGS__) +#else +#define VA_ARGS(...) , ##__VA_ARGS__ +#define FError(fmt, ...) Error("{}: " fmt, __func__ VA_ARGS(__VA_ARGS__)) +#undef VA_ARGS +#endif using qfile_t = std::unique_ptr; @@ -610,7 +616,7 @@ struct membuf : std::streambuf { public: // construct membuf for reading and/or writing - membuf(void *base, size_t size, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) + inline membuf(void *base, size_t size, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) { auto cbase = reinterpret_cast(base); @@ -624,7 +630,7 @@ public: } // construct membuf for reading - membuf(const void *base, size_t size, std::ios_base::openmode which = std::ios_base::in) + inline membuf(const void *base, size_t size, std::ios_base::openmode which = std::ios_base::in) { auto cbase = const_cast(reinterpret_cast(base)); @@ -641,7 +647,7 @@ protected: } // seek operations - pos_type seekpos(pos_type off, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) + pos_type seekpos(pos_type off, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override { if (which & std::ios_base::in) { setg(eback(), eback() + off, egptr()); @@ -659,7 +665,7 @@ protected: } pos_type seekoff(off_type off, std::ios_base::seekdir dir, - std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) + std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) override { if (which & std::ios_base::in) { if (dir == std::ios_base::cur) @@ -725,7 +731,7 @@ protected: struct memstream : virtual membuf, std::ostream, std::istream { - memstream(void *base, size_t size, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) + inline memstream(void *base, size_t size, std::ios_base::openmode which = std::ios_base::in | std::ios_base::out) : membuf(base, size, which), std::ostream(static_cast(this)), std::istream(static_cast(this)) { diff --git a/include/common/log.hh b/include/common/log.hh index a6d1e185..593dd4b2 100644 --- a/include/common/log.hh +++ b/include/common/log.hh @@ -82,7 +82,13 @@ inline void LogPrint(const char *fmt, const Args &...args) LogPrint(LOG_DEFAULT, fmt::format(fmt, std::forward(args)...).c_str()); } +#ifdef _MSC_VER #define FLogPrint(fmt, ...) LogPrint("{}: " fmt, __func__, __VA_ARGS__) +#else +#define VA_ARGS(...) , ##__VA_ARGS__ +#define FLogPrint(fmt, ...) LogPrint("{}: " fmt, __func__ VA_ARGS(__VA_ARGS__)) +#undef VA_ARGS +#endif /* Print only into log file */ void LogPrintSilent(const char *str); diff --git a/include/common/mathlib.hh b/include/common/mathlib.hh index 12c8c63b..78cf45a3 100644 --- a/include/common/mathlib.hh +++ b/include/common/mathlib.hh @@ -31,10 +31,6 @@ #include -using vec_t = double; -using vec3_t = vec_t[3]; -constexpr vec_t VECT_MAX = std::numeric_limits::max(); - struct plane_t { qvec3d normal; @@ -241,23 +237,6 @@ inline vec_t GetDir(const Tstart &start, const Tstop &stop, Tdir &dir) return VectorNormalize(dir); } -template -constexpr vec_t DistanceAbovePlane(const T &normal, const vec_t dist, const T &point) -{ - // static_assert(std::size(normal) == 3); - - return DotProduct(normal, point) - dist; -} - -template -constexpr void ProjectPointOntoPlane(const T &normal, const vec_t dist, T &point) -{ - vec_t distAbove = DistanceAbovePlane(normal, dist, point); - vec3_t move; - VectorScale(normal, -distAbove, move); - VectorAdd(point, move, point); -} - bool SetPlanePts(const std::array &planepts, qvec3d &normal, vec_t &dist); // Maps uniform random variables U and V in [0, 1] to uniformly distributed points on a sphere diff --git a/include/common/qvec.hh b/include/common/qvec.hh index 1fd04dc3..ecdc0aa2 100644 --- a/include/common/qvec.hh +++ b/include/common/qvec.hh @@ -622,4 +622,9 @@ struct fmt::formatter> : formatter return formatter::format(p[N - 1], ctx); } -}; \ No newline at end of file +}; + +using vec_t = double; +// "vec3" type. legacy; eventually will be replaced entirely +using vec3_t = vec_t[3]; +constexpr vec_t VECT_MAX = std::numeric_limits::max(); diff --git a/light/test_light.cc b/light/test_light.cc index 5a6657ce..c2ceb6e7 100644 --- a/light/test_light.cc +++ b/light/test_light.cc @@ -280,17 +280,6 @@ TEST(mathlib, DistAbovePlane) EXPECT_FLOAT_EQ(90, GLM_DistAbovePlane(plane, point)); } -TEST(mathlib, ProjectPointOntoPlane) -{ - qvec4f plane(0, 0, 1, 10); - qvec3f point(100, 100, 100); - - qvec3f projected = GLM_ProjectPointOntoPlane(plane, point); - EXPECT_FLOAT_EQ(100, projected[0]); - EXPECT_FLOAT_EQ(100, projected[1]); - EXPECT_FLOAT_EQ(10, projected[2]); -} - TEST(mathlib, InterpolateNormalsDegenerate) { EXPECT_FALSE(GLM_InterpolateNormal({}, {}, qvec3f(0, 0, 0)).first);