Inkscape
Vector Graphics Editor
Geom::Point Class Reference

Two-dimensional point that doubles as a vector. More...

#include <point.h>

Inheritance diagram for Geom::Point:
Inkscape::LivePathEffect::PointParam InputPoint

Classes

struct  LexGreater
 
struct  LexGreater< X >
 
struct  LexGreater< Y >
 
struct  LexGreaterRt
 
struct  LexLess
 Lexicographical ordering functor. More...
 
struct  LexLess< X >
 
struct  LexLess< Y >
 
struct  LexLessRt
 Lexicographical ordering functor with runtime dimension. More...
 

Public Types

using D1Value = Coord
 
using D1Reference = Coord &
 
using D1ConstReference = Coord const &
 

Public Member Functions

Access the coordinates of a point
Coord operator[] (unsigned i) const
 
Coordoperator[] (unsigned i)
 
constexpr Coord operator[] (Dim2 d) const noexcept
 
constexpr Coordoperator[] (Dim2 d) noexcept
 
constexpr Coord x () const noexcept
 
constexpr Coordx () noexcept
 
constexpr Coord y () const noexcept
 
constexpr Coordy () noexcept
 
template<size_t I>
constexpr Coord get () const
 
template<size_t I>
constexpr Coordget ()
 
Vector operations
Coord length () const
 Compute the distance from origin. More...
 
constexpr Coord lengthSq () const
 
void normalize ()
 Normalize the vector representing the point. More...
 
Point normalized () const
 
constexpr Point ccw () const
 Return a point like this point but rotated -90 degrees. More...
 
constexpr Point cw () const
 Return a point like this point but rotated +90 degrees. More...
 
Vector-like arithmetic operations
constexpr Point operator- () const
 
constexpr Pointoperator+= (Point const &o)
 
constexpr Pointoperator-= (Point const &o)
 
constexpr Pointoperator*= (Coord s)
 
constexpr Pointoperator*= (Point const &o)
 
constexpr Pointoperator*= (IntPoint const &o)
 
constexpr Pointoperator/= (Coord s)
 
constexpr Pointoperator/= (Point const &o)
 
constexpr Pointoperator/= (IntPoint const &o)
 
Affine transformations
Pointoperator*= (Affine const &m)
 Transform the point by the specified matrix. More...
 
Pointoperator*= (Translate const &t)
 
Pointoperator*= (Scale const &s)
 
Pointoperator*= (Rotate const &r)
 
Pointoperator*= (HShear const &s)
 
Pointoperator*= (VShear const &s)
 
Pointoperator*= (Zoom const &z)
 
Conversion to integer points
IntPoint round () const
 Round to nearest integer coordinates. More...
 
IntPoint floor () const
 Round coordinates downwards. More...
 
IntPoint ceil () const
 Round coordinates upwards. More...
 
Various utilities
bool isFinite () const
 Check whether both coordinates are finite. More...
 
constexpr bool isZero () const
 Check whether both coordinates are zero. More...
 
bool isNormalized (Coord eps=EPSILON) const
 Check whether the length of the vector is close to 1. More...
 
constexpr bool operator== (Point const &p) const
 Equality operator. More...
 
constexpr bool operator< (Point const &p) const
 Lexicographical ordering for points. More...
 

Private Attributes

Coord _pt [2] = { 0, 0 }
 

Related Functions

(Note that these are not member functions.)

std::ostream & operator<< (std::ostream &out, Point const &p)
 Output operator for points. More...
 
Coord L2 (Point const &p)
 Compute the second (Euclidean) norm of p. More...
 
constexpr Coord L2sq (Point const &p)
 Compute the square of the Euclidean norm of p. More...
 
constexpr Point rot90 (Point const &p)
 Returns p * Geom::rotate_degrees(90), but more efficient. More...
 
Point lerp (Coord t, Point const &a, Point const &b)
 Linear interpolation between two points. More...
 
Point middle_point (Point const &p1, Point const &p2)
 Return a point halfway between the specified ones. More...
 
constexpr Coord dot (Point const &a, Point const &b)
 Compute the dot product of a and b. More...
 
constexpr Coord cross (Point const &a, Point const &b)
 Compute the 2D cross product. More...
 
Coord distance (Point const &a, Point const &b)
 Compute the (Euclidean) distance between points. More...
 
Coord distanceSq (Point const &a, Point const &b)
 Compute the square of the distance between points. More...
 
bool are_near (Point const &a, Point const &b, double eps=EPSILON)
 Test whether two points are no further apart than some threshold. More...
 
