Add converting from [f64; 2], (f64, f64), [..] for ImPlotRange

#15
This commit is contained in:
Ilya Averyanov 2021-03-06 02:09:41 +03:00
parent bfcaad3ad1
commit 672bbc0052

View file

@ -6,4 +6,55 @@
#[cfg(test)]
use imgui_sys as _;
use std::ops::Range;
include!("bindings.rs");
impl From<Range<f64>> for ImPlotRange {
fn from(from: Range<f64>) -> Self {
ImPlotRange {
Min: from.start,
Max: from.end,
}
}
}
impl From<[f64; 2]> for ImPlotRange {
fn from(from: [f64; 2]) -> Self {
ImPlotRange {
Min: from[0],
Max: from[1],
}
}
}
impl From<(f64, f64)> for ImPlotRange {
fn from(from: (f64, f64)) -> Self {
ImPlotRange {
Min: from.0,
Max: from.1,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_plot_range_from_range() {
let r = 5.0..7.0;
let im_range: ImPlotRange = r.clone().into();
assert_eq!(im_range.Min, r.start);
assert_eq!(im_range.Max, r.end);
let arr = [7.0, 8.0];
let im_range: ImPlotRange = arr.clone().into();
assert_eq!(im_range.Min, arr[0]);
assert_eq!(im_range.Max, arr[1]);
let tuple = (12.0, 19.0);
let im_range: ImPlotRange = tuple.clone().into();
assert_eq!(im_range.Min, tuple.0);
assert_eq!(im_range.Max, tuple.1);
}
}