mirror of
https://github.com/EngineHub/WorldGuard.git
synced 2025-02-09 17:02:20 +01:00
Optimized the countBlocks() method for polygonal regions
This commit is contained in:
parent
97aa259b2d
commit
dbf65f798f
@ -139,14 +139,14 @@ public String getTypeName() {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public int countBlocks() {
|
public int countBlocks() {
|
||||||
if(points.size() < 3) {
|
int volume = 0;
|
||||||
|
int numPoints = points.size();
|
||||||
|
if(numPoints < 3) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
double area = 0;
|
double area = 0;
|
||||||
int volume = 0;
|
|
||||||
int xa, za, z1, z2;
|
int xa, za, z1, z2;
|
||||||
int numPoints = points.size();
|
|
||||||
|
|
||||||
for (int i = 0; i <= numPoints - 1; i++) {
|
for (int i = 0; i <= numPoints - 1; i++) {
|
||||||
xa = points.get(i).getBlockX();
|
xa = points.get(i).getBlockX();
|
||||||
@ -171,7 +171,7 @@ public int countBlocks() {
|
|||||||
|
|
||||||
area = area + (xa * (points.get(1).getBlockZ() - points.get(numPoints - 1).getBlockZ()));
|
area = area + (xa * (points.get(1).getBlockZ() - points.get(numPoints - 1).getBlockZ()));
|
||||||
|
|
||||||
volume = (Math.abs(maxY - minY) + 1) * (int)Math.ceil((Math.abs(area) / 2));;
|
volume = (Math.abs(maxY - minY) + 1) * (int)Math.ceil((Math.abs(area) / 2));
|
||||||
|
|
||||||
return volume;
|
return volume;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user