1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#![allow(non_upper_case_globals)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#[cfg(test)]
use imgui_sys;
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,
}
}
}
impl From<ImVec2> for ImPlotRange {
fn from(from: ImVec2) -> Self {
ImPlotRange {
Min: from.x as f64,
Max: from.y as f64,
}
}
}
#[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);
let imvec = imgui_sys::ImVec2::new(33.0, 55.0);
let im_range: ImPlotRange = imvec.clone().into();
assert_eq!(im_range.Min, imvec.x as f64);
assert_eq!(im_range.Max, imvec.y as f64);
}
}