Line. More...

#include <rline.h>

Collaboration diagram for RLine:
[legend]

Public Member Functions

 RLine (void)
 
 RLine (const RLine &line)
 
 RLine (tCoord x1, tCoord y1, tCoord x2, tCoord y2, bool seg=true, bool reorder=true)
 
 RLine (const RPoint &pt1, const RPoint &pt2, bool seg=true, bool reorder=true)
 
int Compare (const RLine &line) const
 
tCoord GetLength (void) const
 
tCoord GetAngle (bool ccw=true) const
 
tCoord GetAngle (const RLine &line, bool ccw=true) const
 
void SetPoints (tCoord x1, tCoord y1, tCoord x2, tCoord y2, bool seg=true, bool reorder=true)
 
void SetPoints (const RPoint &pt1, const RPoint &pt2, bool seg=true, bool reorder=true)
 
bool IsOrientedTop (void) const
 
bool IsOrientedRight (void) const
 
bool Inter (const RLine &line, RPoint &pt) const
 
bool Inter (const RLine &line) const
 
bool IsIn (const RPoint &pt) const
 
tCoord GetX1 (void) const
 
tCoord GetY1 (void) const
 
tCoord GetX2 (void) const
 
tCoord GetY2 (void) const
 
RPoint GetPt1 (void) const
 
RPoint GetPt2 (void) const
 
bool IsSegment (void) const
 
bool IsHorizontal (void) const
 
bool IsVertical (void) const
 

Private Member Functions

void ReOrder (void)
 
int CounterClockwise (const RPoint &pt) const
 

Private Attributes

RPoint Pt1
 
RPoint Pt2
 
bool Segment
 
bool OrientedTop
 
bool OrientedRight
 

Detailed Description

Line.

This class represent a line. Be default, Pt1 is always the most bottom/left point and Pt2 is always the most upper/right point.

A line can also be considered as an oriented segment.

Constructor & Destructor Documentation

RLine ( void  )

Construct a imaginary line.

RLine ( const RLine line)

Copy constructor.

Parameters
lineLine used for the initialisation.
RLine ( tCoord  x1,
tCoord  y1,
tCoord  x2,
tCoord  y2,
bool  seg = true,
bool  reorder = true 
)

Construct a line. The points are eventually exchanged to ensure that the first one is the most left-upper point.

Parameters
x1X-coordinate of the first point used.
y1Y-coordinate of the first point used.
x2X-coordinate of the second point used.
y2Y-coordinate of the second point used.
segIs the line a segment.
reorderDefine if the line must be reorder.
RLine ( const RPoint pt1,
const RPoint pt2,
bool  seg = true,
bool  reorder = true 
)

Construct a line. The points are eventually exchanged to ensure that the first one is the most left-upper point.

Parameters
pt1The first point used.
pt2The second point used.
segIs the line a segment.
reorderDefine if the line must be reorder.

Member Function Documentation

void ReOrder ( void  )
private

ReOrder de points if necessary to follow the convention.

int Compare ( const RLine line) const

Compare two lines. This function is used with the class RContainer.

Parameters
lineLine used for the comparison.
Returns
  • -1 The left-bottom point of the current line is more at the left (at the bottom) of the other one. If identical, the second points are compared.
  • 0 if there have the points.
  • +1 The left-bottom point of the current line is more at the right ( upper) of the other one. If identical, the second points are compared.
tCoord GetLength ( void  ) const

Compute the length of the segment formed by both points.

Returns
the length.
tCoord GetAngle ( bool  ccw = true) const

Compute the angle of the line compared to an horizontal one.

Parameters
ccwDefine if the angles are measured counter-clockwise or not.
Returns
the angle.
tCoord GetAngle ( const RLine line,
bool  ccw = true 
) const

Compute the angle of the line compared to another one.

Parameters
lineLine to compared with.
ccwDefine if the angles are measured counter-clockwise or not.
Returns
the angle.
void SetPoints ( tCoord  x1,
tCoord  y1,
tCoord  x2,
tCoord  y2,
bool  seg = true,
bool  reorder = true 
)

Set new points to the line.

Parameters
x1X-coordinate of the first point used.
y1Y-coordinate of the first point used.
x2X-coordinate of the second point used.
y2Y-coordinate of the second point used.
segIs the line a segment.
reorderDefine if the line must be reorder.
void SetPoints ( const RPoint pt1,
const RPoint pt2,
bool  seg = true,
bool  reorder = true 
)

Set new points to the line.

Parameters
pt1The first point used.
pt2The second point used.
segIs the line a segment.
reorderDefine if the line must be reorder.
bool IsOrientedTop ( void  ) const

Look a segment is oriented to the top.

Returns
true if it is the case.
Exceptions
Anexception is generated if the line is not a segment.
bool IsOrientedRight ( void  ) const

Look a segment is oriented to the right.

Returns
true if it is the case.
Exceptions
Anexception is generated if the line is not a segment.
int CounterClockwise ( const RPoint pt) const
private

Look at the needed clock direction to go between the two extremities by passing by an intermediate point.

Parameters
ptIntermediate point.
Returns
-1 if the direction is anticlockwise. 0 if the point is one the two extremities. +1 if the direction is clockwise.
bool Inter ( const RLine line,
RPoint pt 
) const

Determine if there is an intersection between two lines. If the two lines are similar, the intersection point is left undefined.

Parameters
lineLine used for the comparison.
ptPoint that will contain the intersection point (if any).
Returns
true if there is at least one intersection.
bool Inter ( const RLine line) const

Determine if there is an intersection between two lines (To verify!!!).

Parameters
lineLine used for the comparison.
Returns
true if there is an intersection.
bool IsIn ( const RPoint pt) const

Determine if a point is on the line/segment.

Parameters
ptPoint used for the comparison.
Returns
true if there the point is contained.
tCoord GetX1 ( void  ) const

Get the X position of the first point.

Returns
a coordinate.
tCoord GetY1 ( void  ) const

Get the Y position of the first point.

Returns
a coordinate.
tCoord GetX2 ( void  ) const

Get the X position of the second point.

Returns
a coordinate.
tCoord GetY2 ( void  ) const

Get the Y position of the second point.

Returns
a coordinate.
RPoint GetPt1 ( void  ) const

Get the most left-bottom point.

Returns
a point.
RPoint GetPt2 ( void  ) const

Get the most right-up point.

Returns
a point.
bool IsSegment ( void  ) const

Verify that if the line is a segment or not.

Returns
true if it is a segment.
bool IsHorizontal ( void  ) const

Verify if a line is a horizontal one.

Returns
true if the line is horizontal.
bool IsVertical ( void  ) const

Verify if a line is a vertical one.

Returns
true if the line is vertical.

Field Documentation

RPoint Pt1
private

The First point of the line.

RPoint Pt2
private

The second point of the line.

bool Segment
private

Is the line a segment delimited by the two points.

bool OrientedTop
private

Is the segment oriented to the top.

bool OrientedRight
private

Is the segment oriented to the right.