Public Member Functions | Public Attributes

CL_LineSegment2x< Type > Class Template Reference
[clanCore Math]

2D line segment More...

#include <line_segment.h>

Inheritance diagram for CL_LineSegment2x< Type >:
Inheritance graph
[legend]

List of all members.

Public Member Functions

 CL_LineSegment2x ()
 CL_LineSegment2x (const CL_Vec2< Type > &point_p, const CL_Vec2< Type > &point_q)
 CL_LineSegment2x (const CL_LineSegment2x< Type > &copy)
Attributes

CL_Vec2< Type > get_midpoint () const
 Get the midpoint of this line.
Type point_distance (const CL_Vec2< Type > &point)
 Return the distance from a point to a line.
bool collinear (const CL_LineSegment2x< Type > &second) const
 Return true if two line segments are collinear. (All points are on the same line.).
bool intersects (const CL_LineSegment2x< Type > &second, bool collinear_intersect) const
 Return true if two line segments intersect.
CL_Vec2< Type > get_intersection (const CL_LineSegment2x< Type > &second, bool &intersect) const
 Return the intersection point of two lines.
Type point_right_of_line (const CL_Vec2< Type > &point) const
 Return [<0, 0, >0] if the Point P is right, on or left of the line trough A,B.
CL_Vec2< Type > normal () const
 Return the normal vector of the line from point A to point B.
Operations

CL_LineSegment2x< Type > & clip (const CL_Rectx< Type > &rect, bool &clipped)
 Clip this line to a rectangle.
Operators

CL_LineSegment2x< Type > & operator= (const CL_LineSegment2x< Type > &copy)
 = operator.
bool operator== (const CL_LineSegment2x< Type > &line) const
 == operator.
bool operator!= (const CL_LineSegment2x< Type > &line) const
 != operator.

Public Attributes

CL_Vec2< Type > p
 Start point on the line.
CL_Vec2< Type > q

Detailed Description

template<typename Type>
class CL_LineSegment2x< Type >

2D line segment

A line segment has a start point and an end point
These line templates are defined for: int (CL_LineSegment2i), float (CL_LineSegment2f), double (CL_LineSegment2d)


Constructor & Destructor Documentation

template<typename Type>
CL_LineSegment2x< Type >::CL_LineSegment2x (  )  [inline]
template<typename Type>
CL_LineSegment2x< Type >::CL_LineSegment2x ( const CL_LineSegment2x< Type > &  copy  )  [inline]
template<typename Type>
CL_LineSegment2x< Type >::CL_LineSegment2x ( const CL_Vec2< Type > &  point_p,
const CL_Vec2< Type > &  point_q 
) [inline]

Member Function Documentation

template<typename Type>
CL_LineSegment2x<Type>& CL_LineSegment2x< Type >::clip ( const CL_Rectx< Type > &  rect,
bool &  clipped 
)

Clip this line to a rectangle.

If clipping was not successful, this object is undefined

Parameters:
rect = Rectangle to clip to
clipped = On Return: true if the line could be clipped, false if line exists outside the rectangle
Returns:
reference to this object
template<typename Type>
bool CL_LineSegment2x< Type >::collinear ( const CL_LineSegment2x< Type > &  second  )  const

Return true if two line segments are collinear. (All points are on the same line.).

Parameters:
second = The second line to check with
Returns:
true = They are collinear
template<typename Type>
CL_Vec2<Type> CL_LineSegment2x< Type >::get_intersection ( const CL_LineSegment2x< Type > &  second,
bool &  intersect 
) const

Return the intersection point of two lines.

Parameters:
second = Second line.
intersect = On Return: The intercept. If the lines are parallel, this contains this line's first point
Returns:
true if the lines intersect, false if the lines are parallel
template<typename Type>
CL_Vec2<Type> CL_LineSegment2x< Type >::get_midpoint (  )  const [inline]

Get the midpoint of this line.

Returns:
The midpoint
template<typename Type>
bool CL_LineSegment2x< Type >::intersects ( const CL_LineSegment2x< Type > &  second,
bool  collinear_intersect 
) const

Return true if two line segments intersect.

Parameters:
second = Second line.
collinear_intersect = true if a collision is reported when all points are on the same line.
Returns:
true = Intersects
template<typename Type>
CL_Vec2<Type> CL_LineSegment2x< Type >::normal (  )  const

Return the normal vector of the line from point A to point B.

When using CL_Vec2i, the vector is an 8 bit fraction (multiplied by 256)

Returns:
The normal vector
template<typename Type>
bool CL_LineSegment2x< Type >::operator!= ( const CL_LineSegment2x< Type > &  line  )  const [inline]

!= operator.

template<typename Type>
CL_LineSegment2x<Type>& CL_LineSegment2x< Type >::operator= ( const CL_LineSegment2x< Type > &  copy  )  [inline]

= operator.

template<typename Type>
bool CL_LineSegment2x< Type >::operator== ( const CL_LineSegment2x< Type > &  line  )  const [inline]

== operator.

template<typename Type>
Type CL_LineSegment2x< Type >::point_distance ( const CL_Vec2< Type > &  point  ) 

Return the distance from a point to a line.

Parameters:
point = The point.
template<typename Type>
Type CL_LineSegment2x< Type >::point_right_of_line ( const CL_Vec2< Type > &  point  )  const [inline]

Return [<0, 0, >0] if the Point P is right, on or left of the line trough A,B.

Parameters:
point = The point
Returns:
Value representing - left (>0), centre (=0), or right (<0)

Member Data Documentation

template<typename Type>
CL_Vec2<Type> CL_LineSegment2x< Type >::p
template<typename Type>
CL_Vec2<Type> CL_LineSegment2x< Type >::q

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