[QGIS-Developer] Suggestion of a different perpendicularSegment geometry method

Nyall Dawson nyall.dawson at gmail.com
Wed Oct 21 23:12:22 PDT 2020


On Thu, 22 Oct 2020 at 06:43, Tobias Schmetzer <tschmetzer at gmx.de> wrote:
>
> Dear developer colleagues,
>
> I'm new to QGIS development and my cpp and git experience is a long
> while ago. Yet I want to make the effort to contribute to this project
> in return for using it for months.
>
> During my python scripting I was missing a function that I created
> for myself in python which I would need to split a polyline using
> QgsGeometry.splitGeometry().
>
> The function I want to contribute will create a perpendicular segment to
> a given segment with it's center at a given point (the already available
> function QgsGeometryUtils.perpendicularSegment doesn't fullfill that need)
>
> I would suggest to add to the cpp code of QgsGeometryUtils. A good old
> friend of mine and cpp expert will do the first code review once it's
> finished before I do the PR.
>
> I am already working on that function and its test. The header looks
> like this:
>
> /**
> * \brief Create a perpendicular line segment to a given segment
> * [segmentPoint1, segmentPoint2] with its center at centerPoint
> * May be used to split geometries
> * \param centerPoint Point where the center of the perpendicular should
> * be located
> * \param segmentPoint1 The segment's start point
> * \param segmentPoint2 The segment's end point
> * \returns A line (segment) centered in point p and perpendicular to
> * segment [segmentPoint1, segmentPoint2]
> */
>
> static QgsLineString perpendicularCenterSegment(  const QgsPoint &point,
> const QgsPoint &segmentPoint1, const QgsPoint &segmentPoint2  ) SIP_HOLDGIL;

Looks good to me! Some suggestions:
- instead of accepting QgsPoint values, consider making the arguments
plain doubles instead. (e.g. double segmentPoint1x, double
segmentPoint1y, etc). This makes the API more flexible because callers
who have QgsPointXY or some other input values don't need to do a
conversion to QgsPoint first.
- For the same reasons, consider making the method return 4 doubles
instead of a QgsLineString. E.g. add double& perpendicular1x SIP_OUT,
double &perpendicular1y SIP_OUT, double& perpendicular2x SIP_OUT,
double &perpendicular2y SIP_OUT. This again avoids the forced use of
QgsLineString, and will reap benefits if the function is called many
times and the caller does not need a QgsLineString object
- Do you need to add a "segment length" argument for controlling the
length of the perpendicular line generated?

Nyall


>
> Any comments or did I even miss an already available
> function for what I am suggesting?
>
> Kind regards, Tobias
> _______________________________________________
> QGIS-Developer mailing list
> QGIS-Developer at lists.osgeo.org
> List info: https://lists.osgeo.org/mailman/listinfo/qgis-developer
> Unsubscribe: https://lists.osgeo.org/mailman/listinfo/qgis-developer


More information about the QGIS-Developer mailing list