Struct libreda_db::prelude::Path
source · [−]pub struct Path<T> {
pub points: PointString<T>,
pub width: T,
pub path_type: PathEndType<T>,
}
Expand description
Path
is essentially a chain of line segments but with a possibly a non-zero width.
It can be thought of the shape resulting by a stroke of a thick pen along the line segments.
Fields
points: PointString<T>
The vertices of the path which define the sequence of line segments.
width: T
Width of the path.
path_type: PathEndType<T>
Type of the path endings.
Implementations
sourceimpl<T> Path<T> where
T: Copy,
impl<T> Path<T> where
T: Copy,
sourcepub fn new<I>(i: I, width: T) -> Path<T> where
I: Into<PointString<T>>,
pub fn new<I>(i: I, width: T) -> Path<T> where
I: Into<PointString<T>>,
Create new path by taking vertices from a type that implements Into<PointString<T>>
.
sourcepub fn new_extended<I>(i: I, width: T, ext_begin: T, ext_end: T) -> Path<T> where
I: Into<PointString<T>>,
pub fn new_extended<I>(i: I, width: T, ext_begin: T, ext_end: T) -> Path<T> where
I: Into<PointString<T>>,
Create a path with extended beginning and end.
sourcepub fn new_rounded<I>(i: I, width: T) -> Path<T> where
I: Into<PointString<T>>,
pub fn new_rounded<I>(i: I, width: T) -> Path<T> where
I: Into<PointString<T>>,
Create a path with rounded beginning and end.
sourceimpl<T> Path<T> where
T: CoordinateType,
impl<T> Path<T> where
T: CoordinateType,
sourcepub fn rotate_ortho(&self, angle: Angle) -> Path<T>
pub fn rotate_ortho(&self, angle: Angle) -> Path<T>
Rotate the path by a multiple of 90 degrees around the origin (0, 0)
.
sourcepub fn transform(&self, tf: &SimpleTransform<T>) -> Path<T>
pub fn transform(&self, tf: &SimpleTransform<T>) -> Path<T>
Get the transformed version of this path by applying tf
.
sourceimpl<T> Path<T> where
T: CoordinateType + NumCast,
impl<T> Path<T> where
T: CoordinateType + NumCast,
sourcepub fn area_approx<F>(&self) -> F where
F: Float,
pub fn area_approx<F>(&self) -> F where
F: Float,
Compute approximate area occupied by the path. Simply computes length*width.
Examples
use iron_shapes::prelude::*;
let path = Path::new(&[(0, 0), (0, 2)], 1);
assert_eq!(path.area_approx::<f64>(), 2f64);
sourcepub fn to_polygon_approx(&self) -> SimplePolygon<f64>
pub fn to_polygon_approx(&self) -> SimplePolygon<f64>
Convert the path into a polygon. The polygon can be self-intersecting.
Examples
use iron_shapes::prelude::*;
let path = Path::new(&[(0, 0), (10, 0), (10, 20)], 4);
let polygon = path.to_polygon_approx();
assert_eq!(polygon, SimplePolygon::from(&[(0., 2.), (0., -2.), (12., -2.), (12., 20.), (8., 20.), (8., 2.)]));
Trait Implementations
sourceimpl<'de, T> Deserialize<'de> for Path<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Path<T> where
T: Deserialize<'de>,
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<Path<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D
) -> Result<Path<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
sourceimpl<T> Serialize for Path<T> where
T: Serialize,
impl<T> Serialize for Path<T> where
T: Serialize,
sourcefn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
Serialize this value into the given Serde serializer. Read more
sourceimpl<T> TryBoundingBox<T> for Path<T> where
T: Copy + PartialOrd<T> + Num,
impl<T> TryBoundingBox<T> for Path<T> where
T: Copy + PartialOrd<T> + Num,
sourcefn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
Compute the bounding box of this path. The returned bounding box is not necessarily the smallest bounding box.
TODO: Find a better approximation.
sourceimpl<T, Dst> TryCastCoord<T, Dst> for Path<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Path<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T> Eq for Path<T> where
T: Eq,
impl<T> StructuralEq for Path<T>
impl<T> StructuralPartialEq for Path<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Path<T> where
T: RefUnwindSafe,
impl<T> Send for Path<T> where
T: Send,
impl<T> Sync for Path<T> where
T: Sync,
impl<T> Unpin for Path<T> where
T: Unpin,
impl<T> UnwindSafe for Path<T> where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more