bool are_collinear (Point const &p1, Point const &p2, Point const &p3, double eps=EPSILON)
 Test whether three points lie approximately on the same line. More...
 
Coord L1 (Point const &p)
 Compute the first norm (Manhattan distance) of p. More...
 
Coord LInfty (Point const &p)
 Compute the infinity norm (maximum norm) of p. More...
 
bool is_zero (Point const &p)
 True if the point has both coordinates zero. More...
 
bool is_unit_vector (Point const &p, Coord eps)
 True if the point has a length near 1. More...
 
Coord atan2 (Point const &p)
 Return the angle between the point and the +X axis. More...
 
Coord angle_between (Point const &a, Point const &b)
 Compute the angle between a and b relative to the origin. More...
 
Point unit_vector (Point const &a)
 Create a normalized version of a point. More...
 
Point abs (Point const &b)
 Return the "absolute value" of the point's vector. More...
 
Point constrain_angle (Point const &A, Point const &B, unsigned int n, Point const &dir)
 Snap the angle B - A - dir to multiples of \(2\pi/n\). More...
 

Create points

constexpr Point ()=default
 Construct a point at the origin. More...
 
constexpr Point (Coord x, Coord y)
 Construct a point from its coordinates. More...
 
constexpr Point (IntPoint const &p)
 Construct from integer point. More...
 
static Point polar (Coord angle, Coord radius)
 Construct a point from its polar coordinates. More...
 
static Point polar (Coord angle)
 Construct an unit vector from its angle. More...
 

Detailed Description

Two-dimensional point that doubles as a vector.

Points in 2Geom are represented in Cartesian coordinates, e.g. as a pair of numbers that store the X and Y coordinates. Each point is also a vector in \(\mathbb{R}^2\) from the origin (point at 0,0) to the stored coordinates, and has methods implementing several vector operations (like length()).

Operator note

Most operators are provided by Boost operator helpers, so they are not visible in this class. If p, q, r denote points, s a floating-point scalar, and m a transformation matrix, then the following operations are available:

p += q; p -= q; r = p + q; r = p - q;
p *= s; p /= s; q = p * s; q = s * p; q = p / s;
p *= m; q = p * m; q = m * p;
static const Triplet m[3]
Definition: hsluv.cpp:44

It is possible to left-multiply a point by a matrix, even though mathematically speaking this is undefined. The result is a point identical to that obtained by right-multiplying.

Definition at line 52 of file point.h.

Member Typedef Documentation

◆ D1ConstReference

using Geom::Point::D1ConstReference = Coord const &

Definition at line 71 of file point.h.

◆ D1Reference

using Geom::Point::D1Reference = Coord &

Definition at line 70 of file point.h.

◆ D1Value

using Geom::Point::D1Value = Coord

Definition at line 69 of file point.h.

Constructor & Destructor Documentation

◆ Point() [1/3]

constexpr Geom::Point::Point ( )
constexprdefault

Construct a point at the origin.

Referenced by ccw(), cw(), operator-(), and rot90().

◆ Point() [2/3]

constexpr Geom::Point::Point ( Coord  x,
Coord  y 
)
inlineconstexpr

Construct a point from its coordinates.

Definition at line 78 of file point.h.

◆ Point() [3/3]

constexpr Geom::Point::Point ( IntPoint const &  p)
inlineconstexpr

Construct from integer point.

Definition at line 82 of file point.h.

Member Function Documentation

◆ ccw()

constexpr Point Geom::Point::ccw ( ) const
inlineconstexpr

Return a point like this point but rotated -90 degrees.

If the y axis grows downwards and the x axis grows to the right, then this is 90 degrees counter-clockwise.

Definition at line 130 of file point.h.

References _pt, Point(), Geom::X, and Geom::Y.

Referenced by Inkscape::UI::Tools::PenTool::_setToNearestHorizVert(), ArcAnglesAndCenter(), avoid_item_poly(), Inkscape::LivePathEffect::LPEParallel::doOnApply(), SweepTree::Find(), Box3D::Line::Line(), Inkscape::UI::Tools::PenTool::nextParaxialDirection(), Path::Outline(), rot90_rel(), Box3D::Line::set_direction(), and wrap_point().

◆ ceil()

IntPoint Geom::Point::ceil ( ) const
inline

Round coordinates upwards.

Definition at line 210 of file point.h.

References _pt, ceil(), Geom::X, and Geom::Y.

Referenced by ceil(), and Geom::TEST().

◆ cw()

◆ floor()

IntPoint Geom::Point::floor ( ) const
inline

◆ get() [1/2]

template<size_t I>
constexpr Coord & Geom::Point::get ( )
inlineconstexpr

Definition at line 111 of file point.h.

