Kelsidavis-WoWee/tools/editor/editor_brush.cpp
Kelsi 12bcd0ef8c fix(brush): defensive guards in EditorBrush::getInfluence
Three issues:
1. NaN distance returned 1.0 (full influence) because distance >=
   radius is false for NaN; the inner-radius check then returned 1.
2. Non-positive radius would divide by zero in the t computation.
3. falloff = 0 produces division by zero in the outer falloff path.

Also clamps falloff to [0,1] so a slider extreme can't break the math.
2026-05-06 07:38:50 -07:00

27 lines
924 B
C++

#include "editor_brush.hpp"
#include <algorithm>
#include <cmath>
namespace wowee {
namespace editor {
float EditorBrush::getInfluence(float distance) const {
// NaN distance must produce 0 influence — comparisons against NaN
// return false, so without this the function would fall through to
// the "fully inside" branch and return 1.0 for every queried point.
if (!std::isfinite(distance) || !std::isfinite(settings_.radius) ||
settings_.radius <= 0.0f) return 0.0f;
if (distance >= settings_.radius) return 0.0f;
float t = distance / settings_.radius;
float falloff = std::clamp(settings_.falloff, 0.0f, 1.0f);
float innerRadius = 1.0f - falloff;
if (t <= innerRadius) return 1.0f;
if (falloff <= 0.0f) return 1.0f; // hard edge
float falloffT = (t - innerRadius) / falloff;
return 1.0f - (falloffT * falloffT);
}
} // namespace editor
} // namespace wowee