29 : closed_( closed ) {}
33 , closed_( closed ) {}
38 double distTo(
const T& pt,
int* segmentidxptr=0,
39 double* fractionptr=0)
const;
41 T closestPoint(
const T& pt)
const;
43 double arcLength(
int idx,
double frac=0.0)
const;
44 double arcLength(
const T& pt)
const;
45 double arcLength()
const;
47 T getPoint(
int idx,
double frac=0.0)
const;
48 T getPoint(
double arclen)
const;
52 int nextIdx(
int)
const;
57 template <
class T>
inline 60 if ( idx<0 || idx>=this->size() || !(*
this)[idx].isDefined() )
64 if ( idy>=this->size() || !(*
this)[idy].isDefined() )
66 while ( (--idy)>=0 && (*
this)[idy].isDefined() ) ;
70 if ( !closed_ && idy!=idx )
90 #define mUpdateMinDist( dist, idx, frac ) \ 94 if ( segmentidxptr ) \ 95 *segmentidxptr = idx; \ 97 *fractionptr = frac; \ 100 template <
class T>
inline 102 double* fractionptr )
const 106 for (
int idx=0; idx<this->size(); idx++ )
108 const int idy = nextIdx( idx );
112 const double a2 = pt.sqDistTo( (*
this)[idx] );
113 const double b2 = pt.sqDistTo( (*
this)[idy] );
114 const double c2 = (*this)[idx].sqDistTo( (*
this)[idy] );
116 if ( c2<=0.0 || b2>=a2+c2 )
121 else if ( a2 >= b2+c2 )
129 const double d = (a2+c2-b2) / (2*c);
130 const double h = (a2-d*d)>0 ?
Math::Sqrt(a2-d*d) : 0.0;
139 template <
class T>
inline 144 if (
mIsUdf( distTo(pt,&idx,&frac) ) )
147 const int idy = nextIdx( idx );
151 return (*
this)[idx]*(1.0-frac) + (*
this)[idy]*frac;
155 template <
class T>
inline 158 if ( index<0 || index>=this->size() || frac<0.0 || frac>1.0 )
163 for (
int idx=0; idx<=index; idx++ )
165 const int idy = nextIdx( idx );
169 const double len = (*this)[idx].distTo( (*
this)[idy] );
171 return arclen + len * frac;
180 template <
class T>
inline 185 if (
mIsUdf( distTo(pt,&idx,&frac) ) )
188 return arcLength( idx, frac );
192 template <
class T>
inline 195 return arcLength( this->size()-1, 1.0 );
199 template <
class T>
inline 202 if ( idx<0 || idx>=this->size() || frac<0.0 || frac>1.0 )
208 if ( frac==1.0 && !(*
this)[idx].isDefined() )
209 return getPoint( idx+1, 0.0 );
211 const int idy = nextIdx( idx );
215 return (*
this)[idx]*(1.0-frac) + (*
this)[idy]*frac;
219 template <
class T>
inline 225 for (
int idx=0; idx<this->size(); idx++ )
227 const int idy = nextIdx( idx );
231 const double len = (*this)[idx].distTo( (*
this)[idy] );
234 const double frac = arclen / len;
235 return (*
this)[idx]*(1.0-frac) + (*
this)[idy]*frac;
#define mIsUdf(val)
Use mIsUdf to check for undefinedness of simple types.
Definition: undefval.h:287
bool closed_
Definition: polylinend.h:53
#define mUpdateMinDist(dist, idx, frac)
Point-to-segment distance:
Definition: polylinend.h:90
T closestPoint(const T &pt) const
Definition: polylinend.h:140
PolyLineND(bool closed=false)
Definition: polylinend.h:28
Set of (small) copyable elements.
Definition: commontypes.h:30
double arcLength() const
Definition: polylinend.h:193
#define mUdf(type)
Use this macro to get the undefined for simple types.
Definition: undefval.h:272
(Closed) sequence(s) of connected n-D coordinates. Undefined coordinates separate consecutive sequenc...
Definition: polylinend.h:25
T getPoint(int idx, double frac=0.0) const
Definition: polylinend.h:200
bool isClosed() const
Definition: polylinend.h:36
double distTo(const T &pt, int *segmentidxptr=0, double *fractionptr=0) const
Definition: polylinend.h:101
int nextIdx(int) const
Definition: polylinend.h:58
#define MAXDOUBLE
Definition: commondefs.h:107
#define mClass(module)
Definition: commondefs.h:164
PolyLineND(const TypeSet< T > &coords, bool closed=false)
Definition: polylinend.h:31
void setClosed(bool yn)
Definition: polylinend.h:35