plotters/coord/
mod.rs

1/*!
2
3One of the key features of Plotters is flexible coordinate system abstraction and this module
4provides all the abstraction used for the coordinate abstarction of Plotters.
5
6Generally speaking, the coordinate system in Plotters is responsible for mapping logic data points into
7pixel 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
9about the coordinate values, thus we are able to extend Plotters's coordinate system to other types of coorindate
10easily.
11
12Another important trait is [ReverseCoordTranslate](trait.ReverseCoordTranslate.html). This trait allows some coordinate
13retrieve the logic value based on the pixel-based backend coordinate. This is particularly interesting for interactive plots.
14
15Plotters contains a set of pre-defined coordinate specifications that fulfills the most common use. See documentation for
16module [types](types/index.html) for details about the basic 1D types.
17
18The coordinate system also can be tweaked by the coordinate combinators, such as logarithmic coordinate, nested coordinate, etc.
19See documentation for module [combinators](combinators/index.html)  for details.
20
21Currently 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
27use plotters_backend::BackendCoord;
28
29pub 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.
36pub mod combinators {
37    pub use super::ranged1d::combinators::*;
38}
39
40/// The primitive types supported by Plotters coordinate system
41pub mod types {
42    pub use super::ranged1d::types::*;
43}
44
45mod ranged2d;
46pub mod ranged3d;
47
48pub mod cartesian {
49    pub use super::ranged2d::cartesian::{Cartesian2d, MeshLine};
50    pub use super::ranged3d::Cartesian3d;
51}
52
53mod translate;
54pub use translate::{CoordTranslate, ReverseCoordTranslate};
55
56/// The coordinate translation that only impose shift
57#[derive(Debug, Clone)]
58pub struct Shift(pub BackendCoord);
59
60impl CoordTranslate for Shift {
61    type From = BackendCoord;
62    fn translate(&self, from: &Self::From) -> BackendCoord {
63        (from.0 + (self.0).0, from.1 + (self.0).1)
64    }
65}
66
67impl ReverseCoordTranslate for Shift {
68    fn reverse_translate(&self, input: BackendCoord) -> Option<BackendCoord> {
69        Some((input.0 - (self.0).0, input.1 - (self.0).1))
70    }
71}