Skip to content

Commit

Permalink
[native] Start porting all jni code to rust #10
Browse files Browse the repository at this point in the history
The first parts of ProximityInfo have been fully ported.
  • Loading branch information
nyancrimew committed Aug 2, 2022
1 parent dbd0434 commit 4769d95
Show file tree
Hide file tree
Showing 9 changed files with 621 additions and 0 deletions.
9 changes: 9 additions & 0 deletions native/rust/src/defines.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// TODO: move constants to more reasonable locations in the future
// constants from defines.h

/// The max number of the keys in one keyboard layout
pub const MAX_KEY_COUNT_IN_A_KEYBOARD: usize = 64;

pub const KEYCODE_SPACE: char = ' ';
pub const KEYCODE_SINGLE_QUOTE: char = '\'';
pub const KEYCODE_HYPHEN_MINUS: char = '-';
3 changes: 3 additions & 0 deletions native/rust/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
mod defines;
mod emojisearch;
mod expect_droid;
mod log;
mod math;
mod suggest;
14 changes: 14 additions & 0 deletions native/rust/src/math.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#[inline]
pub fn square_float(x: f32) -> f32 {
x * x
}

#[inline]
pub fn get_distance_int(x1: i32, y1: i32, x2: i32, y2: i32) -> i32 {
((x1 - x2) as f32).hypot((y1 - y2) as f32) as i32
}

#[inline]
pub fn get_distance(x1: f32, y1: f32, x2: f32, y2: f32) -> i32 {
(x1 - x2).hypot(y1 - y2) as i32
}
2 changes: 2 additions & 0 deletions native/rust/src/suggest.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
mod core;
mod entrypoints;
1 change: 1 addition & 0 deletions native/rust/src/suggest/core.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub(crate) mod layout;
2 changes: 2 additions & 0 deletions native/rust/src/suggest/core/layout.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pub(crate) mod proximity_info;
mod proximity_info_params;
Loading

0 comments on commit 4769d95

Please sign in to comment.