JUCE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
Public Member Functions | List of all members
Line< ValueType > Class Template Reference

Represents a line. More...

Public Member Functions

 Line () noexcept
 Creates a line, using (0, 0) as its start and end points.
 
 Line (const Line &other) noexcept
 Creates a copy of another line.
 
 Line (ValueType startX, ValueType startY, ValueType endX, ValueType endY) noexcept
 Creates a line based on the coordinates of its start and end points.
 
 Line (const Point< ValueType > startPoint, const Point< ValueType > endPoint) noexcept
 Creates a line from its start and end points.
 
Lineoperator= (const Line &other) noexcept
 Copies a line from another one.
 
 ~Line () noexcept
 Destructor.
 
ValueType getStartX () const noexcept
 Returns the x coordinate of the line's start point.
 
ValueType getStartY () const noexcept
 Returns the y coordinate of the line's start point.
 
ValueType getEndX () const noexcept
 Returns the x coordinate of the line's end point.
 
ValueType getEndY () const noexcept
 Returns the y coordinate of the line's end point.
 
Point< ValueType > getStart () const noexcept
 Returns the line's start point.
 
Point< ValueType > getEnd () const noexcept
 Returns the line's end point.
 
void setStart (ValueType newStartX, ValueType newStartY) noexcept
 Changes this line's start point.
 
void setEnd (ValueType newEndX, ValueType newEndY) noexcept
 Changes this line's end point.
 
void setStart (const Point< ValueType > newStart) noexcept
 Changes this line's start point.
 
void setEnd (const Point< ValueType > newEnd) noexcept
 Changes this line's end point.
 
const Line reversed () const noexcept
 Returns a line that is the same as this one, but with the start and end reversed,.
 
void applyTransform (const AffineTransform &transform) noexcept
 Applies an affine transform to the line's start and end points.
 
ValueType getLength () const noexcept
 Returns the length of the line.
 
bool isVertical () const noexcept
 Returns true if the line's start and end x coordinates are the same.
 
bool isHorizontal () const noexcept
 Returns true if the line's start and end y coordinates are the same.
 
Point< ValueType >::FloatType getAngle () const noexcept
 Returns the line's angle.
 
Line< float > toFloat () const noexcept
 Casts this line to float coordinates.
 
Line< double > toDouble () const noexcept
 Casts this line to double coordinates.
 
bool operator== (const Line &other) const noexcept
 Compares two lines.
 
bool operator!= (const Line &other) const noexcept
 Compares two lines.
 
Point< ValueType > getIntersection (const Line &line) const noexcept
 Finds the intersection between two lines.
 
bool intersects (const Line &line, Point< ValueType > &intersection) const noexcept
 Finds the intersection between two lines.
 
bool intersects (const Line &other) const noexcept
 Returns true if this line intersects another.
 
Point< ValueType > getPointAlongLine (ValueType distanceFromStart) const noexcept
 Returns the location of the point which is a given distance along this line.
 
Point< ValueType > getPointAlongLine (ValueType distanceFromStart, ValueType perpendicularDistance) const noexcept
 Returns a point which is a certain distance along and to the side of this line.
 
Point< ValueType > getPointAlongLineProportionally (ValueType proportionOfLength) const noexcept
 Returns the location of the point which is a given distance along this line proportional to the line's length.
 
ValueType getDistanceFromPoint (const Point< ValueType > targetPoint, Point< ValueType > &pointOnLine) const noexcept
 Returns the smallest distance between this line segment and a given point.
 
ValueType findNearestProportionalPositionTo (const Point< ValueType > point) const noexcept
 Finds the point on this line which is nearest to a given point, and returns its position as a proportional position along the line.
 
Point< ValueType > findNearestPointTo (const Point< ValueType > point) const noexcept
 Finds the point on this line which is nearest to a given point.
 
bool isPointAbove (const Point< ValueType > point) const noexcept
 Returns true if the given point lies above this line.
 
Line withShortenedStart (ValueType distanceToShortenBy) const noexcept
 Returns a shortened copy of this line.
 
Line withShortenedEnd (ValueType distanceToShortenBy) const noexcept
 Returns a shortened copy of this line.
 

Detailed Description

template<typename ValueType>
class Line< ValueType >

Represents a line.

This class contains a bunch of useful methods for various geometric tasks.

The ValueType template parameter should be a primitive type - float or double are what it's designed for. Integer types will work in a basic way, but some methods that perform mathematical operations may not compile, or they may not produce sensible results.

See Also
Point, Rectangle, Path, Graphics::drawLine

