[][src]Trait embedded_graphics::transform::Transform

pub trait Transform {
    fn translate(&self, by: Point) -> Self;
fn translate_mut(&mut self, by: Point) -> &mut Self; }

Transform operations

Required methods

fn translate(&self, by: Point) -> Self

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

Move the origin of an object by a given number of (x, y) pixels, mutating the object in place

Loading content...

Implementors

impl Transform for Circle[src]

fn translate(&self, by: Point) -> Self[src]

Translate the circle center 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.center, Point::new(15, 20));

fn translate_mut(&mut self, by: Point) -> &mut Self[src]

Translate the circle center 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.center, Point::new(15, 20));

impl Transform for Line[src]

fn translate(&self, by: Point) -> Self[src]

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

fn translate_mut(&mut self, by: Point) -> &mut Self[src]

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

impl Transform for Rectangle[src]

fn translate(&self, by: Point) -> Self[src]

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), Point::new(15, 20));
let moved = rect.translate(Point::new(10, 10));

assert_eq!(moved.top_left, Point::new(15, 20));
assert_eq!(moved.bottom_right, Point::new(25, 30));

fn translate_mut(&mut self, by: Point) -> &mut Self[src]

Translate the rect from its current position to a new position by (x, y) pixels.

let mut rect = Rectangle::new(Point::new(5, 10), Point::new(15, 20));
rect.translate_mut(Point::new(10, 10));

assert_eq!(rect.top_left, Point::new(15, 20));
assert_eq!(rect.bottom_right, Point::new(25, 30));

impl Transform for Triangle[src]

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

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

impl<'_> Transform for Text<'_>[src]

impl<'_, I, C> Transform for Image<'_, I, C>[src]

fn translate(&self, by: Point) -> Self[src]

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

let image: Image<_, BinaryColor> = Image::new(&image, Point::zero());

let image_moved = image.translate(Point::new(10, 20));

assert_eq!(image.top_left(), Point::zero());
assert_eq!(image_moved.top_left(), Point::new(10, 20));

fn translate_mut(&mut self, by: Point) -> &mut Self[src]

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

let mut image: Image<_, BinaryColor> = Image::new(&image, Point::zero());

image.translate_mut(Point::new(10, 20));

assert_eq!(image.top_left(), Point::new(10, 20));

impl<T, S> Transform for Styled<T, S> where
    T: Transform,
    S: Clone
[src]

Loading content...