Skip to content

Commit

Permalink
Cleanup (#723)
Browse files Browse the repository at this point in the history
* Fix code block end

* Clean up some clippy warnings

* Fix a few typos

* Add note about defmt and MSRV
  • Loading branch information
bugadani authored May 17, 2023
1 parent 0caad9e commit 46cfe2c
Show file tree
Hide file tree
Showing 14 changed files with 32 additions and 31 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ calculation.

* `defmt` - provide implementations of `defmt::Format` for all types where possible. [`defmt`]
is a library for logging that moves as much work as possible over to a separate logging
machine, making it especially suited to low-resource MCUs.
machine, making it especially suited to low-resource MCUs. Note that `defmt` might not work with
older versions of rustc that are otherwise supported by embedded-graphics.

## Migrating from older versions

Expand Down
5 changes: 3 additions & 2 deletions core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Applications should instead depend on [embedded-graphics] itself.

Like any other crate, embedded-graphics-core will change over time, however it will change at a
much slower rate than embedded-graphics itself, and will likely release fewer breaking changes.
This will provide more stability and compatability for the weider embedded-graphics ecosystem,
This will provide more stability and compatibility for the wider embedded-graphics ecosystem,
whilst allowing non-core features of embedded-graphics to evolve at a faster pace. The same
version of embedded-graphics-core may be used for multiple major versions of embedded-graphics.

Expand Down Expand Up @@ -62,7 +62,8 @@ a spritemap.

## Features

- `defmt` - implements `defmt::Format` for all types where this is possible.
- `defmt` - implements `defmt::Format` for all types where this is possible. Note that `defmt`
might not work with older versions of rustc that are otherwise supported by embedded-graphics-core.

[embedded-graphics]: https://docs.rs/embedded-graphics
[`Rgb888`]: pixelcolor::Rgb888
Expand Down
4 changes: 2 additions & 2 deletions core/src/geometry/size.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,8 @@ impl Size {

/// Creates a size from two corner points of a bounding box.
pub(crate) const fn from_bounding_box(corner_1: Point, corner_2: Point) -> Self {
let width = (corner_1.x - corner_2.x).abs() as u32 + 1;
let height = (corner_1.y - corner_2.y).abs() as u32 + 1;
let width = (corner_1.x - corner_2.x).unsigned_abs() + 1;
let height = (corner_1.y - corner_2.y).unsigned_abs() + 1;

Self { width, height }
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
//!
//! Like any other crate, embedded-graphics-core will change over time, however it will change at a
//! much slower rate than embedded-graphics itself, and will likely release fewer breaking changes.
//! This will provide more stability and compatability for the weider embedded-graphics ecosystem,
//! This will provide more stability and compatibility for the wider embedded-graphics ecosystem,
//! whilst allowing non-core features of embedded-graphics to evolve at a faster pace. The same
//! version of embedded-graphics-core may be used for multiple major versions of embedded-graphics.
//!
Expand Down Expand Up @@ -52,7 +52,8 @@
//!
//! # Features
//!
//! - `defmt` - implements `defmt::Format` for all types where this is possible.
//! - `defmt` - implements `defmt::Format` for all types where this is possible. Note that `defmt`
//! might not work with older versions of rustc that are otherwise supported by embedded-graphics-core.
//!
//! [embedded-graphics]: https://docs.rs/embedded-graphics
//! [`Pixel`]: drawable::Pixel
Expand Down
6 changes: 3 additions & 3 deletions core/src/primitives/rectangle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ impl Rectangle {
/// );
/// ```
pub fn resized(&self, size: Size, anchor_point: AnchorPoint) -> Self {
let mut resized = self.clone();
let mut resized = *self;
resized.resize_width_mut(size.width, anchor_point.x());
resized.resize_height_mut(size.height, anchor_point.y());

Expand All @@ -295,7 +295,7 @@ impl Rectangle {
/// );
/// ```
pub fn resized_width(&self, width: u32, anchor_x: AnchorX) -> Self {
let mut resized = self.clone();
let mut resized = *self;
resized.resize_width_mut(width, anchor_x);

resized
Expand All @@ -321,7 +321,7 @@ impl Rectangle {
/// );
/// ```
pub fn resized_height(&self, height: u32, anchor_y: AnchorY) -> Self {
let mut resized = self.clone();
let mut resized = *self;
resized.resize_height_mut(height, anchor_y);

resized
Expand Down
15 changes: 6 additions & 9 deletions src/framebuffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ pub struct Framebuffer<C, R, BO, const WIDTH: usize, const HEIGHT: usize, const
color_type: PhantomData<C>,
raw_type: PhantomData<R>,
byte_order: PhantomData<BO>,
n_assert: (),
}

impl<C, BO, const WIDTH: usize, const HEIGHT: usize, const N: usize>
Expand All @@ -70,23 +71,19 @@ where

/// Static assertion that N is correct.
// MSRV: remove N when constant generic expressions are stabilized
const CHECK_N: () = if N < Self::BUFFER_SIZE {
panic!("Invalid N: see Framebuffer documentation for more information");
};
const CHECK_N: () = assert!(
N >= Self::BUFFER_SIZE,
"Invalid N: see Framebuffer documentation for more information"
);

/// Creates a new framebuffer.
pub const fn new() -> Self {
#[allow(path_statements)]
{
// Make sure CHECK_N isn't optimized out.
Self::CHECK_N;
}

Self {
data: [0; N],
color_type: PhantomData,
raw_type: PhantomData,
byte_order: PhantomData,
n_assert: Self::CHECK_N,
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@
//!
//! * `defmt` - provide implementations of `defmt::Format` for all types where possible. [`defmt`]
//! is a library for logging that moves as much work as possible over to a separate logging
//! machine, making it especially suited to low-resource MCUs.
//! machine, making it especially suited to low-resource MCUs. Note that `defmt` might not work with
//! older versions of rustc that are otherwise supported by embedded-graphics.
//!
//! # Migrating from older versions
//!
Expand Down
2 changes: 1 addition & 1 deletion src/mock_display/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ where
mirrored
}

/// Maps a `MockDisplay<C>' to a `MockDisplay<CT>` by applying a function
/// Maps a `MockDisplay<C>` to a `MockDisplay<CT>` by applying a function
/// to each pixel.
///
/// # Examples
Expand Down
2 changes: 1 addition & 1 deletion src/mono_font/draw_target.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ impl<T: DrawTarget> DrawTarget for MonoFontDrawTarget<'_, T, Background<T::Color
self.parent.draw_iter(
colors
.into_iter()
.into_pixels(&area)
.into_pixels(area)
.filter(|Pixel(_, color)| color.is_off())
.map(|Pixel(pos, _)| Pixel(pos, foreground_color)),
)
Expand Down
10 changes: 4 additions & 6 deletions src/primitives/common/scanline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,10 @@ impl Scanline {
fn extend(&mut self, x: i32) {
if self.is_empty() {
self.x = x..x + 1;
} else {
if x < self.x.start {
self.x.start = x;
} else if x >= self.x.end {
self.x.end = x + 1;
}
} else if x < self.x.start {
self.x.start = x;
} else if x >= self.x.end {
self.x.end = x + 1;
}
}

Expand Down
1 change: 1 addition & 0 deletions src/primitives/line/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ impl Line {
let mut right = (self.start, ParallelLineType::Normal);

match stroke_offset {
#[allow(clippy::while_let_loop)]
StrokeOffset::None => loop {
if let Some((bresenham, reduce)) = it.next() {
right = (bresenham.point, reduce);
Expand Down
2 changes: 1 addition & 1 deletion src/primitives/line/styled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ impl<C: PixelColor> StyledPixelsIterator<C> {

Self {
stroke_color,
line_iter: ThickPoints::new(&primitive, stroke_width),
line_iter: ThickPoints::new(primitive, stroke_width),
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/primitives/triangle/scanline_intersections.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ impl Iterator for ScanlineIntersections {
type Item = (Scanline, PointType);

fn next(&mut self) -> Option<Self::Item> {
#[allow(clippy::manual_map)]
if let Some(internal) = self.lines.internal.try_take() {
Some((internal, self.lines.internal_type))
} else if let Some(first) = self.lines.first.try_take() {
Expand Down
4 changes: 2 additions & 2 deletions src/primitives/triangle/styled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct StyledPixelsIterator<C> {
impl<C: PixelColor> StyledPixelsIterator<C> {
pub(in crate::primitives) fn new(primitive: &Triangle, style: &PrimitiveStyle<C>) -> Self {
let mut lines_iter = ScanlineIterator::new(
&primitive,
primitive,
style.stroke_width,
StrokeOffset::from(style.stroke_alignment),
style.fill_color.is_some(),
Expand Down Expand Up @@ -97,7 +97,7 @@ impl<C: PixelColor> StyledDrawable<PrimitiveStyle<C>> for Triangle {
}

for (line, kind) in ScanlineIterator::new(
&self,
self,
style.stroke_width,
StrokeOffset::from(style.stroke_alignment),
style.fill_color.is_some(),
Expand Down

0 comments on commit 46cfe2c

Please sign in to comment.