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