Skip to content

ColorBuckets

Namespace Nfty.Core.Generation in assembly Nfty.Ticket.

public static class ColorBuckets

The one place a rolled color is folded into the quantized bucket that identifies it.

Two callers must agree exactly: Dna, which decides whether two assets are the same asset, and UniqueSpace, which promises how many distinct assets exist. They used to compute it separately and disagreed, because ColorRoller.Roll() divides saturation by 100 and the DNA multiplies it back — and that round-trip is not the identity: (29/100.0)*100.0 is 28.999999999999996, which floors to 28, not 29. The counter worked from the raw percentage and said 29. On a book Validator called clean, the count over-promised and Generate failed with the self-contradicting "this cookbook allows exactly N unique DNA, but N were requested".

Sharing one function is the fix: equivalent-looking arithmetic in two files is what broke, so the arithmetic now exists once. UniqueSpace reaches saturation through ColorRoller.SampleSat() and then ColorBuckets.Sat(), rather than shortcutting from the stored percentage to percent / quantize — the /100 round-trip's rounding is load-bearing, because it is what the shipped DNA of every Set ever generated already encodes. Skipping it would be the tidier arithmetic and would silently invalidate every existing collection.

Methods

Hue(double, int)

public static long Hue(double hue, int quantize);

The bucket a hue lands in. Hue needs no round-trip — it is carried in degrees end to end — so this is a plain floor-divide.

Parameters

  • hue (double) - Hue in degrees, as ColorRoller.Roll() produces it.
  • quantize (int) - Bucket width in degrees; values below 1 are treated as 1.

Returns. The zero-based bucket index.

Sat(double, int)

public static long Sat(double saturation, int quantize);

The bucket a saturation lands in, taking saturation in the 0..1 form RolledColor.S carries.

Parameters

  • saturation (double) - Saturation as a 0..1 fraction.
  • quantize (int) - Bucket width in percentage points; values below 1 are treated as 1.

Returns. The zero-based bucket index.