light: fix lightgrid assertion failure if lightgrid gets a nan (separate bug)
This commit is contained in:
parent
ec7b848f76
commit
e6d9605b86
|
|
@ -67,6 +67,10 @@ struct lightgrid_sample_t
|
|||
qvec3b round_to_int() const;
|
||||
float brightness() const;
|
||||
|
||||
/**
|
||||
* - if !used, style and color are ignored for equality
|
||||
* - if a color component is nan, nan is considered equal to nan for the purposes of this comparison
|
||||
*/
|
||||
bool operator==(const lightgrid_sample_t &other) const;
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -3555,7 +3555,29 @@ float lightgrid_sample_t::brightness() const
|
|||
|
||||
bool lightgrid_sample_t::operator==(const lightgrid_sample_t &other) const
|
||||
{
|
||||
return used == other.used && style == other.style && color == other.color;
|
||||
if (used != other.used)
|
||||
return false;
|
||||
|
||||
if (!used) {
|
||||
// if unused, style and color don't matter
|
||||
return true;
|
||||
}
|
||||
|
||||
if (style != other.style)
|
||||
return false;
|
||||
|
||||
// color check requires special handling for nan
|
||||
for (int i=0; i<3; ++i) {
|
||||
if (std::isnan(color[i])) {
|
||||
if (!std::isnan(other.color[i]))
|
||||
return false;
|
||||
} else {
|
||||
if (color[i] != other.color[i])
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int lightgrid_samples_t::used_styles() const
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <doctest/doctest.h>
|
||||
|
||||
#include <light/light.hh>
|
||||
#include <light/ltface.hh>
|
||||
#include <light/surflight.hh>
|
||||
#include <common/bspinfo.hh>
|
||||
#include <qbsp/qbsp.hh>
|
||||
|
|
@ -103,6 +104,48 @@ testresults_t QbspVisLight_Q2(
|
|||
return QbspVisLight_Common(name, {"-q2bsp"}, extra_light_args, run_vis);
|
||||
}
|
||||
|
||||
TEST_CASE("lightgrid_sample_t equality")
|
||||
{
|
||||
SUBCASE("style equality") {
|
||||
lightgrid_sample_t a {.used = true, .style = 4, .color = {}};
|
||||
lightgrid_sample_t b = a;
|
||||
CHECK(a == b);
|
||||
|
||||
b.style = 6;
|
||||
CHECK(a != b);
|
||||
}
|
||||
|
||||
SUBCASE("color equality") {
|
||||
lightgrid_sample_t a {.used = true, .style = 4, .color = {1,2,3}};
|
||||
lightgrid_sample_t b = a;
|
||||
CHECK(a == b);
|
||||
|
||||
b.color = {6,5,4};
|
||||
CHECK(a != b);
|
||||
}
|
||||
|
||||
SUBCASE("nan colors") {
|
||||
lightgrid_sample_t a {.used = true, .style = 4, .color = {std::numeric_limits<double>::quiet_NaN(), 1.0, 1.0}};
|
||||
lightgrid_sample_t b = a;
|
||||
CHECK(a == b);
|
||||
|
||||
b.color = { 0,0,0};
|
||||
CHECK(a != b);
|
||||
}
|
||||
|
||||
SUBCASE("unused equality doesn't consider other attributes") {
|
||||
lightgrid_sample_t a, b;
|
||||
CHECK(!a.used);
|
||||
CHECK(a == b);
|
||||
|
||||
b.style = 5;
|
||||
CHECK(a == b);
|
||||
|
||||
b.color = {1, 0, 0};
|
||||
CHECK(a == b);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("-world_units_per_luxel, -lightgrid")
|
||||
{
|
||||
auto [bsp, bspx] = QbspVisLight_Q2("q2_lightmap_custom_scale.map", {"-lightgrid"});
|
||||
|
|
|
|||
Loading…
Reference in New Issue