JUCE  v6.1.6 (6.0.8-1114)
JUCE API
Looking for a senior C++ dev?
I'm looking for work. Hire me!
juce::Line< ValueType > Class Template Reference

Represents a line. More...

#include <juce_Line.h>

Collaboration diagram for juce::Line< ValueType >:

Public Member Functions

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

Static Public Member Functions

static Line fromStartAndAngle (Point< ValueType > startPoint, ValueType length, ValueType angle) noexcept
 Creates a line from a start point, length and angle. More...
 

Static Private Member Functions

static bool findIntersection (const Point< ValueType > p1, const Point< ValueType > p2, const Point< ValueType > p3, const Point< ValueType > p4, Point< ValueType > &intersection) noexcept
 
static bool isZeroToOne (ValueType v) noexcept
 

Private Attributes

Point< ValueType > end
 
Point< ValueType > start
 

Detailed Description

template<typename ValueType>
class juce::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

@tags{Graphics}

Constructor & Destructor Documentation

◆ Line() [1/4]

template<typename ValueType >
juce::Line< ValueType >::Line ( )
default

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

◆ Line() [2/4]

template<typename ValueType >
juce::Line< ValueType >::Line ( const Line< ValueType > &  )
default

Creates a copy of another line.

◆ Line() [3/4]

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

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

◆ Line() [4/4]

template<typename ValueType >
juce::Line< ValueType >::Line ( Point< ValueType >  startPoint,
Point< ValueType >  endPoint 
)
inlinenoexcept

Creates a line from its start and end points.

◆ ~Line()

template<typename ValueType >
juce::Line< ValueType >::~Line ( )
default

Destructor.

Member Function Documentation

◆ applyTransform()

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

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

References juce::Line< ValueType >::end, juce::Line< ValueType >::start, and juce::gl::transform.

◆ findIntersection()

template<typename ValueType >
static bool juce::Line< ValueType >::findIntersection ( const Point< ValueType >  p1,
const Point< ValueType >  p2,
const Point< ValueType >  p3,
const Point< ValueType >  p4,
Point< ValueType > &  intersection 
)
inlinestaticprivatenoexcept

◆ findNearestPointTo()

template<typename ValueType >
Point<ValueType> juce::Line< ValueType >::findNearestPointTo ( Point< ValueType >  point) const
inlinenoexcept

◆ findNearestProportionalPositionTo()

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

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 juce::Line< ValueType >::end, juce::jlimit(), juce::gl::length, and juce::Line< ValueType >::start.

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

◆ fromStartAndAngle()

template<typename ValueType >
static Line juce::Line< ValueType >::fromStartAndAngle ( Point< ValueType >  startPoint,
ValueType  length,
ValueType  angle 
)
inlinestaticnoexcept

Creates a line from a start point, length and angle.

This angle 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.

References juce::gl::angle, and juce::gl::length.

◆ getAngle()

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

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.

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ getDistanceFromPoint()

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

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 juce::Line< ValueType >::end, juce::gl::length, and juce::Line< ValueType >::start.

◆ getEnd()

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

Returns the line's end point.

References juce::Line< ValueType >::end.

◆ getEndX()

template<typename ValueType >
ValueType juce::Line< ValueType >::getEndX ( ) const
inlinenoexcept

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

References juce::Line< ValueType >::end.

◆ getEndY()

template<typename ValueType >
ValueType juce::Line< ValueType >::getEndY ( ) const
inlinenoexcept

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

References juce::Line< ValueType >::end.

◆ getIntersection()

template<typename ValueType >
Point<ValueType> juce::Line< ValueType >::getIntersection ( Line< ValueType >  line) const
inlinenoexcept

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

References juce::Line< ValueType >::end, juce::Line< ValueType >::findIntersection(), juce::gl::p, and juce::Line< ValueType >::start.

◆ getLength()

◆ getLengthSquared()

template<typename ValueType >
ValueType juce::Line< ValueType >::getLengthSquared ( ) const
inlinenoexcept

Returns the length of the line.

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ getPointAlongLine() [1/2]

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

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 juce::Line< ValueType >::end, juce::Line< ValueType >::getLength(), juce::gl::length, and juce::Line< ValueType >::start.

Referenced by juce::RenderingHelpers::GradientPixelIterators::Linear::Linear(), juce::Line< ValueType >::withShortenedEnd(), and juce::Line< ValueType >::withShortenedStart().

