[PR #7617] The beard kernel table holds vanilla's values, checked entry by entry #7718

Open
opened 2026-11-03 07:22:40 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/7617
Author: @MSedgeMC
Created: 11/2/2026
Status: 🔄 Open

Base: main ← Head: test/beardifier-kernel-table


📝 Commits (2)

  • 8918c86 rerun
  • 86f6464 test: pin the beard kernel table to vanilla's values

📊 Changes

1 file changed (+44 additions, -0 deletions)

View changed files

📝 crates/horizon-core/src/density/beardifier.rs (+44 -0)

📄 Description

crates/horizon-core/src/density/beardifier.rs::kernel fills the 13824-entry
table Beardifier.BEARD_KERNEL holds. Nothing checked it: the table is inside
the crate, 24³ floats, and a wrong exponent, offset or index order in it would
only show up as subtly wrong terrain under every beard_thin/beard_box
structure. This adds the check, with the values read off vanilla.

Vanilla

Beardifier's static initialiser:

private static final float[] BEARD_KERNEL = Util.make(new float[13824], kernel -> {
   for (int zi = 0; zi < 24; zi++)
      for (int xi = 0; xi < 24; xi++)
         for (int yi = 0; yi < 24; yi++)
            kernel[zi * 24 * 24 + xi * 24 + yi] = (float)computeBeardContribution(xi - 12, yi - 12, zi - 12);
});

private static double computeBeardContribution(final int dx, final int dy, final int dz) {
   return computeBeardContribution(dx, dy + 0.5, dz);
}

private static double computeBeardContribution(final int dx, final double dy, final int dz) {
   double distanceSqr = Mth.lengthSquared(dx, dy, dz);
   return Math.pow(Math.E, -distanceSqr / 16.0);
}

So entry zi * 576 + xi * 24 + yi is e^(-(dx² + (dy + 0.5)² + dz²) / 16) as a
float, with the half-block lift on y only.

What Horizon had

kernel() builds the same array with std::array::from_fn, mapping the index
back to (x, y, z) = ((i / 24) % 24, i % 24, i / 576) and adding the same 0.5
to y before jmath::pow(E, -squared / 16.). Written that way it is right —
and it is, value for value — but nothing said so, and jmath::pow's promise of
HotSpot-exact Math.pow was the only thing holding the numbers up.

Proven

cargo test -q -p horizon-core --lib the_beard_kernel:

  • every one of the 13824 entries has the bits vanilla's formula gives it: the
    test hashes the whole table (float bits, 31-multiplier) and gets
    b44d13f8c3d98c65 from both sides, and pins seven entries by index —
    kernel[0] = 3.9172745e-12, kernel[7212] = 0.9844964 (the centre, where
    dy is 0.5), kernel[13823] = 6.9435353e-11 among them.
  • the centre is asserted to be the table's maximum, so an index order that
    transposes x and z (they are symmetric in the formula, but y is not)
    cannot pass by accident.

Failing without the fix: move the falloff from 16 to 12 — the one constant a
reader is most likely to mistype — and the test stops on
kernel[0] is 6.175119e-13 not 3.9172745e-12 (bits 640810070 vs 747230124);
the table hash moves too. Nothing else in the suite notices.

How the values were read

The class cannot be run here: client-26.3.jar holds class files of version 69
and the only JDK on this machine is 21, so Class.forName("…Beardifier") ends
in UnsupportedClassVersionError and the private field cannot be reflected out.
The values therefore come from the initialiser's own formula, transcribed
(computeBeardContribution above, including the + 0.5 in the three-argument
overload), compiled and run under java 21, printing Float.floatToIntBits of
each entry; the Rust side was compared against those bits entry by entry and
agrees on all 13824.

javap -p -c over the same jar does disassemble the class, and its bytecode is
where the formula above is read from rather than taken on trust:
lambda$static$0 computes zi * 24 * 24 + xi * 24 + yi (three nested loops over
0..23) and calls computeBeardContribution(xi - 12, yi - 12, zi - 12); the
three-argument overload adds double 0.5d to y before calling
computeBeardContribution(int, double, int), which is
Math.pow(2.718281828459045d, -Mth.lengthSquared(dx, dy, dz) / 16.0d).

Not proven

  • Only the table. getBeardContribution's fastInvSqrt, the 0.8/0.4
    weights, getBuryContribution's radius of 6 and the rigid/junction loops are
    untouched here and were verified elsewhere.
  • No behaviour changes and no port_map row changes: the map already carries
    Beardifier.computeBeardContribution inline …beardifier.rs::kernel fills the beard kernel table, which this makes true rather than aspirational.

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/7617 **Author:** [@MSedgeMC](https://github.com/MSedgeMC) **Created:** 11/2/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `test/beardifier-kernel-table` --- ### 📝 Commits (2) - [`8918c86`](https://github.com/horizon-rust/horizon/commit/8918c8615e058483e0c9155650827cd3eb4fdf7d) rerun - [`86f6464`](https://github.com/horizon-rust/horizon/commit/86f6464cc43732f2cef79d0a8bc7583a79d10729) test: pin the beard kernel table to vanilla's values ### 📊 Changes **1 file changed** (+44 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `crates/horizon-core/src/density/beardifier.rs` (+44 -0) </details> ### 📄 Description `crates/horizon-core/src/density/beardifier.rs::kernel` fills the 13824-entry table `Beardifier.BEARD_KERNEL` holds. Nothing checked it: the table is inside the crate, 24³ floats, and a wrong exponent, offset or index order in it would only show up as subtly wrong terrain under every `beard_thin`/`beard_box` structure. This adds the check, with the values read off vanilla. ## Vanilla `Beardifier`'s static initialiser: ```java private static final float[] BEARD_KERNEL = Util.make(new float[13824], kernel -> { for (int zi = 0; zi < 24; zi++) for (int xi = 0; xi < 24; xi++) for (int yi = 0; yi < 24; yi++) kernel[zi * 24 * 24 + xi * 24 + yi] = (float)computeBeardContribution(xi - 12, yi - 12, zi - 12); }); private static double computeBeardContribution(final int dx, final int dy, final int dz) { return computeBeardContribution(dx, dy + 0.5, dz); } private static double computeBeardContribution(final int dx, final double dy, final int dz) { double distanceSqr = Mth.lengthSquared(dx, dy, dz); return Math.pow(Math.E, -distanceSqr / 16.0); } ``` So entry `zi * 576 + xi * 24 + yi` is `e^(-(dx² + (dy + 0.5)² + dz²) / 16)` as a `float`, with the half-block lift on `y` only. ## What Horizon had `kernel()` builds the same array with `std::array::from_fn`, mapping the index back to `(x, y, z) = ((i / 24) % 24, i % 24, i / 576)` and adding the same 0.5 to `y` before `jmath::pow(E, -squared / 16.)`. Written that way it is right — and it is, value for value — but nothing said so, and `jmath::pow`'s promise of HotSpot-exact `Math.pow` was the only thing holding the numbers up. ## Proven `cargo test -q -p horizon-core --lib the_beard_kernel`: - every one of the 13824 entries has the bits vanilla's formula gives it: the test hashes the whole table (`float` bits, 31-multiplier) and gets `b44d13f8c3d98c65` from both sides, and pins seven entries by index — `kernel[0] = 3.9172745e-12`, `kernel[7212] = 0.9844964` (the centre, where `dy` is 0.5), `kernel[13823] = 6.9435353e-11` among them. - the centre is asserted to be the table's maximum, so an index order that transposes `x` and `z` (they are symmetric in the formula, but `y` is not) cannot pass by accident. Failing without the fix: move the falloff from 16 to 12 — the one constant a reader is most likely to mistype — and the test stops on `kernel[0] is 6.175119e-13 not 3.9172745e-12` (bits `640810070` vs `747230124`); the table hash moves too. Nothing else in the suite notices. ## How the values were read The class cannot be run here: `client-26.3.jar` holds class files of version 69 and the only JDK on this machine is 21, so `Class.forName("…Beardifier")` ends in `UnsupportedClassVersionError` and the private field cannot be reflected out. The values therefore come from the initialiser's own formula, transcribed (`computeBeardContribution` above, including the `+ 0.5` in the three-argument overload), compiled and run under java 21, printing `Float.floatToIntBits` of each entry; the Rust side was compared against those bits entry by entry and agrees on all 13824. `javap -p -c` over the same jar does disassemble the class, and its bytecode is where the formula above is read from rather than taken on trust: `lambda$static$0` computes `zi * 24 * 24 + xi * 24 + yi` (three nested loops over 0..23) and calls `computeBeardContribution(xi - 12, yi - 12, zi - 12)`; the three-argument overload adds `double 0.5d` to `y` before calling `computeBeardContribution(int, double, int)`, which is `Math.pow(2.718281828459045d, -Mth.lengthSquared(dx, dy, dz) / 16.0d)`. ## Not proven - Only the table. `getBeardContribution`'s `fastInvSqrt`, the `0.8`/`0.4` weights, `getBuryContribution`'s radius of 6 and the rigid/junction loops are untouched here and were verified elsewhere. - No behaviour changes and no `port_map` row changes: the map already carries `Beardifier.computeBeardContribution inline …beardifier.rs::kernel fills the beard kernel table`, which this makes true rather than aspirational. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#7718
No description provided.