12#include "Kanoop/kanoopcommon.h"
38 Line(
const QPoint& p1,
const QPoint& p2) :
46 Line(
const QPointF& p1,
const QPointF& p2) :
55 Line(
const QPointF& origin,
double bearing,
double distance);
69 Line(
const QLineF& other) :
70 Line(other.p1(), other.p2()) {}
77 Line(other.p1(), other.p2()) {}
84 bool operator ==(
const Line& other)
const {
return _p1 == other._p1 && _p2 == other._p2; }
90 bool operator !=(
const Line& other)
const {
return (*
this == other) ==
false; }
126 class KANOOP_EXPORT
List :
public QList<Line>
136 List(
const QList<Line>& other) {
137 for(
const Line& line : other) {
450 bool isEndpoint(
const QPointF& point,
int precision = 0)
const;
573 bool isValid()
const {
return length() != 0; }
580 static inline bool isBetween(
double value,
double v1,
double v2)
582 return value >= v1 && value <= v2;
A compass bearing angle measured in degrees, with wraparound arithmetic.
Represents a 2D circle with centre and radius, supporting geometric queries.
A list of Line objects with spatial query helpers.
QPointF closestPointTo(const QPointF &other)
Return the point on any line closest to the given point.
List()
Default constructor.
bool containsLineWithSameEndpoints(const Line &line) const
Test whether the list contains a line with the same two endpoints.
Line highest() const
Return the line with the smallest Y start or end coordinate.
QString toString() const
Format the list as a human-readable string.
double maxX() const
Return the maximum X coordinate across all line endpoints.
double totalLength() const
Return the total combined length of all lines.
Line lineNearPoint(const Point &point, int margin) const
Return the first line near the given point within a margin.
Rectangle boundingRectangle() const
Return the bounding rectangle of all lines in the list.
List(const QList< Line > &other)
Construct from a QList<Line>.
double maxY() const
Return the maximum Y coordinate across all line endpoints.
QList< QLineF > toQLineFList() const
Convert all lines to a list of QLineF objects.
Line longestVerticalLine()
Return the longest vertical line in the list.
Line lowest() const
Return the line with the largest Y start or end coordinate.
static List fromString(const QString &value)
Parse a List from a string produced by toString().
double minY() const
Return the minimum Y coordinate across all line endpoints.
List & moveDelta(double dx, double dy)
Move all lines by the given delta.
Line longestHorizontalLine()
Return the longest horizontal line in the list.
Line lineContainingPoint(const Point &point) const
Return the first line that contains the given point.
QList< QLine > toQLineList() const
Convert all lines to a list of QLine objects.
static List fromPoints(const QList< QPointF > &points)
Build a list of lines connecting adjacent points in a QList<QPointF>.
double minX() const
Return the minimum X coordinate across all line endpoints.
Line longest() const
Return the longest line in the list.
static List fromPoints(const QList< QPoint > &points)
Build a list of lines connecting adjacent points in a QList<QPoint>.
QPointF closestPointTo(const QPointF &other, Line &closestLine, double &closestDistance)
Return the closest point, and output which line and distance produced it.
Line shortest() const
Return the shortest line in the list.
Represents a 2D line segment between two Point endpoints.
Point bottomMostPoint() const
Return the endpoint with the largest Y coordinate.
double maxY() const
Return the maximum Y coordinate of the two endpoints.
Angle angle() const
Return the angle of this line as an Angle object.
Point midpoint() const
Return the midpoint of this line.
bool isRightOf(const Line &other) const
Test whether this line is entirely to the right of other.
Line & round()
Round both endpoints to integer coordinates in place.
Line(const QPointF &origin, double bearing, double distance)
Construct a line from an origin point, bearing, and distance.
double minX() const
Return the minimum X coordinate of the two endpoints.
Line & extend(double howMuch)
Extend this line by adding length at the far end.
bool intersects(const Line &other) const
Test whether this line intersects another.
Line & move(double bearing, double distance)
Move this line by bearing and distance.
Line(const QLine &other)
Construct from a QLine.
Point::List points() const
Return a list containing both endpoints.
QString toString() const
Format this line as a human-readable string.
Point p2() const
Return the end point.
double bearing() const
Return the compass bearing from p1 to p2, in degrees.
bool isAbove(const Line &other) const
Test whether this line is entirely above other.
Point p1() const
Return the start point.
QLineF toQLineF() const
Convert to a QLineF (floating-point endpoints).
Point leftMostPoint() const
Return the endpoint with the smallest X coordinate.
Point furthestPointFrom(const QPointF &point) const
Return the endpoint furthest from the given point.
bool hasYBetween(double y1, double y2) const
Test whether the line spans a Y range.
bool isEndpoint(const QPointF &point, int precision=0) const
Test whether a point is an endpoint of this line.
static Line fromString(const QString &value)
Parse a Line from a string produced by toString().
bool isVertical() const
Test whether this line is exactly vertical.
Line(const QLineF &other)
Construct from a QLineF.
bool crossesY(double y) const
Test whether the line crosses a specific Y coordinate.
double intercept() const
Return the Y-intercept of the line's equation.
bool intersects(const Line &other, Point &intersection) const
Test whether this line intersects another and output the intersection point.
bool isHorizontal() const
Test whether this line is exactly horizontal.
bool isValid() const
Test whether this line has non-zero length.
bool hasXBetween(double x1, double x2) const
Test whether the line spans an X range.
bool sharesAxisWith(const Line &other) const
Test whether this line shares an axis with other (both horizontal or both vertical).
static List verticalLines(const QRectF &rect)
Return vertical lines along the left and right edges of a rectangle.
bool sharesEndpointWith(const Line &other, double maxDistance=0) const
Test whether this line shares an endpoint with other within a tolerance.
Line(const QPointF &p1, const QPointF &p2)
Construct a line from two floating-point points.
bool intersects(const Circle &other) const
Test whether this line intersects a circle.
double minY() const
Return the minimum Y coordinate of the two endpoints.
QLine toQLine() const
Convert to a QLine (integer endpoints).
double length() const
Return the length (Euclidean distance between endpoints).
static List horizontalLines(const QRectF &rect)
Return horizontal lines along the top and bottom edges of a rectangle.
double maxX() const
Return the maximum X coordinate of the two endpoints.
Point topMostPoint() const
Return the endpoint with the smallest Y coordinate.
Point closestPointTo(const QPointF &point, double &distance) const
Return the closest point and output the distance.
Point rightMostPoint() const
Return the endpoint with the largest X coordinate.
bool sharesSameEndpoints(const Line &other) const
Test whether this line has exactly the same two endpoints as other.
Line & moveDelta(double dx, double dy)
Translate this line by a (dx, dy) delta.
bool intersects(const QRectF &other) const
Test whether this line intersects a rectangle.
bool isPerpendicular() const
Test whether this line is perpendicular (horizontal or vertical).
Line & move(Geo::Direction direction, double distance)
Move this line in a cardinal direction by a distance.
Line & shorten(double howMuch)
Shorten this line by removing length from the far end.
Geo::Direction direction() const
Return the cardinal direction of this line.
Line(const QPoint &p1, const QPoint &p2)
Construct a line from two integer points.
Rectangle makeRectangle(int expandedWidth) const
Create a rectangle of the given width centred on this line.
Line()
Default constructor — creates a zero-length line at the origin.
Line & grow(double howMuch)
Grow this line symmetrically by adding length at both ends.
Line(const QPointF &origin, Geo::Direction direction, double distance)
Construct a line from an origin point, cardinal direction, and distance.
Point intersection(const Line &other) const
Compute the intersection point with another line.
bool isBelow(const Line &other) const
Test whether this line is entirely below other.
void setP1(const Point &value)
Set the start point.
double distanceTo(const QPointF &to) const
Return the perpendicular distance from this line to a point.
bool containsPoint(const QPointF &point) const
Test whether a point lies on this line segment.
double slope() const
Return the slope (rise/run), or infinity for vertical lines.
Line & rotate(const Point ¢roid, double angle)
Rotate this line around a centroid by an angle.
bool crossesX(double x) const
Test whether the line crosses a specific X coordinate.
void setP2(const Point &value)
Set the end point.
bool isLeftOf(const Line &other) const
Test whether this line is entirely to the left of other.
Point closestPointTo(const QPointF &point) const
Return the point on this line closest to the given point.
A list of Point objects with corner-finding helpers.
A 2D floating-point point extending QPointF with movement and spatial query methods.
A 2D rectangle extending QRectF with edge, corner, and geometric query helpers.
Direction
Cardinal directions, aliased to the corresponding Side values.