Skip to content

Commit

Permalink
remove type parameters from RoundTiesEven trait
Browse files Browse the repository at this point in the history
they were indeed useless... thanks Colin
  • Loading branch information
anthrotype committed Oct 28, 2024
1 parent ba1d291 commit 66b997e
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions fontir/src/variations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ use write_fonts::{

use crate::error::VariationModelError;

/// Generic trait for rounding half-way values to the nearest even number.
/// Trait for rounding half-way values to the nearest even number.
///
/// For example, 2.5 rounds to 2.0, 3.5 rounds to 4.0, and -2.5 rounds to -2.0.
/// This is the same rounding mode as [`f64::round_ties_even`], which was
/// stabilized in Rust 1.77.0. The trait provides a generic way to apply this
/// stabilized in Rust 1.77.0. The trait provides a common way to apply this
/// to different types besides `f64` e.g. `kurbo::Vec2`.
/// We use it below in [`VariationModel`] for rounding variation deltas.
///
Expand All @@ -39,25 +39,25 @@ use crate::error::VariationModelError;
/// For more info, see:
/// - discussion in a related FontTools PR <https://github.com/fonttools/fonttools/pull/2214>
/// - 'Rounding half to even' section in <https://en.wikipedia.org/wiki/Rounding>.
pub trait RoundTiesEven<U, T = Self> {
fn round_ties_even(self) -> U;
pub trait RoundTiesEven {
fn round_ties_even(self) -> Self;
}

impl RoundTiesEven<f64> for f64 {
impl RoundTiesEven for f64 {
#[inline]
fn round_ties_even(self) -> f64 {
self.round_ties_even()
}
}

impl RoundTiesEven<f32> for f32 {
impl RoundTiesEven for f32 {
#[inline]
fn round_ties_even(self) -> f32 {
self.round_ties_even()
}
}

impl RoundTiesEven<kurbo::Vec2> for kurbo::Vec2 {
impl RoundTiesEven for kurbo::Vec2 {
#[inline]
fn round_ties_even(self) -> kurbo::Vec2 {
kurbo::Vec2::new(self.x.round_ties_even(), self.y.round_ties_even())
Expand Down Expand Up @@ -214,7 +214,7 @@ impl VariationModel {
) -> Result<Vec<(VariationRegion, Vec<V>)>, DeltaError>
where
P: Copy + Default + Sub<P, Output = V>,
V: Copy + Mul<f64, Output = V> + Sub<V, Output = V> + RoundTiesEven<V>,
V: Copy + Mul<f64, Output = V> + Sub<V, Output = V> + RoundTiesEven,
{
if point_seqs.is_empty() {
return Ok(Vec::new());
Expand Down Expand Up @@ -1419,7 +1419,7 @@ mod tests {
#[derive(Debug, Default, Copy, Clone, PartialEq)]
struct NoRoundF64(f64);

impl RoundTiesEven<NoRoundF64> for NoRoundF64 {
impl RoundTiesEven for NoRoundF64 {
#[inline]
fn round_ties_even(self) -> NoRoundF64 {
self
Expand Down

0 comments on commit 66b997e

Please sign in to comment.