Trait embedded_graphics::transform::Transform [−][src]
pub trait Transform { fn translate(&self, by: Point) -> Self; fn translate_mut(&mut self, by: Point) -> &mut Self; }
Expand description
Transform operations
Required methods
Move the origin of an object by a given number of (x, y) pixels, returning a new object
fn translate_mut(&mut self, by: Point) -> &mut Self
[src]
fn translate_mut(&mut self, by: Point) -> &mut Self
[src]Move the origin of an object by a given number of (x, y) pixels, mutating the object in place
Implementors
Translate the arc from its current position to a new position by (x, y) pixels,
returning a new Arc
. For a mutating transform, see translate_mut
.
let arc = Arc::new(Point::new(5, 10), 10, 0.0.deg(), 90.0.deg()); let moved = arc.translate(Point::new(10, 10)); assert_eq!(moved.top_left, Point::new(15, 20));
Translate the arc from its current position to a new position by (x, y) pixels.
let mut arc = Arc::new(Point::new(5, 10), 10, 0.0.deg(), 90.0.deg()); arc.translate_mut(Point::new(10, 10)); assert_eq!(arc.top_left, Point::new(15, 20));
Translate the circle from its current position to a new position by (x, y) pixels,
returning a new Circle
. For a mutating transform, see translate_mut
.
let circle = Circle::new(Point::new(5, 10), 10); let moved = circle.translate(Point::new(10, 10)); assert_eq!(moved.top_left, Point::new(15, 20));
Translate the circle from its current position to a new position by (x, y) pixels.
let mut circle = Circle::new(Point::new(5, 10), 10); circle.translate_mut(Point::new(10, 10)); assert_eq!(circle.top_left, Point::new(15, 20));
Translate the ellipse from its current position to a new position by (x, y) pixels,
returning a new Ellipse
. For a mutating transform, see translate_mut
.
let ellipse = Ellipse::new(Point::new(5, 10), Size::new(10, 15)); let moved = ellipse.translate(Point::new(10, 10)); assert_eq!(moved.top_left, Point::new(15, 20));
Translate the ellipse from its current position to a new position by (x, y) pixels.
let mut ellipse = Ellipse::new(Point::new(5, 10), Size::new(10, 15)); ellipse.translate_mut(Point::new(10, 10)); assert_eq!(ellipse.top_left, Point::new(15, 20));
Translate the line from its current position to a new position by (x, y) pixels, returning
a new Line
. For a mutating transform, see translate_mut
.
let line = Line::new(Point::new(5, 10), Point::new(15, 20)); let moved = line.translate(Point::new(10, 10)); assert_eq!(moved.start, Point::new(15, 20)); assert_eq!(moved.end, Point::new(25, 30));
Translate the line from its current position to a new position by (x, y) pixels.
let mut line = Line::new(Point::new(5, 10), Point::new(15, 20)); line.translate_mut(Point::new(10, 10)); assert_eq!(line.start, Point::new(15, 20)); assert_eq!(line.end, Point::new(25, 30));
Translate the rect from its current position to a new position by (x, y) pixels, returning
a new Rectangle
. For a mutating transform, see translate_mut
.
let rect = Rectangle::new(Point::new(5, 10), Size::new(10, 10)); let moved = rect.translate(Point::new(10, 10)); assert_eq!(moved.top_left, Point::new(15, 20)); assert_eq!(moved.size, Size::new(10, 10));
Translate the rect from its current position to a new position by (x, y) pixels.
let mut rect = Rectangle::new(Point::new(5, 10), Size::new(10, 10)); rect.translate_mut(Point::new(10, 10)); assert_eq!(rect.top_left, Point::new(15, 20)); assert_eq!(rect.size, Size::new(10, 10));
Translate the rounded rectangle from its current position to a new position by (x, y)
pixels, returning a new RoundedRectangle
. For a mutating transform, see translate_mut
.
use embedded_graphics::primitives::{Rectangle, RoundedRectangle}; let original = RoundedRectangle::with_equal_corners( Rectangle::new(Point::new(5, 10), Size::new(20, 30)), Size::new(10, 15), ); let moved = original.translate(Point::new(10, 12)); assert_eq!(original.bounding_box().top_left, Point::new(5, 10)); assert_eq!(moved.bounding_box().top_left, Point::new(15, 22));
Translate the rounded rectangle from its current position to a new position by (x, y) pixels.
use embedded_graphics::primitives::{Rectangle, RoundedRectangle}; let mut shape = RoundedRectangle::with_equal_corners( Rectangle::new(Point::new(5, 10), Size::new(20, 30)), Size::new(10, 15), ); shape.translate_mut(Point::new(10, 12)); assert_eq!(shape.bounding_box().top_left, Point::new(15, 22));
Translate the sector from its current position to a new position by (x, y) pixels,
returning a new Sector
. For a mutating transform, see translate_mut
.
let sector = Sector::new(Point::new(5, 10), 10, 0.0.deg(), 90.0.deg()); let moved = sector.translate(Point::new(10, 10)); assert_eq!(moved.top_left, Point::new(15, 20));
Translate the sector from its current position to a new position by (x, y) pixels.
let mut sector = Sector::new(Point::new(5, 10), 10, 0.0.deg(), 90.0.deg()); sector.translate_mut(Point::new(10, 10)); assert_eq!(sector.top_left, Point::new(15, 20));
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)) );
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)) )
Translate the polyline from its current position to a new position by (x, y) pixels, returning
a new Polyline
. For a mutating transform, see translate_mut
.
let points = [ Point::new(5, 10), Point::new(7, 7), Point::new(5, 8), Point::new(10, 10), ]; let polyline = Polyline::new(&points); let moved = polyline.translate(Point::new(10, 12)); assert_eq!(polyline.bounding_box().top_left, Point::new(5, 7)); assert_eq!(moved.bounding_box().top_left, Point::new(15, 19));
Translate the polyline from its current position to a new position by (x, y) pixels.
let points = [ Point::new(5, 10), Point::new(7, 7), Point::new(5, 8), Point::new(10, 10), ]; let mut polyline = Polyline::new(&points); polyline.translate_mut(Point::new(10, 12)); assert_eq!(polyline.bounding_box().top_left, Point::new(15, 19));
Translate the image by a given delta, returning a new image
Examples
Move an image around
This examples moves a 4x4 black and white image by (10, 20)
pixels without mutating the
original image
use embedded_graphics::{ geometry::Point, image::{Image, ImageRaw}, pixelcolor::BinaryColor, prelude::*, }; let image: ImageRaw<BinaryColor> = ImageRaw::new(&[0xff, 0x00, 0xff, 0x00], 4); let image = Image::new(&image, Point::zero()); let image_moved = image.translate(Point::new(10, 20)); assert_eq!(image.bounding_box().top_left, Point::zero()); assert_eq!(image_moved.bounding_box().top_left, Point::new(10, 20));
Translate the image by a given delta, modifying the original object
Examples
Move an image around
This examples moves a 4x4 black and white image by (10, 20)
pixels by mutating the
original image
use embedded_graphics::{ geometry::Point, image::{Image, ImageRaw}, pixelcolor::BinaryColor, prelude::*, }; let image: ImageRaw<BinaryColor> = ImageRaw::new(&[0xff, 0x00, 0xff, 0x00], 4); let mut image = Image::new(&image, Point::zero()); image.translate_mut(Point::new(10, 20)); assert_eq!(image.bounding_box().top_left, Point::new(10, 20));