/** * 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(); }
return vla.toArray();
packed[l] = ALL_WALL; else packed[l] = packing[l].toArray();
else if(!anyAdded) return ALL_WALL; return packing.toArray();
/** * Gets the positions that are "on" in the given packed array, without unpacking it, repeatedly goes through a * number of "on" cells equal to fraction and stores one of those cells as a Coord, and returns the accumulated * portion of positions as an array of Hilbert Curve indices. * <br> * For purposes of finding mostly cells with a similar distance to each other but without obvious patterns, a value * of 5, 6, or 7 for fraction works well. * @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). * @param fraction the approximate fraction of "on" cells to use * @return a Hilbert Curve index array corresponding to a fraction of the "on" cells in packed. */ public static short[] fractionPackedHilbert(short[] packed, int fraction) { if(fraction <= 1) return allPackedHilbert(packed); ShortVLA vla = new ShortVLA(64); boolean on = false; int idx = 0, ctr = 0; for(int p = 0; p < packed.length; p++, on = !on) { if (on) { for (int i = idx; i < idx + (packed[p] & 0xffff); i++, ctr = (ctr + 1) % fraction) { if(ctr == 0) vla.add((short)i); } } idx += packed[p] & 0xffff; } return vla.toArray(); }
else if(!anyAdded) return ALL_WALL; return packing.toArray();
else if(!anyAdded) return ALL_WALL; return packing.toArray();
else if(!anyAdded) return ALL_WALL; return packing.toArray();
return vla.toArray();
/** * Returns a new packed short[] containing the Hilbert distances in hilbert as "on" cells, and all other cells "off" * @param hilbert a vararg or array of Hilbert distances that will be encoded as "on" * @return the points given to this encoded as "on" in a packed short array */ public static short[] packSeveral(int... hilbert) { if(hilbert == null || hilbert.length == 0) return ALL_WALL; Arrays.sort(hilbert); ShortVLA vla = new ShortVLA(128); int current, past = hilbert[0], skip = 0; vla.add((short)hilbert[0]); for (int i = 1; i < hilbert.length; i++) { current = hilbert[i]; if (current - past > 1) { vla.add((short) (skip+1)); skip = 0; vla.add((short)(current - past - 1)); } else if(current != past) skip++; past = current; } vla.add((short)(skip+1)); return vla.toArray(); }
else if(!anyAdded) return ALL_WALL; return packing.toArray();
return vla.toArray();
return vla.toArray();
return vla.toArray();
return vla.toArray();
packed[l] = ALL_WALL; else packed[l] = packing[l].toArray();
return vla.toArray();
return vla.toArray();
return vla.toArray();