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;
46/// Ranged coordinates in 3d.
47pub mod ranged3d;
48
49/// Groups Cartesian ranged coordinates in 2d and 3d.
50pub mod cartesian {
51 pub use super::ranged2d::cartesian::{Cartesian2d, MeshLine};
52 pub use super::ranged3d::Cartesian3d;
53}
54
55mod translate;
56pub use translate::{CoordTranslate, ReverseCoordTranslate};
57
58/// The coordinate translation that only impose shift
59#[derive(Debug, Clone)]
60pub struct Shift(pub BackendCoord);
61
62impl 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
69impl 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