[−][src]Struct embedded_graphics::primitives::triangle::Triangle
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]
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]
pub fn bounding_box(&self) -> Rectangle
[src]
impl Eq for Triangle
[src]
impl Hash for Triangle
[src]
pub fn hash<__H: Hasher>(&self, state: &mut __H)
[src]
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Ord for Triangle
[src]
pub fn cmp(&self, other: &Triangle) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Triangle> for Triangle
[src]
impl PartialOrd<Triangle> for Triangle
[src]
pub fn partial_cmp(&self, other: &Triangle) -> Option<Ordering>
[src]
pub fn lt(&self, other: &Triangle) -> bool
[src]
pub fn le(&self, other: &Triangle) -> bool
[src]
pub fn gt(&self, other: &Triangle) -> bool
[src]
pub fn ge(&self, other: &Triangle) -> bool
[src]
impl PointsIter for Triangle
[src]
type Iter = Points
Iterator over all points inside the primitive.
pub fn points(&self) -> Self::Iter
[src]
impl Primitive for Triangle
[src]
pub fn into_styled<C>(
self,
style: PrimitiveStyle<C>
) -> Styled<Self, PrimitiveStyle<C>> where
C: PixelColor,
Self: Sized,
[src]
self,
style: PrimitiveStyle<C>
) -> Styled<Self, PrimitiveStyle<C>> where
C: PixelColor,
Self: Sized,
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
impl RefUnwindSafe for Triangle
impl Send for Triangle
impl Sync for Triangle
impl Unpin for Triangle
impl UnwindSafe for Triangle
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
[src]
Dst: LosslessTryFrom<Src>,
pub fn lossless_try_into(self) -> Option<Dst>
[src]
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
[src]
Dst: LossyFrom<Src>,
pub fn lossy_into(self) -> Dst
[src]
impl<T> Pointable for T
pub const ALIGN: usize
type Init = T
The type for initializers.
pub unsafe fn init(init: <T as Pointable>::Init) -> usize
pub unsafe fn deref<'a>(ptr: usize) -> &'a T
pub unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T
pub unsafe fn drop(ptr: usize)
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]
T: PartialEq<T> + Copy + Any + Debug,
impl<SS, SP> SupersetOf<SS> for SP where
SS: SubsetOf<SP>,
SS: SubsetOf<SP>,
pub fn to_subset(&self) -> Option<SS>
pub fn is_in_subset(&self) -> bool
pub fn to_subset_unchecked(&self) -> SS
pub fn from_subset(element: &SS) -> SP
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,