LTI-Lib latest version v1.9 - last update 10 Apr 2010

lti::tfastLine< T > Class Template Reference
[Geometry Data Structures]

Type for computations with lines. More...

#include <ltiFastLine.h>

Inheritance diagram for lti::tfastLine< T >:
Inheritance graph
[legend]
Collaboration diagram for lti::tfastLine< T >:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 tfastLine ()
 tfastLine (const tpoint< T > &theStart, const tpoint< T > &theEnd)
template<class U >
 tfastLine (const tfastLine< U > &other)
template<class U >
 tfastLine (const tline< U > &other)
template<class U >
tfastLine< T > & castFrom (const tfastLine< U > &other)
void set (const tpoint< T > &theStart, const tpoint< T > &theEnd)
void setStart (const tpoint< T > &theStart)
void setEnd (const tpoint< T > &theEnd)
void invert ()
tfastLine< T > & copy (const tline< T > &other)
tfastLine< T > & copy (const tfastLine< T > &other)
tfastLine< T > & operator= (const tfastLine< T > &other)
tfastLine< T > & operator= (const tline< T > &other)
Computation of line attributes



void updateSlope ()
const tpoint< T > & getDelta () const
bool getNormalizedSlope (float &slope) const
void getLineAttributes (tpoint< T > &deltaLine, float &nslope, bool &normalSlope) const
Distance computation



distanceSqrXPol (const tpoint< T > &c, tpoint< T > &p) const
distanceToXPol (const tpoint< T > &c, tpoint< T > &p) const
distanceSqrXPol (const tpoint< T > &c) const
distanceToXPol (const tpoint< T > &c) const
Intersections



bool doIntersect (const tfastLine< T > &other) const
bool getIntersectionPointXPol (const tfastLine< T > &other, tpoint< T > &p, bool &onThisLine, bool &onOtherLine, bool &colinear) const
bool intersect (const trectangle< T > &rect)
bool intersect (const tfastLine< T > &other, const trectangle< T > &rect)
bool intersectXPol (const trectangle< T > &rect)
bool intersectXPol (const tfastLine< T > &other, const trectangle< T > &rect)
Scaling and Translation operations



template<class U >
tfastLine< T > & scale (const U c)
template<class U >
tfastLine< T > operator* (const U c) const
template<class U >
tfastLine< T > & operator*= (const U c)
template<class U >
tfastLine< T > & divide (const U c)
template<class U >
tfastLine< T > operator/ (const U c) const
template<class U >
tfastLine< T > & operator/= (const U c)
tfastLine< T > & translate (const tpoint< T > &p)
tfastLine< T > & translate (const tline< T > &other, const tpoint< T > &p)

Protected Member Functions

void updateRequest ()
void ensureCorrectSlope () const

Protected Attributes

dependent attributes

These attributes depend on the start and end points and cannot be considered as a normal state component of a line instance.

They can be changed by "const" methods, which do not change the start and end points. Therefore, this attributes are all mutable.



bool uptodate
tpoint< T > delta
bool invSlope
float normSlope

Detailed Description

template<class T>
class lti::tfastLine< T >

Type for computations with lines.

A line (or more generally a tfastLine<T>) is represented by a start point and an end point.

The type T correspond to the coordinate type used in both points.

This class stores besides the two delimiting points other derived information that can save some time in some intensive computations involving distances and intersections of lines.

Of course, the class becomes faster, if the operations are done with lines that do not change much in time. If you have thousends of lines and want to compute the intersection among all of them, this class provides a good solution. If you have one line that changes continously and want to compute the intersection with another changing line, the parent class can be even faster, due to the fact that the internal stage do not need to be updated.

See also:
tline<T>

Constructor & Destructor Documentation

template<class T>
lti::tfastLine< T >::tfastLine (  )  [explicit]

default constructor.

Both points are left uninitialized (this can save some time)

template<class T>
lti::tfastLine< T >::tfastLine ( const tpoint< T > &  theStart,
const tpoint< T > &  theEnd 
)

constructor with both points

template<class T>
template<class U >
lti::tfastLine< T >::tfastLine ( const tfastLine< U > &  other  )  [inline]

copy constructor

template<class T>
template<class U >
lti::tfastLine< T >::tfastLine ( const tline< U > &  other  )  [inline]

copy constructor


Member Function Documentation

template<class T>
template<class U >
tfastLine<T>& lti::tfastLine< T >::castFrom ( const tfastLine< U > &  other  )  [inline]

cast operator

Reimplemented from lti::tline< T >.

References lti::tfastLine< T >::updateRequest().

template<class T>
tfastLine<T>& lti::tfastLine< T >::copy ( const tfastLine< T > &  other  )  [inline]

copy operator

Reimplemented from lti::tline< T >.

template<class T>
tfastLine<T>& lti::tfastLine< T >::copy ( const tline< T > &  other  )  [inline]

copy operator

template<class T>
T lti::tfastLine< T >::distanceSqrXPol ( const tpoint< T > &  c  )  const

