MeshLib C++ Docs
Loading...
Searching...
No Matches
MRSphere.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRMeshFwd.h"
4
5namespace MR
6{
9
10
12template <typename V>
13struct Sphere
14{
15 using T = typename V::ValueType;
16
18 T radius = 0;
19
20 constexpr Sphere() noexcept = default;
21 constexpr Sphere( const V & c, T r ) noexcept : center( c ), radius( r ) { }
22
25 template <typename U> MR_REQUIRES_IF_SUPPORTED( !std::is_same_v<V, U> )
26 constexpr explicit Sphere( const Sphere<U> & l ) noexcept : center( l.center ), radius( T( l.radius ) ) { }
27
29 [[nodiscard]] V project( const V & x ) const { return center + radius * ( x - center ).normalized(); }
30
33 [[nodiscard]] T distance( const V & x ) const { return ( x - center ).length() - radius; }
34
36 [[nodiscard]] T distanceSq( const V & x ) const { return sqr( distance( x ) ); }
37
38 friend bool operator == ( const Sphere & a, const Sphere & b ) = default;
39};
40
41}
constexpr Sphere() noexcept=default
friend bool operator==(const Sphere &a, const Sphere &b)=default
T distance(const V &x) const
Definition MRSphere.h:33
V project(const V &x) const
finds the closest point on sphere
Definition MRSphere.h:29
typename V::ValueType T
Definition MRSphere.h:15
MR_REQUIRES_IF_SUPPORTED(!std::is_same_v< V, U >) const expr explicit Sphere(const Sphere< U > &l) noexcept
Definition MRSphere.h:25
T distanceSq(const V &x) const
returns squared distance from given point to this sphere
Definition MRSphere.h:36
V center
Definition MRSphere.h:17
T radius
Definition MRSphere.h:18
only for bindings generation
Definition MRCameraOrientationPlugin.h:8
Definition MRSphere.h:14