Skip to content

Commit

Permalink
pdhalf_bi/uni
Browse files Browse the repository at this point in the history
this closes #164
  • Loading branch information
tomara-x committed May 23, 2024
1 parent ca8d6b7 commit 28a74d9
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,30 @@ pub fn str_to_net(op: &str) -> Net32 {
return Net32::wrap(Box::new(tap_linear(min(p0,p1), max(p0,p1))));
}
}
"pdhalf_bi" => {
return Net32::wrap(Box::new(map(|i: &Frame<f32,U2>| {
let midpoint = i[1].clamp(-1.,1.);
if i[0] < midpoint {
let leftslope = if midpoint != -1. { (midpoint + 1.).recip() } else { 0. };
leftslope * i[0]
} else {
let rightslope = if midpoint != 1. { (1. - midpoint).recip() } else { 0. };
rightslope * (i[0] - midpoint) + 0.5
}
})));
}
"pdhalf_uni" => {
return Net32::wrap(Box::new(map(|i: &Frame<f32,U2>| {
let midpoint = if i[1] >= 1. { 1. } else if i[1] <= -1. { 0. } else { (i[1] + 1.) / 2. } ;
if i[0] < midpoint {
let leftslope = if midpoint != 0. { 0.5/midpoint } else { 0. };
leftslope * i[0]
} else {
let rightslope = if midpoint != 1. { 0.5/(1. - midpoint) } else { 0. };
rightslope * (i[0] - midpoint) + 0.5
}
})));
}

// -------------------- math --------------------
"add" => {
Expand Down

0 comments on commit 28a74d9

Please sign in to comment.