MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSphere.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h" // To fix `attribute declaration must precede definition` on `Sphere`.
4
5namespace MR
6{
7
9template <typename V>
10struct Sphere
11{
12 using T = typename V::ValueType;
13
15 T radius = 0;
16
17 constexpr Sphere() noexcept = default;
18 constexpr Sphere( const V & c, T r ) noexcept : center( c ), radius( r ) { }
19
20 // Here `V == U` doesn't seem to cause any issues in the C++ code, but we're still disabling it because it somehow gets emitted
21 // when generating the bindings, and results in duplicate functions in C#.
22 template <typename U> MR_REQUIRES_IF_SUPPORTED( !std::is_same_v<V, U> )
23 constexpr explicit Sphere( const Sphere<U> & l ) noexcept : center( l.center ), radius( T( l.radius ) ) { }
24
26 [[nodiscard]] V project( const V & x ) const { return center + radius * ( x - center ).normalized(); }
27
30 [[nodiscard]] T distance( const V & x ) const { return ( x - center ).length() - radius; }
31
33 [[nodiscard]] T distanceSq( const V & x ) const { return sqr( distance( x ) ); }
34
35 friend bool operator == ( const Sphere & a, const Sphere & b ) = default;
36};
37
38} // namespace MR
Definition MRCameraOrientationPlugin.h:8
constexpr T sqr(T x) noexcept
squared value
Definition MRMeshFwd.h:752
Definition MRSphere.h:11
constexpr Sphere() noexcept=default
friend bool operator==(const Sphere &a, const Sphere &b)=default
T distance(const V &x) const
Definition MRSphere.h:30
V project(const V &x) const
finds the closest point on sphere
Definition MRSphere.h:26
typename V::ValueType T
Definition MRSphere.h:12
MR_REQUIRES_IF_SUPPORTED(!std::is_same_v< V, U >) const expr explicit Sphere(const Sphere< U > &l) noexcept
Definition MRSphere.h:22
T distanceSq(const V &x) const
returns squared distance from given point to this sphere
Definition MRSphere.h:33
V center
Definition MRSphere.h:14
T radius
Definition MRSphere.h:15