dariogoetz / keyboard_layout_optimizer

A keyboard layout optimizer supporting multiple layers. Implemented in Rust.
https://dariogoetz.github.io/keyboard_layout_optimizer/
GNU General Public License v3.0
86 stars 13 forks source link

Why is euclidian distance being distorted? #38

Closed Glitchy-Tozier closed 2 years ago

Glitchy-Tozier commented 2 years ago

In two places, we calculate the euclidian distance. However, in both implementations, we distort the result by reducing the horizontal distance. Why is that?

impl MatrixPosition {
    /// Euclidean distance to another row/column position on the keyboard
    pub fn distance(&self, other: &MatrixPosition) -> f64 {
        (0.5 * (self.0 as f64 - other.0 as f64).powi(2) + (self.1 as f64 - other.1 as f64).powi(2))
            .sqrt()
    }
}
impl Position {
    /// Euclidean distance to another row/column position on the keyboard
    pub fn distance(&self, other: &Position) -> f64 {
        (0.5 * (self.0 - other.0).powi(2) + (self.1 - other.1).powi(2)).sqrt()
    }
}
dariogoetz commented 2 years ago

That is, indeed, a very good question... Probably a mistake.

Glitchy-Tozier commented 2 years ago

Actually … I just checked and it turned out these two methods aren't even used anywhere. At all. They're not even mentioned in any commented-out code.

Should I fix them or remove them?

dariogoetz commented 2 years ago

I guess they can be removed, then. Thanks for finding and removing :)