FLAMEGPU / FLAMEGPU2

FLAME GPU 2 is a GPU accelerated agent based modelling framework for CUDA C++ and Python
https://flamegpu.com
MIT License
106 stars 22 forks source link

Fix Spatial Wrapped invalid env/radii detection #1182

Open ptheywood opened 10 months ago

ptheywood commented 10 months ago

Closes #1177

ptheywood commented 9 months ago

The following appears to work for values tested so far. Not the cheapest method so worth only doing this once on the host and storing if wrapped is available for a given spatial message list on the device, rather than doing this per call to the wrapped iterator on the device

template <typename T>
bool approxExactlyDivisible(T a, T b) {
    // Scale machine epsilon by the magnitude of the larger value
    T scaledEpsilon = std::max(std::abs(a), std::abs(b)) * std::numeric_limits<T>::epsilon();
    // Compute the remainder
    T v = std::fmod(a, b);
    // approx equal if the remainder is within scaledEpsilon of 0 or b (fmod(1, 0.05f) returns ~0.05f)
    return v <= scaledEpsilon || v > b - scaledEpsilon;
}