pub struct Triangle {
pub vertices: [Point; 3],
}
Expand description
Triangle primitive
§Examples §Create some triangles with different stylesuse embedded_graphics::{
pixelcolor::Rgb565, prelude::*, primitives::{Triangle, PrimitiveStyle},
};
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::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]);
The vertices of the triangle.
Source§ SourceCreate a new triangle with the given vertices.
SourceCreates a new triangle from a Point
slice.
This method will panic if the given slice is not exactly 3 items long.
Source§ Source§ Source§Returns true
if the given point is inside the shape.
Writes the defmt representation of self
to fmt
.
Tests for self
and other
values to be equal, and is used by ==
.
Tests for !=
. The default implementation is almost always sufficient, and should not be overridden without very good reason.
This method returns an ordering between
self
and
other
values if one exists.
Read more 1.0.0 · Source§Tests less than (for
self
and
other
) and is used by the
<
operator.
Read more 1.0.0 · Source§Tests less than or equal to (for
self
and
other
) and is used by the
<=
operator.
Read more 1.0.0 · Source§Tests greater than (for
self
and
other
) and is used by the
>
operator.
Read more 1.0.0 · Source§Tests greater than or equal to (for
self
and
other
) and is used by the
>=
operator.
Read more Source§ Source§Iterator over all points inside the primitive.
Source§Returns an iterator over all points inside the primitive.
Source§ Source§Converts this primitive into a Styled
.
Returns the bounding box using the given style.
Source§ Source§ Source§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§
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))
)
Source§ Source§ Source§
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4