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
//! The [avar](https://learn.microsoft.com/en-us/typography/opentype/spec/avar) table

include!("../../generated/generated_avar.rs");

impl SegmentMaps {
    /// Returns true if all the axis value maps are identity maps.
    pub fn is_identity(&self) -> bool {
        self.axis_value_maps
            .iter()
            .all(|av| av.from_coordinate == av.to_coordinate)
    }
}

#[cfg(test)]
mod tests {

    use super::*;
    use font_types::F2Dot14;

    #[test]
    fn test_is_identity() {
        let mut segment_maps = SegmentMaps::default();

        assert!(segment_maps.is_identity());

        segment_maps.axis_value_maps.push(AxisValueMap {
            from_coordinate: F2Dot14::from_f32(-1.0),
            to_coordinate: F2Dot14::from_f32(-1.0),
        });

        assert!(segment_maps.is_identity());

        segment_maps.axis_value_maps.push(AxisValueMap {
            from_coordinate: F2Dot14::from_f32(0.0),
            to_coordinate: F2Dot14::from_f32(0.0),
        });
        segment_maps.axis_value_maps.push(AxisValueMap {
            from_coordinate: F2Dot14::from_f32(0.3),
            to_coordinate: F2Dot14::from_f32(0.6),
        });
        segment_maps.axis_value_maps.push(AxisValueMap {
            from_coordinate: F2Dot14::from_f32(1.0),
            to_coordinate: F2Dot14::from_f32(1.0),
        });

        assert!(!segment_maps.is_identity());
    }
}