Struct picocadrs::assets::point::Point2D

source ·
pub struct Point2D<T> {
    pub u: T,
    pub v: T,
}
Expand description

Represents a 2-dimensional point in space. In this crates context used for uv-mapping.

It can be either created by using the method new or by using the point macro.

§Example

use picocadrs::assets::Point2D;
use picocadrs::point;

let mut point = Point2D::new(2, 4);

assert_eq!(point.u, 2);
assert_eq!(point.v, 4);

assert_eq!(point, point!(2, 4));

point.set(1, 2);
assert_eq!(point, point!(1, 2));

assert_eq!(point + point, point!(2, 4));
assert_eq!(point - point, point!(0, 0));

Fields§

§u: T§v: T

Implementations§

source§

impl<T> Point2D<T>

source

pub fn new(u: T, v: T) -> Point2D<T>

Used to create new points in a 2-dimensional space. Takes the points u and v coordinates as arguments.

A simpler way to create new Point2Ds is to use the point! macro.

§Example
use picocadrs::assets::Point2D;
use picocadrs::point;

let point = Point2D::new(2, 4);

assert_eq!(point.u, 2);
assert_eq!(point.v, 4);

assert_eq!(point, point!(2, 4))
source

pub fn set(&mut self, u: T, v: T)

Sets the points coordinates to the ones given.

§Example
use picocadrs::assets::Point2D;

let mut point = Point2D::new(2, 4);

assert_eq!(point.u, 2);
assert_eq!(point.v, 4);

point.set(3, 4);

assert_eq!(point.u, 3);
assert_eq!(point.v, 4);
source

pub fn map(&mut self, f: fn(_: &T) -> T)

Used to apply functions on every coordinate.

§Example
use picocadrs::assets::Point2D;

let mut point = Point2D::new(2, 3);

assert_eq!(point, Point2D::new(2, 3));
point.map(|c| {
   c * 2
});
assert_eq!(point, Point2D::new(4, 6));

Trait Implementations§

source§

impl<T: Add<Output = T>> Add for Point2D<T>

source§

fn add(self, rhs: Self) -> Self::Output

Adds points together.

§Example
use picocadrs::assets::Point2D;

let p1 = Point2D::new(1, 4);
let p2 = Point2D::new(2, 1);

assert_eq!(p1 + p2, Point2D::new(3, 5));
§

type Output = Point2D<T>

The resulting type after applying the + operator.
source§

impl<T: Clone> Clone for Point2D<T>

source§

fn clone(&self) -> Point2D<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug> Debug for Point2D<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<T: Display> Display for Point2D<T>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl FromStr for Point2D<f64>

source§

fn from_str(s: &str) -> Result<Self, Self::Err>

Parses a Point2D from a string representing a lua table with 2 float values. Fails if table does not have 2 fields or they cant be parsed into f64.

§Example
use picocadrs::assets::Point2D;

assert_eq!(
    "-1.5,2.2",
    "{-1.5,2.2}".parse::<Point2D<f64>>().unwrap().to_string()
)
§

type Err = PicoError

The associated error which can be returned from parsing.
source§

fn index(&self, index: Point2D<usize>) -> &Self::Output

Panics if u >= 128 or v >= 120.

§Example
use picocadrs::assets::{Footer, Color, Point2D};
use picocadrs::point;

let footer = Footer::default();

assert_eq!(footer[point!(0, 0)], Color::Black);
assert_eq!(footer[point!(127, 119)], Color::Black);
// assert_eq!(footer[point!(127, 120)], Color::Black); These panic
// assert_eq!(footer[point!(128, 119)], Color::Black);
§

type Output = Color

The returned type after indexing.
source§

fn index_mut(&mut self, index: Point2D<usize>) -> &mut Self::Output

Panics if u >= 128 or v >= 120.

§Example
use picocadrs::assets::{Footer, Color, Point2D};
use picocadrs::point;

let footer = Footer::default();

assert_eq!(footer[point!(0, 0)], Color::Black);
assert_eq!(footer[point!(127, 119)], Color::Black);
// assert_eq!(footer[point!(127, 120)], Color::Black); These panic
// assert_eq!(footer[point!(128, 119)], Color::Black);
source§

impl<T: PartialEq> PartialEq for Point2D<T>

source§

fn eq(&self, other: &Point2D<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Sub<Output = T>> Sub for Point2D<T>

source§

fn sub(self, rhs: Self) -> Self::Output

Subtracts points from each other.

§Example
use picocadrs::assets::Point2D;

let p1 = Point2D::new(1, 4);
let p2 = Point2D::new(2, 1);

assert_eq!(p1 - p2, Point2D::new(-1, 3));
§

type Output = Point2D<T>

The resulting type after applying the - operator.
source§

impl TryFrom<Table<'_>> for Point2D<f64>

source§

fn try_from(value: Table<'_>) -> Result<Self, Self::Error>

Tries to create a Point2D from a lua table. Only succeeds if the table has 2 fields that can be parsed into a f64. Partly used as a helper method to parse from a string.

§

type Error = PicoError

The type returned in the event of a conversion error.
source§

impl<T: Copy> Copy for Point2D<T>

source§

impl<T: Eq> Eq for Point2D<T>

source§

impl<T> StructuralPartialEq for Point2D<T>

Auto Trait Implementations§

§

impl<T> Freeze for Point2D<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Point2D<T>
where T: RefUnwindSafe,

§

impl<T> Send for Point2D<T>
where T: Send,

§

impl<T> Sync for Point2D<T>
where T: Sync,

§

impl<T> Unpin for Point2D<T>
where T: Unpin,

§

impl<T> UnwindSafe for Point2D<T>
where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.