Class PolygonHelper

java.lang.Object
journeymap.api.v2.client.util.PolygonHelper

public class PolygonHelper extends Object
Utility class related to Polygons.
  • Constructor Details

    • PolygonHelper

      public PolygonHelper()
  • Method Details

    • createChunkPolygonForWorldCoords

      public 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.
      Parameters:
      x - world X
      y - world Y
      z - world Z
      Returns:
      a polygon for the surrounding chunk
    • createChunkPolygon

      public 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.
      Parameters:
      chunkX - chunk x
      y - block y
      chunkZ - chunk z
      Returns:
      polygon
    • createBlockRect

      public 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. The supplied coordinates don't need to be in order, just opposite.
      Parameters:
      corner1 - One corner of the desired rectangle
      corner2 - The opposite corner
      Returns:
      polygon
    • createChunksArea

      @Nonnull public static Area createChunksArea(@Nonnull Collection<net.minecraft.world.level.ChunkPos> chunks)
      Given a collection of chunks, creates an Area that covers them.
      Parameters:
      chunks - The set of chunks.
      Returns:
      An Area of the corresponding block coordinates.
    • createChunksPolygon

      @Nonnull public static List<MapPolygonWithHoles> createChunksPolygon(@Nonnull Collection<net.minecraft.world.level.ChunkPos> chunks, int y)
      Given a collection of chunks, creates one or more MapPolygonWithHoles that covers them. (Just a convenience wrapper for the Area-based methods.)
      Parameters:
      chunks - The set of chunks.
      y - The y-coordinate for the resulting polygons.
      Returns:
      One or more polygons that cover the specified chunks.
    • toArea

      @Nonnull public static Area toArea(@Nonnull MapPolygon polygon)
      Converts a MapPolygon into an Area (keeping XZ coords only).
      Parameters:
      polygon - The polygon.
      Returns:
      The corresponding area.
    • createPolygonFromArea

      @Nonnull public static List<MapPolygonWithHoles> createPolygonFromArea(@Nonnull Area area, int y)
      Creates a set of 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.

      Parameters:
      area - The area to cover.
      y - The y-coordinate.
      Returns:
      The polygons.
    • classifyAndGroup

      @Nonnull public static List<MapPolygonWithHoles> classifyAndGroup(@Nonnull List<MapPolygon> polygons)
      Given an arbitrary list of polygons, determine which are hulls and holes and which holes are associated with which hulls.

      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).

      Parameters:
      polygons - The input list of MapPolygons.
      Returns:
      The resulting list of MapPolygonWithHoles.