[][src]Struct embedded_graphics::primitives::triangle::Triangle

pub struct Triangle {
    pub vertices: [Point; 3],
}

Triangle primitive

Examples

Create some triangles with different styles

use embedded_graphics::{
    pixelcolor::Rgb565, prelude::*, primitives::Triangle, style::PrimitiveStyle,
};

// Triangle with red 1 px wide stroke
Triangle::new(Point::new(40, 20), Point::new(50, 25), Point::new(60, 60))
    .into_styled(PrimitiveStyle::with_stroke(Rgb565::RED, 1))
    .draw(&mut display)?;

// Triangle with translation applied
Triangle::new(Point::new(40, 20), Point::new(50, 25), Point::new(60, 60))
    .translate(Point::new(-10, -20))
    .into_styled(PrimitiveStyle::with_stroke(Rgb565::GREEN, 1))
    .draw(&mut display)?;

Create a triangle from a slice

A triangle can be created from a &[Point] slice. If the slice is not exactly 3 elements long, the from_slice method will panic.

use embedded_graphics::{geometry::Point, primitives::Triangle};

let p1 = Point::new(5, 10);
let p2 = Point::new(15, 25);
let p3 = Point::new(5, 25);

let tri = Triangle::from_slice(&[p1, p2, p3]);

Fields

vertices: [Point; 3]

The vertices of the triangle.

Implementations

impl Triangle[src]

pub const fn new(vertex1: Point, vertex2: Point, vertex3: Point) -> Self[src]

Create a new triangle with the given vertices.

pub fn from_slice(vertices: &[Point]) -> Self[src]

Creates a new triangle from a Point slice.

Panics

This method will panic if the given slice is not exactly 3 items long.

Trait Implementations

impl Clone for Triangle[src]

impl ContainsPoint for Triangle[src]

impl Copy for Triangle[src]

impl Debug for Triangle[src]

impl Default for Triangle[src]

impl Dimensions for Triangle[src]

impl Eq for Triangle[src]

impl Hash for Triangle[src]

impl Ord for Triangle[src]

impl PartialEq<Triangle> for Triangle[src]

impl PartialOrd<Triangle> for Triangle[src]

impl PointsIter for Triangle[src]

type Iter = Points

Iterator over all points inside the primitive.

impl Primitive for Triangle[src]

impl StructuralEq for Triangle[src]

impl StructuralPartialEq for Triangle[src]

impl Transform for Triangle[src]

pub fn translate(&self, by: Point) -> Self[src]

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(Point::new(5, 10), Point::new(15, 20), Point::new(8, 15));
let moved = tri.translate(Point::new(10, 10));

assert_eq!(
    moved,
    Triangle::new(Point::new(15, 20), Point::new(25, 30), Point::new(18, 25))
);

pub fn translate_mut(&mut self, by: Point) -> &mut Self[src]

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

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

assert_eq!(
    tri,
    Triangle::new(Point::new(15, 20), Point::new(25, 30), Point::new(20, 25))
)

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<Src, Dst> LosslessTryInto<Dst> for Src where
    Dst: LosslessTryFrom<Src>, 
[src]

impl<Src, Dst> LossyInto<Dst> for Src where
    Dst: LossyFrom<Src>, 
[src]

impl<T> Pointable for T

type Init = T

The type for initializers.

impl<T> Same<T> for T

type Output = T

Should always be Self

impl<T> Scalar for T where
    T: PartialEq<T> + Copy + Any + Debug
[src]

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

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,