FLAMEGPU2
FLAMEGPU2 copied to clipboard
Fix Spatial Wrapped invalid env/radii detection
- [x] Reproduce python-native edge case in c++ test suite
- [ ] Expand edge case tests coverage to exposes a broader range of floating point issues
- [ ] Fix tests
- [ ] Optional: Migrate float logic to the host, making in-device checks a single global read.
Closes #1177
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;
}