d3_geo_rs/projection/transform/
st.rs

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
use geo::CoordFloat;
use geo_types::Coord;

use crate::Transform;

/// An inner type of [`ScaleTranslateRotate`](super::ScaleTranslateRotate).
///
/// Simplification when only  translate is needed.
#[derive(Clone, Debug)]
pub struct St<T> {
    k: T,
    dx: T,
    dy: T,
    sx: T,
    sy: T,
}

impl<T> St<T>
where
    T: Copy,
{
    /// Constructor.
    #[inline]
    pub const fn new(k: &T, dx: &T, dy: &T, sx: &T, sy: &T) -> Self {
        Self {
            k: *k,
            dx: *dx,
            dy: *dy,
            sx: *sx,
            sy: *sy,
        }
    }
}

impl<T> Transform for St<T>
where
    T: CoordFloat,
{
    type T = T;

    #[inline]
    fn transform(&self, p: &Coord<T>) -> Coord<T> {
        let x = p.x * self.sx;
        let y = p.y * self.sy;
        Coord {
            x: self.dx + self.k * x,
            y: self.dy - self.k * y,
        }
    }

    #[inline]
    fn invert(&self, p: &Coord<T>) -> Coord<T> {
        Coord {
            x: (p.x - self.dx) / self.k * self.sx,
            y: (self.dy - p.y) / self.k * self.sy,
        }
    }
}