zeus/include/zeus/CSphere.hpp
Lioncash 81f9b4a4ee General: Mark functions as nodiscard where applicable
Given this aims to be a general purpose math library for use in various
other libraries applications for axiodl, we can annotate functions that
return by value or reference with [[nodiscard]] where it's very obvious
that not making use of the return value is a bug.

This allows the compiler to diagnose and emit warnings for these API
misuses at compile-time, preventing silent bugs from occurring.

Any cases where not using the return value is desirable may still be
casted to void in order to silence warnings.
2020-03-04 03:07:54 -05:00

21 lines
541 B
C++

#pragma once
#include "zeus/CVector3f.hpp"
namespace zeus {
class CSphere {
public:
constexpr CSphere(const CVector3f& position, float radius) : position(position), radius(radius) {}
[[nodiscard]] CVector3f getSurfaceNormal(const CVector3f& coord) const { return (coord - position).normalized(); }
[[nodiscard]] bool intersects(const CSphere& other) const {
const float dist = (position - other.position).magnitude();
return dist < (radius + other.radius);
}
CVector3f position;
float radius;
};
} // namespace zeus