Skip to content

RLine

Class in Math Module
Header: #include <src/core/math/RLine.h>
Inherits: RShape
Inherited by: RLineData

Low-level mathematical representation of a line.

Scriptable: This class is available in script environments.

Shared Pointer Support: Objects can be used in QSharedPointer.

Copyable: Objects are cleaned up automatically by the garbage collector of the script engine.

Stream Operator: Object has a stream operator to present itself as string, for example when using toString() in a script.

RLine()
RLine(const RVector &startPoint, const RVector &endPoint)
Creates a line object with the given start and end point.
RLine(const RVector &startPoint, double angle, double distance)
Creates a line from a start point, angle (in rad) and length.
RLine(double x1, double y1, double x2, double y2)
Creates a line from two coordinate pairs.
void clipToXY(const RBox &box)
Clips this line to the given 2D bounding box using the Liang-Barsky algorithm.
virtual QSharedPointer< RShape > clone() const
QSharedPointer< RLine > cloneToLine() const
virtual bool flipHorizontal()
Mirrors the line at the Y-axis (flips X coordinates).
virtual bool flipVertical()
Mirrors the line at the X-axis (flips Y coordinates).
double getAngle() const
virtual double getAngleAt(double distance, RS::From from=RS::FromStart) const
virtual RBox getBoundingBox() const
virtual QList< RVector > getCenterPoints() const
virtual double getDirection1() const
virtual double getDirection2() const
virtual double getDistanceFromStart(const RVector &p) const
virtual RVector getEndPoint() const
virtual QList< RVector > getEndPoints() const
virtual double getLength() const
virtual RVector getMiddlePoint() const
virtual QList< RVector > getMiddlePoints() const
virtual QList< QSharedPointer< RShape > > getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)
virtual QList< RVector > getPointCloud(double segmentLength) const
virtual QList< RVector > getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const
virtual RShape::Type getShapeType() const
virtual RS::Side getSideOfPoint(const RVector &point) const
virtual RVector getStartPoint() const
virtual QSharedPointer< RShape > getTransformed(const QTransform &transform) const
virtual RS::Ending getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)
virtual QList< RVector > getVectorProperties() const
virtual RVector getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const
bool isCollinear(const RLine &line) const
virtual bool isDirected() const
bool isHorizontal(double tolerance=RS::PointTolerance) const
bool isParallel(const RLine &line) const
virtual bool isValid() const
bool isVertical(double tolerance=RS::PointTolerance) const
virtual bool mirror(const RLine &axis)
Mirrors the line at the given axis line.
virtual bool move(const RVector &offset)
Moves the line by the given offset.
virtual bool moveTo(const RVector &dest)
Moves the line so that the start point coincides with dest.
virtual bool reverse()
Swaps start and end point, reversing the line direction.
virtual bool rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)
Rotates the line around center by rotation (in rad).
virtual bool scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)
Scales the line by scaleFactors around center.
void setAngle(double a)
Sets the angle of the line (in rad), keeping start point and length fixed.
void setEndPoint(const RVector &vector)
Sets the end point of the line.
void setLength(double l, bool fromStart=true)
Sets the length of the line, adjusting the end point (fromStart=true) or the start point (fromStart=false), keeping the other endpoint fixed.
void setStartPoint(const RVector &vector)
Sets the start point of the line.
virtual void setZ(double z)
Sets the Z coordinate of both endpoints.
virtual QList< QSharedPointer< RShape > > splitAt(const QList< RVector > &points) const
virtual bool stretch(const RPolyline &area, const RVector &offset)
Moves the start and/or end point by offset if they lie inside area.
virtual bool trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Moves the end point to the closest point on the line to trimPoint.
virtual bool trimEndPoint(double trimDist)
virtual bool trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)
Moves the start point to the closest point on the line to trimPoint.
virtual bool trimStartPoint(double trimDist)
RVector endPoint
Getter function for this property: getEndPoint.
RVector startPoint
Getter function for this property: getStartPoint.
virtual void print(QDebug dbg) const
Writes a human-readable representation of this line to dbg.

RLine::RLine()

All rights reserved.

This file is part of the QCAD project.

QCAD is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.

QCAD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with QCAD. Creates a line object with invalid start and end points.

RLine::RLine(const RVector &startPoint, const RVector &endPoint)

Creates a line object with the given start and end point.

RLine::RLine(const RVector &startPoint, double angle, double distance)

Creates a line from a start point, angle (in rad) and length.

RLine::RLine(double x1, double y1, double x2, double y2)

Creates a line from two coordinate pairs.

void RLine::clipToXY(const RBox &box)

Clips this line to the given 2D bounding box using the Liang-Barsky algorithm.

