Trait libreda_pnr::route::router::TryCastCoord [−]
This trait defines the type-casting of the coordinate types for geometrical objects.
Associated Types
type Output
Output type of the cast. This is likely the same geometrical type just with other coordinate types.
Required methods
pub fn try_cast(&self) -> Option<Self::Output>
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.
Provided methods
pub fn cast(&self) -> Self::Output
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.
Implementors
impl<T, Dst> TryCastCoord<T, Dst> for Geometry<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = Geometry<Dst>
pub fn try_cast(&self) -> Option<<Geometry<T> as TryCastCoord<T, Dst>>::Output>
impl<T, Dst> TryCastCoord<T, Dst> for Edge<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Path<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Point<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = Point<Dst>
pub fn try_cast(&self) -> Option<<Point<T> as TryCastCoord<T, Dst>>::Output>
impl<T, Dst> TryCastCoord<T, Dst> for PointString<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = PointString<Dst>
pub fn try_cast(
&self
) -> Option<<PointString<T> as TryCastCoord<T, Dst>>::Output>
&self
) -> Option<<PointString<T> as TryCastCoord<T, Dst>>::Output>
impl<T, Dst> TryCastCoord<T, Dst> for Polygon<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = Polygon<Dst>
pub fn try_cast(&self) -> Option<<Polygon<T> as TryCastCoord<T, Dst>>::Output>
impl<T, Dst> TryCastCoord<T, Dst> for REdge<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = REdge<Dst>
pub fn try_cast(&self) -> Option<<REdge<T> as TryCastCoord<T, Dst>>::Output>
impl<T, Dst> TryCastCoord<T, Dst> for Rect<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for SimplePolygon<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = SimplePolygon<Dst>
pub fn try_cast(
&self
) -> Option<<SimplePolygon<T> as TryCastCoord<T, Dst>>::Output>
&self
) -> Option<<SimplePolygon<T> as TryCastCoord<T, Dst>>::Output>
impl<T, Dst> TryCastCoord<T, Dst> for SimpleRPolygon<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = SimpleRPolygon<Dst>
pub fn try_cast(
&self
) -> Option<<SimpleRPolygon<T> as TryCastCoord<T, Dst>>::Output>
&self
) -> Option<<SimpleRPolygon<T> as TryCastCoord<T, Dst>>::Output>
impl<T, Dst> TryCastCoord<T, Dst> for Vector<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = Vector<Dst>
pub fn try_cast(&self) -> Option<<Vector<T> as TryCastCoord<T, Dst>>::Output>
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,
S: Clone,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,