References _pt, and Geom::SL::I.

◆ get() [2/2]

template<size_t I>
constexpr Coord Geom::Point::get ( ) const
inlineconstexpr

◆ isFinite()

◆ isNormalized()

bool Geom::Point::isNormalized ( Coord  eps = EPSILON) const
inline

Check whether the length of the vector is close to 1.

Definition at line 231 of file point.h.

References are_near(), and length().

◆ isZero()

constexpr bool Geom::Point::isZero ( ) const
inlineconstexpr

Check whether both coordinates are zero.

Definition at line 227 of file point.h.

References _pt, Geom::X, and Geom::Y.

Referenced by Geom::PlanarGraph< EdgeLabel >::_getAzimuth(), Inkscape::LivePathEffect::endpoints2angles(), and Geom::BezierCurveN< degree >::intersect().

◆ length()

Coord Geom::Point::length ( ) const
inline

Compute the distance from origin.

Returns
Length of the vector from origin to this point

Definition at line 118 of file point.h.

References _pt, Geom::X, and Geom::Y.

Referenced by Inkscape::UI::Widget::OKWheel::_discColor(), Inkscape::UI::Widget::OKWheel::_onClick(), Inkscape::CanvasItemGridXY::_render(), Inkscape::UI::Widget::OKWheel::_setColor(), Inkscape::UI::Node::_updateAutoHandles(), Inkscape::UI::Widget::apply_profile(), are_near(), Geom::are_near_rel(), Inkscape::UI::Tools::CalligraphicTool::brush(), Inkscape::UI::Widget::cap_length(), SPMeshNodeArray::color_smooth(), Geom::Ellipse::contains(), Inkscape::DrawingRadialGradient::create_pattern(), Geom::cubics_with_prescribed_curvature(), Inkscape::LivePathEffect::LPEAttachPath::doEffect(), Inkscape::UI::Tools::ArcTool::drag(), Inkscape::LivePathEffect::LPEPts2Ellipse::genFitEllipse(), Inkscape::LivePathEffect::LPEPts2Ellipse::genIsometricEllipse(), Inkscape::LivePathEffect::LPEPts2Ellipse::genSteinerEllipse(), Geom::BezierCurveN< degree >::intersect(), Geom::Circle::intersect(), Geom::Circle::intersects(), isNormalized(), HatchKnotHolderEntityScale::knot_set(), L2(), Inkscape::UI::Handle::length(), Geom::linear_intersect(), Geom::ConvexHull::minAreaRotation(), Inkscape::UI::Widget::Canvas::on_motion(), Inkscape::UI::PathManipulator::scaleHandle(), Inkscape::UI::Node::setType(), Inkscape::UI::Widget::RegisteredVector::setValue(), TEST(), Geom::Line::transformTo(), Inkscape::UI::Widget::PatternEditor::update_widgets_from_pattern(), and wrap_point().

◆ lengthSq()

constexpr Coord Geom::Point::lengthSq ( ) const
inlineconstexpr

Definition at line 119 of file point.h.

References _pt, Geom::X, and Geom::Y.

Referenced by L2sq().

◆ normalize()

void Geom::Point::normalize ( )

Normalize the vector representing the point.

After this method returns, the length of the vector will be 1 (unless both coordinates are zero - the zero point will be returned then). The function tries to handle infinite coordinates gracefully. If any of the coordinates are NaN, the function will do nothing.

Postcondition
\(-\epsilon < \left|this\right| - 1 < \epsilon\)
See also
unit_vector(Geom::Point const &)

Definition at line 96 of file point.cpp.

References _pt, len, and Geom::sqrt().

Referenced by box3d_XY_axes_are_swapped(), cubic_length_subdividing(), Geom::darray_center_tangent(), Geom::BezierFitter::darray_center_tangent(), Inkscape::Text::Layout::fitToPathAlign(), SPSpiral::getTangent(), normalized(), SPGuide::set(), Geom::Ray::setPoints(), Geom::TEST(), unit_vector(), Geom::Ellipse::unitTangentAt(), and wrap_point().

◆ normalized()

Point Geom::Point::normalized ( ) const
inline

◆ operator*=() [1/10]

Point & Geom::Point::operator*= ( Affine const &  m)

Transform the point by the specified matrix.

Definition at line 229 of file point.cpp.

References _pt, Hsluv::m, Geom::X, x(), Geom::Y, and y().

◆ operator*=() [2/10]

constexpr Point & Geom::Point::operator*= ( Coord  s)
inlineconstexpr

Definition at line 157 of file point.h.

References _pt.

◆ operator*=() [3/10]

