MeshLib Documentation
Loading...
Searching...
No Matches
MRLine.h
Go to the documentation of this file.
1#pragma once
2
3#include "MRAffineXf.h"
4
5namespace MR
6{
7
10template <typename V>
11struct Line
12{
13 using T = typename V::ValueType;
14
15 V p, d;
16
17 constexpr Line() noexcept = default;
18 constexpr Line( const V & p, const V & d ) noexcept : p( p ), d( d ) { }
19 template <typename U>
20 constexpr explicit Line( const Line<U> & l ) noexcept : p( l.p ), d( l.d ) { }
21
23 [[nodiscard]] V operator()( T param ) const { return p + param * d; }
24
26 [[nodiscard]] T distanceSq( const V & x ) const
27 { return ( x - project( x ) ).lengthSq(); }
28
30 [[nodiscard]] Line operator -() const { return Line( p, -d ); }
32 [[nodiscard]] const Line & operator +() const { return *this; }
34 [[nodiscard]] Line normalized() const { return { p, d.normalized() }; }
35
37 [[nodiscard]] V project( const V & x ) const { return p + dot( d, x - p ) / d.lengthSq() * d; }
38};
39
42
46template <typename V>
47[[nodiscard]] inline Line<V> transformed( const Line<V> & l, const AffineXf<V> & xf )
48{
49 return Line<V>{ xf( l.p ), xf.A * l.d };
50}
51
52template <typename V>
53[[nodiscard]] inline bool operator == ( const Line<V> & a, const Line<V> & b )
54{
55 return a.p == b.p && a.d == b.d;
56}
57
59
60} // namespace MR
MRMESH_API bool operator==(const BitSet &a, const BitSet &b)
compare that two bit sets have the same set bits (they can be equal even if sizes are distinct but la...
Definition MRCameraOrientationPlugin.h:8
Definition MRMesh/MRAffineXf.h:14
M A
Definition MRMesh/MRAffineXf.h:18
Definition MRLine.h:12
typename V::ValueType T
Definition MRLine.h:13
const Line & operator+() const
returns same representation
Definition MRLine.h:32
T distanceSq(const V &x) const
returns squared distance from given point to this line
Definition MRLine.h:26
constexpr Line(const Line< U > &l) noexcept
Definition MRLine.h:20
Line operator-() const
returns same line represented with flipped direction of d-vector
Definition MRLine.h:30
constexpr Line() noexcept=default
V operator()(T param) const
returns point on the line, where param=0 returns p and param=1 returns p+d
Definition MRLine.h:23
V d
Definition MRLine.h:15
Line< V > transformed(const Line< V > &l, const AffineXf< V > &xf)
Definition MRLine.h:47
Line normalized() const
returns same line represented with unit d-vector
Definition MRLine.h:34
V p
Definition MRLine.h:15
V project(const V &x) const
finds the closest point on line
Definition MRLine.h:37