clan::LineSegment2x< Type > Class Template Reference - ClanLib SDK
Description: clan::LineSegment2x< Type > Class Template Reference

Public Member Functions | Public Attributes | List of all members
clan::LineSegment2x< Type > Class Template Reference
clanCore Math

2D line segment More...

`#include <line_segment.h>`

## Public Member Functions
| LineSegment2x ()
| LineSegment2x (const LineSegment2x< Type > &copy)=default
| LineSegment2x (const Vec2< Type > &point_p, const Vec2< Type > &point_q)
LineSegment2x< Type > & | clip (const Rectx< Type > &rect, bool &clipped)
| Clip this line to a rectangle.
bool | collinear (const LineSegment2x< Type > &second) const
| Return true if two line segments are collinear. (All points are on the same line.)
Vec2< Type > | get_intersection (const LineSegment2x< Type > &second, bool &intersect) const
| Return the intersection point of two lines.
Vec2< Type > | get_midpoint () const
| Get the midpoint of this line.
bool | intersects (const LineSegment2x< Type > &second, bool collinear_intersect) const
| Return true if two line segments intersect.
Vec2< Type > | normal () const
| Return the normal vector of the line from point A to point B.
bool | operator!= (const LineSegment2x< Type > &line) const
| != operator.
LineSegment2x< Type > & | operator= (const LineSegment2x< Type > &copy)=default
| = operator.
bool | operator== (const LineSegment2x< Type > &line) const
| == operator.
Type | point_distance (const Vec2< Type > &point)
| Return the distance from a point to a line.
Type | point_right_of_line (const Vec2< Type > &point) const
| Return [<0, 0, >0] if the Point P is right, on or left of the line trough A,B.

## Public Attributes
Vec2< Type > | p
| Start point on the line.
Vec2< Type > | q

## Detailed Description

template<typename Type>
class clan::LineSegment2x< Type >

2D line segment

A line segment has a start point and an end point
These line templates are defined for: int (LineSegment2i), float (LineSegment2f), double (LineSegment2d)

## Constructor & Destructor Documentation

## ◆ LineSegment2x() [1/3]

template<typename Type>

clan::LineSegment2x< Type >::LineSegment2x | ( |  | ) |
| inline

References p, and q.

Referenced by LineSegment2x(), clip(), collinear(), get_intersection(), intersects(), operator!=(), operator=(), and operator==().

## ◆ LineSegment2x() [2/3]

template<typename Type>

clan::LineSegment2x< Type >::LineSegment2x | ( | const LineSegment2x< Type > & | copy | ) |
| default

References LineSegment2x().

## ◆ LineSegment2x() [3/3]

template<typename Type>

clan::LineSegment2x< Type >::LineSegment2x | ( | const Vec2< Type > & | point_p,
|  | const Vec2< Type > & | point_q )
| inline

References p, and q.

## Member Function Documentation

## ◆ clip()

template<typename Type>

LineSegment2x< Type > & clan::LineSegment2x< Type >::clip | ( | const 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

References LineSegment2x().

## ◆ collinear()

template<typename Type>

bool clan::LineSegment2x< Type >::collinear | ( | const 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

References LineSegment2x().

## ◆ get_intersection()

template<typename Type>

Vec2< Type > clan::LineSegment2x< Type >::get_intersection | ( | const 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

References LineSegment2x().

## ◆ get_midpoint()

template<typename Type>

Vec2< Type > clan::LineSegment2x< Type >::get_midpoint | ( |  | ) | const
| inline

Get the midpoint of this line.

Returns
  The midpoint

References p, and q.

## ◆ intersects()

template<typename Type>

bool clan::LineSegment2x< Type >::intersects | ( | const 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

References LineSegment2x().

## ◆ normal()

template<typename Type>

Vec2< Type > clan::LineSegment2x< Type >::normal | ( |  | ) | const

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

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

Returns
  The normal vector

## ◆ operator!=()

template<typename Type>

bool clan::LineSegment2x< Type >::operator!= | ( | const LineSegment2x< Type > & | line | ) | const
| inline

!= operator.

References LineSegment2x(), clan::line, p, and q.

## ◆ operator=()

template<typename Type>

LineSegment2x< Type > & clan::LineSegment2x< Type >::operator= | ( | const LineSegment2x< Type > & | copy | ) |
| default

= operator.

References LineSegment2x().

## ◆ operator==()

template<typename Type>

bool clan::LineSegment2x< Type >::operator== | ( | const LineSegment2x< Type > & | line | ) | const
| inline

== operator.

References LineSegment2x(), clan::line, p, and q.

## ◆ point_distance()

template<typename Type>

Type clan::LineSegment2x< Type >::point_distance | ( | const Vec2< Type > & | point | ) |

Return the distance from a point to a line.

Parameters

  point | = The point.

References clan::point.

## ◆ point_right_of_line()

template<typename Type>

Type clan::LineSegment2x< Type >::point_right_of_line | ( | const 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)

References p, clan::point, and q.

## Member Data Documentation

## ◆ p

template<typename Type>

Vec2<Type> clan::LineSegment2x< Type >::p

Start point on the line.

Referenced by LineSegment2x(), LineSegment2x(), get_midpoint(), operator!=(), operator==(), and point_right_of_line().

## ◆ q

template<typename Type>

Vec2<Type> clan::LineSegment2x< Type >::q

Referenced by LineSegment2x(), LineSegment2x(), get_midpoint(), operator!=(), operator==(), and point_right_of_line().

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

- line_segment.h