Point & Geom::Point::operator*= ( HShear const &  s)

Definition at line 74 of file transforms.cpp.

References _pt, Geom::ShearBase< S >::f, and Geom::X.

◆ operator*=() [4/10]

constexpr Point & Geom::Point::operator*= ( IntPoint const &  o)
inlineconstexpr

Definition at line 166 of file point.h.

References _pt, Geom::X, Geom::IntPoint::x(), Geom::Y, and Geom::IntPoint::y().

◆ operator*=() [5/10]

constexpr Point & Geom::Point::operator*= ( Point const &  o)
inlineconstexpr

Definition at line 161 of file point.h.

References _pt, Geom::X, and Geom::Y.

◆ operator*=() [6/10]

Point & Geom::Point::operator*= ( Rotate const &  r)

Definition at line 67 of file transforms.cpp.

References _pt, Geom::Rotate::vec, Geom::X, x(), Geom::Y, and y().

◆ operator*=() [7/10]

Point & Geom::Point::operator*= ( Scale const &  s)

Definition at line 61 of file transforms.cpp.

References _pt, Geom::Scale::vec, Geom::X, and Geom::Y.

◆ operator*=() [8/10]

Point & Geom::Point::operator*= ( Translate const &  t)

Definition at line 55 of file transforms.cpp.

References _pt, Geom::Translate::vec, Geom::X, and Geom::Y.

◆ operator*=() [9/10]

Point & Geom::Point::operator*= ( VShear const &  s)

Definition at line 79 of file transforms.cpp.

References _pt, Geom::SL::v, and Geom::Y.

◆ operator*=() [10/10]

Point & Geom::Point::operator*= ( Zoom const &  z)

Definition at line 84 of file transforms.cpp.

References _pt, Geom::Zoom::_scale, Geom::Zoom::_trans, Geom::X, and Geom::Y.

◆ operator+=()

constexpr Point & Geom::Point::operator+= ( Point const &  o)
inlineconstexpr

Definition at line 147 of file point.h.

References _pt, Geom::X, and Geom::Y.

◆ operator-()

constexpr Point Geom::Point::operator- ( ) const
inlineconstexpr

Definition at line 144 of file point.h.

References _pt, Point(), Geom::X, and Geom::Y.

◆ operator-=()

constexpr Point & Geom::Point::operator-= ( Point const &  o)
inlineconstexpr

Definition at line 152 of file point.h.

References _pt, Geom::X, and Geom::Y.

◆ operator/=() [1/3]

constexpr Point & Geom::Point::operator/= ( Coord  s)
inlineconstexpr

Definition at line 171 of file point.h.

References _pt.

◆ operator/=() [2/3]

constexpr Point & Geom::Point::operator/= ( IntPoint const &  o)
inlineconstexpr

Definition at line 180 of file point.h.

References _pt, Geom::X, Geom::IntPoint::x(), Geom::Y, and Geom::IntPoint::y().

◆ operator/=() [3/3]

constexpr Point & Geom::Point::operator/= ( Point const &  o)
inlineconstexpr

Definition at line 175 of file point.h.

References _pt, Geom::X, and Geom::Y.

◆ operator<()

constexpr bool Geom::Point::operator< ( Point const &  p) const
inlineconstexpr

Lexicographical ordering for points.

Y coordinate is regarded as more significant. When sorting according to this ordering, the points will be sorted according to the Y coordinate, and within points with the same Y coordinate according to the X coordinate.

Definition at line 244 of file point.h.

References _pt, Geom::X, and Geom::Y.

◆ operator==()

constexpr bool Geom::Point::operator== ( Point const &  p) const
inlineconstexpr

Equality operator.

This tests for exact identity (as opposed to are_near()). Note that due to numerical errors, this test might return false even if the points should be identical.

Definition at line 237 of file point.h.

References _pt, Geom::X, and Geom::Y.

◆ operator[]() [1/4]

constexpr Coord Geom::Point::operator[] ( Dim2  d) const
inlineconstexprnoexcept

Definition at line 101 of file point.h.

References _pt.

◆ operator[]() [2/4]

constexpr Coord & Geom::Point::operator[] ( Dim2  d)
inlineconstexprnoexcept

Definition at line 102 of file point.h.

References _pt.

◆ operator[]() [3/4]

Coord & Geom::Point::operator[] ( unsigned  i)
inline

Definition at line 100 of file point.h.

References _pt.

◆ operator[]() [4/4]

Coord Geom::Point::operator[] ( unsigned  i) const
inline

Definition at line 99 of file point.h.

References _pt.

◆ polar() [1/2]

Point Geom::Point::polar ( Coord  angle)
static

