Remove unused functions, fix math issues

MacOSX potential fix for __VA_ARGS__
This commit is contained in:
Jonathan 2021-10-05 22:35:30 -04:00
parent 37cb535f1a
commit f4fc8bc72b
5 changed files with 23 additions and 38 deletions

View File

@ -119,7 +119,13 @@ template<typename... Args>
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<FILE, decltype(&fclose)>;
@ -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<char *>(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<char *>(reinterpret_cast<const char *>(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<std::streambuf *>(this)),
std::istream(static_cast<std::streambuf *>(this))
{

View File

@ -82,7 +82,13 @@ inline void LogPrint(const char *fmt, const Args &...args)
LogPrint(LOG_DEFAULT, fmt::format(fmt, std::forward<const Args &>(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);

View File

@ -31,10 +31,6 @@
#include <common/qvec.hh>
using vec_t = double;
using vec3_t = vec_t[3];
constexpr vec_t VECT_MAX = std::numeric_limits<vec_t>::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<typename T>
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<typename T>
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<qvec3d, 3> &planepts, qvec3d &normal, vec_t &dist);
// Maps uniform random variables U and V in [0, 1] to uniformly distributed points on a sphere

View File

@ -622,4 +622,9 @@ struct fmt::formatter<qvec<N, T>> : formatter<T>
return formatter<T>::format(p[N - 1], ctx);
}
};
};
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<vec_t>::max();

View File

@ -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);