Sets both endpoints to invalid if the line is entirely outside the box.

virtual QSharedPointer< RShape > RLine::clone() const

virtual inline const

Reimplemented from clone.

QSharedPointer< RLine > RLine::cloneToLine() const

inline const

virtual bool RLine::flipHorizontal()

virtual

Mirrors the line at the Y-axis (flips X coordinates).

Reimplemented from flipHorizontal.

Reimplemented in flipHorizontal.

virtual bool RLine::flipVertical()

virtual

Mirrors the line at the X-axis (flips Y coordinates).

Reimplemented from flipVertical.

Reimplemented in flipVertical.

double RLine::getAngle() const

const

Returns: Angle of the line from start to end point (in rad).

virtual double RLine::getAngleAt(double distance, RS::From from=RS::FromStart) const

virtual const

Returns: Angle of the line at the given distance from the given end (always constant for a line).

Reimplemented from getAngleAt.

virtual RBox RLine::getBoundingBox() const

virtual const

Returns: Axis-aligned bounding box of the line.

Reimplemented from getBoundingBox.

virtual QList< RVector > RLine::getCenterPoints() const

virtual const

Returns: Same as getMiddlePoints() (center = midpoint for a line).

Reimplemented from getCenterPoints.

virtual double RLine::getDirection1() const

virtual const

Returns: Direction angle at the start of the line (start towards end, in rad).

Reimplemented from getDirection1.

Reimplemented in getDirection1.

virtual double RLine::getDirection2() const

virtual const

Returns: Direction angle at the end of the line (end towards start, in rad).

Reimplemented from getDirection2.

Reimplemented in getDirection2.

virtual double RLine::getDistanceFromStart(const RVector &p) const

virtual const

Returns: Signed arc-length distance from the start point to the projection of p onto the (infinite) line. Positive in the line direction, negative behind the start.

Reimplemented from getDistanceFromStart.

virtual RVector RLine::getEndPoint() const

virtual const

Returns: End point of the line.

Reimplemented from getEndPoint.

Reimplemented in getEndPoint.

virtual QList< RVector > RLine::getEndPoints() const

virtual const

Returns: List containing start and end point.

Reimplemented from getEndPoints.

virtual double RLine::getLength() const

virtual const

Returns: Length of the line.

Reimplemented from getLength.

virtual RVector RLine::getMiddlePoint() const

virtual const

Returns: Midpoint of the line.

Reimplemented from getMiddlePoint.

virtual QList< RVector > RLine::getMiddlePoints() const

virtual const

Returns: List containing the midpoint of the line.

Reimplemented from getMiddlePoints.

virtual QList< QSharedPointer< RShape > > RLine::getOffsetShapes(double distance, int number, RS::Side side, const RVector &position=RVector::invalid)

virtual inline

Returns: Parallels to this shape.

Parameters:

  • distance: Distance of first parallel or concentric arc or circle.
  • number: Number of offset shapes to generate.
  • side: Side, should be RS.LeftHand or RS.RightHand or RS.BothSides.
  • sidePosition: Position indicating what side of the shape the parallels should be.

Reimplemented from getOffsetShapes.

virtual QList< RVector > RLine::getPointCloud(double segmentLength) const

virtual const

Returns: Points sampled along the line at intervals of segmentLength, always including start and end points.

Reimplemented from getPointCloud.

virtual QList< RVector > RLine::getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) const

virtual const

Returns: Points at the given distance from the start and/or end of the line, measured along the line direction (controlled by the from flags).

Reimplemented from getPointsWithDistanceToEnd.

virtual RShape::Type RLine::getShapeType() const

virtual inline const

Reimplemented from getShapeType.

virtual RS::Side RLine::getSideOfPoint(const RVector &point) const

virtual const

Returns: Which side of the line the given point is on (LeftHand or RightHand), relative to the direction from start to end.

Reimplemented from getSideOfPoint.

Reimplemented in getSideOfPoint.

virtual RVector RLine::getStartPoint() const

virtual const

Returns: Start point of the line.

Reimplemented from getStartPoint.

Reimplemented in getStartPoint.

virtual QSharedPointer< RShape > RLine::getTransformed(const QTransform &transform) const

virtual const

Returns: A new line with both endpoints transformed by the given 2D transformation matrix.

Reimplemented from getTransformed.

virtual RS::Ending RLine::getTrimEnd(const RVector &trimPoint, const RVector &clickPoint)

virtual

Returns: Which end of the line to trim, based on where the click point is relative to the trim point. Returns EndingStart if the click is closer to the start direction.

Reimplemented from getTrimEnd.

Reimplemented in getTrimEnd.

virtual QList< RVector > RLine::getVectorProperties() const

virtual const

Returns: List of the start and end point (used for property-based transformations).

