// Copyright (C) 2024 Jérôme "SirLynix" Leclercq (lynix680@gmail.com) // This file is part of the "Nazara Engine - Math module" // For conditions of distribution and use, see copyright notice in Export.hpp #pragma once #ifndef NAZARA_MATH_SPHERE_HPP #define NAZARA_MATH_SPHERE_HPP #include #include namespace Nz { struct SerializationContext; template class Box; template class Sphere { public: constexpr Sphere() = default; constexpr Sphere(T X, T Y, T Z, T Radius); constexpr Sphere(const Vector3& center, T Radius); constexpr Sphere(const T sphere[4]); template constexpr explicit Sphere(const Sphere& sphere); constexpr Sphere(const Sphere&) = default; constexpr Sphere(Sphere&&) = default; ~Sphere() = default; constexpr bool ApproxEqual(const Sphere& sphere, T maxDifference = std::numeric_limits::epsilon()) const; constexpr bool Contains(T X, T Y, T Z, T epsilon = std::numeric_limits::epsilon()) const; constexpr bool Contains(const Box& box, T epsilon = std::numeric_limits::epsilon()) const; constexpr bool Contains(const Vector3& point, T epsilon = std::numeric_limits::epsilon()) const; T Distance(T X, T Y, T Z) const; T Distance(const Vector3& point) const; Sphere& ExtendTo(T X, T Y, T Z); Sphere& ExtendTo(const Vector3& point); constexpr Vector3 GetNegativeVertex(const Vector3& normal) const; constexpr Vector3 GetPosition() const; constexpr Vector3 GetPositiveVertex(const Vector3& normal) const; constexpr bool Intersect(const Box& box) const; constexpr bool Intersect(const Sphere& sphere) const; constexpr bool IsValid() const; std::string ToString() const; constexpr T& operator[](std::size_t i); constexpr T operator[](std::size_t i) const; constexpr Sphere operator*(T scalar) const; constexpr Sphere& operator=(const Sphere& other) = default; constexpr Sphere& operator=(Sphere&&) = default; constexpr Sphere& operator*=(T scalar); constexpr bool operator==(const Sphere& sphere) const; constexpr bool operator!=(const Sphere& sphere) const; constexpr bool operator<(const Sphere& sphere) const; constexpr bool operator<=(const Sphere& sphere) const; constexpr bool operator>(const Sphere& sphere) const; constexpr bool operator>=(const Sphere& sphere) const; static constexpr bool ApproxEqual(const Sphere& lhs, const Sphere& rhs, T maxDifference = std::numeric_limits::epsilon()); static constexpr Sphere Lerp(const Sphere& from, const Sphere& to, T interpolation); static constexpr Sphere Unit(); static constexpr Sphere Zero(); T x, y, z, radius; }; using Sphered = Sphere; using Spheref = Sphere; template bool Serialize(SerializationContext& context, const Sphere& sphere, TypeTag>); template bool Unserialize(SerializationContext& context, Sphere* sphere, TypeTag>); template std::ostream& operator<<(std::ostream& out, const Nz::Sphere& sphere); } #include #endif // NAZARA_MATH_SPHERE_HPP