Package worldBuilder

Class Cartesian


  • public class Cartesian
    extends java.lang.Object
    a dense 2D array w/Cartesian coordinates, whose values have been interpolated from the Voronoi mesh points.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  Cartesian.vicinity
      types of vicinities
    • Field Summary

      Fields 
      Modifier and Type Field Description
      Vicinity[][] cells
      the nearest MeshPoints to every tile in our map
      int height
      number of tile rows in this map
      int width
      number of tile columns in this map
    • Constructor Summary

      Constructors 
      Constructor Description
      Cartesian​(Mesh mesh, double left, double top, double right, double bottom, int width, int height, Cartesian.vicinity type)
      create a new Cartesian map
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static int[][] encode​(double[][] array, int minValue, int maxValue)
      interpret a 2D array of doubles into ranges in an integer value (typically used to translate altitudes to colors
      double[][] interpolate​(double[] meshValues)
      interpolate values for every Cartesian cell
      double[][] nearest​(double[] meshValues)
      use nearest MeshPoint value for every Cartesian cell
      static void smooth​(double[][] array)
      perform Gaussian Blurr on a (potentially noisy) array
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • width

        public int width
        number of tile columns in this map
      • height

        public int height
        number of tile rows in this map
      • cells

        public Vicinity[][] cells
        the nearest MeshPoints to every tile in our map
    • Constructor Detail

      • Cartesian

        public Cartesian​(Mesh mesh,
                         double left,
                         double top,
                         double right,
                         double bottom,
                         int width,
                         int height,
                         Cartesian.vicinity type)
        create a new Cartesian map
        Parameters:
        mesh - ... Mesh of Voronoi points
        left - ... left edge of mapped area
        top - ... top of mapped area
        right - ... right edge of mapped area
        bottom - ... bottom edge of mapped area
        width - ... width of desired array
        height - ... height of desired array
        type - ... type of vicinity (NEAREST, NEIGHBORS, POLYGON)
    • Method Detail

      • interpolate

        public double[][] interpolate​(double[] meshValues)
        interpolate values for every Cartesian cell
        Parameters:
        meshValues - - array of per-MeshPoint values
        Returns:
        Cartesian array of interpolated values
      • nearest

        public double[][] nearest​(double[] meshValues)
        use nearest MeshPoint value for every Cartesian cell
        Parameters:
        meshValues - - array of per-MeshPoint values
        Returns:
        Cartesian array of per-tile values
      • encode

        public static int[][] encode​(double[][] array,
                                     int minValue,
                                     int maxValue)
        interpret a 2D array of doubles into ranges in an integer value (typically used to translate altitudes to colors
        Parameters:
        array - - 2D array of doubles
        minValue - - minimum value of output range
        maxValue - - maximum value of output range
        Returns:
        2D array of integers representing re-encoded values
      • smooth

        public static void smooth​(double[][] array)
        perform Gaussian Blurr on a (potentially noisy) array
        Parameters:
        array - - 2D array of doubles The Cartesian translation process can yield discontinuities when neighboring tiles have different sets of closest MeshPoints. In most cases, these are inconsequential, but they need to be cleaned up for high-resolution altitude maps. A 2D Gaussian Kernel is merely the product of a pair of 1D kernels, but (because multiplication is associative) we can get the same result in (O(n) time) by applying the 1D kernel twice: 1. recompute each point as the average of its horizontal neighbors 2. recompute each point as the average of its vertical neighbors