Struct embedded_graphics::primitives::triangle::Triangle
source · pub struct Triangle {
pub vertices: [Point; 3],
}
Expand description
Triangle primitive
Examples
Create some triangles with different styles
use embedded_graphics::{
pixelcolor::Rgb565, prelude::*, primitives::{Triangle, 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§
Trait Implementations§
source§impl ContainsPoint for Triangle
impl ContainsPoint for Triangle
source§impl Dimensions for Triangle
impl Dimensions for Triangle
source§fn bounding_box(&self) -> Rectangle
fn bounding_box(&self) -> Rectangle
Returns the bounding box.
source§impl Ord for Triangle
impl Ord for Triangle
source§impl PartialEq<Triangle> for Triangle
impl PartialEq<Triangle> for Triangle
source§impl PartialOrd<Triangle> for Triangle
impl PartialOrd<Triangle> for Triangle
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl PointsIter for Triangle
impl PointsIter for Triangle
source§impl Primitive for Triangle
impl Primitive for Triangle
source§fn into_styled<S>(self, style: S) -> Styled<Self, S>where
Self: Sized,
fn into_styled<S>(self, style: S) -> Styled<Self, S>where Self: Sized,
Converts this primitive into a
Styled
.source§impl<C: PixelColor> StyledDimensions<PrimitiveStyle<C>> for Triangle
impl<C: PixelColor> StyledDimensions<PrimitiveStyle<C>> for Triangle
source§fn styled_bounding_box(&self, style: &PrimitiveStyle<C>) -> Rectangle
fn styled_bounding_box(&self, style: &PrimitiveStyle<C>) -> Rectangle
Returns the bounding box using the given style.
source§impl<C: PixelColor> StyledDrawable<PrimitiveStyle<C>> for Triangle
impl<C: PixelColor> StyledDrawable<PrimitiveStyle<C>> for Triangle
source§fn draw_styled<D>(
&self,
style: &PrimitiveStyle<C>,
target: &mut D
) -> Result<Self::Output, D::Error>where
D: DrawTarget<Color = C>,
fn draw_styled<D>( &self, style: &PrimitiveStyle<C>, target: &mut D ) -> Result<Self::Output, D::Error>where D: DrawTarget<Color = C>,
Draws the primitive using the given style.
source§impl Transform for Triangle
impl Transform for Triangle
source§fn translate(&self, by: Point) -> Self
fn translate(&self, by: Point) -> 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(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))
);
source§fn translate_mut(&mut self, by: Point) -> &mut Self
fn translate_mut(&mut self, by: Point) -> &mut Self
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))
)
impl Copy for Triangle
impl Eq for Triangle
impl StructuralEq for Triangle
impl StructuralPartialEq for Triangle
Auto Trait Implementations§
impl RefUnwindSafe for Triangle
impl Send for Triangle
impl Sync for Triangle
impl Unpin for Triangle
impl UnwindSafe for Triangle
Blanket Implementations§
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where T: CheckedCast<Dst>,
Casts the value.
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
Casts the value.
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where T: OverflowingCast<Dst>,
Casts the value.
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
Casts the value.
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere T: SaturatingCast<Dst>,
Casts the value.
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> UnwrappedAs for T
impl<T> UnwrappedAs for T
source§fn unwrapped_as<Dst>(self) -> Dstwhere
T: UnwrappedCast<Dst>,
fn unwrapped_as<Dst>(self) -> Dstwhere T: UnwrappedCast<Dst>,
Casts the value.
source§impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere
Src: UnwrappedCast<Dst>,
impl<Src, Dst> UnwrappedCastFrom<Src> for Dstwhere Src: UnwrappedCast<Dst>,
source§fn unwrapped_cast_from(src: Src) -> Dst
fn unwrapped_cast_from(src: Src) -> Dst
Casts the value.
source§impl<T> WrappingAs for T
impl<T> WrappingAs for T
source§fn wrapping_as<Dst>(self) -> Dstwhere
T: WrappingCast<Dst>,
fn wrapping_as<Dst>(self) -> Dstwhere T: WrappingCast<Dst>,
Casts the value.
source§impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere
Src: WrappingCast<Dst>,
impl<Src, Dst> WrappingCastFrom<Src> for Dstwhere Src: WrappingCast<Dst>,
source§fn wrapping_cast_from(src: Src) -> Dst
fn wrapping_cast_from(src: Src) -> Dst
Casts the value.