Calculate square of distance to the point c to the infinite line (eXtraPolated) containing this line segment.

Parameters:
c point to which the minimal distance is searched.
Returns:
the square of the minimal distance to c
See also:
sqrDistanceTo()

This method is faster than distanceToXPol (because it does not calculate the square root).

Reimplemented from lti::tline< T >.

template<class T>
T lti::tfastLine< T >::distanceSqrXPol ( const tpoint< T > &  c,
tpoint< T > &  p 
) const

Calculate square of distance to the point c to the infinite line (eXtraPolated) containing this line segment.

Parameters:
c point to which the minimal distance is searched.
p point in the extrapolated line segment with the minimal distance to c.

This method is faster than distanceToXPol (because it does not calculate the square root).

If not update of state (slope, delta and so on) is required, this method is about 12% faster than the normal one (in tline<T>). If an update is required, the opposite happens, and this method is about 10% slower than the tline<T> one.

See also:
sqrDistanceTo()

Reimplemented from lti::tline< T >.

template<class T>
T lti::tfastLine< T >::distanceToXPol ( const tpoint< T > &  c  )  const [inline]

Calculate distance to the point c to the infinite line (eXtraPolated) containing this line segment.

Returns:
the minimal distance to c

Reimplemented from lti::tline< T >.

template<class T>
T lti::tfastLine< T >::distanceToXPol ( const tpoint< T > &  c,
tpoint< T > &  p 
) const [inline]

Calculate distance to the point c to the infinite line (eXtraPolated) containing this line segment.

Returns:
the minimal distance to c
template<class T>
template<class U >
tfastLine<T>& lti::tfastLine< T >::divide ( const U  c  )  [inline]

divide both points by the given c factor

Reimplemented from lti::tline< T >.

References lti::tline< T >::end, lti::tline< T >::start, and lti::tfastLine< T >::updateRequest().

Referenced by lti::tfastLine< T >::operator/=().

template<class T>
bool lti::tfastLine< T >::doIntersect ( const tfastLine< T > &  other  )  const

Check if this line segment intersects the other given one.

Parameters:
other the other line segment to which an intersection is going to be checked.
Returns:
true if both line segments intersect.
template<class T>
void lti::tfastLine< T >::ensureCorrectSlope (  )  const [inline, protected]

const method called when slope and other attributes need to be updated.

template<class T>
const tpoint<T>& lti::tfastLine< T >::getDelta (  )  const [inline]

returns a point containing getEnd() - getStart().

template<class T>
bool lti::tfastLine< T >::getIntersectionPointXPol ( const tfastLine< T > &  other,
tpoint< T > &  p,
bool &  onThisLine,
bool &  onOtherLine,
bool &  colinear 
) const

Check if this line segment intersects the other given one.

Parameters:
other the other line segment to which an intersection is going to be checked.
p if there is an intersection between both line segments or between their respective infinite line extrapolations, the intersection point will be written here.
onThisLine if the intersection occurs on a point on the line segment, this parameter will be set to true. Otherwise false.
onOtherLine if the intersection occurs on a point on the other line segment, this parameter will be set to true.
colinear this parameter is set to true in case both line segments are parallel and co-linear.
Returns:
true if both line segments intersect, i.e. this method returns true if the intersection of both infinite extrapolations lay within both line segments (onThisLine and onOtherLine are both set to true). It returns false otherwise. Note that even if the return value is false, the value of the point p is updated to the proper intersection of the two infinite lines containing the segments. If both line segments are parallel and colinear, this method returns true only if both segments overlap.

For parallel line segments following values can be therefore expected:

  • Parallel but not colinear: return false and colinear is false.
  • Parallel and colinear: return true if both segments overlap, false otherwise. colinear is set to true.

In case the lines are parallel (colinear or not) the point p is leaved unchaged, because the intersection occurs at none or more than one points.

This method is for updated slope values about 25% faster than the normal tline method. When one of the lines needs update both methods need almost the same time.

template<class T>
void lti::tfastLine< T >::getLineAttributes ( tpoint< T > &  deltaLine,
float &  nslope,
bool &  normalSlope 
) const [inline]

To avoid extra computations, this method allows you to get three line attributes at once:.

Parameters:
deltaLine corresponds to end-start.
nslope normalized slope, always in interval -1 to 1.
normalSlope if true, nslope contains the usual definition of slope (deltaLine.y/deltaLine.x), if false, nslope contains (deltaLine.x/deltaLine.y)
template<class T>
bool lti::tfastLine< T >::getNormalizedSlope ( float &  slope  )  const [inline]

Get slope of the line ensuring that its absolute value is between -1 and 1.

Let delta=getDelta():

  • If the returned boolean is true, the slope variable will contain usual slope (delta.y/delta.x).
  • If the returned boolean is false, it means that the inverse of the slope has being set in slope (delta.x/delta.y).

This way, there is no risk to become an infinite slope.

template<class T>
bool lti::tfastLine< T >::intersect ( const tfastLine< T > &  other,
const trectangle< T > &  rect 
) [inline]

