[][src]Struct embedded_graphics::coord::Coord

pub struct Coord(pub i32, pub i32);

2D signed integer coordinate type

This coordinate should be used to define graphics object coordinates. For example, a Rect may be defined that has its top left at (-1,-2). To specify positive-only screen coordinates and the like, see UnsignedCoord.

use embedded_graphics::{coord::Coord, icoord};

// Create a coord using the `new` constructor method
let c1 = Coord::new(10, 20);

// Create a coord using the handy `icoord` macro
let c2 = icoord!(10, 20);

assert_eq!(c1, c2);

Note that enabling the nalgebra feature will alias Nalgebra's Vector2<i32> type to Coord instead of this builtin implementation.

Methods

impl Coord[src]

pub fn new(x: i32, y: i32) -> Self[src]

Create a new coordinate with X and Y values

pub fn clamp_positive(&self) -> Self[src]

Clamp coordinate components to positive integer range

let coord = Coord::new(-5, 10);

assert_eq!(coord.clamp_positive(), Coord::new(0, 10));

pub fn abs(&self) -> Self[src]

Remove the sign from a coordinate

let coord = Coord::new(-5, -10);

assert_eq!(coord.abs(), Coord::new(5, 10));

Trait Implementations

impl Add<Coord> for Coord[src]

type Output = Coord

The resulting type after applying the + operator.

impl AddAssign<Coord> for Coord[src]

impl Clone for Coord[src]

impl Copy for Coord[src]

impl Debug for Coord[src]

impl Eq for Coord[src]

impl<'_> From<&'_ [i32; 2]> for Coord[src]

impl<'_> From<&'_ [u32; 2]> for Coord[src]

impl<'_> From<&'_ Coord> for (i32, i32)[src]

impl From<[i32; 2]> for Coord[src]

impl From<[u32; 2]> for Coord[src]

impl From<(i32, i32)> for Coord[src]

impl From<(u32, u32)> for Coord[src]

impl From<Coord> for (i32, i32)[src]

impl Index<usize> for Coord[src]

type Output = i32

The returned type after indexing.

impl Neg for Coord[src]

type Output = Coord

The resulting type after applying the - operator.

impl PartialEq<Coord> for Coord[src]

impl StructuralEq for Coord[src]

impl StructuralPartialEq for Coord[src]

impl Sub<Coord> for Coord[src]

type Output = Coord

The resulting type after applying the - operator.

impl SubAssign<Coord> for Coord[src]

impl ToUnsigned for Coord[src]

fn to_unsigned(self) -> UnsignedCoord[src]

Convert to a positive-only coordinate, clamping negative values to zero

let coord = Coord::new(-5, 10);

assert_eq!(coord.to_unsigned(), UnsignedCoord::new(0, 10));

Auto Trait Implementations

impl Send for Coord

impl Sync for Coord

impl Unpin for Coord

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.