Reimplemented from getVectorProperties.

virtual RVector RLine::getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) const

virtual const

Returns: Vector from the closest point on this line to point. The projection is done in 2D (XY plane). When limited is true, the closest point is clamped to the line segment; when the projection falls outside the segment, the nearest endpoint vector is returned only if it is within strictRange. Returns an invalid vector if out of range.

Reimplemented from getVectorTo.

Reimplemented in getVectorTo.

bool RLine::isCollinear(const RLine &line) const

const

Returns: True if this line and the given line are collinear (lie on the same infinite line). Note: the triangle area tolerance comparison is in square units while RS::PointTolerance is a linear unit; this is an intentional simplification that works for typical CAD tolerances.

virtual bool RLine::isDirected() const

virtual inline const

Reimplemented from isDirected.

bool RLine::isHorizontal(double tolerance=RS::PointTolerance) const

const

Returns: True if the line is horizontal. If the start and end points of the line are identical, the line is both vertical and horizontal.

bool RLine::isParallel(const RLine &line) const

const

Returns: True if this line is parallel to the given line (same or opposite direction).

virtual bool RLine::isValid() const

virtual const

Returns: True if both endpoints are valid and finite.

Reimplemented from isValid.

Reimplemented in isValid.

bool RLine::isVertical(double tolerance=RS::PointTolerance) const

const

Returns: True if the line is vertical. If the start and end points of the line are identical, the line is both vertical and horizontal.

virtual bool RLine::mirror(const RLine &axis)

virtual

Mirrors the line at the given axis line.

Reimplemented from mirror.

Reimplemented in mirror.

virtual bool RLine::move(const RVector &offset)

virtual

Moves the line by the given offset.

Returns false if the offset is invalid or negligibly small.

Reimplemented from move.

Reimplemented in move.

virtual bool RLine::moveTo(const RVector &dest)

virtual

Moves the line so that the start point coincides with dest.

virtual bool RLine::reverse()

virtual

Swaps start and end point, reversing the line direction.

Reimplemented from reverse.

Reimplemented in reverse.

virtual bool RLine::rotate(double rotation, const RVector &center=RDEFAULT_RVECTOR)

virtual

Rotates the line around center by rotation (in rad).

Returns false if the rotation angle is negligibly small.

Reimplemented from rotate.

Reimplemented in rotate.

virtual bool RLine::scale(const RVector &scaleFactors, const RVector &center=RDEFAULT_RVECTOR)

virtual

Scales the line by scaleFactors around center.

Reimplemented from scale.

Reimplemented in scale.

void RLine::setAngle(double a)

Sets the angle of the line (in rad), keeping start point and length fixed.

void RLine::setEndPoint(const RVector &vector)

Sets the end point of the line.

void RLine::setLength(double l, bool fromStart=true)

Sets the length of the line, adjusting the end point (fromStart=true) or the start point (fromStart=false), keeping the other endpoint fixed.

void RLine::setStartPoint(const RVector &vector)

Sets the start point of the line.

virtual void RLine::setZ(double z)

virtual

Sets the Z coordinate of both endpoints.

Reimplemented from setZ.

Reimplemented in setZ.

virtual QList< QSharedPointer< RShape > > RLine::splitAt(const QList< RVector > &points) const

virtual const

Returns: This line split into segments at the given points. Points are sorted by distance from the start point. Duplicate or endpoint-coincident points are handled gracefully.

Reimplemented from splitAt.

virtual bool RLine::stretch(const RPolyline &area, const RVector &offset)

virtual

Moves the start and/or end point by offset if they lie inside area.

Reimplemented from stretch.

Reimplemented in stretch.

virtual bool RLine::trimEndPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)

virtual

Moves the end point to the closest point on the line to trimPoint.

Reimplemented from trimEndPoint.

Reimplemented in trimEndPoint.

virtual bool RLine::trimEndPoint(double trimDist)

virtual inline

Reimplemented from trimEndPoint.

virtual bool RLine::trimStartPoint(const RVector &trimPoint, const RVector &clickPoint=RVector::invalid, bool extend=false)

virtual

Moves the start point to the closest point on the line to trimPoint.

Reimplemented from trimStartPoint.

Reimplemented in trimStartPoint.

virtual bool RLine::trimStartPoint(double trimDist)

virtual inline

Reimplemented from trimStartPoint.

RVector RLine::endPoint

Getter function for this property: getEndPoint.

Setter function for this property: setEndPoint

RVector RLine::startPoint

Getter function for this property: getStartPoint.

Setter function for this property: setStartPoint

virtual void RLine::print(QDebug dbg) const

virtual const protected

Writes a human-readable representation of this line to dbg.

Reimplemented from print.