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

Improve Pie Chart Rendering #261

Open
Hop311 opened this issue Sep 5, 2024 · 0 comments
Open

Improve Pie Chart Rendering #261

Hop311 opened this issue Sep 5, 2024 · 0 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@Hop311
Copy link
Contributor

Hop311 commented Sep 5, 2024

Problem

OpenVic's GFXPieChartTextures are generated based on the polar coordinates of each pixel relative to the texture's centre. This approach can result in sampling artefacts and messy looking slice edges, especially for very thin slices.

Solution

Instead of using polar coordinates, GFXPieChartTexture.cpp's _generate_pie_chart_image function should use a "sweeping line" approach where lines are drawn from the centre to each pixel on the outer edge of the pie chart, starting with the point directly to the right of the centre and sweeping around the whole circle anti-clockwise, choosing the colour of each line based on the polar angle of the edge point at the end the line.

The lines should be drawn using a smooth 2D line drawing function (e.g. Bresenham's Line Algorithm) and a similar smooth circle generating function should be used to to find the edge points to draw to (e.g. the Midpoint Circle Algorithm). It may be necessary to adjust the width and height of the pie chart image from their current value of 2 * radius to an odd number like 2 * radius - 1, which in turn may require offsetting the drawn pie chart image by a pixel in each axis in order to keep it aligned with the semi-transparent overlay textures covering most pie charts.

Although this still involves polar coordinates, it results in fewer sampling artefacts as the slice-edges are farther apart on the outer rim and results in cleaner edges thanks to the use of specialised smooth 2D line drawing functions.

@Hop311 Hop311 added bug Something isn't working enhancement New feature or request labels Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant