refactor: 配置面板改造为顶部固定栏 + 压力归一化优化

This commit is contained in:
lenn
2026-07-06 14:07:23 +08:00
parent 5264f0c247
commit c4bccc1747
4 changed files with 194 additions and 44 deletions

View File

@@ -1246,11 +1246,11 @@ fn build_hand_palm_dot_instances(
for row in 0..chip.rows {
for col in 0..chip.cols {
let index = (row * chip.cols + col) as usize;
let offset = match chip_index {
0 => HAND_PALM_HORIZONTAL_OFFSET,
_ => HAND_PALM_VERTICAL_OFFSET,
};
let index = hand_palm_pressure_index(chip_index, row, col, chip.rows, chip.cols);
let [normalized, display_value] =
sample_pressure_at(pressure, offset + index, index);
@@ -1278,6 +1278,20 @@ fn build_hand_palm_dot_instances(
instances
}
fn hand_palm_pressure_index(
chip_index: usize,
row: u32,
col: u32,
rows: u32,
cols: u32,
) -> usize {
if chip_index == 0 {
(col * rows + (rows - 1 - row)) as usize
} else {
(row * cols + col) as usize
}
}
fn sample_pressure_at(pressure: &[[f32; 2]], index: usize, fallback_index: usize) -> [f32; 2] {
pressure
.get(index)
@@ -1409,3 +1423,24 @@ impl GlyphInstance {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn hand_palm_horizontal_uses_column_major_pressure_order() {
assert_eq!(hand_palm_pressure_index(0, 0, 0, 5, 14), 4);
assert_eq!(hand_palm_pressure_index(0, 1, 0, 5, 14), 3);
assert_eq!(hand_palm_pressure_index(0, 0, 1, 5, 14), 9);
assert_eq!(hand_palm_pressure_index(0, 4, 13, 5, 14), 65);
}
#[test]
fn hand_palm_vertical_keeps_row_major_pressure_order() {
assert_eq!(hand_palm_pressure_index(1, 0, 0, 11, 4), 0);
assert_eq!(hand_palm_pressure_index(1, 0, 1, 11, 4), 1);
assert_eq!(hand_palm_pressure_index(1, 1, 0, 11, 4), 4);
assert_eq!(hand_palm_pressure_index(1, 10, 3, 11, 4), 43);
}
}