Trait libreda_db::layout::prelude::TryCastCoord[][src]

pub trait TryCastCoord<Src, Dst> where
    Src: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
{ type Output; pub fn try_cast(&self) -> Option<Self::Output>; pub fn cast(&self) -> Self::Output { ... } }

This trait defines the type-casting of the coordinate types for geometrical objects.

Associated Types

type Output[src]

Output type of the cast. This is likely the same geometrical type just with other coordinate types.

Loading content...

Required methods

pub fn try_cast(&self) -> Option<Self::Output>[src]

Try to cast to target data type.

Conversion from float to int can fail and will return None. Float values like infinity or non-a-number have no integer representation.

Loading content...

Provided methods

pub fn cast(&self) -> Self::Output[src]

Cast to target data type.

Conversion from float to int can fail and panic because float values like infinity or non-a-number have no integer representation.

Panics

Panics if casting of the coordinate values fails. For instance when trying to cast a 'NaN' float into a integer. Use try_cast to detect and handle this failure.

Loading content...

Implementors

impl<T, Dst> TryCastCoord<T, Dst> for Geometry<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Geometry<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for Edge<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Edge<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for Path<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Path<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for Point<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Point<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for PointString<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = PointString<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for Polygon<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Polygon<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for REdge<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = REdge<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for Rect<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Rect<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for SimplePolygon<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = SimplePolygon<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for SimpleRPolygon<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = SimpleRPolygon<Dst>

impl<T, Dst> TryCastCoord<T, Dst> for Vector<T> where
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Vector<Dst>

pub fn try_cast(&self) -> Option<<Vector<T> as TryCastCoord<T, Dst>>::Output>[src]

Try to cast to vector of target data type.

Conversion from float to int can fail and will return None. Float values like infinity or non-a-number have no integer representation.

Examples

use iron_shapes::vector::Vector;
use iron_shapes::traits::TryCastCoord;

let v_int = Vector::new(1,2);
let maybe_v_float: Option<Vector<f64>> = v_int.try_cast();

assert_eq!(maybe_v_float, Some(Vector::new(1.0, 2.0)));

// Conversion from float to int can fail.

let w_float = Vector::new(42.0, 0. / 0.);
let maybe_w_int: Option<Vector<i32>> = w_float.try_cast();

assert_eq!(maybe_w_int, None);

impl<T, Dst, S> TryCastCoord<T, Dst> for Text<T, S> where
    S: Clone,
    T: CoordinateType + NumCast,
    Dst: CoordinateType + NumCast
[src]

type Output = Text<Dst, S>

Loading content...