Changeset 810 for cpp


Ignore:
Timestamp:
07/27/18 16:21:58 (6 years ago)
Author:
Maciej Komosinski
Message:

Don't unnecessarily calculate sqrt(negative_value) [fixes #51]

File:
1 edited

Legend:

Unmodified
Added
Removed
  • cpp/frams/model/geometry/geometryutils.cpp

    r658 r810  
    336336{
    337337        x += d / sqrt(1.0 + (b*b * x*x) / (a*a * (a*a - x*x)));
    338         y = b * sqrt(1.0 - (x*x) / (a*a));
     338        double sqrt_arg = 1.0 - (x*x) / (a*a);
     339        if (sqrt_arg >= 0)
     340                y = b * sqrt(sqrt_arg);
     341        else
     342                y = std::numeric_limits<double>::signaling_NaN();
     343        //This function is called from MeshBuilder::EllipsoidSurface::findNextAreaEdgeAndPhase().
     344        //y=NaN set above co-occurs with the value of x that doesn't meet the condition tested in findNextAreaEdgeAndPhase().
     345        //If the condition is true (i.e., x exceeds the allowed range), entirely new values of x and y are set in the next step anyway.
     346        //An impossible-to-calculate y should never be used for invalid x, hence y=NaN is set here to indicate this specific situation and signal just in case anyone would try to use such y.
    339347}
    340348
Note: See TracChangeset for help on using the changeset viewer.