pub fn render_sdf(bitmap: &BitmapGlyph, radius: usize) -> Vec<f64> {
    // Create two bitmaps, one for the pixels outside the filled area, and another for
    // values inside it.
    let mut outer_df: Vec<f64> = bitmap
        .alpha
        .iter()
        .map(|alpha| {
            if *alpha == 0 {
                f64::MAX // Perfectly outside the shape
            } else {
                // Values with alpha < 50% will be treated as progressively
                // further "outside" the shape as their alpha decreases. Alpha > 50%
                // will be treated as "inside" the shape and get a zero value here.
                0f64.max(0.5 - (*alpha as f64 / 255.0)).powi(2)
            }
        })
        .collect();
    let mut inner_df: Vec<f64> = bitmap
        .alpha
        .iter()
        .map(|alpha| {
            if *alpha == 255 {
                f64::MAX // Perfectly inside the shape
            } else {
                // Values with alpha > 50% will be treated as progressively
                // further "inside" the shape as their alpha decreases. Alpha < 50%
                // will be treated as "outside" the shape and get a zero value here.
                0f64.max((*alpha as f64 / 255.0) - 0.5).powi(2)
            }
        })
        .collect();

    let buffered_width = bitmap.width + bitmap.buffer + bitmap.buffer;
    let buffered_height = bitmap.height + bitmap.buffer + bitmap.buffer;

    // Per page 8 (422), the 2D distance transform can be obtained by computing the
    // one-dimensional distance transform along each column first and then computing
    // the transform along each row of the result. We run the transform over both the
    // outer and inner to get the respective Euclidean squared distances
    // (the math is much easier this way).
    for col in 0..buffered_width {
        dt(&mut outer_df, col, buffered_width, buffered_height);
        dt(&mut inner_df, col, buffered_width, buffered_height);
    }

    for row in 0..buffered_height {
        dt(&mut outer_df, row * buffered_width, 1, buffered_width);
        dt(&mut inner_df, row * buffered_width, 1, buffered_width);
    }

    outer_df
        .iter()
        .zip(inner_df.iter())
        .map(|(outer_df, inner_df)| {
            // Determine the euclidean distance inside or outside the alpha mask, then
            // clamp the range according to the radius so that the overall range of the
            // output field is [-1, 1] as a percentage of the radius.
            ((outer_df.sqrt() - inner_df.sqrt()) / radius as f64)
                .min(1.0)
                .max(-1.0)
        })
        .collect()
}
/// Render a signed distance field for the given bitmap, recording distances
/// out to `radius` pixels from the shape outline (the rest will be clamped).
/// The range of the output field is [-1.0, 1.0], normalised to units of `radius`.
Render a signed distance field for the given bitmap, recording distances
out to `radius` pixels from the shape outline (the rest will be clamped).
The range of the output field is [-1.0, 1.0], normalised to units of `radius`.
Render a signed distance field for the given bitmap recording distances out to ` radius ` pixels from the shape outline ( the rest will be clamped ) . The range of the output field is [ - 1 . 0 1 . 0 ] normalised to units of ` radius ` .
pub fn render_sdf(bitmap: &BitmapGlyph, radius: usize) -> Vec<f64> {
    // Create two bitmaps, one for the pixels outside the filled area, and another for
    // values inside it.
    let mut outer_df: Vec<f64> = bitmap
        .alpha
        .iter()
        .map(|alpha| {
            if *alpha == 0 {
                f64::MAX // Perfectly outside the shape
            } else {
                // Values with alpha < 50% will be treated as progressively
                // further "outside" the shape as their alpha decreases. Alpha > 50%
                // will be treated as "inside" the shape and get a zero value here.
                0f64.max(0.5 - (*alpha as f64 / 255.0)).powi(2)
            }
        })
        .collect();
    let mut inner_df: Vec<f64> = bitmap
        .alpha
        .iter()
        .map(|alpha| {
            if *alpha == 255 {
                f64::MAX // Perfectly inside the shape
            } else {
                // Values with alpha > 50% will be treated as progressively
                // further "inside" the shape as their alpha decreases. Alpha < 50%
                // will be treated as "outside" the shape and get a zero value here.
                0f64.max((*alpha as f64 / 255.0) - 0.5).powi(2)
            }
        })
        .collect();
    let buffered_width = bitmap.width + bitmap.buffer + bitmap.buffer;
    let buffered_height = bitmap.height + bitmap.buffer + bitmap.buffer;
    // Per page 8 (422), the 2D distance transform can be obtained by computing the
    // one-dimensional distance transform along each column first and then computing
    // the transform along each row of the result. We run the transform over both the
    // outer and inner to get the respective Euclidean squared distances
    // (the math is much easier this way).
    for col in 0..buffered_width {
        dt(&mut outer_df, col, buffered_width, buffered_height);
        dt(&mut inner_df, col, buffered_width, buffered_height);
    }
    for row in 0..buffered_height {
        dt(&mut outer_df, row * buffered_width, 1, buffered_width);
        dt(&mut inner_df, row * buffered_width, 1, buffered_width);
    }
    outer_df
        .iter()
        .zip(inner_df.iter())
        .map(|(outer_df, inner_df)| {
            // Determine the euclidean distance inside or outside the alpha mask, then
            // clamp the range according to the radius so that the overall range of the
            // output field is [-1, 1] as a percentage of the radius.
            ((outer_df.sqrt() - inner_df.sqrt()) / radius as f64)
                .min(1.0)
                .max(-1.0)
        })
        .collect()
}
pub fn render_sdf ( bitmap : & BitmapGlyph , radius : usize ) -> Vec < f64 > { // Create two bitmaps, one for the pixels outside the filled area, and another for // values inside it. let mut outer_df : Vec < f64 > = bitmap . alpha . iter ( ) . map ( | alpha | { if * alpha == 0 { f64 :: MAX // Perfectly outside the shape } else { // Values with alpha < 50% will be treated as progressively // further "outside" the shape as their alpha decreases. Alpha > 50% // will be treated as "inside" the shape and get a zero value here. 0f64 . max ( 0.5 - ( * alpha as f64 / 255.0 ) ) . powi ( 2 ) } } ) . collect ( ) ; let mut inner_df : Vec < f64 > = bitmap . alpha . iter ( ) . map ( | alpha | { if * alpha == 255 { f64 :: MAX // Perfectly inside the shape } else { // Values with alpha > 50% will be treated as progressively // further "inside" the shape as their alpha decreases. Alpha < 50% // will be treated as "outside" the shape and get a zero value here. 0f64 . max ( ( * alpha as f64 / 255.0 ) - 0.5 ) . powi ( 2 ) } } ) . collect ( ) ; let buffered_width = bitmap . width + bitmap . buffer + bitmap . buffer ; let buffered_height = bitmap . height + bitmap . buffer + bitmap . buffer ; // Per page 8 (422), the 2D distance transform can be obtained by computing the // one-dimensional distance transform along each column first and then computing // the transform along each row of the result. We run the transform over both the // outer and inner to get the respective Euclidean squared distances // (the math is much easier this way). for col in 0 .. buffered_width { dt ( & mut outer_df , col , buffered_width , buffered_height ) ; dt ( & mut inner_df , col , buffered_width , buffered_height ) ; } for row in 0 .. buffered_height { dt ( & mut outer_df , row * buffered_width , 1 , buffered_width ) ; dt ( & mut inner_df , row * buffered_width , 1 , buffered_width ) ; } outer_df . iter ( ) . zip ( inner_df . iter ( ) ) . map ( | ( outer_df , inner_df ) | { // Determine the euclidean distance inside or outside the alpha mask, then // clamp the range according to the radius so that the overall range of the // output field is [-1, 1] as a percentage of the radius. ( ( outer_df . sqrt ( ) - inner_df . sqrt ( ) ) / radius as f64 ) . min ( 1.0 ) . max ( - 1.0 ) } ) . collect ( ) }
Render a signed distance field for the given bitmap, recording distances
out to `radius` pixels from the shape outline (the rest will be clamped).
Render a signed distance field for the given bitmap recording distances out to ` radius ` pixels from the shape outline ( the rest will be clamped ) .
bitmap
&BitmapGlyph
radius
usize
bitmap
&BitmapGlyph
radius
usize