Struct picocadrs::assets::point::Point3D

source ·
pub struct Point3D<T> {
    pub x: T,
    pub y: T,
    pub z: T,
}
Expand description

Represents a 3-dimensional point in space. In this crates context mostly used for displaying points of vertices.

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

§Example

use picocadrs::assets::Point3D;
use picocadrs::point;

let mut point = Point3D::new(2, 4, -1);

assert_eq!(point.x, 2);
assert_eq!(point.y, 4);
assert_eq!(point.z, -1);

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

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

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

Fields§

§x: T§y: T§z: T

Implementations§

source§

impl<T> Point3D<T>

source

pub fn new(x: T, y: T, z: T) -> Point3D<T>

Used to create new points in a 3-dimensional space. Takes the points x, y and z coordinates as arguments.

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

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

let point = Point3D::new(2, 4, -1);

assert_eq!(point.x, 2);
assert_eq!(point.y, 4);
assert_eq!(point.z, -1);

assert_eq!(point, point!(2, 4, -1));
source

pub fn set(&mut self, x: T, y: T, z: T)

Sets the points coordinates to the ones given.

§Example
use picocadrs::assets::Point3D;

let mut point = Point3D::new(2, 4, -1);

assert_eq!(point.x, 2);
assert_eq!(point.y, 4);
assert_eq!(point.z, -1);

point.set(-3, 4, 2);

assert_eq!(point.x, -3);
assert_eq!(point.y, 4);
assert_eq!(point.z, 2);
source

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

Used to apply functions on every coordinate.

§Example
use picocadrs::assets::Point3D;

let mut point = Point3D::new(2, 3, -1);

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

Trait Implementations§

source§

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

source§

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

Adds points together.

§Example
use picocadrs::assets::Point3D;

let p1 = Point3D::new(1, 4, -2);
let p2 = Point3D::new(2, -2, 3);

assert_eq!(p1 + p2, Point3D::new(3, 2, 1));
§

type Output = Point3D<T>

The resulting type after applying the + operator.
source§

impl<T: Clone> Clone for Point3D<T>

source§

fn clone(&self) -> Point3D<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 Point3D<T>

source§

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

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

impl<T: Display> Display for Point3D<T>

source§

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

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

impl FromStr for Point3D<f64>

source§

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

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

§Example
use picocadrs::assets::Point3D;

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

type Err = PicoError

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

impl<T: PartialEq> PartialEq for Point3D<T>

source§

fn eq(&self, other: &Point3D<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 Point3D<T>

source§

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

Subtracts points from each other.

§Example
use picocadrs::assets::Point3D;

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

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

type Output = Point3D<T>

The resulting type after applying the - operator.
source§

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

source§

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

Tries to create a Point3D from a lua table. Only succeeds if the table has 3 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 Point3D<T>

source§

impl<T: Eq> Eq for Point3D<T>

source§

impl<T> StructuralPartialEq for Point3D<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Point3D<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.