MeshLib
 
Loading...
Searching...
No Matches
MRSphere.h
Go to the documentation of this file.
1#pragma once
2
3namespace MR
4{
5
7template <typename V>
8struct Sphere
9{
10 using T = typename V::ValueType;
11
13 T radius = 0;
14
15 constexpr Sphere() noexcept = default;
16 constexpr Sphere( const V & c, T r ) noexcept : center( c ), radius( r ) { }
17 template <typename U>
18 constexpr explicit Sphere( const Sphere<U> & l ) noexcept : center( l.center ), radius( T( l.radius ) ) { }
19
21 [[nodiscard]] V project( const V & x ) const { return center + radius * ( x - center ).normalized(); }
22
25 [[nodiscard]] T distance( const V & x ) const { return ( x - center ).length() - radius; }
26
28 [[nodiscard]] T distanceSq( const V & x ) const { return sqr( distance( x ) ); }
29
30 friend bool operator == ( const Sphere & a, const Sphere & b ) = default;
31};
32
33} // namespace MR
Definition MRCameraOrientationPlugin.h:7
constexpr T sqr(T x) noexcept
Definition MRMesh/MRMeshFwd.h:613
Definition MRSphere.h:9
constexpr Sphere() noexcept=default
friend bool operator==(const Sphere &a, const Sphere &b)=default
T distance(const V &x) const
Definition MRSphere.h:25
V project(const V &x) const
finds the closest point on sphere
Definition MRSphere.h:21
constexpr Sphere(const Sphere< U > &l) noexcept
Definition MRSphere.h:18
typename V::ValueType T
Definition MRSphere.h:10
T distanceSq(const V &x) const
returns squared distance from given point to this sphere
Definition MRSphere.h:28
V center
Definition MRSphere.h:12
T radius
Definition MRSphere.h:13