public class PolygonHelper
extends java.lang.Object
| Constructor and Description |
|---|
PolygonHelper() |
| Modifier and Type | Method and Description |
|---|---|
static java.util.List<MapPolygonWithHoles> |
classifyAndGroup(java.util.List<MapPolygon> polygons)
Given an arbitrary list of polygons, determine which are hulls and holes and which holes are
associated with which hulls.
|
static MapPolygon |
createBlockRect(net.minecraft.core.BlockPos corner1,
net.minecraft.core.BlockPos corner2)
Creates a polygon for the block coords, starting with the lower-left (southwest) corner
and going counter-clockwise.
|
static MapPolygon |
createChunkPolygon(int chunkX,
int y,
int chunkZ)
Creates a polygon for the chunk coords, starting with the lower-left (southwest) corner
and going counter-clockwise.
|
static MapPolygon |
createChunkPolygonForWorldCoords(int x,
int y,
int z)
Creates a polygon for the chunk containing worldCoords, starting with the lower-left (southwest) corner
and going counter-clockwise.
|
static java.awt.geom.Area |
createChunksArea(java.util.Collection<net.minecraft.world.level.ChunkPos> chunks)
Given a collection of chunks, creates an
Area that covers them. |
static java.util.List<MapPolygonWithHoles> |
createChunksPolygon(java.util.Collection<net.minecraft.world.level.ChunkPos> chunks,
int y)
Given a collection of chunks, creates one or more
MapPolygonWithHoles that covers them. |
static java.util.List<MapPolygonWithHoles> |
createPolygonFromArea(java.awt.geom.Area area,
int y)
Creates a set of
MapPolygonWithHoles from the given Area (XZ block
coords) and the given Y coord. |
static java.awt.geom.Area |
toArea(MapPolygon polygon)
Converts a
MapPolygon into an Area (keeping XZ coords only). |
public static MapPolygon createChunkPolygonForWorldCoords(int x, int y, int z)
x - world Xy - world Yz - world Zpublic static MapPolygon createChunkPolygon(int chunkX, int y, int chunkZ)
chunkX - chunk xy - block ychunkZ - chunk zpublic static MapPolygon createBlockRect(net.minecraft.core.BlockPos corner1, net.minecraft.core.BlockPos corner2)
corner1 - One corner of the desired rectanglecorner2 - The opposite corner@Nonnull
public static java.awt.geom.Area createChunksArea(@Nonnull
java.util.Collection<net.minecraft.world.level.ChunkPos> chunks)
Area that covers them.chunks - The set of chunks.@Nonnull public static java.util.List<MapPolygonWithHoles> createChunksPolygon(@Nonnull java.util.Collection<net.minecraft.world.level.ChunkPos> chunks, int y)
MapPolygonWithHoles that covers them.
(Just a convenience wrapper for the Area-based methods.)chunks - The set of chunks.y - The y-coordinate for the resulting polygons.@Nonnull
public static java.awt.geom.Area toArea(@Nonnull
MapPolygon polygon)
MapPolygon into an Area (keeping XZ coords only).polygon - The polygon.@Nonnull public static java.util.List<MapPolygonWithHoles> createPolygonFromArea(@Nonnull java.awt.geom.Area area, int y)
MapPolygonWithHoles from the given Area (XZ block
coords) and the given Y coord.
Note that this includes some point-simplification that currently only works if the area is only made up of rectangular subregions -- i.e. all lines are perfectly horizontal or vertical. If you do have diagonal lines this is mostly harmless; just might leave more points than are strictly required.
area - The area to cover.y - The y-coordinate.@Nonnull public static java.util.List<MapPolygonWithHoles> classifyAndGroup(@Nonnull java.util.List<MapPolygon> polygons)
Assumes that hulls use CCW point winding and holes use CW point winding, which seems to be
consistent with createPolygonFromArea(java.awt.geom.Area, int).
Each hole is grouped with the innermost hull that fully contains it. A hole that no hull
contains but that intersects one or more hulls (possible only for arbitrary input, not for
the normalized Area contours createPolygonFromArea(java.awt.geom.Area, int) emits) falls back to the
first hull it intersects; a hole that touches no hull is dropped. The innermost-owner
result is independent of contour order when the hulls strictly nest, as they do for
normalized Area contours; for overlapping or equal-area hulls that both contain a
hole the first candidate wins.
polygons - The input list of MapPolygons.MapPolygonWithHoles.