◆ getPointAlongLine() [2/2]

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

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::Line< ValueType >::end, juce::juce_hypot(), juce::gl::length, and juce::Line< ValueType >::start.

◆ getPointAlongLineProportionally()

template<typename ValueType >
Point<ValueType> juce::Line< ValueType >::getPointAlongLineProportionally ( typename Point< ValueType >::FloatType  proportionOfLength) const
inlinenoexcept

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

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

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

◆ getStart()

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

Returns the line's start point.

References juce::Line< ValueType >::start.

◆ getStartX()

template<typename ValueType >
ValueType juce::Line< ValueType >::getStartX ( ) const
inlinenoexcept

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

References juce::Line< ValueType >::start.

◆ getStartY()

template<typename ValueType >
ValueType juce::Line< ValueType >::getStartY ( ) const
inlinenoexcept

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

References juce::Line< ValueType >::start.

◆ intersects() [1/2]

template<typename ValueType >
bool juce::Line< ValueType >::intersects ( Line< ValueType >  line,
Point< ValueType > &  intersection 
) const
inlinenoexcept

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 don't. Even if they don't intersect, the intersection coordinates returned will still be valid

References juce::Line< ValueType >::end, juce::Line< ValueType >::findIntersection(), and juce::Line< ValueType >::start.

◆ intersects() [2/2]

template<typename ValueType >
bool juce::Line< ValueType >::intersects ( Line< ValueType >  other) const
inlinenoexcept

◆ isHorizontal()

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

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

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ isPointAbove()

template<typename ValueType >
bool juce::Line< ValueType >::isPointAbove ( Point< ValueType >  point) const
inlinenoexcept

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).

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ isVertical()

template<typename ValueType >
bool juce::Line< ValueType >::isVertical ( ) const
inlinenoexcept

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

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ isZeroToOne()

template<typename ValueType >
static bool juce::Line< ValueType >::isZeroToOne ( ValueType  v)
inlinestaticprivatenoexcept

◆ operator!=()

template<typename ValueType >
bool juce::Line< ValueType >::operator!= ( Line< ValueType >  other) const
inlinenoexcept

Compares two lines.

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ operator=()

template<typename ValueType >
Line& juce::Line< ValueType >::operator= ( const Line< ValueType > &  )
default

Copies a line from another one.

◆ operator==()

template<typename ValueType >
bool juce::Line< ValueType >::operator== ( Line< ValueType >  other) const
inlinenoexcept

Compares two lines.

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ reversed()

template<typename ValueType >
Line juce::Line< ValueType >::reversed ( ) const
inlinenoexcept

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

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ setEnd() [1/2]

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

Changes this line's end point.

References juce::Line< ValueType >::end.

◆ setEnd() [2/2]

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

Changes this line's end point.

References juce::Line< ValueType >::end.

◆ setStart() [1/2]

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

Changes this line's start point.

References juce::Line< ValueType >::start.

◆ setStart() [2/2]

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

Changes this line's start point.

References juce::Line< ValueType >::start.

◆ toDouble()

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

Casts this line to double coordinates.

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ toFloat()

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

Casts this line to float coordinates.

References juce::Line< ValueType >::end, and juce::Line< ValueType >::start.

◆ withLengthenedEnd()

template<typename ValueType >
Line juce::Line< ValueType >::withLengthenedEnd ( ValueType  distanceToLengthenBy) const
inlinenoexcept

Returns a lengthened copy of this line.

This will extend the line by a certain amount by moving the end away from the start (leaving the start-point the same), and return the new line.

References juce::Line< ValueType >::withShortenedEnd().

◆ withLengthenedStart()

template<typename ValueType >
Line juce::Line< ValueType >::withLengthenedStart ( ValueType  distanceToLengthenBy) const
inlinenoexcept

Returns a lengthened copy of this line.

This will extend the line by a certain amount by moving the start away from the end (leaving the end-point the same), and return the new line.

References juce::Line< ValueType >::withShortenedStart().

◆ withShortenedEnd()

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

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 juce::Line< ValueType >::getLength(), juce::Line< ValueType >::getPointAlongLine(), juce::jmin(), juce::gl::length, and juce::Line< ValueType >::start.

Referenced by juce::Line< ValueType >::withLengthenedEnd().

◆ withShortenedStart()

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

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 juce::Line< ValueType >::end, juce::Line< ValueType >::getLength(), juce::Line< ValueType >::getPointAlongLine(), and juce::jmin().

Referenced by juce::Line< ValueType >::withLengthenedStart().

Member Data Documentation

◆ end

◆ start


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