Constructor & Destructor Documentation

template<typename ValueType>
Line< ValueType >::Line ( )
noexcept

Creates a line, using (0, 0) as its start and end points.

Referenced by Line< ValueType >::reversed(), Line< ValueType >::withShortenedEnd(), and Line< ValueType >::withShortenedStart().

template<typename ValueType>
Line< ValueType >::Line ( const Line< ValueType > &  other)
noexcept

Creates a copy of another line.

template<typename ValueType>
Line< ValueType >::Line ( ValueType  startX,
ValueType  startY,
ValueType  endX,
ValueType  endY 
)
noexcept

Creates a line based on the coordinates of its start and end points.

template<typename ValueType>
Line< ValueType >::Line ( const Point< ValueType >  startPoint,
const Point< ValueType >  endPoint 
)
noexcept

Creates a line from its start and end points.

template<typename ValueType>
Line< ValueType >::~Line ( )
noexcept

Destructor.

Member Function Documentation

template<typename ValueType>
Line& Line< ValueType >::operator= ( const Line< ValueType > &  other)
noexcept

Copies a line from another one.

template<typename ValueType>
ValueType Line< ValueType >::getStartX ( ) const
noexcept

Returns the x coordinate of the line's start point.

template<typename ValueType>
ValueType Line< ValueType >::getStartY ( ) const
noexcept

Returns the y coordinate of the line's start point.

template<typename ValueType>
ValueType Line< ValueType >::getEndX ( ) const
noexcept

Returns the x coordinate of the line's end point.

template<typename ValueType>
ValueType Line< ValueType >::getEndY ( ) const
noexcept

Returns the y coordinate of the line's end point.

template<typename ValueType>
Point<ValueType> Line< ValueType >::getStart ( ) const
noexcept

Returns the line's start point.

template<typename ValueType>
Point<ValueType> Line< ValueType >::getEnd ( ) const
noexcept

Returns the line's end point.

template<typename ValueType>
void Line< ValueType >::setStart ( ValueType  newStartX,
ValueType  newStartY 
)
noexcept

Changes this line's start point.

template<typename ValueType>
void Line< ValueType >::setEnd ( ValueType  newEndX,
ValueType  newEndY 
)
noexcept

Changes this line's end point.

template<typename ValueType>
void Line< ValueType >::setStart ( const Point< ValueType >  newStart)
noexcept

Changes this line's start point.

template<typename ValueType>
void Line< ValueType >::setEnd ( const Point< ValueType >  newEnd)
noexcept

Changes this line's end point.

template<typename ValueType>
const Line Line< ValueType >::reversed ( ) const
noexcept

Returns a line that is the same as this one, but with the start and end reversed,.

References Line< ValueType >::Line().

template<typename ValueType>
void Line< ValueType >::applyTransform ( const AffineTransform transform)
noexcept

Applies an affine transform to the line's start and end points.

template<typename ValueType>
ValueType Line< ValueType >::getLength ( ) const
noexcept
template<typename ValueType>
bool Line< ValueType >::isVertical ( ) const
noexcept

Returns true if the line's start and end x coordinates are the same.

template<typename ValueType>
bool Line< ValueType >::isHorizontal ( ) const
noexcept

Returns true if the line's start and end y coordinates are the same.

template<typename ValueType>
Point<ValueType>::FloatType Line< ValueType >::getAngle ( ) const
noexcept

Returns the line's angle.

This value is the number of radians clockwise from the 12 o'clock direction, where the line's start point is considered to be at the centre.

template<typename ValueType>
Line<float> Line< ValueType >::toFloat ( ) const
noexcept

Casts this line to float coordinates.

template<typename ValueType>
Line<double> Line< ValueType >::toDouble ( ) const
noexcept

Casts this line to double coordinates.

template<typename ValueType>
bool Line< ValueType >::operator== ( const Line< ValueType > &  other) const
noexcept

Compares two lines.

template<typename ValueType>
bool Line< ValueType >::operator!= ( const Line< ValueType > &  other) const
noexcept

Compares two lines.

template<typename ValueType>
Point<ValueType> Line< ValueType >::getIntersection ( const Line< ValueType > &  line) const
noexcept

Finds the intersection between two lines.

Parameters
linethe line to intersect with
Returns
the point at which the lines intersect, even if this lies beyond the end of the lines
template<typename ValueType>
bool Line< ValueType >::intersects ( const Line< ValueType > &  line,
Point< ValueType > &  intersection 
) const
noexcept

Finds the intersection between two lines.

