/* This Source Code Form is subject to the terms of the Mozilla Public *License,v.2.0.IfacopyoftheMPLwasnotdistributedwiththis
* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
/// An alias of the computed timing function. pubtype TimingFunction = ComputedTimingFunction;
impl ComputedTimingFunction { fn calculate_step_output(
steps: i32,
pos: StepPosition,
progress: f64,
before_flag: BeforeFlag,
) -> f64 { // User specified values can cause overflow (bug 1706157). Increments/decrements // should be gravefully handled. letmut current_step = (progress * (steps as f64)).floor() as i32;
// Increment current step if it is jump-start or start. if pos == StepPosition::Start ||
pos == StepPosition::JumpStart ||
pos == StepPosition::JumpBoth
{
current_step = current_step.checked_add(1).unwrap_or(current_step);
}
// If the "before flag" is set and we are at a transition point, // drop back a step if before_flag == BeforeFlag::Set &&
(progress * steps as f64).rem_euclid(1.0).approx_eq(&0.0)
{
current_step = current_step.checked_sub(1).unwrap_or(current_step);
}
// We should not produce a result outside [0, 1] unless we have an // input outside that range. This takes care of steps that would otherwise // occur at boundaries. if progress >= 0.0 && current_step < 0 {
current_step = 0;
}
// |jumps| should always be in [1, i32::MAX]. let jumps = if pos == StepPosition::JumpBoth {
steps.checked_add(1).unwrap_or(steps)
} elseif pos == StepPosition::JumpNone {
steps.checked_sub(1).unwrap_or(steps)
} else {
steps
};
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.