logo
pub struct Triangle {
    pub p1: Point,
    pub p2: Point,
    pub p3: Point,
}
Expand description

Triangle primitive

Examples

The macro examples make for more concise code.

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(50, 20), Point::new(60, 35), Point::new(70, 80))
    .into_styled(PrimitiveStyle::with_stroke(Rgb565::RED, 1))
    .draw(&mut display)?;

// Triangle with translation applied
Triangle::new(Point::new(50, 20), Point::new(60, 35), Point::new(70, 80))
    .translate(Point::new(65, 35))
    .into_styled(PrimitiveStyle::with_stroke(Rgb565::GREEN, 1))
    .draw(&mut display)?;

Create a triangle from an array of points

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);

// Owned
let tri = Triangle::from_points([p1, p2, p3]);

// Or borrowed
let tri_ref = Triangle::from_points(&[p1, p2, p3]);

Fields

p1: Point

First point of the triangle

p2: Point

Second point of the triangle

p3: Point

Third point of the triangle

Implementations

Create a new triangle with a given style

Creates a new triangle from an array of points.

This supports both Points, as well as anything that implements Into<Point> like (i32, i32).

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

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

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

Get the width and height for an object

Feeds this value into the given Hasher. Read more

Feeds a slice of this type into the given Hasher. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method returns an ordering between self and other values if one exists. Read more

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Converts this primitive into a Styled.

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.p1, Point::new(15, 20));
assert_eq!(moved.p2, Point::new(25, 30));
assert_eq!(moved.p3, Point::new(18, 25));

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.p1, Point::new(15, 20));
assert_eq!(tri.p2, Point::new(25, 30));
assert_eq!(tri.p3, Point::new(20, 25));

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

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

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.