HDest-Community / Ugly-as-Sin

Enhancement modules for Hideous Destructor
zlib License
21 stars 17 forks source link

medical: Don't divide by zero #226

Closed dastrukar closed 1 year ago

dastrukar commented 1 year ago

Just adds a check to see if width is 0 or not. Also, I'm not sure if this is the best/cleanest way to implement this check, but oh well.

caligari87 commented 1 year ago

I usually prefer some variation on min(), max(), or clamp() because I have a hard time parsing ternaries at a glance. I think the latter is also more expensive because it's a branching instruction? Could be wrong on that and it may or may not make a difference here anyway.

If you felt like rewriting that part thusly, it would be nice. But if not, or there's no way to do it cleanly, then this is fine and you can merge at your convenience.

dastrukar commented 1 year ago

So far, the only other two I can come up with is this:

        if (width > 0.) { BP.StartAlpha = min(1, max((depth / width), 0.3)); }
        else { BP.StartAlpha = 0.3; }

and this

        BP.StartAlpha = min(1, max(depth / (width + 0.00001), 0.3));
dastrukar commented 1 year ago

Changed it to the "if else" check, since that probably makes more sense than the "add 0.00001 to prevent div by zero" and also more readable than the ternary thing.