Struct embedded_graphics::primitives::triangle::Triangle

source ·
pub struct Triangle<C: PixelColor> {
    pub p1: Coord,
    pub p2: Coord,
    pub p3: Coord,
    pub style: Style<C>,
}
Expand description

Triangle primitive

§Examples

The macro examples make for more concise code.

§Create some triangles with different styles

use embedded_graphics::prelude::*;
use embedded_graphics::primitives::Triangle;

// Default triangle with no styling
let t1 = Triangle::new(Coord::new(10, 20), Coord::new(30, 40), Coord::new(50, 60));

// Triangle with styled stroke from (50, 20) to (60, 35)
let t2 = Triangle::new(Coord::new(50, 20), Coord::new(60, 35), Coord::new(70, 80))
    .stroke(Some(5u8));

// Triangle with translation applied
let t3 = Triangle::new(Coord::new(50, 20), Coord::new(60, 35), Coord::new(70, 80))
    .translate(Coord::new(65, 35));

display.draw(t1);
display.draw(t2);
display.draw(t3);

Fields§

§p1: Coord

First point of the triangle

§p2: Coord

Second point of the triangle

§p3: Coord

Third point of the triangle

§style: Style<C>

Object style

Implementations§

source§

impl<C> Triangle<C>
where C: PixelColor,

source

pub fn new(p1: Coord, p2: Coord, p3: Coord) -> Self

Create a new triangle with a given style

Trait Implementations§

source§

impl<C: Clone + PixelColor> Clone for Triangle<C>

source§

fn clone(&self) -> Triangle<C>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<C: Debug + PixelColor> Debug for Triangle<C>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<C> Dimensions for Triangle<C>
where C: PixelColor,

source§

fn top_left(&self) -> Coord

Get the top left corner of the bounding box for an object
source§

fn bottom_right(&self) -> Coord

Get the bottom right corner of the bounding box for an object
source§

fn size(&self) -> UnsignedCoord

Get the width and height for an object
source§

impl<'a, C> IntoIterator for &'a Triangle<C>
where C: PixelColor,

§

type Item = Pixel<C>

The type of the elements being iterated over.
§

type IntoIter = TriangleIterator<C>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<C> IntoIterator for Triangle<C>
where C: PixelColor,

§

type Item = Pixel<C>

The type of the elements being iterated over.
§

type IntoIter = TriangleIterator<C>

Which kind of iterator are we turning this into?
source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
source§

impl<C> Transform for Triangle<C>
where C: PixelColor,

source§

fn translate(&self, by: Coord) -> Self

Translate the triangle from its current position to a new position by (x, y) pixels, returning a new Triangle. For a mutating transform, see translate_mut.

let tri = Triangle::new(Coord::new(5, 10), Coord::new(15, 20), Coord::new(8, 15))
let moved = tri.translate(Coord::new(10, 10));

assert_eq!(moved.p1, Coord::new(15, 20));
assert_eq!(moved.p2, Coord::new(25, 30));
assert_eq!(moved.p3, Coord::new(18, 25));
source§

fn translate_mut(&mut self, by: Coord) -> &mut Self

Translate the triangle from its current position to a new position by (x, y) pixels.

let mut tri = Triangle::new(Coord::new(5, 10), Coord::new(15, 20), Coord::new(10, 15))
tri.translate_mut(Coord::new(10, 10));

assert_eq!(tri.p1, Coord::new(15, 20));
assert_eq!(tri.p2, Coord::new(25, 30));
assert_eq!(tri.p3, Coord::new(20, 25));
source§

impl<C> WithStyle<C> for Triangle<C>
where C: PixelColor,

source§

fn style(self, style: Style<C>) -> Self

Add a complete style to the object
source§

fn stroke(self, color: Option<C>) -> Self

Set the stroke colour for the object Read more
source§

fn stroke_width(self, width: u8) -> Self

Set the stroke width for the object Read more
source§

fn fill(self, color: Option<C>) -> Self

Set the fill property of the object’s style Read more
source§

impl<C: Copy + PixelColor> Copy for Triangle<C>

source§

impl<C> Drawable for Triangle<C>
where C: PixelColor,

source§

impl<C> Primitive for Triangle<C>
where C: PixelColor,

Auto Trait Implementations§

§

impl<C> Freeze for Triangle<C>
where C: Freeze,

§

impl<C> RefUnwindSafe for Triangle<C>
where C: RefUnwindSafe,

§

impl<C> Send for Triangle<C>
where C: Send,

§

impl<C> Sync for Triangle<C>
where C: Sync,

§

impl<C> Unpin for Triangle<C>
where C: Unpin,

§

impl<C> UnwindSafe for Triangle<C>
where C: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Same for T

§

type Output = T

Should always be Self
source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
source§

unsafe fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.