Compute the part of the other line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented from lti::tline< T >.

template<class T>
bool lti::tfastLine< T >::intersect ( const trectangle< T > &  rect  ) 

Compute the part of this line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented from lti::tline< T >.

template<class T>
bool lti::tfastLine< T >::intersectXPol ( const tfastLine< T > &  other,
const trectangle< T > &  rect 
) [inline]

Compute the part of the infinite extrapolated line containing the other line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented from lti::tline< T >.

template<class T>
bool lti::tfastLine< T >::intersectXPol ( const trectangle< T > &  rect  ) 

Compute the part of the infinite extrapolated line containing this line segment which lies within the given rectangle, and leave the result here.

This method assumes, the rectangle is already consistent, i.e. the rect.ul point is in both coordinates smaller than rect.br.

Returns:
true if part of this line lies within the rectangle or its border, false otherwise.

Reimplemented from lti::tline< T >.

template<class T>
void lti::tfastLine< T >::invert (  )  [inline]

exchange the start and end points, making the previous end a start point and the previous start the end point.

Reimplemented from lti::tline< T >.

template<class T>
template<class U >
tfastLine<T> lti::tfastLine< T >::operator* ( const U  c  )  const [inline]

create a new line equal this one scaled by the given c factor.

Reimplemented from lti::tline< T >.

References lti::tline< T >::end, and lti::tline< T >::start.

template<class T>
template<class U >
tfastLine<T>& lti::tfastLine< T >::operator*= ( const U  c  )  [inline]

scale this line by the given c factor.

Reimplemented from lti::tline< T >.

template<class T>
template<class U >
tfastLine<T> lti::tfastLine< T >::operator/ ( const U  c  )  const [inline]

divide both points by the given c factor

Reimplemented from lti::tline< T >.

References lti::tline< T >::end, and lti::tline< T >::start.

template<class T>
template<class U >
tfastLine<T>& lti::tfastLine< T >::operator/= ( const U  c  )  [inline]

divide both points of tfastLine<T> by a given factor

Reimplemented from lti::tline< T >.

References lti::tfastLine< T >::divide().

template<class T>
tfastLine<T>& lti::tfastLine< T >::operator= ( const tline< T > &  other  )  [inline]

operator =

template<class T>
tfastLine<T>& lti::tfastLine< T >::operator= ( const tfastLine< T > &  other  )  [inline]

operator =

Reimplemented from lti::tline< T >.

template<class T>
template<class U >
tfastLine<T>& lti::tfastLine< T >::scale ( const U  c  )  [inline]

scale this line by the given c factor.

Reimplemented from lti::tline< T >.

References lti::tline< T >::end, lti::tline< T >::start, and lti::tfastLine< T >::updateRequest().

template<class T>
void lti::tfastLine< T >::set ( const tpoint< T > &  theStart,
const tpoint< T > &  theEnd 
) [inline]

general operator to set both points of the line

Reimplemented from lti::tline< T >.

template<class T>
void lti::tfastLine< T >::setEnd ( const tpoint< T > &  theEnd  )  [inline]

set the end point.

Does not compute the slope.

Reimplemented from lti::tline< T >.

template<class T>
void lti::tfastLine< T >::setStart ( const tpoint< T > &  theStart  )  [inline]

set the start point.

Reimplemented from lti::tline< T >.

template<class T>
tfastLine<T>& lti::tfastLine< T >::translate ( const tline< T > &  other,
const tpoint< T > &  p 
) [inline]

add given point to both ends of the other line and leave the result here.

Parameters:
other the other line to be tranlated
p the translation factor
Returns:
a reference to this line
template<class T>
tfastLine<T>& lti::tfastLine< T >::translate ( const tpoint< T > &  p  )  [inline]

add given point to both ends of this line and leave the result here.

Parameters:
p the other line to be added to this one
Returns:
a reference to this line

Reimplemented from lti::tline< T >.

template<class T>
void lti::tfastLine< T >::updateRequest (  )  [inline, protected]

Method called if a change in the points have been done.

This policy does nothing here.

Referenced by lti::tfastLine< T >::castFrom(), lti::tfastLine< T >::divide(), and lti::tfastLine< T >::scale().

template<class T>
void lti::tfastLine< T >::updateSlope (  )  [inline]

Update slope can be called to force update of the internal variables containing the line attributes (for example, at a not critical computation time you will want to call this.

)


Member Data Documentation

template<class T>
tpoint<T> lti::tfastLine< T >::delta [mutable, protected]

delta

template<class T>
bool lti::tfastLine< T >::invSlope [mutable, protected]

flag indicating if the stored value is slope (false) or 1/slope (true)

template<class T>
float lti::tfastLine< T >::normSlope [mutable, protected]

value of the slope: always between -1 and 1.

template<class T>
bool lti::tfastLine< T >::uptodate [mutable, protected]

flag indicating state of the slope


The documentation for this class was generated from the following file:

Generated on Sat Apr 10 15:28:20 2010 for LTI-Lib by Doxygen 1.6.1