45template <
typename ValueType>
111 start.applyTransform (transform);
112 end.applyTransform (transform);
168 findIntersection (start, end, line.start, line.end, p);
186 return findIntersection (start, end, line.start, line.end,
intersection);
193 return findIntersection (start, end,
other.start,
other.end, ignored);
226 auto delta = end - start;
265 auto delta = end - start;
266 auto length = delta.x * delta.x + delta.y * delta.y;
270 auto prop = ((targetPoint.x - start.x) * delta.x
271 + (targetPoint.y - start.y) * delta.y) / (
double) length;
280 auto fromStart = targetPoint.getDistanceFrom (start);
281 auto fromEnd = targetPoint.getDistanceFrom (end);
303 auto delta = end - start;
304 auto length = delta.x * delta.x + delta.y * delta.y;
306 return length <= 0 ? 0
307 :
jlimit (ValueType(),
static_cast<ValueType
> (1),
308 static_cast<ValueType
> ((((point.x - start.x) * delta.x
309 + (point.y - start.y) * delta.y) / length)));
328 return start.x != end.x
329 && point.y < ((end.y - start.y) * (point.x - start.x)) / (end.x - start.x) + start.y;
380 static bool findIntersection (
const Point<ValueType>
p1,
const Point<ValueType>
p2,
381 const Point<ValueType>
p3,
const Point<ValueType>
p4,
394 const auto zero = ValueType{};
398 if (! (
d1.isOrigin() ||
d2.isOrigin()))
404 return isZeroToOne (
along);
411 return isZeroToOne (
along);
418 return isZeroToOne (
along);
425 return isZeroToOne (
along);
436 if (! isZeroToOne (
along1))
440 return isZeroToOne (
along2);
Line(Point< ValueType > startPoint, Point< ValueType > endPoint) noexcept
Creates a line from its start and end points.
Line reversed() const noexcept
Returns a line that is the same as this one, but with the start and end reversed,.
ValueType getStartY() const noexcept
Returns the y coordinate of the line's start point.
static Line fromStartAndAngle(Point< ValueType > startPoint, ValueType length, ValueType angle) noexcept
Creates a line from a start point, length and angle.
~Line()=default
Destructor.
bool isVertical() const noexcept
Returns true if the line's start and end x coordinates are the same.
Line withLengthenedEnd(ValueType distanceToLengthenBy) const noexcept
Returns a lengthened copy of this line.
void setStart(ValueType newStartX, ValueType newStartY) noexcept
Changes this line's start point.
Point< ValueType >::FloatType getAngle() const noexcept
Returns the line's angle.
ValueType getEndY() const noexcept
Returns the y coordinate of the line's end point.
void setStart(const Point< ValueType > newStart) noexcept
Changes this line's start point.
Point< ValueType > getIntersection(Line line) const noexcept
Finds the intersection between two lines.
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'...
Point< ValueType > getPointAlongLine(ValueType distanceFromStart) const noexcept
Returns the location of the point which is a given distance along this line.
Line withLengthenedStart(ValueType distanceToLengthenBy) const noexcept
Returns a lengthened copy of this line.
Line(ValueType startX, ValueType startY, ValueType endX, ValueType endY) noexcept
Creates a line based on the coordinates of its start and end points.
ValueType getLengthSquared() const noexcept
Returns the length of the line.
bool isPointAbove(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.
bool operator!=(Line other) const noexcept
Compares two lines.
void setEnd(const Point< ValueType > newEnd) noexcept
Changes this line's end point.
bool intersects(Line other) const noexcept
Returns true if this line intersects another.
Line & operator=(const Line &)=default
Copies a line from another one.
ValueType getLength() const noexcept
Returns the length of the line.
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 proport...
Line()=default
Creates a line, using (0, 0) as its start and end points.
Line< float > toFloat() const noexcept
Casts this line to float coordinates.
ValueType getStartX() const noexcept
Returns the x coordinate of the line's start point.
Point< ValueType > findNearestPointTo(Point< ValueType > point) const noexcept
Finds the point on this line which is nearest to a given point.
ValueType getDistanceFromPoint(Point< ValueType > targetPoint, Point< ValueType > &pointOnLine) const noexcept
Returns the smallest distance between this line segment and a given point.
bool operator==(Line other) const noexcept
Compares two lines.
void setEnd(ValueType newEndX, ValueType newEndY) noexcept
Changes this line's end point.
Line(const Line &)=default
Creates a copy of another line.
bool isHorizontal() const noexcept
Returns true if the line's start and end y coordinates are the same.
Point< ValueType > getEnd() const noexcept
Returns the line's end point.
ValueType getEndX() const noexcept
Returns the x coordinate of the line's end point.
Line< double > toDouble() const noexcept
Casts this line to double coordinates.
void applyTransform(const AffineTransform &transform) noexcept
Applies an affine transform to the line's start and end points.
Line withShortenedEnd(ValueType distanceToShortenBy) const noexcept
Returns a shortened copy of 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.
bool intersects(Line line, Point< ValueType > &intersection) const noexcept
Finds the intersection between two lines.
Point< ValueType > getStart() const noexcept
Returns the line's start point.
A pair of (x, y) coordinates.
constexpr bool approximatelyEqual(Type a, Type b, Tolerance< Type > tolerance=Tolerance< Type >{} .withAbsolute(std::numeric_limits< Type >::min()) .withRelative(std::numeric_limits< Type >::epsilon()))
Returns true if the two floating-point numbers are approximately equal.
constexpr Type jmin(Type a, Type b)
Returns the smaller of two values.
Type jlimit(Type lowerLimit, Type upperLimit, Type valueToConstrain) noexcept
Constrains a value to keep it within a given range.
Type juce_hypot(Type a, Type b) noexcept
Using juce_hypot is easier than dealing with the different types of hypot function that are provided ...
Type unalignedPointerCast(void *ptr) noexcept
Casts a pointer to another type via void*, which suppresses the cast-align warning which sometimes ar...