1 | /*! |
2 | |
3 | One of the key features of Plotters is flexible coordinate system abstraction and this module |
4 | provides all the abstraction used for the coordinate abstarction of Plotters. |
5 | |
6 | Generally speaking, the coordinate system in Plotters is responsible for mapping logic data points into |
7 | pixel based backend coordinate. This task is abstracted by a simple trait called |
8 | [CoordTranslate](trait.CoordTranslate.html). Please note `CoordTranslate` trait doesn't assume any property |
9 | about the coordinate values, thus we are able to extend Plotters's coordinate system to other types of coorindate |
10 | easily. |
11 | |
12 | Another important trait is [ReverseCoordTranslate](trait.ReverseCoordTranslate.html). This trait allows some coordinate |
13 | retrieve the logic value based on the pixel-based backend coordinate. This is particularly interesting for interactive plots. |
14 | |
15 | Plotters contains a set of pre-defined coordinate specifications that fulfills the most common use. See documentation for |
16 | module [types](types/index.html) for details about the basic 1D types. |
17 | |
18 | The coordinate system also can be tweaked by the coordinate combinators, such as logarithmic coordinate, nested coordinate, etc. |
19 | See documentation for module [combinators](combinators/index.html) for details. |
20 | |
21 | Currently we support the following 2D coordinate system: |
22 | |
23 | - 2-dimensional Cartesian Coordinate: This is done by the combinator [Cartesian2d](cartesian/struct.Cartesian2d.html). |
24 | |
25 | */ |
26 | |
27 | use plotters_backend::BackendCoord; |
28 | |
29 | pub mod ranged1d; |
30 | |
31 | /// The coordinate combinators |
32 | /// |
33 | /// Coordinate combinators are very important part of Plotters' coordinate system. |
34 | /// The combinator is more about the "combinator pattern", which takes one or more coordinate specification |
35 | /// and transform them into a new coordinate specification. |
36 | pub mod combinators { |
37 | pub use super::ranged1d::combinators::*; |
38 | } |
39 | |
40 | /// The primitive types supported by Plotters coordinate system |
41 | pub mod types { |
42 | pub use super::ranged1d::types::*; |
43 | } |
44 | |
45 | mod ranged2d; |
46 | /// Ranged coordinates in 3d. |
47 | pub mod ranged3d; |
48 | |
49 | /// Groups Cartesian ranged coordinates in 2d and 3d. |
50 | pub mod cartesian { |
51 | pub use super::ranged2d::cartesian::{Cartesian2d, MeshLine}; |
52 | pub use super::ranged3d::Cartesian3d; |
53 | } |
54 | |
55 | mod translate; |
56 | pub use translate::{CoordTranslate, ReverseCoordTranslate}; |
57 | |
58 | /// The coordinate translation that only impose shift |
59 | #[derive(Debug, Clone)] |
60 | pub struct Shift(pub BackendCoord); |
61 | |
62 | impl CoordTranslate for Shift { |
63 | type From = BackendCoord; |
64 | fn translate(&self, from: &Self::From) -> BackendCoord { |
65 | (from.0 + (self.0).0, from.1 + (self.0).1) |
66 | } |
67 | } |
68 | |
69 | impl ReverseCoordTranslate for Shift { |
70 | fn reverse_translate(&self, input: BackendCoord) -> Option<BackendCoord> { |
71 | Some((input.0 - (self.0).0, input.1 - (self.0).1)) |
72 | } |
73 | } |
74 | |