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

Fix incorrect area calculation in QgsLineString::sumUpArea #59156

Closed

Conversation

lbartoletti
Copy link
Member

Description

This PR fixes the area calculation in the QgsLineString::sumUpArea method. The previous formula incorrectly computed the area for closed rings, always returning negative values regardless of the orientation of the vertices. The issue occurred because the formula used in the loop didn't properly account for the orientation of the line.

Changes:

  • Updated the area calculation using the correct shoelace formula, ensuring that areas for clockwise-oriented rings return negative values, and counterclockwise-oriented rings return positive values.
  • Added a check to ensure the method only calculates the area for polygons with at least 3 points.

This resolves the issue returned by @agiudiceandrea where both clockwise and counterclockwise rings returned negative areas.

Fixes #58333

⚠️ Since I also "fix" tests, let's open it as draft and see how many tests have to be fixed.⚠️

@lbartoletti lbartoletti self-assigned this Oct 21, 2024
@github-actions github-actions bot added this to the 3.40.0 milestone Oct 21, 2024
Copy link

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit fc2a221)

Copy link

Tests failed for Qt 6

One or more tests failed using the build from commit fc2a221

line_offset_negative

line_offset_negative

Test failed at testLineOffset at tests/src/python/test_qgshashlinesymbollayer.py:377

Rendered image did not match tests/testdata/control_images/symbol_hashline/expected_line_offset_negative/expected_line_offset_negative.png (found 4881 pixels different)

lineburst_offset

lineburst_offset

Test failed at testLineOffset at tests/src/python/test_qgslineburstsymbollayer.py:226

Rendered image did not match tests/testdata/control_images/symbol_lineburst/expected_lineburst_offset/expected_lineburst_offset.png (found 5543 pixels different)

rasterline_offset

rasterline_offset

Test failed at testLineOffset at tests/src/python/test_qgsrasterlinesymbollayer.py:178

Rendered image did not match tests/testdata/control_images/symbol_rasterline/expected_rasterline_offset/expected_rasterline_offset.png (found 1166 pixels different)

The full test report (included comparison of rendered vs expected images) can be found here.

Further documentation on the QGIS test infrastructure can be found in the Developer's Guide.

Copy link

Tests failed for Qt 5

One or more tests failed using the build from commit fc2a221

embedded_mapinfo_lines

embedded_mapinfo_lines

Test failed at testMapInfoLineSymbolConversion at tests/src/python/test_qgsembeddedsymbolrenderer.py:250

Rendered image did not match tests/testdata/control_images/embedded/expected_embedded_mapinfo_lines/expected_embedded_mapinfo_lines.png (found 24839 pixels different)

line_offset_negative

line_offset_negative

Test failed at testLineOffset at tests/src/python/test_qgshashlinesymbollayer.py:377

Rendered image did not match tests/testdata/control_images/symbol_hashline/expected_line_offset_negative/expected_line_offset_negative.png (found 4841 pixels different)

lineburst_offset

lineburst_offset

Test failed at testLineOffset at tests/src/python/test_qgslineburstsymbollayer.py:226

Rendered image did not match tests/testdata/control_images/symbol_lineburst/expected_lineburst_offset/expected_lineburst_offset.png (found 5543 pixels different)

rasterline_offset

rasterline_offset

Test failed at testLineOffset at tests/src/python/test_qgsrasterlinesymbollayer.py:178

Rendered image did not match tests/testdata/control_images/symbol_rasterline/expected_rasterline_offset/expected_rasterline_offset.png (found 1166 pixels different)

The full test report (included comparison of rendered vs expected images) can be found here.

Further documentation on the QGIS test infrastructure can be found in the Developer's Guide.

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

Successfully merging this pull request may close these issues.

Incorrect winding/orientation/order of polygon's vertices in Memory layers
1 participant