Struct iron_shapes::edge::Edge

source ·
pub struct Edge<T> {
    pub start: Point<T>,
    pub end: Point<T>,
}
Expand description

An edge (line segment) is represented by its starting point and end point.

Fields§

§start: Point<T>

Start-point of the edge.

§end: Point<T>

End-point of the edge.

Implementations§

source§

impl<T: Copy> Edge<T>

source

pub fn new<C>(start: C, end: C) -> Self
where C: Into<Point<T>>,

Create a new Edge from two arguments that implement Into<Point>.

source

pub fn reversed(&self) -> Self

Return the same edge but with the two points swapped.

source§

impl<T: PartialEq> Edge<T>

source

pub fn is_degenerate(&self) -> bool

Check if edge is degenerate. An edge is degenerate if start point and end point are equal.

source

pub fn is_rectilinear(&self) -> bool

Test if this edge is either horizontal or vertical.

source

pub fn is_horizontal(&self) -> bool

Test if this edge is horizontal.

source

pub fn is_vertical(&self) -> bool

Test if this edge is vertical.

source§

impl<T: CoordinateType> Edge<T>

source

pub fn vector(&self) -> Vector<T>

Returns the vector from self.start to self.end.

source

pub fn side_of(&self, point: Point<T>) -> Side

Tells on which side of the edge a point is.

§Panics

Panics if the edge is degenerate.

Returns Side::Left if the point is on the left side, Side::Right if the point is on the right side or Side::Center if the point lies exactly on the line.

source

pub fn contains_point(&self, point: Point<T>) -> ContainsResult

Test if point lies on the edge. Includes start and end points of edge.

source

pub fn line_contains_point(&self, point: Point<T>) -> bool

Test if point lies on the line defined by the edge.

source

pub fn is_parallel(&self, other: &Edge<T>) -> bool

Test if two edges are parallel.

source

pub fn is_collinear(&self, other: &Edge<T>) -> bool
where T: CoordinateType,

Test if two edges are collinear, i.e. are on the same line.

source

pub fn is_coincident(&self, other: &Edge<T>) -> bool

Test edges for coincidence. Two edges are coincident if they are oriented the same way and share more than one point (implies that they must be parallel).

source

pub fn is_parallel_approx(&self, other: &Edge<T>, epsilon_squared: T) -> bool

Test if two edges are approximately parallel. To be used for float coordinates. Inspired by algorithm on page 241 of “Geometric Tools for Computer Graphics”.

source

pub fn is_collinear_approx(&self, other: &Edge<T>, epsilon_squared: T) -> bool

Test if two edges are approximately collinear, i.e. are on the same line. Inspired by algorithm on page 241 of “Geometric Tools for Computer Graphics”.

source

pub fn lines_intersect_approx( &self, other: &Edge<T>, epsilon_squared: T, ) -> bool

Test if lines defined by the edges intersect. If the lines are collinear they are also considered intersecting.

source

pub fn crossed_by_line(&self, other: &Edge<T>) -> ContainsResult

Test if this edge is crossed by the line defined by the other edge.

Returns WithinBounds if start and end point of this edge lie on different sides of the line defined by the other edge or OnBounds if at least one of the points lies on the line.

source

pub fn lines_intersect(&self, other: &Edge<T>) -> bool

Test if lines defined by the edges intersect. If the lines are collinear they are also considered intersecting.

source

pub fn edges_intersect(&self, other: &Edge<T>) -> ContainsResult

Test if two edges intersect. If the edges coincide, they also intersect.

source§

impl<T: CoordinateType + NumCast> Edge<T>

source

pub fn line_contains_point_approx<F: Float + NumCast>( &self, point: Point<T>, tolerance: F, ) -> bool

Test if point lies on the line defined by the edge.

source

pub fn line_intersection_approx<F: Float>( &self, other: &Edge<T>, tolerance: F, ) -> LineIntersection<F, T>

Compute the intersection point of the lines defined by the two edges.

Degenerate lines don’t intersect by definition.

Returns LineIntersection::None iff the two lines don’t intersect. Returns LineIntersection::Collinear iff both lines are equal. Returns LineIntersection::Point(p,(a,b,c)) iff the lines intersect in exactly one point p. f is a value such that self.start + self.vector()*a/c == p and other.start + other.vector()*b/c == p.

§Examples
use iron_shapes::point::Point;
use iron_shapes::edge::*;

