plotters_unstable/coord/translate.rs
1use plotters_backend::BackendCoord;
2use std::ops::Deref;
3
4/// The trait that translates some customized object to the backend coordinate
5pub trait CoordTranslate {
6 type From;
7
8 /// Translate the guest coordinate to the guest coordinate
9 fn translate(&self, from: &Self::From) -> BackendCoord;
10}
11
12impl<C, T> CoordTranslate for T
13where
14 C: CoordTranslate,
15 T: Deref<Target = C>,
16{
17 type From = C::From;
18 fn translate(&self, from: &Self::From) -> BackendCoord {
19 self.deref().translate(from)
20 }
21}
22
23/// The trait indicates that the coordinate system supports reverse transform
24/// This is useful when we need an interactive plot, thus we need to map the event
25/// from the backend coordinate to the logical coordinate
26pub trait ReverseCoordTranslate: CoordTranslate {
27 /// Reverse translate the coordinate from the drawing coordinate to the
28 /// logic coordinate.
29 /// Note: the return value is an option, because it's possible that the drawing
30 /// coordinate isn't able to be represented in te guest coordinate system
31 fn reverse_translate(&self, input: BackendCoord) -> Option<Self::From>;
32}