Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor QgsCircularString::curveToLine #4746

Merged
merged 9 commits into from
Aug 25, 2017
Merged

Refactor QgsCircularString::curveToLine #4746

merged 9 commits into from
Aug 25, 2017

Conversation

strk
Copy link
Contributor

@strk strk commented Jun 17, 2017

@strk strk self-assigned this Jul 21, 2017
@strk strk changed the title Add test for QgsCircularString::curveToLine Refactor QgsCircularString::curveToLine Aug 11, 2017
@strk
Copy link
Contributor Author

strk commented Aug 11, 2017

This became both a bugfix and an enhancement.
Bugfix because it fixed https://issues.qgis.org/issues/16717 and https://issues.qgis.org/issues/16722
Enhancement because it adds truly symmetric curveToLine output

Do you see any reason to use the old behavior of output being non-symmetric ? As that would need a parameter...

@strk
Copy link
Contributor Author

strk commented Aug 11, 2017

Another enhancement that could be added is avoiding duplicated vertices in a multi-arc curve, whereas right now there will be an additional duplicated point on every arc.

@strk
Copy link
Contributor Author

strk commented Aug 11, 2017

Oh, one more note: the code before this change had a control structure ensuring that the control point in the input curve still appeared in the output curve. I obviously removed that check because it's clearly incompatible with a symmetric output. If there's any good reason to retain that point it should once again become a parameter to keep it. I cannot think of any good reason, but there's a test guarding for that, which is currently failing: https://travis-ci.org/qgis/QGIS/jobs/263558531#L1785

@strk
Copy link
Contributor Author

strk commented Aug 22, 2017

@mhugent or @andreasneumann do you know why it was desired for control point to always be in output ? For a regularly-spaced output the control point may be just very close to previous or next vertex, introducing vicinities that are probably not wanted..

@andreasneumann
Copy link
Member

@edigonzales can you help here? Or maybe @mhugent ?

@strk
Copy link
Contributor Author

strk commented Aug 22, 2017

Commit da18565 restores control point addition (while avoiding a point duplication). Chances of nearby points are still there.

@strk
Copy link
Contributor Author

strk commented Aug 22, 2017

Travis succeeds with Python 3.5 and fails with Python 3.3 but I don't see what's the error in here: https://travis-ci.org/qgis/QGIS/jobs/267145607

@3nids
Copy link
Member

3nids commented Aug 22, 2017

@3nids
Copy link
Member

3nids commented Aug 22, 2017

the build with Python 3.5 is for code layout (spelling, syntax, sip bindings, etc)

@strk
Copy link
Contributor Author

strk commented Aug 22, 2017

@3nids can you tell what's missing in this case, for the build to fail ?

@strk
Copy link
Contributor Author

strk commented Aug 22, 2017

got it, now that I followed the CDash link (sorry) - it would be great to see that link in cubital fonts in the logs of the build :)

@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

This PR should now be passing Travis, but I had to expect the control point to be in the output for all new tests I added. I don't really like to see that control point in, because it makes the output ugly in the best case (non same-length segments) and dangerous at worst (very small segments).

@edigonzales, @mhugent, @andreasneumann I'm still interested in your opinion about this: why is it desired to have control point in output ?

@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

I'm working on adding a parameter to make it optional to force or not inclusion of the control point, but I still think the default should be NOT to force it, do you agree ?

@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

now the test fails for an unrelated issue ...

@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

Rebased to latest-passing commit, to see if that fixes this unrelated error:

234: ======================================================================
234: FAIL: testInterpolateAngle (__main__.TestQgsGeometry)
234: test QgsGeometry.interpolateAngle()
234: ----------------------------------------------------------------------
234: Traceback (most recent call last):
234:   File "/usr/src/qgis/qgis-master/tests/src/python/test_qgsgeometry.py", line 3545, in testInterpolateAngle
234:     self.assertAlmostEqual(geom.interpolateAngle(5), 1.69120, places=3)
234: AssertionError: 1.6919297347154518 != 1.6912 within 3 places
234:
234: ======================================================================
234: FAIL: testLineLocatePoint (__main__.TestQgsGeometry)
234: test QgsGeometry.lineLocatePoint()
234: ----------------------------------------------------------------------
234: Traceback (most recent call last):
234:   File "/usr/src/qgis/qgis-master/tests/src/python/test_qgsgeometry.py", line 3501, in testLineLocatePoint
234:     self.assertAlmostEqual(geom.lineLocatePoint(point), 7.372, places=3)
234: AssertionError: 7.3773841496377 != 7.372 within 3 places
234:
234: ======================================================================

@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

Ok I surrender: the failure is not unlrelated. It's for "interpolateAngle" which ensures to always work on linearized curve. Then computes the angle parallel to the "curve" at the specified distance. It is expected that the number can be slightly different upon refactoring the curveToLine function. The other are similar: functions that operate on segmentation of curves.

I'll update the expected results. Then one day these functions will work directly on curves so that the results will be more precise

@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

Expected results updated, but I'd love to be able to have the control point not added by default before doing this, as that additional point may very well affect reuslts.

So say, the same curve (only defined with a different control-point) would end up having a different centroid, or interpolated angle, or located point. It isn't nice is it ?

Control point is any point on the arc, so could be everywhere, hardly with a meaning on itself other than defining the curve...

@nyalldawson
Copy link
Collaborator

Control point is any point on the arc, so could be everywhere, hardly with a meaning on itself other than defining the curve...

I'm +0 on this, but am not a heavy curved geometry user myself so don't know exactly what users want in this situation. In the absence of any reply from @mhugent or @andreasneumann I'd say your safe to go with your instinct and change the behavior.

…ference curves

These values change because they are computed on the *linearization*
of those curves, and refactoring linearization codes results in
slighly different values.

NOTE: adding or not adding the control point would also affect these
results
@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

Ok rebased to fix conflicts and reverted to NOT include the control point, let's see how centroid/interpolateAngle/locatPoint change again with this (maybe those tests should be made more tolerant, btw)

@strk strk merged commit 650cf6a into qgis:master Aug 25, 2017
@strk
Copy link
Contributor Author

strk commented Aug 25, 2017

I'm considering this closed, no force of central point. Curves will be segmentized with segments of equal length.

@strk strk deleted the bugfix/16717 branch August 25, 2017 21:07
bool addP2 = true;
if ( qgsDoubleNear( circlePoint1.x(), circlePoint3.x() ) && qgsDoubleNear( circlePoint1.y(), circlePoint3.y() ) )
{
addP2 = false;
}

for ( double angle = a1 + increment; angle < a3; angle += increment )
addP2 = false;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@strk this has left a lot of unreachable code in the loop below - was this intended?

@strk
Copy link
Contributor Author

strk commented Sep 1, 2017 via email

@nyalldawson
Copy link
Collaborator

@strk

was intended in case anyone (@andreasneumann?) comes out with
a reason why that control-point addition was required to be in output
in the first place (there was a testcase guarding for that occurrence)

To me, the code needs to go, but I feel like stepping on somebody's
thought by removing that part (although nobody complained so far)

Fair enough. In that case can we #ifdef 0 it out so that it's obvious to readers that the unused code is intended here? The static analysis tools will also have issues if we leave it in.

@mhugent
Copy link
Contributor

mhugent commented Sep 2, 2017

@strk: control point on segmented curve was a requirement in the first implementation. I've asked back at the office that ordered this functionality. It seems it's ok for them if it is removed.

strk added a commit to strk/QGIS that referenced this pull request Sep 4, 2017
Drops the unused support for including control points in output.
See qgis#4746 (comment)
@strk
Copy link
Contributor Author

strk commented Sep 4, 2017

Thanks @mhugent - @nyalldawson please see #5120 5120

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants