Skip to content

Commit

Permalink
Added motivity
Browse files Browse the repository at this point in the history
  • Loading branch information
Kuuuube committed Jul 25, 2024
1 parent 5c2a9be commit a41c12b
Show file tree
Hide file tree
Showing 9 changed files with 191 additions and 8 deletions.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,14 @@ Filling all arguments is not required. Some curves conditionally change what the

- `--syncspeed` (Default: `5`) The `SyncSpeed` field in rawaccel.

### Motivity

- `--growthrate` (Default: `1`) The `Growth Rate` field in rawaccel.

- `--motivity` (Default: `1.5`) The `Motivity` field in rawaccel.

- `--midpoint` (Default: `5`) The `Midpoint` field in rawaccel.

### Power

- `--scale` (Default: `1`) The `Scale` field in rawaccel.
Expand Down
1 change: 1 addition & 0 deletions src/accel_curves/mod.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
pub mod classic;
pub mod jump;
pub mod motivity;
pub mod natural;
pub mod noaccel;
pub mod power;
Expand Down
115 changes: 115 additions & 0 deletions src/accel_curves/motivity.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
use std::cmp::min;

use crate::{
types::{AccelArgs, FpRepRange},
utility::{ilogb, lerp, scalbn, LUT_RAW_DATA_CAPACITY},
};

pub fn motivity(x: f64, args: &AccelArgs) -> f64 {
if args.gain {
return motivity_gain(x, args);
} else {
return motivity_legacy(x, args);
}
}

fn motivity_legacy(x: f64, args: &AccelArgs) -> f64 {
let accel: f64 = args.gamma.exp(); //args.growth_rate.exp()
let motivity: f64 = 2.0 * args.motivity.ln();
let midpoint: f64 = args.sync_speed.ln(); //args.midpoint.ln()
let constant: f64 = -motivity / 2.0;

//operator
let denom: f64 = (accel * (midpoint - x.ln())).exp() + 1.0;
return (motivity / denom + constant).exp();
}

fn motivity_gain(x: f64, args: &AccelArgs) -> f64 {
let capacity = LUT_RAW_DATA_CAPACITY;
let velocity: bool = true;
let range = FpRepRange {
start: -3,
stop: 9,
num: 8,
};
let x_start: f64 = scalbn(1.0, range.start);

let mut sum: f64 = 0.0;
let mut a: f64 = 0.0;

let mut args_data: Vec<f64> = vec![];

let mut e: i32 = 0;
while e < range.stop - range.start {
let exp_scale: f64 = scalbn(1.0, e + range.start) / range.num as f64;
let mut i: i32 = 0;
while i < range.num {
args_data.push(make_args_data(
(i + range.num) as f64 * exp_scale,
&mut sum,
&mut a,
velocity,
&args,
));
i += 1;
}
e += 1;
}

args_data.push(make_args_data(
scalbn(1.0, range.stop),
&mut sum,
&mut a,
velocity,
&args,
));

//operator
let data = args_data;

let e: i32 = min(ilogb(x), range.stop - 1);

if e >= range.start {
let idx_int_log_part: i32 = e - range.start;
let idx_frac_lin_part: f64 = scalbn(x, -e) - 1.0;
let idx_f: f64 = range.num as f64 * (idx_int_log_part as f64 + idx_frac_lin_part);

let idx: u32 = min(idx_f as i32, range.size() - 2) as u32;

if idx < capacity - 1 {
let mut y: f64 = lerp(
data[idx as usize],
data[(idx + 1) as usize],
idx_f - idx as f64,
);
if velocity {
y /= x;
}
return y;
}
}

let mut y: f64 = data[0];
if velocity {
y /= x_start;
}
return y;
}

fn make_args_data(x: f64, sum: &mut f64, a: &mut f64, velocity: bool, args: &AccelArgs) -> f64 {
let b: f64 = x;
let partitions: i32 = 2;

let interval: f64 = (b - *a) / partitions as f64;
let mut i = 1;
while i <= partitions {
*sum += motivity_legacy(*a + i as f64 * interval, args) * interval;
i += 1;
}
*a = b;
let mut y: f64 = *sum;
if !velocity {
y /= x;
}
return y;
}
46 changes: 46 additions & 0 deletions src/args_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub fn parser(args: Vec<String>) -> Option<AccelArgs> {
"natural" => types::AccelMode::Natural,
"synchronous" => types::AccelMode::Synchronous,
"power" => types::AccelMode::Power,
"motivity" => types::AccelMode::Motivity,
_ => types::AccelMode::Noaccel,
};

Expand Down Expand Up @@ -285,6 +286,51 @@ pub fn parser(args: Vec<String>) -> Option<AccelArgs> {
}
}
}
types::AccelMode::Motivity => {
for arg in args {
let split: (&str, &str) = unwrap_option_or_continue!(arg.split_once("="));
match &split.0.to_lowercase() as &str {
"--sens" => {
accel_args.sens_multiplier = split
.1
.parse::<f64>()
.unwrap_or_else(|_| AccelArgs::default().sens_multiplier)
}
"--gain" => {
accel_args.gain = split
.1
.parse::<bool>()
.unwrap_or_else(|_| AccelArgs::default().gain)
}
"--growthrate" => {
accel_args.gamma = split
.1
.parse::<f64>()
.unwrap_or_else(|_| AccelArgs::default().gamma)
}
"--smooth" => {
accel_args.cap.x = split
.1
.parse::<f64>()
.unwrap_or_else(|_| AccelArgs::default().smooth)
}
"--motivity" => {
accel_args.limit = split
.1
.parse::<f64>()
.unwrap_or_else(|_| AccelArgs::default().motivity)
}
"--midpoint" => {
accel_args.limit = split
.1
.parse::<f64>()
.unwrap_or_else(|_| AccelArgs::default().sync_speed)
}

_ => {}
}
}
}
types::AccelMode::Noaccel => {}
}

Expand Down
5 changes: 4 additions & 1 deletion src/convert_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ pub fn sensitivity_to_velocity(sensitivity_accel_curve: Vec<Point>) -> Vec<Point
}

pub fn sensitivity_point_to_velocity(sensitivity_point: Point) -> Point {
return Point { x: sensitivity_point.x, y: sensitivity_point.x * sensitivity_point.y };
return Point {
x: sensitivity_point.x,
y: sensitivity_point.x * sensitivity_point.y,
};
}
21 changes: 14 additions & 7 deletions src/generate_curve.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,20 @@ pub fn generate_curve(args: &AccelArgs) -> CurvegenResult {
let curve_steps = match args.point_scaling {
PointScaling::Libinput | PointScaling::LibinputDebug => {
step_maker(64, 0.0, (args.dpi / 20) as f64)
},
_ => {
step_maker(args.point_count * 100, 0.0, (args.dpi / 20) as f64)
},
}
_ => step_maker(args.point_count * 100, 0.0, (args.dpi / 20) as f64),
};
let mut curve_outputs: Vec<Point> = vec![];
for curve_step in curve_steps.x_values {
let output_sens = match args.mode {
crate::types::AccelMode::Classic | crate::types::AccelMode::Linear => crate::classic(curve_step, args),
crate::types::AccelMode::Classic | crate::types::AccelMode::Linear => {
crate::classic(curve_step, args)
}
crate::types::AccelMode::Jump => crate::jump(curve_step, args),
crate::types::AccelMode::Natural => crate::natural(curve_step, args),
crate::types::AccelMode::Synchronous => crate::synchronous(curve_step, args),
crate::types::AccelMode::Power => crate::power(curve_step, args),
crate::types::AccelMode::Motivity => crate::motivity(curve_step, args),
crate::types::AccelMode::Noaccel => crate::noaccel(curve_step, args),
};
curve_outputs.push(Point {
Expand All @@ -45,7 +46,10 @@ pub fn generate_curve(args: &AccelArgs) -> CurvegenResult {
}
}

return CurvegenResult {points: curve_outputs, step_size: curve_steps.step_size};
return CurvegenResult {
points: curve_outputs,
step_size: curve_steps.step_size,
};
}

fn step_maker(step_count: u32, start: f64, end: f64) -> Steps {
Expand All @@ -55,7 +59,10 @@ fn step_maker(step_count: u32, start: f64, end: f64) -> Steps {
steps.push(utility::lerp(start, end, i as f64 * step_distance));
}
let step_size = utility::lerp(start, end, step_distance);
return Steps {x_values: steps, step_size: step_size};
return Steps {
x_values: steps,
step_size: step_size,
};
}

//ramer douglas peuker line decimation
Expand Down
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use accel_curves::classic::classic;
use accel_curves::jump::jump;
use accel_curves::motivity::motivity;
use accel_curves::natural::natural;
use accel_curves::noaccel::noaccel;
use accel_curves::power::power;
Expand Down
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use std::env;

use accel_curves::classic::classic;
use accel_curves::jump::jump;
use accel_curves::motivity::motivity;
use accel_curves::natural::natural;
use accel_curves::noaccel::noaccel;
use accel_curves::power::power;
Expand Down
1 change: 1 addition & 0 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ pub enum AccelMode {
Synchronous,
Power,
//Lookup,
Motivity,
Noaccel,
}

Expand Down

0 comments on commit a41c12b

Please sign in to comment.