Construct an unit vector from its angle.

The angle is specified in radians, in the mathematical convention (increasing counter-clockwise from +X).

Definition at line 69 of file point.cpp.

References Geom::detail::bezier_clipping::angle(), are_near(), Geom::Angle::radians0(), Geom::sincos(), Geom::X, and Geom::Y.

◆ polar() [2/2]

static Point Geom::Point::polar ( Coord  angle,
Coord  radius 
)
inlinestatic

Construct a point from its polar coordinates.

The angle is specified in radians, in the mathematical convention (increasing counter-clockwise from +X).

Definition at line 88 of file point.h.

References Geom::detail::bezier_clipping::angle(), and polar().

Referenced by Inkscape::UI::Widget::CanvasGrid::_createGuideItem(), Inkscape::UI::Dialog::GuidelinePropertiesDialog::_onOKimpl(), Inkscape::LivePathEffect::LPERoughen::addNodesAndJitter(), Inkscape::LivePathEffect::LPEMeasureSegments::createLine(), Inkscape::LivePathEffect::LPEMeasureSegments::doBeforeEffect(), Inkscape::LivePathEffect::LPETransform2Pts::doBeforeEffect(), Inkscape::LivePathEffect::LPERoughen::doEffect(), Inkscape::LivePathEffect::LPEFilletChamfer::doEffect_path(), Inkscape::LivePathEffect::LPEMirrorSymmetry::doEffect_path(), Inkscape::LivePathEffect::LPETransform2Pts::doEffect_pwd2(), Inkscape::LivePathEffect::LPEShowHandles::drawHandleLine(), Inkscape::LivePathEffect::LPESimplify::drawHandleLine(), Inkscape::LivePathEffect::LPESimplify::generateHelperPathAndSmooth(), SPGenericEllipse::getPointAtAngle(), Inkscape::LivePathEffect::LPERoughen::jitter(), Inkscape::UI::Widget::RegisteredVector::on_value_changed(), Geom::Ellipse::operator*=(), Geom::Circle::pointAt(), Geom::Ellipse::pointAt(), polar(), Inkscape::LivePathEffect::LPERoughen::randomize(), SPGenericEllipse::set_shape(), Inkscape::UI::Tools::MeasureTool::setLabelText(), sp_dt_guide_event(), Inkscape::LivePathEffect::LPESlice::splititem(), Inkscape::UI::Tools::MeasureTool::toMarkDimension(), and Geom::Ellipse::unitTangentAt().

◆ round()

IntPoint Geom::Point::round ( ) const
inline

Round to nearest integer coordinates.

Definition at line 202 of file point.h.

References _pt, round(), Geom::X, and Geom::Y.

Referenced by Inkscape::DrawingSurface::pixelArea(), Inkscape::DrawingCache::prepare(), round(), Inkscape::UI::Widget::Canvas::set_pos(), Geom::TEST(), and wrap_point().

◆ x() [1/2]

constexpr Coord Geom::Point::x ( ) const
inlineconstexprnoexcept

Definition at line 104 of file point.h.

References _pt, and Geom::X.

Referenced by Inkscape::UI::Widget::CanvasGrid::_createGuideItem(), SPHatchPath::_readHatchPathVector(), Inkscape::CanvasItemGridTiles::_render(), Inkscape::CanvasItemGuideLine::_render(), Inkscape::CanvasItemQuad::_render(), Inkscape::UI::Dialog::PowerstrokePropertiesDialog::_setKnotPoint(), Inkscape::UI::Dialog::KnotPropertiesDialog::_setKnotPoint(), Inkscape::UI::Tools::TextTool::_setupText(), Inkscape::AlignmentSnapper::_snapBBoxPoints(), Inkscape::DistributionSnapper::_snapEquidistantPoints(), Inkscape::CanvasItemGridTiles::_update(), Inkscape::CanvasItemText::_update(), absolute(), Inkscape::UI::Dialog::add_shadow(), Inkscape::UI::Dialog::PolarArrangeTab::arrange(), bezier_fit(), Inkscape::UI::Widget::Canvas::canvas_point_in_outline_zone(), Inkscape::DrawingMeshGradient::create_pattern(), Inkscape::DrawingRadialGradient::create_pattern(), Inkscape::ObjectSet::createBitmapCopy(), Inkscape::DrawingSurface::createRawContext(), SPGuide::createSPGuide(), Inkscape::LivePathEffect::LPEAttachPath::doEffect(), OutputFile::draw_curved_edges(), Inkscape::LivePathEffect::LPEEmbroderyStitchOrdering::OrderingPoint::Dump(), Inkscape::LivePathEffect::LPEEmbroderyStitchOrdering::OrderingGroupPoint::FindNearestUnused(), getClosestSP(), Geom::Circle::intersect(), HatchKnotHolderEntityScale::knot_set(), FilterKnotHolderEntity::knot_set(), Inkscape::UI::Dialog::SingleExport::loadExportHints(), Inkscape::Display::SnapIndicator::make_alignment_indicator(), Avoid::Router::markPolylineConnectorsNeedingReroutingForDeletedObstacle(), max(), min(), SPGuide::moveto(), Inkscape::Extension::Internal::Emf::myEnhMetaFileProc(), Inkscape::Extension::Internal::Wmf::myMetaFileProc(), operator*=(), operator/(), proj(), Inkscape::Filters::FilterDiffuseLighting::render_cairo(), Inkscape::UI::Dialog::render_icon(), SPObject::setExportDpi(), Inkscape::Text::Layout::show(), Inkscape::UI::Tools::ObjectPickerTool::show_text(), Inkscape::UI::Tools::sort_fill_queue_horizontal(), sp_namedview_document_from_window(), Inkscape::LivePathEffect::sp_pathvector_boolop_slice_intersect(), and Inkscape::Extension::Internal::OdfOutput::writeTree().

