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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
use crate::drawing::backend::BackendCoord;
#[cfg(feature = "chrono")]
mod datetime;
mod logarithmic;
mod numeric;
mod ranged;
#[cfg(feature = "chrono")]
pub use datetime::{RangedDate, RangedDateTime};
pub use numeric::{
RangedCoordf32, RangedCoordf64, RangedCoordi32, RangedCoordi64, RangedCoordu32, RangedCoordu64,
};
pub use ranged::{AsRangedCoord, DescreteRanged, MeshLine, Ranged, RangedCoord, ReversableRanged};
pub use logarithmic::{LogCoord, LogRange, LogScalable};
pub trait CoordTranslate {
type From;
fn translate(&self, from: &Self::From) -> BackendCoord;
}
pub trait ReverseCoordTranslate: CoordTranslate {
fn reverse_translate(&self, input: BackendCoord) -> Option<Self::From>;
}
#[derive(Debug, Clone)]
pub struct Shift(pub BackendCoord);
impl CoordTranslate for Shift {
type From = BackendCoord;
fn translate(&self, from: &Self::From) -> BackendCoord {
(from.0 + (self.0).0, from.1 + (self.0).1)
}
}
impl ReverseCoordTranslate for Shift {
fn reverse_translate(&self, input: BackendCoord) -> Option<BackendCoord> {
Some((input.0 - (self.0).0, input.1 - (self.0).1))
}
}
pub struct ShiftAndTrans<T: CoordTranslate>(Shift, T);
impl<T: CoordTranslate> CoordTranslate for ShiftAndTrans<T> {
type From = T::From;
fn translate(&self, from: &Self::From) -> BackendCoord {
let temp = self.1.translate(from);
self.0.translate(&temp)
}
}
impl<T: ReverseCoordTranslate> ReverseCoordTranslate for ShiftAndTrans<T> {
fn reverse_translate(&self, input: BackendCoord) -> Option<T::From> {
Some(self.1.reverse_translate(self.0.reverse_translate(input)?)?)
}
}