mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-05-07 01:23:52 +00:00
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.
This commit is contained in:
parent
bd6e5fe3de
commit
12bcd0ef8c
1 changed files with 9 additions and 2 deletions
|
|
@ -6,13 +6,20 @@ 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 innerRadius = 1.0f - settings_.falloff;
|
||||
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) / settings_.falloff;
|
||||
float falloffT = (t - innerRadius) / falloff;
|
||||
return 1.0f - (falloffT * falloffT);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue