27 : closed_( closed ) {}
31 , closed_( closed ) {}
36 double distTo(
const T& pt,
int* segmentidxptr=0,
37 double* fractionptr=0)
const;
39 T closestPoint(
const T& pt)
const;
41 double arcLength(
int idx,
double frac=0.0)
const;
42 double arcLength(
const T& pt)
const;
43 double arcLength()
const;
45 T getPoint(
int idx,
double frac=0.0)
const;
46 T getPoint(
double arclen)
const;
50 int nextIdx(
int)
const;
55 template <
class T>
inline 58 if ( idx<0 || idx>=this->size() || !(*
this)[idx].isDefined() )
62 if ( idy>=this->size() || !(*
this)[idy].isDefined() )
64 while ( (--idy)>=0 && (*
this)[idy].isDefined() ) ;
68 if ( !closed_ && idy!=idx )
88 #define mUpdateMinDist( dist, idx, frac ) \ 92 if ( segmentidxptr ) \ 93 *segmentidxptr = idx; \ 95 *fractionptr = frac; \ 98 template <
class T>
inline 100 double* fractionptr )
const 104 for (
int idx=0; idx<this->size(); idx++ )
106 const int idy = nextIdx( idx );
110 const double a2 = pt.sqDistTo( (*
this)[idx] );
111 const double b2 = pt.sqDistTo( (*
this)[idy] );
112 const double c2 = (*this)[idx].sqDistTo( (*
this)[idy] );
114 if ( c2<=0.0 || b2>=a2+c2 )
119 else if ( a2 >= b2+c2 )
127 const double d = (a2+c2-b2) / (2*c);
128 const double h = (a2-d*d)>0 ?
Math::Sqrt(a2-d*d) : 0.0;
137 template <
class T>
inline 142 if (
mIsUdf( distTo(pt,&idx,&frac) ) )
145 const int idy = nextIdx( idx );
149 return (*
this)[idx]*(1.0-frac) + (*
this)[idy]*frac;
153 template <
class T>
inline 156 if ( index<0 || index>=this->size() || frac<0.0 || frac>1.0 )
161 for (
int idx=0; idx<=index; idx++ )
163 const int idy = nextIdx( idx );
167 const double len = (*this)[idx].template distTo<double>( (*this)[idy] );
169 return arclen + len * frac;
178 template <
class T>
inline 183 if (
mIsUdf( distTo(pt,&idx,&frac) ) )
186 return arcLength( idx, frac );
190 template <
class T>
inline 193 return arcLength( this->size()-1, 1.0 );
197 template <
class T>
inline 200 if ( idx<0 || idx>=this->size() || frac<0.0 || frac>1.0 )
206 if ( frac==1.0 && !(*
this)[idx].isDefined() )
207 return getPoint( idx+1, 0.0 );
209 const int idy = nextIdx( idx );
213 return (*
this)[idx]*(1.0-frac) + (*
this)[idy]*frac;
217 template <
class T>
inline 223 for (
int idx=0; idx<this->size(); idx++ )
225 const int idy = nextIdx( idx );
229 const double len = (*this)[idx].template distTo<double>( (*this)[idy] );
232 const double frac = arclen / len;
233 return (*
this)[idx]*(1.0-frac) + (*
this)[idy]*frac;
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:285
bool closed_
Definition: polylinend.h:51
#define mUpdateMinDist(dist, idx, frac)
Point-to-segment distance:
Definition: polylinend.h:88
T closestPoint(const T &pt) const
Definition: polylinend.h:138
PolyLineND(bool closed=false)
Definition: polylinend.h:26
Set of (small) copyable elements.
Definition: commontypes.h:26
double arcLength() const
Definition: polylinend.h:191
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:270
(Closed) sequence(s) of connected n-D coordinates. Undefined coordinates separate consecutive sequenc...
Definition: polylinend.h:23
T getPoint(int idx, double frac=0.0) const
Definition: polylinend.h:198
bool isClosed() const
Definition: polylinend.h:34
double distTo(const T &pt, int *segmentidxptr=0, double *fractionptr=0) const
Definition: polylinend.h:99
int nextIdx(int) const
Definition: polylinend.h:56
#define MAXDOUBLE
Definition: commondefs.h:103
#define mClass(module)
Definition: commondefs.h:161
PolyLineND(const TypeSet< T > &coords, bool closed=false)
Definition: polylinend.h:29
void setClosed(bool yn)
Definition: polylinend.h:33