Skip to content

Commit e5b7520

Browse files
committed
Minor adjustments and use iter_mut().
1 parent 0b4d0c2 commit e5b7520

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

sdf_glyph_renderer/src/core.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl BitmapGlyph {
2525
/// bitmap but still need to buffer it (what you expect from most font renderers, for example),
2626
/// use [`Self::from_unbuffered()`] instead.
2727
///
28-
/// The dimensions provided is expected to describe the input data.
28+
/// The dimensions provided are expected to describe the input data.
2929
pub fn new(
3030
alpha: Vec<u8>,
3131
width: usize,
@@ -153,9 +153,7 @@ impl BitmapGlyph {
153153
// Determine the euclidean distance inside or outside the alpha mask, then
154154
// clamp the range according to the radius so that the overall range of the
155155
// output field is [-1, 1] as a percentage of the radius.
156-
((outer_df.sqrt() - inner_df.sqrt()) / radius as f64)
157-
.min(1.0)
158-
.max(-1.0)
156+
((outer_df.sqrt() - inner_df.sqrt()) / radius as f64).clamp(-1.0, 1.0)
159157
})
160158
.collect()
161159
}
@@ -166,10 +164,10 @@ impl BitmapGlyph {
166164
/// further discussion of the math behind this.
167165
fn dt(grid: &mut [f64], offset: usize, step_by: usize, size: usize) {
168166
// For our purposes, f is a one-dimensional slice of the grid
169-
let mut f = vec![0.0; size];
167+
let mut f = vec![0f64; size];
170168
let mut src = offset;
171-
for dst in 0..size {
172-
f[dst] = grid[src];
169+
for dst in f.iter_mut() {
170+
*dst = grid[src];
173171
src += step_by;
174172
}
175173

@@ -217,7 +215,7 @@ fn dt(grid: &mut [f64], offset: usize, step_by: usize, size: usize) {
217215

218216
/// Compresses a `Vec<f64>` into a `Vec<u8>` for efficiency.
219217
///
220-
/// The highest `cutoff` percent of values in the range (0-255) will be used to encode
218+
/// The highest `cutoff` percentage of values in the range (0-255) will be used to encode
221219
/// negative values (points inside the glyph). This can be tuned based on the intended
222220
/// application.
223221
///
@@ -278,7 +276,7 @@ mod tests {
278276
#[test]
279277
#[allow(clippy::unreadable_literal)]
280278
fn test_nontrivial_glyph() {
281-
// Tests an nontrivial glyph. In this case, we are using the actual bitmap and metrics
279+
// Tests a nontrivial glyph. In this case, we are using the actual bitmap and metrics
282280
// for how Open Sans Light encodes an ampersand (0x25), plus a 3px buffer we added.
283281
let alpha = Vec::from(include!("../fixtures/glyph_alpha.json"));
284282
let sdf_data_f64 = Vec::from(include!("../fixtures/glyph_sdf_f64.json"));

0 commit comments

Comments
 (0)