Parameters
linethe other line
intersectionthe position of the point where the lines meet (or where they would meet if they were infinitely long) the intersection (if the lines intersect). If the lines are parallel, this will just be set to the position of one of the line's endpoints.
Returns
true if the line segments intersect; false if they dont. Even if they don't intersect, the intersection coordinates returned will still be valid
template<typename ValueType>
bool Line< ValueType >::intersects ( const Line< ValueType > &  other) const
noexcept

Returns true if this line intersects another.

template<typename ValueType>
Point<ValueType> Line< ValueType >::getPointAlongLine ( ValueType  distanceFromStart) const
noexcept

Returns the location of the point which is a given distance along this line.

Parameters
distanceFromStartthe distance to move along the line from its start point. This value can be negative or longer than the line itself
See Also
getPointAlongLineProportionally

References Line< ValueType >::getLength().

Referenced by Line< ValueType >::withShortenedEnd(), and Line< ValueType >::withShortenedStart().

template<typename ValueType>
Point<ValueType> Line< ValueType >::getPointAlongLine ( ValueType  distanceFromStart,
ValueType  perpendicularDistance 
) const
noexcept

Returns a point which is a certain distance along and to the side of this line.

This effectively moves a given distance along the line, then another distance perpendicularly to this, and returns the resulting position.

Parameters
distanceFromStartthe distance to move along the line from its start point. This value can be negative or longer than the line itself
perpendicularDistancehow far to move sideways from the line. If you're looking along the line from its start towards its end, then a positive value here will move to the right, negative value move to the left.

References juce_hypot(), Point< ValueType >::x, and Point< ValueType >::y.

template<typename ValueType>
Point<ValueType> Line< ValueType >::getPointAlongLineProportionally ( ValueType  proportionOfLength) const
noexcept

Returns the location of the point which is a given distance along this line proportional to the line's length.

Parameters
proportionOfLengththe distance to move along the line from its start point, in multiples of the line's length. So a value of 0.0 will return the line's start point and a value of 1.0 will return its end point. (This value can be negative or greater than 1.0).
See Also
getPointAlongLine

Referenced by Line< ValueType >::findNearestPointTo().

template<typename ValueType>
ValueType Line< ValueType >::getDistanceFromPoint ( const Point< ValueType >  targetPoint,
Point< ValueType > &  pointOnLine 
) const
noexcept

Returns the smallest distance between this line segment and a given point.

So if the point is close to the line, this will return the perpendicular distance from the line; if the point is a long way beyond one of the line's end-point's, it'll return the straight-line distance to the nearest end-point.

pointOnLine receives the position of the point that is found.

Returns
the point's distance from the line
See Also
getPositionAlongLineOfNearestPoint

References Point< ValueType >::getDistanceFrom(), Point< ValueType >::x, and Point< ValueType >::y.

template<typename ValueType>
ValueType Line< ValueType >::findNearestProportionalPositionTo ( const Point< ValueType >  point) const
noexcept

Finds the point on this line which is nearest to a given point, and returns its position as a proportional position along the line.

Returns
a value 0 to 1.0 which is the distance along this line from the line's start to the point which is nearest to the point passed-in. To turn this number into a position, use getPointAlongLineProportionally().
See Also
getDistanceFromPoint, getPointAlongLineProportionally

References jlimit(), Point< ValueType >::x, and Point< ValueType >::y.

Referenced by Line< ValueType >::findNearestPointTo().

template<typename ValueType>
Point<ValueType> Line< ValueType >::findNearestPointTo ( const Point< ValueType >  point) const
noexcept
template<typename ValueType>
bool Line< ValueType >::isPointAbove ( const Point< ValueType >  point) const
noexcept

Returns true if the given point lies above this line.

The return value is true if the point's y coordinate is less than the y coordinate of this line at the given x (assuming the line extends infinitely in both directions).

template<typename ValueType>
Line Line< ValueType >::withShortenedStart ( ValueType  distanceToShortenBy) const
noexcept

Returns a shortened copy of this line.

This will chop off part of the start of this line by a certain amount, (leaving the end-point the same), and return the new line.

References Line< ValueType >::getLength(), Line< ValueType >::getPointAlongLine(), jmin(), and Line< ValueType >::Line().

template<typename ValueType>
Line Line< ValueType >::withShortenedEnd ( ValueType  distanceToShortenBy) const
noexcept

Returns a shortened copy of this line.

This will chop off part of the end of this line by a certain amount, (leaving the start-point the same), and return the new line.

References Line< ValueType >::getLength(), Line< ValueType >::getPointAlongLine(), jmin(), and Line< ValueType >::Line().


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