let e1 = Edge::new((0, 0), (2, 2));
let e2 = Edge::new((0, 2), (2, 0));

assert_eq!(e1.line_intersection_approx(&e2, 1e-6),
    LineIntersection::Point(Point::new(1., 1.), (4, 4, 8)));

assert_eq!(Point::zero() + e1.vector().cast() * 0.5, Point::new(1., 1.));
source

pub fn edge_intersection_approx<F: Float>( &self, other: &Edge<T>, tolerance: F, ) -> EdgeIntersection<F, T, Edge<T>>

Compute the intersection with another edge.

source§

impl<T: CoordinateType + NumCast> Edge<T>

source

pub fn try_cast<Target>(&self) -> Option<Edge<Target>>
where Target: CoordinateType + NumCast,

Try to cast into other data type. When the conversion fails None is returned.

source

pub fn cast<Target>(&self) -> Edge<Target>
where Target: CoordinateType + NumCast,

Cast to other data type.

§Panics

Panics when the conversion fails.

source

pub fn cast_to_float<Target>(&self) -> Edge<Target>
where Target: CoordinateType + NumCast + Float,

Cast to float.

§Panics

Panics when the conversion fails.

source

pub fn distance_to_line<F: Float>(&self, point: Point<T>) -> F

Calculate the distance from the point to the line given by the edge.

Distance will be positive if the point lies on the right side of the edge and negative if the point is on the left side.

source

pub fn distance<F: Float>(&self, point: Point<T>) -> F

Calculate distance from point to the edge.

source

pub fn projection_approx<F: Float>(&self, point: Point<T>) -> Point<F>

Find the perpendicular projection of a point onto the line of the edge.

source

pub fn reflection_approx<F: Float>(&self, point: Point<T>) -> Point<F>

Find the mirror image of point.

source

pub fn distance_to_line_abs_approx<F: Float>(&self, point: Point<T>) -> F

Calculate the absolute distance from the point onto the unbounded line coincident with this edge.

source

pub fn contains_point_approx<F: Float>( &self, point: Point<T>, tolerance: F, ) -> bool

Test if point lies approximately on the edge. Returns true if point is up to tolerance away from the edge and lies between start and end points (inclusive).

source§

impl<T: CoordinateType + PrimInt + Debug> Edge<T>

source

pub fn line_intersection_rounded( &self, other: Edge<T>, ) -> LineIntersection<T, T>

Compute the intersection point of the lines defined by the two edges. Coordinates of intersection points are rounded towards zero.

Degenerate lines don’t intersect by definition.

Returns LineIntersection::None iff the two lines don’t intersect. Returns LineIntersection::Collinear iff both lines are equal. Returns LineIntersection::Point(p,(a,b,c)) iff the lines intersect in exactly one point p. f is a value such that self.start + self.vector()*a/c == p and other.start + other.vector()*b/c == p.

§Examples
use iron_shapes::point::Point;
use iron_shapes::edge::*;

let e1 = Edge::new((0, 0), (2, 2));
let e2 = Edge::new((0, 2), (2, 0));

assert_eq!(e1.line_intersection_rounded(e2),
    LineIntersection::Point(Point::new(1, 1), (4, 4, 8)));
source

pub fn edge_intersection_rounded( &self, other: &Edge<T>, ) -> EdgeIntersection<T, T, Edge<T>>

Compute the intersection with another edge. Coordinates of intersection points are rounded towards zero.

EdgeIntersection::EndPoint is returned if and only if the intersection lies exactly on an end point.

source§

impl<T: CoordinateType + Integer> Edge<Ratio<T>>

source

pub fn line_intersection_rational( &self, other: Edge<Ratio<T>>, ) -> LineIntersection<Ratio<T>, Ratio<T>>

Compute the intersection point of the lines defined by the two edges.

Degenerate lines don’t intersect by definition.

Returns LineIntersection::None iff the two lines don’t intersect. Returns LineIntersection::Collinear iff both lines are equal. Returns LineIntersection::Point(p,(a,b,c)) iff the lines intersect in exactly one point p. f is a value such that self.start + self.vector()*a/c == p and other.start + other.vector()*b/c == p.

§Examples
extern crate num_rational;
use num_rational::Ratio;
use iron_shapes::point::Point;
use iron_shapes::edge_rational::*;

let r = |i| Ratio::from_integer(i);

let e1 = Edge::new((r(0), r(0)), (r(2), r(2)));
let e2 = Edge::new((r(0), r(2)), (r(2), r(0)));