◆ x() [2/2]

constexpr Coord & Geom::Point::x ( )
inlineconstexprnoexcept

Definition at line 105 of file point.h.

References _pt, and Geom::X.

◆ y() [1/2]

constexpr Coord Geom::Point::y ( ) const
inlineconstexprnoexcept

Definition at line 106 of file point.h.

References _pt, and Geom::Y.

Referenced by SPHatch::_calculateStripExtents(), Inkscape::UI::Widget::CanvasGrid::_createGuideItem(), Inkscape::Extension::Internal::SvgBuilder::_flushText(), SPHatchPath::_readHatchPathVector(), Inkscape::CanvasItemGridTiles::_render(), Inkscape::CanvasItemGridAxonom::_render(), Inkscape::CanvasItemGuideLine::_render(), Inkscape::CanvasItemQuad::_render(), Inkscape::UI::Dialog::PowerstrokePropertiesDialog::_setKnotPoint(), Inkscape::UI::Dialog::KnotPropertiesDialog::_setKnotPoint(), Inkscape::UI::Tools::TextTool::_setupText(), Inkscape::AlignmentSnapper::_snapBBoxPoints(), Inkscape::DistributionSnapper::_snapEquidistantPoints(), Inkscape::CanvasItemGridTiles::_update(), Inkscape::CanvasItemGridAxonom::_update(), Inkscape::CanvasItemText::_update(), absolute(), Inkscape::UI::Dialog::add_shadow(), Inkscape::UI::Dialog::PolarArrangeTab::arrange(), bezier_fit(), Geom::ConvexHull::bottomPoint(), Inkscape::UI::Widget::Canvas::canvas_point_in_outline_zone(), Inkscape::DrawingMeshGradient::create_pattern(), Inkscape::DrawingRadialGradient::create_pattern(), Inkscape::DrawingSurface::createRawContext(), SPGuide::createSPGuide(), Inkscape::LivePathEffect::LPEAttachPath::doEffect(), Inkscape::LivePathEffect::LPEEmbroderyStitchOrdering::OrderingPoint::Dump(), Inkscape::LivePathEffect::LPEEmbroderyStitchOrdering::OrderingGroupPoint::FindNearestUnused(), getClosestSP(), Geom::Circle::intersect(), HatchKnotHolderEntityScale::knot_set(), FilterKnotHolderEntity::knot_set(), Inkscape::Display::SnapIndicator::make_alignment_indicator(), Avoid::Router::markPolylineConnectorsNeedingReroutingForDeletedObstacle(), max(), min(), SPGuide::moveto(), Inkscape::Extension::Internal::Emf::myEnhMetaFileProc(), Inkscape::Extension::Internal::Wmf::myMetaFileProc(), operator*=(), operator/(), proj(), Inkscape::Filters::FilterDiffuseLighting::render_cairo(), Inkscape::UI::Dialog::render_icon(), Inkscape::UI::Tools::TextTool::root_handler(), SPDesktop::set_display_width(), SPObject::setExportDpi(), Inkscape::UI::Tools::ObjectPickerTool::show_text(), Inkscape::UI::Tools::sort_fill_queue_vertical(), sp_namedview_document_from_window(), Geom::ConvexHull::topPoint(), Inkscape::Text::Layout::transform(), and Inkscape::Extension::Internal::OdfOutput::writeTree().

