use crate::problem::Problem;
pub fn scale_value(
original_value: f64,
min_original: f64,
max_original: f64,
min_scaled: f64,
max_scaled: f64,
) -> f64 {
((original_value - min_original) / (max_original - min_original)) * (max_scaled - min_scaled)
+ min_scaled
}
pub fn create_matrix(x_len: usize, y_len: usize) -> Vec<Vec<super::CordinateValue>> {
vec![vec![super::CordinateValue::Empty; x_len]; y_len]
}
pub fn pick_origo_when_middle(
def_start: usize,
max_value: f64,
min_value: f64,
matrix_len: usize,
) -> Option<(usize, usize)> {
let y_float = (max_value / (max_value - min_value)) * (matrix_len as f64 - 1.0);
let y_index = y_float.floor() as usize;
if y_index >= matrix_len {
return None;
}
Some((def_start, y_index))
}
pub fn pick_origo_when_x(
problem: Problem,
x_value: f64,
min_value: f64,
max_value: f64,
min_scaled: f64,
max_scaled: f64,
) -> (usize, usize) {
let raw_y = problem.solve(Some(x_value));
let y = scale_value(raw_y, min_value, max_value, min_scaled, max_scaled) as usize;
(x_value as usize, y)
}