Struct libreda_db::layout::prelude::Edge [−][src]
pub struct Edge<T> where
T: CoordinateType, {
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
Create a new Edge from two arguments that implement Into<Point>.
Check if edge is degenerate. An edge is degenerate if start point and end point are equal.
Test if this edge is either horizontal or vertical.
Test if this edge is horizontal.
Test if this edge is vertical.
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.
Test if point lies on the edge. Includes start and end points of edge.
Test if point lies on the line defined by the edge.
Test if two edges are parallel.
Test if two edges are collinear, i.e. are on the same line.
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).
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”.
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”.
Test if lines defined by the edges intersect. If the lines are collinear they are also considered intersecting.
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.
Test if lines defined by the edges intersect. If the lines are collinear they are also considered intersecting.
Test if two edges intersect. If the edges coincide, they also intersect.
Test if point lies on the line defined by the edge.
pub fn line_intersection_approx<F>(
&self,
other: &Edge<T>,
tolerance: F
) -> LineIntersection<F, T> where
F: Float,
pub fn line_intersection_approx<F>(
&self,
other: &Edge<T>,
tolerance: F
) -> LineIntersection<F, T> where
F: Float,
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.));pub fn edge_intersection_approx<F>(
&self,
other: &Edge<T>,
tolerance: F
) -> EdgeIntersection<F, T> where
F: Float,
pub fn edge_intersection_approx<F>(
&self,
other: &Edge<T>,
tolerance: F
) -> EdgeIntersection<F, T> where
F: Float,
Compute the intersection with another edge.
Try to cast into other data type.
When the conversion fails None is returned.
pub fn cast_to_float<Target>(&self) -> Edge<Target> where
Target: CoordinateType + NumCast + Float,
pub fn cast_to_float<Target>(&self) -> Edge<Target> where
Target: CoordinateType + NumCast + Float,
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.
Calculate distance from point to the edge.
Find the perpendicular projection of a point onto the line of the edge.
Find the mirror image of point.
Calculate the absolute distance from the point onto the unbounded line coincident with this edge.
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).
pub fn line_intersection_rational(
&self,
other: Edge<Ratio<T>>
) -> LineIntersection<Ratio<T>, Ratio<T>>
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))));
pub fn edge_intersection_rational(
&self,
other: &Edge<Ratio<T>>
) -> EdgeIntersection<Ratio<T>, Ratio<T>>
pub fn edge_intersection_rational(
&self,
other: &Edge<Ratio<T>>
) -> EdgeIntersection<Ratio<T>, Ratio<T>>
Compute the intersection with another edge.
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)));
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.
Trait Implementations
Return the bounding box of this geometry.
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Edge<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
pub fn deserialize<__D>(
__deserializer: __D
) -> Result<Edge<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
pub fn serialize<__S>(
&self,
__serializer: __S
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error> where
__S: Serializer,
pub 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
Get bounding box of edge (always exists).
impl<T, Dst> TryCastCoord<T, Dst> for Edge<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Edge<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
Auto Trait Implementations
impl<T> RefUnwindSafe for Edge<T> where
T: RefUnwindSafe,
impl<T> UnwindSafe for Edge<T> where
T: UnwindSafe,
Blanket Implementations
Mutably borrows from an owned value. Read more
Rotate the geometrical shape by a multiple of 90 degrees.