Buttplug sex toy control library
at dev 1.2 kB view raw
1// Buttplug Rust Source Code File - See https://buttplug.io for more info. 2// 3// Copyright 2016-2024 Nonpolynomial Labs LLC. All rights reserved. 4// 5// Licensed under the BSD 3-Clause license. See LICENSE file in the project root 6// for full license information. 7 8#[allow(dead_code)] 9pub fn calculate_distance(duration: u32, mut speed: f64) -> f64 { 10 if speed <= 0f64 { 11 return 0f64; 12 } 13 14 if speed > 1f64 { 15 speed = 1f64; 16 } 17 18 let mil = (speed / 250f64).powf(-0.95); 19 let diff = mil - (duration as f64); 20 if diff.abs() < 0.001 { 21 0f64 22 } else { 23 ((90f64 - (diff / mil * 90f64)) / 100f64) 24 .min(1f64) 25 .max(0f64) 26 } 27} 28 29pub fn calculate_speed(mut distance: f64, duration: u32) -> f64 { 30 if distance < 0f64 { 31 return 0f64; 32 } 33 34 if distance > 1f64 { 35 distance = 1f64; 36 } 37 38 let scalar = ((duration as f64 * 90f64) / (distance * 100f64)).powf(-1.05); 39 40 250f64 * scalar 41} 42 43pub fn calculate_duration(mut distance: f64, mut speed: f64) -> u32 { 44 if distance <= 0f64 || speed <= 0f64 { 45 return 0; 46 } 47 48 if distance > 1f64 { 49 distance = 1f64; 50 } 51 52 if speed > 1f64 { 53 speed = 1f64; 54 } 55 56 let mil = (speed / 250f64).powf(-0.95); 57 (mil / (90f64 / (distance * 100f64))) as u32 58}