RLine
Class in Math Module
Header: #include <src/core/math/RLine.h>
Inherits: RShape
Inherited by: RLineData
Description
Section titled “Description”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.
Public Functions
Section titled “Public Functions”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 ¢er=RDEFAULT_RVECTOR)Rotates the line around center by rotation (in rad). |
| virtual bool | scale(const RVector &scaleFactors, const RVector ¢er=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) |
Public Attributes
Section titled “Public Attributes”| RVector | endPoint Getter function for this property: getEndPoint. |
| RVector | startPoint Getter function for this property: getStartPoint. |
Protected Functions
Section titled “Protected Functions”| virtual void | print(QDebug dbg) constWrites a human-readable representation of this line to dbg. |
Member Documentation
Section titled “Member Documentation”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.
clipToXY
Section titled “clipToXY”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() constvirtual inline const
Reimplemented from clone.
cloneToLine
Section titled “cloneToLine”QSharedPointer< RLine > RLine::cloneToLine() constinline const
flipHorizontal
Section titled “flipHorizontal”virtual bool RLine::flipHorizontal()virtual
Mirrors the line at the Y-axis (flips X coordinates).
Reimplemented from flipHorizontal.
Reimplemented in flipHorizontal.
flipVertical
Section titled “flipVertical”virtual bool RLine::flipVertical()virtual
Mirrors the line at the X-axis (flips Y coordinates).
Reimplemented from flipVertical.
Reimplemented in flipVertical.
getAngle
Section titled “getAngle”double RLine::getAngle() constconst
Returns: Angle of the line from start to end point (in rad).
getAngleAt
Section titled “getAngleAt”virtual double RLine::getAngleAt(double distance, RS::From from=RS::FromStart) constvirtual const
Returns: Angle of the line at the given distance from the given end (always constant for a line).
Reimplemented from getAngleAt.
getBoundingBox
Section titled “getBoundingBox”virtual RBox RLine::getBoundingBox() constvirtual const
Returns: Axis-aligned bounding box of the line.
Reimplemented from getBoundingBox.
getCenterPoints
Section titled “getCenterPoints”virtual QList< RVector > RLine::getCenterPoints() constvirtual const
Returns: Same as getMiddlePoints() (center = midpoint for a line).
Reimplemented from getCenterPoints.
getDirection1
Section titled “getDirection1”virtual double RLine::getDirection1() constvirtual const
Returns: Direction angle at the start of the line (start towards end, in rad).
Reimplemented from getDirection1.
Reimplemented in getDirection1.
getDirection2
Section titled “getDirection2”virtual double RLine::getDirection2() constvirtual const
Returns: Direction angle at the end of the line (end towards start, in rad).
Reimplemented from getDirection2.
Reimplemented in getDirection2.
getDistanceFromStart
Section titled “getDistanceFromStart”virtual double RLine::getDistanceFromStart(const RVector &p) constvirtual 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.
getEndPoint
Section titled “getEndPoint”virtual RVector RLine::getEndPoint() constvirtual const
Returns: End point of the line.
Reimplemented from getEndPoint.
Reimplemented in getEndPoint.
getEndPoints
Section titled “getEndPoints”virtual QList< RVector > RLine::getEndPoints() constvirtual const
Returns: List containing start and end point.
Reimplemented from getEndPoints.
getLength
Section titled “getLength”virtual double RLine::getLength() constvirtual const
Returns: Length of the line.
Reimplemented from getLength.
getMiddlePoint
Section titled “getMiddlePoint”virtual RVector RLine::getMiddlePoint() constvirtual const
Returns: Midpoint of the line.
Reimplemented from getMiddlePoint.
getMiddlePoints
Section titled “getMiddlePoints”virtual QList< RVector > RLine::getMiddlePoints() constvirtual const
Returns: List containing the midpoint of the line.
Reimplemented from getMiddlePoints.
getOffsetShapes
Section titled “getOffsetShapes”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.
getPointCloud
Section titled “getPointCloud”virtual QList< RVector > RLine::getPointCloud(double segmentLength) constvirtual const
Returns: Points sampled along the line at intervals of segmentLength, always including start and end points.
Reimplemented from getPointCloud.
getPointsWithDistanceToEnd
Section titled “getPointsWithDistanceToEnd”virtual QList< RVector > RLine::getPointsWithDistanceToEnd(double distance, int from=RS::FromAny) constvirtual 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.
getShapeType
Section titled “getShapeType”virtual RShape::Type RLine::getShapeType() constvirtual inline const
Reimplemented from getShapeType.
getSideOfPoint
Section titled “getSideOfPoint”virtual RS::Side RLine::getSideOfPoint(const RVector &point) constvirtual 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.
getStartPoint
Section titled “getStartPoint”virtual RVector RLine::getStartPoint() constvirtual const
Returns: Start point of the line.
Reimplemented from getStartPoint.
Reimplemented in getStartPoint.
getTransformed
Section titled “getTransformed”virtual QSharedPointer< RShape > RLine::getTransformed(const QTransform &transform) constvirtual const
Returns: A new line with both endpoints transformed by the given 2D transformation matrix.
Reimplemented from getTransformed.
getTrimEnd
Section titled “getTrimEnd”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.
getVectorProperties
Section titled “getVectorProperties”virtual QList< RVector > RLine::getVectorProperties() constvirtual const
Returns: List of the start and end point (used for property-based transformations).
Reimplemented from getVectorProperties.
getVectorTo
Section titled “getVectorTo”virtual RVector RLine::getVectorTo(const RVector &point, bool limited=true, double strictRange=RMAXDOUBLE) constvirtual 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.
isCollinear
Section titled “isCollinear”bool RLine::isCollinear(const RLine &line) constconst
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.
isDirected
Section titled “isDirected”virtual bool RLine::isDirected() constvirtual inline const
Reimplemented from isDirected.
isHorizontal
Section titled “isHorizontal”bool RLine::isHorizontal(double tolerance=RS::PointTolerance) constconst
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.
isParallel
Section titled “isParallel”bool RLine::isParallel(const RLine &line) constconst
Returns: True if this line is parallel to the given line (same or opposite direction).
isValid
Section titled “isValid”virtual bool RLine::isValid() constvirtual const
Returns: True if both endpoints are valid and finite.
Reimplemented from isValid.
Reimplemented in isValid.
isVertical
Section titled “isVertical”bool RLine::isVertical(double tolerance=RS::PointTolerance) constconst
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.
mirror
Section titled “mirror”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.
moveTo
Section titled “moveTo”virtual bool RLine::moveTo(const RVector &dest)virtual
Moves the line so that the start point coincides with dest.
reverse
Section titled “reverse”virtual bool RLine::reverse()virtual
Swaps start and end point, reversing the line direction.
Reimplemented from reverse.
Reimplemented in reverse.
rotate
Section titled “rotate”virtual bool RLine::rotate(double rotation, const RVector ¢er=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 ¢er=RDEFAULT_RVECTOR)virtual
Scales the line by scaleFactors around center.
Reimplemented from scale.
Reimplemented in scale.
setAngle
Section titled “setAngle”void RLine::setAngle(double a)Sets the angle of the line (in rad), keeping start point and length fixed.
setEndPoint
Section titled “setEndPoint”void RLine::setEndPoint(const RVector &vector)Sets the end point of the line.
setLength
Section titled “setLength”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.
setStartPoint
Section titled “setStartPoint”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.
splitAt
Section titled “splitAt”virtual QList< QSharedPointer< RShape > > RLine::splitAt(const QList< RVector > &points) constvirtual 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.
stretch
Section titled “stretch”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.
trimEndPoint
Section titled “trimEndPoint”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.
trimEndPoint
Section titled “trimEndPoint”virtual bool RLine::trimEndPoint(double trimDist)virtual inline
Reimplemented from trimEndPoint.
trimStartPoint
Section titled “trimStartPoint”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.
trimStartPoint
Section titled “trimStartPoint”virtual bool RLine::trimStartPoint(double trimDist)virtual inline
Reimplemented from trimStartPoint.
endPoint
Section titled “endPoint”RVector RLine::endPointGetter function for this property: getEndPoint.
Setter function for this property: setEndPoint
startPoint
Section titled “startPoint”RVector RLine::startPointGetter function for this property: getStartPoint.
Setter function for this property: setStartPoint
virtual void RLine::print(QDebug dbg) constvirtual const protected
Writes a human-readable representation of this line to dbg.
Reimplemented from print.