◆ y() [2/2]

constexpr Coord & Geom::Point::y ( )
inlineconstexprnoexcept

Definition at line 107 of file point.h.

References _pt, and Geom::Y.

Friends And Related Function Documentation

◆ abs()

Point abs ( Point const &  b)
related

Return the "absolute value" of the point's vector.

This is defined in terms of the default lexicographical ordering. If the point is "larger" that the origin (0, 0), its negation is returned. You can check whether the points' vectors have the same direction (e.g. lie on the same line passing through the origin) using

abs(a).normalize() == abs(b).normalize()
Point abs(Point const &b)
Return the "absolute value" of the point's vector.
Definition: point.cpp:215
void normalize()
Normalize the vector representing the point.
Definition: point.cpp:96

To check with some margin of error, use

bool are_near(Point const &a, Point const &b, double eps=EPSILON)
Test whether two points are no further apart than some threshold.
Definition: point.h:402

Although naively this should take the absolute value of each coordinate, such an operation is not very useful.

Definition at line 215 of file point.cpp.

References Geom::X, and Geom::Y.

Referenced by compare_double(), Inkscape::LivePathEffect::LPESketch::doEffect_pwd2(), draw_axis(), gr_knot_moved_handler(), image_crop(), lambertW(), smash_intersect(), and sp_te_adjust_tspan_letterspacing_screen().

◆ angle_between()

Coord angle_between ( Point const &  a,
Point const &  b 
)
related

Compute the angle between a and b relative to the origin.

The computation is done by projecting b onto the basis defined by a, rot90(a).

Returns
Angle in \((-\pi, \pi]\).

Definition at line 186 of file point.cpp.

References Geom::atan2(), Geom::cross(), and Geom::dot().

◆ are_collinear()

bool are_collinear ( Point const &  p1,
Point const &  p2,
Point const &  p3,
double  eps = EPSILON 
)
related

Test whether three points lie approximately on the same line.

Definition at line 415 of file point.h.

References are_near(), and cross().

◆ are_near()

bool are_near ( Point const &  a,
Point const &  b,
double  eps = EPSILON 
)
related

Test whether two points are no further apart than some threshold.

Definition at line 402 of file point.h.

References are_near(), and length().

Referenced by are_collinear(), are_near(), isNormalized(), and polar().

◆ atan2()

Coord atan2 ( Point const &  p)
related

Return the angle between the point and the +X axis.

Returns
Angle in \((-\pi, \pi]\).

Definition at line 178 of file point.cpp.

References Geom::atan2(), Geom::X, and Geom::Y.

Referenced by Geom::Piecewise< T >::atan2(), cartesian_to_polar(), draw_line_seg_with_arrow(), print_seg(), random_arc(), recursive_bezier4(), sp_te_adjust_rotation_screen(), and test_integ().

◆ constrain_angle()

Point constrain_angle ( Point const &  A,
Point const &  B,
unsigned int  n,
Point const &  dir 
)
related

Snap the angle B - A - dir to multiples of \(2\pi/n\).

The 'dir' argument must be normalized (have unit length), otherwise the result is undefined.

Returns
Point with the same distance from A as B, with a snapped angle.
Postcondition
distance(A, B) == distance(A, result)
angle_between(result - A, dir) == \(2k\pi/n, k \in \mathbb{N}\)

Definition at line 244 of file point.cpp.

References Geom::detail::bezier_clipping::angle(), Geom::angle_between(), Geom::L2(), Spiro::n, and Rotate.

◆ cross()

constexpr Coord cross ( Point const &  a,
Point const &  b 
)
related

Compute the 2D cross product.

This is also known as "perp dot product". It will be zero for parallel vectors, and the absolute value will be highest for perpendicular vectors.

Returns
\(a \times b = a_X b_Y - a_Y b_X\).

Definition at line 380 of file point.h.

References Geom::X, and Geom::Y.

Referenced by are_collinear().

◆ distance()

Coord distance ( Point const &  a,
Point const &  b 
)
related

Compute the (Euclidean) distance between points.

Definition at line 389 of file point.h.

◆ distanceSq()

Coord distanceSq ( Point const &  a,
Point const &  b 
)
related

Compute the square of the distance between points.

Definition at line 395 of file point.h.

References L2sq().

◆ dot()

constexpr Coord dot ( Point const &  a,
Point const &  b 
)
related

Compute the dot product of a and b.

Dot product can be interpreted as a measure of how parallel the vectors are. For perpendicular vectors, it is zero. For parallel ones, its absolute value is highest, and the sign depends on whether they point in the same direction (+) or opposite ones (-).

