keynergy/analysis/
combinedpos.rs1use crate::{fingers::*, Keyboard, Pos};
2use ketos_derive::{ForeignValue, FromValueClone, IntoValue, StructValue};
3use serde::{Deserialize, Serialize};
4#[derive(
5 Clone, Debug, IntoValue, FromValueClone, ForeignValue, StructValue, Serialize, Deserialize,
6)]
7pub struct CombinedPos {
10 x: f64,
11 y: f64,
12 finger: u8,
13}
14
15pub type CombinedPosGroup = Vec<CombinedPos>;
16
17impl CombinedPos {
18 pub fn from(kb: &Keyboard, p: Pos) -> Self {
19 Self {
20 x: kb.rowstagger[p.row] + p.col as f64,
21 y: kb.colstagger[p.col] + p.row as f64,
22 finger: match kb.fingers[p.row][p.col] {
23 LP => 0,
24 LR => 1,
25 LM => 2,
26 LI => 3,
27 LT => 4,
28
29 RP => 9,
30 RR => 8,
31 RM => 7,
32 RI => 6,
33 RT => 5,
34 },
35 }
36 }
37 pub fn from_group(kb: &Keyboard, p: Vec<&Pos>) -> CombinedPosGroup {
39 p.iter()
40 .map(|x| CombinedPos::from(&kb, **x))
41 .collect::<CombinedPosGroup>()
42 }
43}