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

Paths rendering issue #85

Closed
Nohus opened this issue May 22, 2023 · 7 comments
Closed

Paths rendering issue #85

Nohus opened this issue May 22, 2023 · 7 comments
Labels
enhancement New feature or request

Comments

@Nohus
Copy link
Collaborator

Nohus commented May 22, 2023

When using the Paths feature, the paths are drawn with artifacts / empty spaces at each connecting point:

image

For comparison, the same path drawn with the Google Maps Compose library. Notice how the line is fully solid throughout:

image

@Nohus Nohus added the bug Something isn't working label May 22, 2023
@p-lr
Copy link
Owner

p-lr commented May 23, 2023

This due to how path are drawn. MapCompose uses Canvas.drawLines which is hardware accelerated, but rendering isn't as pretty as Canvas.drawPath as your image shows.
Historically, I chose to ditch drawPath because the performance difference can clearly be felt when rendering long paths. I was ok with it since in this case I value performance more than aesthetics.
Now a few years later I gave drawPath another try. It's in the very experimental drawpath branch.

While the demo performs well, my testing on a real app shows a noticeable performance difference. Also, I've seen paths blinks under some circumstances (but this is probably unrelated to drawPath).

It would be nice to investigate this performance issue and see if there's a way to use drawPath while not hindering performance. In the end, I agree paths could look nicer. However I will be careful about performance.

@p-lr p-lr added enhancement New feature or request and removed bug Something isn't working labels May 23, 2023
@p-lr
Copy link
Owner

p-lr commented May 23, 2023

The only idea I have for now is to implement path simplification. When zooming out, a path with 10k points can be simplified to a few dozen lines. This should have impact on performance. However this isn't easy to implement.

EDIT: I've implemented the Ramer–Douglas–Peucker algorithm. The result is amazing. Looks like this fixes the performance issue.

@p-lr
Copy link
Owner

p-lr commented May 23, 2023

@Nohus Could you test the branch drawpath and give me your feedback? It should render path like Google Maps Compose library, plus with a path decimation algorithm to fix performance on zoom out.

@Nohus
Copy link
Collaborator Author

Nohus commented May 23, 2023

Impressive work! I can confirm it works well.

I noticed a small issue: the paths seem to be drawn without anti-aliasing and have jagged edges, especially visible at particular angles. I tried setting isAntiAlias = true on the Paint object but it didn't seem to help.

The path simplification is really good, but I think it's a little bit too aggressive, I can see my paths jumping around as I zoom in and out. I think it may work better for you (and be more required) because you are using paths made of a lot of points. My points are not very dense already.

Updating the epsilon argument from 2.dp to 1.dp made it more sensible, at least on my path data.

val epsilon = with(LocalDensity.current) {
    (1.dp / zoomPRState.scale).toPx().toDouble()
}

@p-lr
Copy link
Owner

p-lr commented May 23, 2023

Ok for reducing the epsilon.
I'm surprised you have an anti-aliasing issue. On my device it renders perfectly. Did you have the issue with previous paths?
I'll double check.

@Nohus
Copy link
Collaborator Author

Nohus commented May 23, 2023

I rechecked on a physical device and the paths render correctly, it seems the anti-aliasing issue was emulator-specific, maybe the emulator I used lacks hardware acceleration. False alarm!

@p-lr
Copy link
Owner

p-lr commented May 23, 2023

I'm relieved!

@Nohus Nohus closed this as completed Jul 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants