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

Fixed volume calculation/Autoprice for 2d Polygonal regions #57

Closed
wants to merge 2 commits into from

Conversation

CyphurTheFox
Copy link

Volume for a 2d polygonal region was not provided by WorldGuard, which breaks autoprice for these region types.
2021-01-23_11 00 35
I implemented an algorithm for calculating the volume of a 2d poly region into the worldguard adapters. Should allow Autoprice to work for polygonal regions.

CyphurTheFox added 2 commits January 23, 2021 10:21
 - Added specific volume case for 2d Polygonal regions, allowing autoprice to properly compute them
@alex9849
Copy link
Owner

alex9849 commented Jan 23, 2021

Thanks for your contribution to AdvancedRegionMarket. Sadly your algorithm is incorrect.
The right region that you see in this picture contains exactly 24 blocks (and is ploygonal). The autoprice is set to 1$ per squareblock. Your algorithm somehow calculates that the region contains -14 (negative) blocks:
https://puu.sh/H9P6P/6e892722dc.jpg
I see you tried to implement the Shoelace formula. The problem with that approach is, that the area only gets calculated to the outer point (exclusively). What leads us to this problem:
https://puu.sh/H7Q4O/a2ca709e4c.png

Also, the Shoelace formula doesn't calculate the exact amount of blocks inside the region. You really get the area in the region (double), but we need the amount of blocks. For example a block that is located at the border of the region may be included into the region by WorldGuard, but the algorithm only counts it as a half block.

@alex9849 alex9849 closed this Jan 23, 2021
@CyphurTheFox
Copy link
Author

Thanks for the feedback, I’ll take another crack at it with some different algorithms later. Hopefully I can put together something more satisfactory.

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.

2 participants