diff --git a/src/lib.rs b/src/lib.rs index fc80ba3..f82dc65 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -2323,13 +2323,11 @@ impl<'a> Face<'a> { for (i, var_axis) in self.variation_axes().into_iter().enumerate() { if var_axis.tag == axis { self.coordinates.data[i] = var_axis.normalized_value(value); - } - } - // TODO: optimize - if let Some(avar) = self.tables.avar { - // Ignore error. - let _ = avar.map_coordinates(self.coordinates.as_mut_slice()); + if let Some(avar) = self.tables.avar { + let _ = avar.map_coordinate(self.coordinates.as_mut_slice(), i); + } + } } Some(()) diff --git a/src/tables/avar.rs b/src/tables/avar.rs index 3925811..0549387 100644 --- a/src/tables/avar.rs +++ b/src/tables/avar.rs @@ -114,13 +114,22 @@ impl<'a> Table<'a> { }) } - /// Maps coordinates. - pub fn map_coordinates(&self, coordinates: &mut [NormalizedCoordinate]) -> Option<()> { + /// Maps a single coordinate + pub fn map_coordinate( + &self, + coordinates: &mut [NormalizedCoordinate], + coordinate_index: usize, + ) -> Option<()> { if usize::from(self.segment_maps.count) != coordinates.len() { return None; } - for (map, coord) in self.segment_maps.into_iter().zip(coordinates) { + if let Some((map, coord)) = self + .segment_maps + .into_iter() + .zip(coordinates) + .nth(coordinate_index) + { *coord = NormalizedCoordinate::from(map_value(&map, coord.0)?); }