Returns
\(a \cdot b = a_X b_X + a_Y b_Y\).

Definition at line 371 of file point.h.

References Geom::X, and Geom::Y.

◆ is_unit_vector()

bool is_unit_vector ( Point const &  p,
Coord  eps 
)
related

True if the point has a length near 1.

The are_near() function is used.

Definition at line 172 of file point.cpp.

References Geom::are_near(), and Geom::L2().

◆ is_zero()

bool is_zero ( Point const &  p)
related

True if the point has both coordinates zero.

NaNs are treated as not equal to zero.

Definition at line 165 of file point.cpp.

◆ L1()

Coord L1 ( Point const &  p)
related

Compute the first norm (Manhattan distance) of p.

This is equal to the sum of absolutes values of the coordinates.

Returns
\(|p_X| + |p_Y|\)

Definition at line 143 of file point.cpp.

Referenced by cairo_path_stitches().

◆ L2()

Coord L2 ( Point const &  p)
related

Compute the second (Euclidean) norm of p.

This corresponds to the length of p. The result will not overflow even if \(p_X^2 + p_Y^2\) is larger that the maximum value that can be stored in a double.

Returns
\(\sqrt{p_X^2 + p_Y^2}\)

Definition at line 323 of file point.h.

References length().

Referenced by arc_length_deriv(), cartesian_to_polar(), curvature(), dist_to(), draw_ratquad(), eat(), nearest_after(), neighbors(), path_simplify(), sort_nearest_bis(), and StrokeNormalize().

◆ L2sq()

constexpr Coord L2sq ( Point const &  p)
related

Compute the square of the Euclidean norm of p.

Warning: this can overflow where L2 won't.

Returns
\(p_X^2 + p_Y^2\)

Definition at line 331 of file point.h.

References lengthSq().

Referenced by distanceSq(), and Geom::BezierCurveN< degree >::nearestTime().

◆ lerp()

Point lerp ( Coord  t,
Point const &  a,
Point const &  b 
)
related

Linear interpolation between two points.

Parameters
tTime value
aFirst point
bSecond point
Returns
Point on a line between a and b. The ratio of its distance from a and the distance between a and b will be equal to t.

Definition at line 355 of file point.h.

Referenced by middle_point().

◆ LInfty()

Coord LInfty ( Point const &  p)
related

Compute the infinity norm (maximum norm) of p.

Returns
\(\max(|p_X|, |p_Y|)\)

Definition at line 154 of file point.cpp.

Referenced by main(), and object_align().

◆ middle_point()

Point middle_point ( Point const &  p1,
Point const &  p2 
)
related

Return a point halfway between the specified ones.

Definition at line 361 of file point.h.

References lerp().

Referenced by Geom::BezierCurveN< degree >::intersect(), and TEST().

◆ operator<<()

std::ostream & operator<< ( std::ostream &  out,
Point const &  p 
)
related

Output operator for points.

Prints out the coordinates.

Definition at line 256 of file point.cpp.

References Geom::format_coord_nice(), Geom::X, and Geom::Y.

◆ rot90()

constexpr Point rot90 ( Point const &  p)
related

Returns p * Geom::rotate_degrees(90), but more efficient.

Angle direction in 2Geom: If you use the traditional mathematics convention that y increases upwards, then positive angles are anticlockwise as per the mathematics convention. If you take the common non-mathematical convention that y increases downwards, then positive angles are clockwise, as is common outside of mathematics.

There is no function to rotate by -90 degrees: use -rot90(p) instead.

Definition at line 344 of file point.h.

References Point(), Geom::X, and Geom::Y.

Referenced by Geom::Piecewise< T >::centroid(), cubic_length_subdividing(), curvature(), doEffect_pwd2(), dot_plot(), draw_line(), draw_ray(), goal_function(), line_best_fit(), plot_offset(), sbofsb_cubic_solve(), and vectors_are_clockwise().

◆ unit_vector()

Point unit_vector ( Point const &  a)
related

Create a normalized version of a point.

This is equivalent to copying the point and calling its normalize() method. The returned point will be (0,0) if the argument has both coordinates equal to zero. If any coordinate is NaN, this function will do nothing.

Parameters
aInput point
Returns
Point on the unit circle in the same direction from origin as a, or the origin if a has both coordinates equal to zero

Definition at line 198 of file point.cpp.

References normalize().

Referenced by draw_ray(), line_best_fit(), main(), plot_offset(), tighten(), toPoly(), and Geom::Piecewise< T >::unitVector().

Member Data Documentation

◆ _pt

Coord Geom::Point::_pt[2] = { 0, 0 }
private

The documentation for this class was generated from the following files: