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
main_angle() function calculates wrong angles in some cases #41022
Comments
This is caused by QGIS/src/core/geometry/qgsinternalgeometryengine.cpp Lines 1508 to 1510 in f327256
I am interested in trying to fix this myself, so unless someone feels super eager to do this bug, give me some time to find a calm hour. Should be easy(tm) and I can figure out how to add a test for this too. :) |
@kannes I fail to see how constraining the angle between 0 and 180 would cause this behaviour, the issue seems to be higher up in the code when generating the hull and iterating through vertices. |
My hunch is that the angles are negative before the modulo and I have not thought about if that makes any sense to be honest. If it could be fixed higher up, that would be perfect of course. |
Any progress on the debug? I'm curious about this one. |
Haven't had a moment to look into it yet, my build process was broken for quite a while. Sorry! |
I'll look into it as soon as I can fix this cursed msvc c++17 build. |
I spoke too soon. Got my setup running and am looking into it now. |
It is definitely not in that code snippet I posted, which does make sense... ;)
-> should be 70
-> should be ~70 I think that for "parallel" ("regular"?) geometries like rectangles the With another |
The main issue is that a box will have the same minimal hull if rotated 90 degree as the width and height are inverted. The only thing that should be done is if currentArea = area pick the one with the biggest height, don't ignore that parameter. That should solve it. No need to uncertainty terms or quitting early as you may only ever get the wide side first. |
That might be a fix for the rectangles but are you sure there are no possible geometries that could have the same convex hull bounding box area for more than two subsequent rotations? It might just be a local minima I guess. |
Current state with my testing data (the top row is two squares, then one vertex being moved to the top resp. right, first with a tiny step, then visibly), lots of printf-ing because I have no proper setup and probably remaining bugs. Should really be tested with better test cases I think. The equality comparison is absolutely not ready for usage and there are remaining broken tests I just introduced this morning, yay... I might continue next weekend but cannot promise it so if someone else wants to have a go, enjoy! :) |
|
The |
try preferring height on stalemate and don't quick abort. Your approach will give varying result depending on the vertex order if you stop too soon. |
stalewhat? :} I would still like to understand what the algorithm is trying to do. I think I mostly got it but guessing seems like a waste of time and potentially introduce new bugs. |
The algorithm creates a convex hull of the geometry ( a minimal all encompassing geometry). From this you iterate over the edges by aligning the bounding box on each edge in order to find the best fit. This is do that way since aligning the box on one edge should produce the optimal result in theory. In your case you hav 4 edged and the bounding box get the same area each time as the width and eight are the only two parameter changing. |
Describe the bug
The new
main_angle()
function calculates wrong angles in some cases. In the following screenshot the top row has "linear" rectangles rotated manually at about 10° per step. The two rows below have a duplicated rectangle rotated at exact steps of 10°. The CRS is EPSG:32618.The blue line points to the North, the red arrow goes from the centroid to a point in the direction of
main_angle($geometry)
, the label showsmain_angle($geometry)
, the line pattern is rotated90-main_angle
degrees (as rotation 0 is in the East).The arrow line is drawn with this Geometry Generator:
You can see that at some rotations of the rectangles, the calculated
main_angle
is 90° off.How to Reproduce
I attached the data and the style to reproduce this.
rectangles.wkt.txt
style.qml.gz
QGIS and OS versions
Master from today:
The text was updated successfully, but these errors were encountered: