Represents a line. More...
#include <juce_Line.h>
Public Member Functions | |
Line () noexcept | |
Creates a line, using (0, 0) as its start and end points. More... | |
Line (const Line &other) noexcept | |
Creates a copy of another line. 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 (Point< ValueType > startPoint, Point< ValueType > endPoint) noexcept | |
Creates a line from its start and end points. More... | |
~Line () noexcept | |
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... | |
Line & | operator= (const Line &other) noexcept |
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 (ValueType newEndX, ValueType newEndY) noexcept |
Changes this line's end point. More... | |
void | setEnd (const Point< ValueType > newEnd) noexcept |
Changes this line's end point. More... | |
void | setStart (ValueType newStartX, ValueType newStartY) noexcept |
Changes this line's start point. More... | |
void | setStart (const Point< ValueType > newStart) noexcept |
Changes this line's start point. More... | |
Line< double > | toDouble () const noexcept |
Casts this line to double coordinates. More... | |
Line< float > | toFloat () const noexcept |
Casts this line to float coordinates. 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 |
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.
Creates a line, using (0, 0) as its start and end points.
|
inlinenoexcept |
Creates a copy of another line.
|
inlinenoexcept |
Creates a line based on the coordinates of its start and end points.
|
inlinenoexcept |
Creates a line from its start and end points.
|
inlinenoexcept |
Applies an affine transform to the line's start and end points.
References Line< ValueType >::end, and Line< ValueType >::start.
|
inlinestaticprivatenoexcept |
References Line< ValueType >::isZeroToOne().
Referenced by Line< ValueType >::getIntersection(), and Line< ValueType >::intersects().
|
inlinenoexcept |
Finds the point on this line which is nearest to a given point.
References Line< ValueType >::findNearestProportionalPositionTo(), and Line< ValueType >::getPointAlongLineProportionally().
|
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.
References Line< ValueType >::end, jlimit(), and Line< ValueType >::start.
Referenced by Line< ValueType >::findNearestPointTo().
|
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.
|
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 Line< ValueType >::end, and Line< ValueType >::start.
|
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.
References Line< ValueType >::end, and Line< ValueType >::start.
Returns the line's end point.
References Line< ValueType >::end.
|
inlinenoexcept |
Returns the x coordinate of the line's end point.
References Line< ValueType >::end.
|
inlinenoexcept |
Returns the y coordinate of the line's end point.
References Line< ValueType >::end.
|
inlinenoexcept |
Finds the intersection between two lines.
line | the line to intersect with |
References Line< ValueType >::end, Line< ValueType >::findIntersection(), and Line< ValueType >::start.
|
inlinenoexcept |
Returns the length of the line.
References Line< ValueType >::end, and Line< ValueType >::start.
Referenced by Line< ValueType >::getPointAlongLine(), Line< ValueType >::withShortenedEnd(), and Line< ValueType >::withShortenedStart().
|
inlinenoexcept |
Returns the length of the line.
References Line< ValueType >::end, and Line< ValueType >::start.
|
inlinenoexcept |
Returns the location of the point which is a given distance along this line.
distanceFromStart | the distance to move along the line from its start point. This value can be negative or longer than the line itself |
References Line< ValueType >::end, Line< ValueType >::getLength(), and Line< ValueType >::start.
Referenced by RenderingHelpers::GradientPixelIterators::Linear::Linear(), Line< ValueType >::withShortenedEnd(), and Line< ValueType >::withShortenedStart().
|
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.
distanceFromStart | the distance to move along the line from its start point. This value can be negative or longer than the line itself |
perpendicularDistance | how 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 Line< ValueType >::end, juce_hypot(), and Line< ValueType >::start.
|
inlinenoexcept |
Returns the location of the point which is a given distance along this line proportional to the line's length.
proportionOfLength | the 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). |
References Line< ValueType >::end, and Line< ValueType >::start.
Referenced by Line< ValueType >::findNearestPointTo().
Returns the line's start point.
References Line< ValueType >::start.
|
inlinenoexcept |
Returns the x coordinate of the line's start point.
References Line< ValueType >::start.
|
inlinenoexcept |
Returns the y coordinate of the line's start point.
References Line< ValueType >::start.
|
inlinenoexcept |
Finds the intersection between two lines.
line | the other line |
intersection | the 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. |
References Line< ValueType >::end, Line< ValueType >::findIntersection(), and Line< ValueType >::start.
|
inlinenoexcept |
Returns true if this line intersects another.
References Line< ValueType >::end, Line< ValueType >::findIntersection(), and Line< ValueType >::start.
|
inlinenoexcept |
Returns true if the line's start and end y coordinates are the same.
References Line< ValueType >::end, and Line< ValueType >::start.
|
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 Line< ValueType >::end, and Line< ValueType >::start.
|
inlinenoexcept |
Returns true if the line's start and end x coordinates are the same.
References Line< ValueType >::end, and Line< ValueType >::start.
|
inlinestaticprivatenoexcept |
Referenced by Line< ValueType >::findIntersection().
|
inlinenoexcept |
Compares two lines.
References Line< ValueType >::end, and Line< ValueType >::start.
|
inlinenoexcept |
Copies a line from another one.
References Line< ValueType >::end, and Line< ValueType >::start.
|
inlinenoexcept |
Compares two lines.
References Line< ValueType >::end, and Line< ValueType >::start.
Returns a line that is the same as this one, but with the start and end reversed,.
References Line< ValueType >::end, and Line< ValueType >::start.
|
inlinenoexcept |
Changes this line's end point.
References Line< ValueType >::end.
|
inlinenoexcept |
Changes this line's end point.
References Line< ValueType >::end.
|
inlinenoexcept |
Changes this line's start point.
References Line< ValueType >::start.
|
inlinenoexcept |
Changes this line's start point.
References Line< ValueType >::start.
Casts this line to double coordinates.
References Line< ValueType >::end, and Line< ValueType >::start.
Casts this line to float coordinates.
References Line< ValueType >::end, and Line< ValueType >::start.
|
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 Line< ValueType >::getLength(), Line< ValueType >::getPointAlongLine(), juce::jmin(), and Line< ValueType >::start.
|
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 Line< ValueType >::end, Line< ValueType >::getLength(), Line< ValueType >::getPointAlongLine(), and juce::jmin().
Referenced by Line< ValueType >::applyTransform(), Line< ValueType >::findNearestProportionalPositionTo(), Line< ValueType >::getAngle(), Line< ValueType >::getDistanceFromPoint(), Line< ValueType >::getEnd(), Line< ValueType >::getEndX(), Line< ValueType >::getEndY(), Line< ValueType >::getIntersection(), Line< ValueType >::getLength(), Line< ValueType >::getLengthSquared(), Line< ValueType >::getPointAlongLine(), Line< ValueType >::getPointAlongLineProportionally(), Line< ValueType >::intersects(), Line< ValueType >::isHorizontal(), Line< ValueType >::isPointAbove(), Line< ValueType >::isVertical(), Line< ValueType >::operator!=(), Line< ValueType >::operator=(), Line< ValueType >::operator==(), Line< ValueType >::reversed(), Line< ValueType >::setEnd(), Line< ValueType >::toDouble(), Line< ValueType >::toFloat(), and Line< ValueType >::withShortenedStart().
Referenced by Line< ValueType >::applyTransform(), Line< ValueType >::findNearestProportionalPositionTo(), Line< ValueType >::getAngle(), Line< ValueType >::getDistanceFromPoint(), Line< ValueType >::getIntersection(), Line< ValueType >::getLength(), Line< ValueType >::getLengthSquared(), Line< ValueType >::getPointAlongLine(), Line< ValueType >::getPointAlongLineProportionally(), Line< ValueType >::getStart(), Line< ValueType >::getStartX(), Line< ValueType >::getStartY(), Line< ValueType >::intersects(), Line< ValueType >::isHorizontal(), Line< ValueType >::isPointAbove(), Line< ValueType >::isVertical(), Line< ValueType >::operator!=(), Line< ValueType >::operator=(), Line< ValueType >::operator==(), Line< ValueType >::reversed(), Line< ValueType >::setStart(), Line< ValueType >::toDouble(), Line< ValueType >::toFloat(), and Line< ValueType >::withShortenedEnd().