/** * Gets all positions that are "on" in the given packed array, without unpacking it, and returns them as an array of * Hilbert Curve indices. * <br> * Typically this method will not be needed by library-consuming code unless that code deals with Hilbert Curves in * a frequent and deeply involved manner. It does have the potential to avoid converting to and from x,y coordinates * and Hilbert Curve indices unnecessarily, which could matter for high-performance code. * @param packed a short[] returned by pack() or one of the sub-arrays in what is returned by packMulti(); must * not be null (this method does not check due to very tight performance constraints). * @return a Hilbert Curve index array, in ascending distance order, corresponding to all "on" cells in packed. */ public static short[] allPackedHilbert(short[] packed) { ShortVLA vla = new ShortVLA(64); boolean on = false; int idx = 0; for(int p = 0; p < packed.length; p++, on = !on) { if (on) { vla.addRange(idx, idx + (packed[p] & 0xffff)); } idx += packed[p] & 0xffff; } return vla.toArray(); }
/** * Gets all positions that are "on" in the given packed array, without unpacking it, and returns them as a Coord[]. * @param packed a short[] returned by pack() or one of the sub-arrays in what is returned by packMulti(); must * not be null (this method does not check due to very tight performance constraints). * @return a Coord[], ordered by distance along the Hilbert Curve, corresponding to all "on" cells in packed. */ public static Coord[] allPacked(short[] packed) { ShortVLA vla = new ShortVLA(64); boolean on = false; int idx = 0; for(int p = 0; p < packed.length; p++, on = !on) { if (on) { vla.addRange(idx, idx + (packed[p] & 0xffff)); } idx += packed[p] & 0xffff; } int[] distances = vla.asInts(); Coord[] cs = new Coord[distances.length]; for (int i = 0; i < distances.length; i++) { cs[i] = Coord.get(hilbertX[distances[i]], hilbertY[distances[i]]); } return cs; }