Struct libreda_db::layout::prelude::Path

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§

§

impl<T> Path<T>

pub fn len(&self) -> usize

Get number of vertices defining the path.

pub fn is_empty(&self) -> bool

Check if path has zero length.

§

impl<T> Path<T>where T: Copy,

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>>.

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.

pub fn new_rounded<I>(i: I, width: T) -> Path<T>where I: Into<PointString<T>>,

Create a path with rounded beginning and end.

§

impl<T> Path<T>where T: Copy + Add<T, Output = T>,

pub fn translate(&self, v: Vector<T>) -> Path<T>

Translate the path by an offset vector.

§

impl<T> Path<T>where T: Copy + Mul<T, Output = T>,

pub fn scale(&self, factor: T) -> Path<T>

Scale the path. Scaling center is the origin (0, 0).

§

impl<T> Path<T>where T: CoordinateType,

pub fn rotate_ortho(&self, angle: Angle) -> Path<T>

Rotate the path by a multiple of 90 degrees around the origin (0, 0).

pub fn transform(&self, tf: &SimpleTransform<T>) -> Path<T>

Get the transformed version of this path by applying tf.

§

impl<T> Path<T>where T: CoordinateType + NumCast,

pub fn area_approx<F>(&self) -> Fwhere 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);

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§

§

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

§

fn clone(&self) -> Path<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
§

impl<T> Debug for Path<T>where T: Debug,

§

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

Formats the value using the given formatter. Read more
§

impl<'de, T> Deserialize<'de> for Path<T>where T: Deserialize<'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
§

impl<T> From<Path<T>> for Geometry<T>

§

fn from(x: Path<T>) -> Geometry<T>

Converts to this type from the input type.
§

impl<T> Hash for Path<T>where T: Hash,

§

fn hash<__H>(&self, state: &mut __H)where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl<T> PartialEq<Path<T>> for Path<T>where T: PartialEq<T>,

§

fn eq(&self, other: &Path<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.
§

impl<T> Serialize for Path<T>where T: Serialize,

§

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
§

impl<T> TryBoundingBox<T> for Path<T>where T: Copy + PartialOrd<T> + Num,

§

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.

§

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

§

type Output = Path<Dst>

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

fn try_cast(&self) -> Option<<Path<T> as TryCastCoord<T, Dst>>::Output>

Try to cast to target data type. Read more
§

fn cast(&self) -> Self::Output

Cast to target data type. Read more
§

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§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere 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, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,

source§

impl<T> IdType for Twhere T: Debug + Clone + Eq + Hash + 'static,

source§

impl<T> IdTypeMT for Twhere T: IdType + Sync + Send,

§

impl<T> TextType for Twhere T: Eq + Hash + Clone + Debug,