mirror of
https://github.com/AxioDL/zeus.git
synced 2025-07-05 20:56:04 +00:00
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.
21 lines
541 B
C++
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
|