Inkscape
Vector Graphics Editor
|
Infinite line on a plane. More...
#include <line.h>
Public Member Functions | |
std::vector< ShapeIntersection > | intersect (Line const &other) const |
std::vector< ShapeIntersection > | intersect (Ray const &r) const |
std::vector< ShapeIntersection > | intersect (LineSegment const &ls) const |
template<typename T > | |
Line & | operator*= (T const &tr) |
bool | operator== (Line const &other) const |
Retrieve and set the line's parameters. | |
Point | origin () const |
Get the line's origin point. | |
Point | vector () const |
Get the line's raw direction vector. | |
Point | versor () const |
Get the line's normalized direction vector. | |
Coord | angle () const |
Angle the line makes with the X axis, in mathematical convention. | |
void | setOrigin (Point const &p) |
Set the point at zero time. | |
void | setVector (Point const &v) |
Set the speed of the line. | |
void | setAngle (Coord angle) |
Set the angle the line makes with the X axis. | |
void | setPoints (Point const &a, Point const &b) |
Set a line based on two points it should pass through. | |
void | setCoefficients (double a, double b, double c) |
Set the coefficients of the line equation. | |
std::vector< double > | coefficients () const |
Get the coefficients of the line equation as a vector. | |
void | coefficients (Coord &a, Coord &b, Coord &c) const |
Get the coefficients of the line equation by reference. | |
bool | isDegenerate () const |
Check if the line has more than one point. | |
bool | isHorizontal () const |
Check if the line is horizontal (y is constant). | |
bool | isVertical () const |
Check if the line is vertical (x is constant). | |
void | normalize () |
Reparametrize the line so that it has unit speed. | |
Line | normalized () const |
Return a new line reparametrized for unit speed. | |
Evaluate the line as a function. | |
Point | initialPoint () const |
Point | finalPoint () const |
Point | pointAt (Coord t) const |
Coord | valueAt (Coord t, Dim2 d) const |
Coord | timeAt (Point const &p) const |
Get a time value corresponding to a point. | |
Coord | timeAtProjection (Point const &p) const |
Get a time value corresponding to a projection of a point on the line. | |
Coord | nearestTime (Point const &p) const |
Find a point on the line closest to the query point. | |
std::vector< Coord > | roots (Coord v, Dim2 d) const |
Find intersection with an axis-aligned line. | |
Coord | root (Coord v, Dim2 d) const |
Create other objects based on this line. | |
void | reverse () |
Line | reversed () const |
Create a line containing the same points, but in opposite direction. | |
Curve * | portion (Coord f, Coord t) const |
Same as segment(), but allocate the line segment dynamically. | |
LineSegment | segment (Coord f, Coord t) const |
Create a segment of this line. | |
std::optional< LineSegment > | clip (Rect const &r) const |
Return the portion of the line that is inside the given rectangle. | |
Ray | ray (Coord t) |
Create a ray starting at the specified time value. | |
Line | derivative () const |
Create a derivative of the line. | |
Line | transformed (Affine const &m) const |
Create a line transformed by an affine transformation. | |
Point | normal () const |
Get a unit vector normal to the line. | |
Point | normalAndDist (double &dist) const |
Affine | reflection () const |
Compute an affine matrix representing a reflection about the line. | |
Affine | rotationToZero (Dim2 d) const |
Compute an affine which transforms all points on the line to zero X or Y coordinate. | |
Affine | rotationToAxis (Dim2 d) const |
Compute a rotation affine which transforms the line to one of the axes. | |
Affine | transformTo (Line const &other) const |
Create a transformation that maps one line to another. | |
Private Attributes | |
Point | _initial |
Point | _final |
Friends | |
template<typename T > | |
Line | operator* (Line const &l, T const &tr) |
Related Symbols | |
(Note that these are not member symbols.) | |
double | distance (Point const &p, Line const &line) |
Compute distance from point to line. | |
bool | are_same (Line const &l1, Line const &l2, double eps=EPSILON) |
Test whether two lines are approximately the same. | |
bool | are_orthogonal (Line const &l1, Line const &l2, double eps=EPSILON) |
Test whether two lines are perpendicular. | |
Creating lines. | |
Line () | |
Create a default horizontal line. | |
Line (Point const &origin, Coord angle) | |
Create a line with the specified inclination. | |
Line (Point const &a, Point const &b) | |
Create a line going through two points. | |
Line (double a, double b, double c) | |
Create a line based on the coefficients of its equation. | |
Line (LineSegment const &seg) | |
Create a line by extending a line segment. | |
Line (Ray const &r) | |
Create a line by extending a ray. | |
Line * | duplicate () const |
static Line | from_normal_distance (Point const &n, Coord c) |
Create a line normal to a vector at a specified distance from origin. | |
static Line | from_origin_and_vector (Point const &o, Point const &v) |
Create a line from origin and unit vector. | |
Infinite line on a plane.
A line is specified as two points through which it passes. Lines can be interpreted as functions \( f: (-\infty, \infty) \to \mathbb{R}^2\). Zero corresponds to the first (origin) point, one corresponds to the second (final) point. All other points are computed as a linear interpolation between those two: \(p = (1-t) a + t b\). Many such functions have the same image and therefore represent the same lines; for example, adding \(b-a\) to both points yields the same line.
2Geom can represent the same line in many ways by design: using a different representation would lead to precision loss. For example, a line from (1e30, 1e30) to (10,0) would actually evaluate to (0,0) at time 1 if it was stored as origin and normalized versor, or origin and angle.
|
inline |
Create a default horizontal line.
Creates a line with unit speed going in +X direction.
Definition at line 62 of file line.h.
Referenced by duplicate().
|
inline |
Create a line based on the coefficients of its equation.
Definition at line 88 of file line.h.
References c, and setCoefficients().
|
inlineexplicit |
|
inlineexplicit |
|
inline |
Angle the line makes with the X axis, in mathematical convention.
Definition at line 137 of file line.h.
References _final, _initial, Geom::X, and Geom::Y.
Referenced by Geom::xAx::axis_angle(), Inkscape::LivePathEffect::LPEMirrorSymmetry::doEffect_path(), Line(), setAngle(), sp_gradient_reset_to_userspace(), Inkscape::LivePathEffect::LPESlice::splititem(), and TEST().
std::optional< LineSegment > Geom::Line::clip | ( | Rect const & | r | ) | const |
Return the portion of the line that is inside the given rectangle.
Definition at line 151 of file line.cpp.
References _initial, Geom::GenericRect< C >::clamp(), Geom::contains(), Geom::Interval::isFinite(), Geom::GenericRect< C >::max(), Geom::max(), Geom::GenericRect< C >::min(), Geom::min(), Geom::other_dimension(), pointAt(), result, root, vector(), Geom::X, and Geom::Y.
Referenced by Geom::clip(), Inkscape::LivePathEffect::LPELineSegment::doEffect_path(), draw_line(), and Geom::intersection().
std::vector< Coord > Geom::Line::coefficients | ( | ) | const |
Get the coefficients of the line equation as a vector.
Get the implicit line equation coefficients.
Note that conversion to implicit form always causes loss of precision when dealing with lines that start far from the origin and end very close to it. It is recommended to normalize the line before converting it to implicit form.
Definition at line 120 of file line.cpp.
References c, and coefficients().
Referenced by coefficients(), draw_line(), Geom::Ellipse::intersect(), Geom::xAx::set(), Geom::xAx::set(), Geom::detail::bezier_clipping::signed_distance(), and TEST().
Get the coefficients of the line equation by reference.
Definition at line 105 of file line.cpp.
References _final, _initial, c, Geom::cross(), Geom::Point::cw(), vector(), Geom::X, and Geom::Y.
|
inline |
Create a derivative of the line.
The new line will always be degenerate. Its origin will be equal to this line's vector.
Definition at line 305 of file line.h.
References result, and vector().
Referenced by wrap_line().
|
inline |
|
inline |
Definition at line 228 of file line.h.
References _final.
Referenced by Geom::bezier_line_intersections(), Geom::Circle::intersect(), Geom::Circle::intersects(), Inkscape::UI::Widget::line_angle(), and Inkscape::LivePathEffect::LPESlice::splititem().
Create a line normal to a vector at a specified distance from origin.
Definition at line 105 of file line.h.
References c, Geom::rot90(), and start.
Create a line from origin and unit vector.
Note that each line direction has two possible unit vectors.
o | Point through which the line will pass |
v | Unit vector of the line's direction |
Definition at line 114 of file line.h.
Referenced by Inkscape::CanvasItemGridXY::_render(), Inkscape::CanvasItemGuideLine::_render(), Inkscape::CanvasItemGuideLine::closest_distance_to(), Geom::decompose_degenerate(), Geom::PlanarGraph< EdgeLabel >::deviatesLeft(), Geom::RatQuad::fromPointsTangents(), Inkscape::Extension::Internal::PdfBuilder::Document::get_radial_pattern(), and Geom::xAx::toCurve().
|
inline |
Definition at line 225 of file line.h.
References _initial.
Referenced by Geom::bezier_line_intersections(), distance(), Geom::Circle::intersect(), intersect(), Geom::Circle::intersects(), is_straight_curve(), Inkscape::UI::Widget::line_angle(), Inkscape::signed_distance(), and Inkscape::LivePathEffect::LPESlice::splititem().
std::vector< ShapeIntersection > Geom::Line::intersect | ( | Line const & | other | ) | const |
Definition at line 253 of file line.cpp.
References Geom::cross(), initialPoint(), result, and vector().
Referenced by Geom::Ellipse::intersect(), intersect(), intersect(), and TEST().
std::vector< ShapeIntersection > Geom::Line::intersect | ( | LineSegment const & | ls | ) | const |
Definition at line 277 of file line.cpp.
References Geom::filter_line_segment_intersections(), intersect(), and result.
std::vector< ShapeIntersection > Geom::Line::intersect | ( | Ray const & | r | ) | const |
Definition at line 269 of file line.cpp.
References Geom::filter_ray_intersections(), intersect(), and result.
|
inline |
Check if the line has more than one point.
A degenerate line can be created if the line is created from a line equation that has no solutions.
Definition at line 190 of file line.h.
References _final, and _initial.
Referenced by distance(), Geom::Ellipse::intersect(), timeAtProjection(), and wrap_line().
|
inline |
|
inline |
Find a point on the line closest to the query point.
This is an alias for timeAtProjection().
Definition at line 252 of file line.h.
References timeAtProjection().
Referenced by distance(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::doBeforeEffect(), Inkscape::UI::Handle::dragged(), Inkscape::LivePathEffect::LPELattice2::horizontal(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::horizontal(), operator==(), Geom::projection(), Geom::projection(), Inkscape::UI::Widget::ColorWheelHSLuv::updateGeometry(), Inkscape::LivePathEffect::LPELattice2::vertical(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::vertical(), and wrap_line().
|
inline |
Get a unit vector normal to the line.
If Y grows upwards, then this is the left normal. If Y grows downwards, then this is the right normal.
Definition at line 320 of file line.h.
References Geom::Point::normalized(), Geom::rot90(), and vector().
Referenced by normalAndDist(), and wrap_line().
|
inline |
Definition at line 325 of file line.h.
References _initial, Geom::dot(), and normal().
Referenced by Geom::xAx::fromLine(), and wrap_line().
|
inline |
Reparametrize the line so that it has unit speed.
Note that the direction of the line may also change.
Definition at line 204 of file line.h.
References _final, and _initial.
Referenced by Geom::detail::bezier_clipping::clip< intersection_point_tag >().
|
inline |
|
inline |
|
inline |
Definition at line 382 of file line.h.
References _final, _initial, distance(), nearestTime(), and pointAt().
|
inline |
Get the line's origin point.
Definition at line 128 of file line.h.
References _initial.
Referenced by are_same(), avoid_item_poly(), Geom::intersection(), Geom::detail::intersection_impl(), Geom::detail::intersection_impl(), and Geom::xAx::roots().
Definition at line 231 of file line.h.
References _final, _initial, and Geom::lerp().
Referenced by Inkscape::CanvasItemGuideLine::_render(), Geom::xAx::arc_bound(), Geom::CLIPPER_CLASS::are_paired(), box3d_half_line_crosses_joining_line(), clip(), Geom::CLIPPER_CLASS::clip(), Inkscape::LineSnapper::constrainedSnap(), curvature(), Geom::decompose_degenerate(), distance(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::doBeforeEffect(), Inkscape::UI::Handle::dragged(), Geom::CLIPPER_CLASS::find_inner_point(), Geom::CLIPPER_CLASS::find_inner_point_by_bisector_line(), Geom::RatQuad::fromPointsTangents(), Inkscape::GridSnapper::getSnapLinesAxonom(), Inkscape::LivePathEffect::LPELattice2::horizontal(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::horizontal(), Inkscape::intersect_line_rectangle(), Geom::make_angle_bisector_line(), operator==(), portion(), Geom::projection(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::projectPoint(), ray(), segment(), Geom::xAx::set(), TEST(), Geom::xAx::toCurve(), Inkscape::UI::Widget::ColorWheelHSLuv::updateGeometry(), Inkscape::LivePathEffect::LPELattice2::vertical(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::vertical(), and wrap_line().
Create a ray starting at the specified time value.
The created ray will go in the direction of the line's vector (in the direction of increasing time values).
t | Time value where the ray should start |
Definition at line 295 of file line.h.
References pointAt(), result, Geom::Ray::setOrigin(), and vector().
Referenced by sp_gradient_reset_to_userspace(), and Inkscape::LivePathEffect::LPESlice::splititem().
|
inline |
|
inline |
|
inline |
Find intersection with an axis-aligned line.
v | Coordinate of the axis-aligned line |
d | Which axis the coordinate is on. X means a vertical line, Y means a horizontal line. |
Definition at line 131 of file line.cpp.
Referenced by wrap_line().
Compute a rotation affine which transforms the line to one of the axes.
d | Which line should be the axis |
Definition at line 362 of file line.h.
References Geom::other_dimension(), and rotationToZero().
Compute an affine which transforms all points on the line to zero X or Y coordinate.
This operation is useful in reducing intersection problems to root-finding problems. There are many affines which do this transformation. This function returns one that preserves angles, areas and distances - a rotation combined with a translation, and additionally moves the initial point of the line to (0,0). This way it works without problems even for lines perpendicular to the target, though may in some cases have lower precision than e.g. a shear transform.
d | Which coordinate of points on the line should be zero after the transformation |
Definition at line 350 of file line.h.
References _initial, vector(), Geom::X, and Geom::Y.
Referenced by Geom::bezier_line_intersections(), rotationToAxis(), and TEST().
|
inline |
Create a segment of this line.
f | Time value for the initial point of the segment |
t | Time value for the final point of the segment |
Definition at line 283 of file line.h.
References pointAt().
Referenced by Inkscape::SnappedCurve::intersect(), Geom::projection(), and Geom::rect_line_intersect().
|
inline |
Set the angle the line makes with the X axis.
Origin remains unchanged.
Definition at line 160 of file line.h.
References _final, _initial, angle(), distance(), Geom::sincos(), Geom::X, and Geom::Y.
void Geom::Line::setCoefficients | ( | double | a, |
double | b, | ||
double | c | ||
) |
Set the coefficients of the line equation.
Set the line by solving the line equation.
The line equation is: \(ax + by = c\). Points that satisfy the equation are on the line.
A line is a set of points that satisfies the line equation \(Ax + By + C = 0\). This function changes the line so that its points satisfy the line equation with the given coefficients.
Definition at line 62 of file line.cpp.
References _final, _initial, c, offset, Geom::X, and Geom::Y.
Referenced by Geom::xAx::arc_bound(), Geom::xAx::decompose(), Line(), and wrap_line().
|
inline |
Set the point at zero time.
The orientation remains unchanged, modulo numeric errors during addition.
Definition at line 147 of file line.h.
References _final, and _initial.
Referenced by avoid_item_poly().
Set a line based on two points it should pass through.
Definition at line 168 of file line.h.
References _final, and _initial.
Referenced by avoid_item_poly(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::doBeforeEffect(), Geom::CLIPPER_CLASS::find_inner_point(), Inkscape::LivePathEffect::LPEPerspectiveEnvelope::projectPoint(), and wrap_line().
|
inline |
Set the speed of the line.
Origin remains unchanged.
Definition at line 154 of file line.h.
References _final, and _initial.
Referenced by avoid_item_poly().
Get a time value corresponding to a point.
p | Point on the line. If the point is not on the line, the returned value will be meaningless. |
Definition at line 223 of file line.cpp.
References _initial, vector(), Geom::X, and Geom::Y.
Referenced by Geom::Ellipse::intersect(), Geom::Circle::intersect(), and Geom::xAx::set().
Get a time value corresponding to a projection of a point on the line.
p | Arbitrary point. |
p
. Definition at line 244 of file line.h.
References _initial, Geom::dot(), isDegenerate(), and vector().
Referenced by nearestTime(), and Geom::xAx::set().
Create a line transformed by an affine transformation.
Definition at line 312 of file line.h.
References _final, and _initial.
Referenced by Inkscape::SnappedCurve::intersect(), and wrap_line().
Create a transformation that maps one line to another.
This will return a transformation \(A\) such that \(L_1(t) \cdot A = L_2(t)\), where \(L_1\) is this line and \(L_2\) is the line passed as the parameter. The returned transformation will preserve angles.
Definition at line 244 of file line.cpp.
References _initial, Geom::angle_between(), Geom::Point::length(), Geom::length(), result, and vector().
Definition at line 235 of file line.h.
References _final, _initial, and Geom::lerp().
Referenced by wrap_line().
|
inline |
Get the line's raw direction vector.
The length of the retrieved vector is equal to the length of a segment parametrized by a time interval of length 1.
Definition at line 132 of file line.h.
References _final, and _initial.
Referenced by Inkscape::CanvasItemGridXY::_render(), Geom::angle_between(), are_orthogonal(), Geom::are_parallel(), clip(), coefficients(), derivative(), Inkscape::LivePathEffect::LPEMirrorSymmetry::doAfterEffect(), Inkscape::LivePathEffect::LPEMirrorSymmetry::doEffect_path(), Geom::Ellipse::intersect(), Geom::Circle::intersect(), intersect(), Geom::intersection(), Geom::detail::intersection_impl(), Geom::detail::intersection_impl(), Geom::Circle::intersects(), Geom::make_angle_bisector_line(), Geom::make_orthogonal_line(), normal(), ray(), root(), rotationToZero(), TEST(), timeAt(), timeAtProjection(), and transformTo().
|
inline |
Get the line's normalized direction vector.
The retrieved vector is normalized to unit length.
Definition at line 135 of file line.h.
References _final, _initial, and Geom::Point::normalized().
Referenced by avoid_item_poly(), Inkscape::LineSnapper::constrainedSnap(), reflection(), Geom::xAx::roots(), Inkscape::signed_distance(), and TEST().
Test whether two lines are perpendicular.
Definition at line 447 of file line.h.
References Geom::are_near(), Geom::dot(), and vector().
Test whether two lines are approximately the same.
This tests for being parallel and the origin of one line being close to the other, so it tests whether the images of the lines are similar, not whether the same time values correspond to similar points. For example a line from (1,1) to (2,2) and a line from (-1,-1) to (0,0) will be the same, because their images match, even though there is no time value for which the lines give similar points.
Definition at line 439 of file line.h.
References Geom::are_near(), Geom::are_parallel(), and origin().
Compute distance from point to line.
Definition at line 409 of file line.h.
References initialPoint(), isDegenerate(), nearestTime(), and pointAt().
Referenced by operator==(), and setAngle().
|
private |
Definition at line 56 of file line.h.
Referenced by angle(), coefficients(), finalPoint(), isDegenerate(), isHorizontal(), isVertical(), Line(), normalize(), normalized(), operator*=(), operator==(), pointAt(), reverse(), reversed(), setAngle(), setCoefficients(), setOrigin(), setPoints(), setVector(), transformed(), valueAt(), vector(), and versor().
|
private |
Definition at line 55 of file line.h.
Referenced by angle(), clip(), coefficients(), initialPoint(), isDegenerate(), isHorizontal(), isVertical(), Line(), normalAndDist(), normalize(), normalized(), operator*=(), operator==(), origin(), pointAt(), reflection(), reverse(), reversed(), root(), rotationToZero(), setAngle(), setCoefficients(), setOrigin(), setPoints(), setVector(), timeAt(), timeAtProjection(), transformed(), transformTo(), valueAt(), vector(), and versor().