assert_eq!(e1.line_intersection_rational(e2),
    LineIntersection::Point(Point::new(r(1), r(1)), (r(4), r(4), r(8))));
source

pub fn edge_intersection_rational( &self, other: &Edge<Ratio<T>>, ) -> EdgeIntersection<Ratio<T>, Ratio<T>, Edge<Ratio<T>>>

Compute the intersection with another edge.

Trait Implementations§

source§

impl<T: Copy + PartialOrd> BoundingBox<T> for Edge<T>

source§

fn bounding_box(&self) -> Rect<T>

Return the bounding box of this geometry.
source§

impl<T: Clone> Clone for Edge<T>

source§

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

source§

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

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

impl<T: Copy> EdgeEndpoints<T> for Edge<T>

source§

fn start(&self) -> Point<T>

Get the start point of the edge.
source§

fn end(&self) -> Point<T>

Get the end point of the edge.
source§

impl<T: Copy> From<&Edge<T>> for (Point<T>, Point<T>)

source§

fn from(e: &Edge<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Copy> From<&REdge<T>> for Edge<T>

source§

fn from(e: &REdge<T>) -> Self

Converts to this type from the input type.
source§

impl<T: CoordinateType> From<[Point<T>; 2]> for Edge<T>

source§

fn from(points: [Point<T>; 2]) -> Self

Converts to this type from the input type.
source§

impl<T: CoordinateType> From<(Point<T>, Point<T>)> for Edge<T>

source§

fn from(points: (Point<T>, Point<T>)) -> Self

Converts to this type from the input type.
source§

impl<T: Copy> From<Edge<T>> for (Point<T>, Point<T>)

source§

fn from(e: Edge<T>) -> Self

Converts to this type from the input type.
source§

impl<T> From<Edge<T>> for Geometry<T>

source§

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

Converts to this type from the input type.
source§

impl<T: Copy> From<REdge<T>> for Edge<T>

source§

fn from(e: REdge<T>) -> Self

Converts to this type from the input type.
source§

impl<T: Hash> Hash for Edge<T>

source§

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

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
source§

impl<T: Copy> MapPointwise<T> for Edge<T>

source§

fn transform<F: Fn(Point<T>) -> Point<T>>(&self, tf: F) -> Self

Point wise transformation.
source§

impl<T: PartialEq> PartialEq for Edge<T>

source§

fn eq(&self, other: &Edge<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: Copy + PartialOrd> TryBoundingBox<T> for Edge<T>

source§

fn try_bounding_box(&self) -> Option<Rect<T>>

Get bounding box of edge (always exists).

source§

impl<T: Copy + NumCast, Dst: Copy + NumCast> TryCastCoord<T, Dst> for Edge<T>

§

type Output = Edge<Dst>

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

fn try_cast(&self) -> Option<Self::Output>

Try to cast to target data type. Read more
source§

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

Cast to target data type. Read more
source§

impl<T: CoordinateType> TryFrom<&Edge<T>> for REdge<T>

source§

fn try_from(value: &Edge<T>) -> Result<Self, Self::Error>

Try to convert an edge into a rectilinear edge. Returns none if the edge is not rectilinear.

§

type Error = ()

The type returned in the event of a conversion error.
source§

impl<T: Copy> Copy for Edge<T>

source§

impl<T: Eq> Eq for Edge<T>

source§

impl<T> StructuralPartialEq for Edge<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Edge<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> IntoEither for T

source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
source§

impl<S, T> Mirror<T> for S
where T: Copy + Zero + Sub<Output = T>, S: MapPointwise<T>,

source§

fn mirror_x(&self) -> S

Return the geometrical object mirrored at the x axis.

source§

fn mirror_y(&self) -> S

Return the geometrical object mirrored at the y axis.

source§

impl<S, T> RotateOrtho<T> for S
where T: Copy + Zero + Sub<Output = T>, S: MapPointwise<T>,

source§

fn rotate_ortho(&self, a: Angle) -> S

Rotate the geometrical shape by a multiple of 90 degrees.
source§

impl<S, T> Scale<T> for S
where T: Copy + Mul<Output = T>, S: MapPointwise<T>,

source§

fn scale(&self, factor: T) -> S

Scale the geometrical shape. Scaling center is the origin (0, 0).
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<S, T> Translate<T> for S
where T: Copy + Add<Output = T>, S: MapPointwise<T>,

source§

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

Translate the geometrical object by a vector v.
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.
source§

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