Struct libreda_pnr::db::Edge [−]
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
impl<T> Edge<T> where
T: CoordinateType,
T: CoordinateType,
pub fn new<C>(start: C, end: C) -> Edge<T> where
C: Into<Point<T>>,
C: Into<Point<T>>,
Create a new Edge
from two arguments that implement Into<Point>
.
pub fn reversed(&self) -> Edge<T>
Return the same edge but with the two points swapped.
pub fn is_degenerate(&self) -> bool
Check if edge is degenerate. An edge is degenerate if start point and end point are equal.
pub fn is_rectilinear(&self) -> bool
Test if this edge is either horizontal or vertical.
pub fn is_horizontal(&self) -> bool
Test if this edge is horizontal.
pub fn is_vertical(&self) -> bool
Test if this edge is vertical.
pub fn vector(&self) -> Vector<T>
Returns the vector from self.start
to self.end
.
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.
pub fn contains_point(&self, point: Point<T>) -> ContainsResult
Test if point lies on the edge. Includes start and end points of edge.
pub fn line_contains_point(&self, point: Point<T>) -> bool
Test if point lies on the line defined by the edge.
pub fn is_parallel(&self, other: &Edge<T>) -> bool
Test if two edges are parallel.
pub fn is_collinear(&self, other: &Edge<T>) -> bool where
T: CoordinateType,
T: CoordinateType,
Test if two edges are collinear, i.e. are on the same line.
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).
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".
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".
pub fn lines_intersect_approx(
&self,
other: &Edge<T>,
epsilon_squared: T
) -> bool
&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.
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.
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.
pub fn edges_intersect(&self, other: &Edge<T>) -> ContainsResult
Test if two edges intersect. If the edges coincide, they also intersect.
impl<T> Edge<T> where
T: CoordinateType + NumCast,
T: CoordinateType + NumCast,
pub fn line_contains_point_approx<F>(
&self,
point: Point<T>,
tolerance: F
) -> bool where
F: NumCast + Float,
&self,
point: Point<T>,
tolerance: F
) -> bool where
F: NumCast + Float,
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,
&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,
&self,
other: &Edge<T>,
tolerance: F
) -> EdgeIntersection<F, T> where
F: Float,
Compute the intersection with another edge.
impl<T> Edge<T> where
T: CoordinateType + NumCast,
T: CoordinateType + NumCast,
pub fn try_cast<Target>(&self) -> Option<Edge<Target>> where
Target: NumCast + CoordinateType,
Target: NumCast + CoordinateType,
Try to cast into other data type.
When the conversion fails None
is returned.
pub fn cast<Target>(&self) -> Edge<Target> where
Target: CoordinateType + NumCast,
Target: CoordinateType + NumCast,
pub fn cast_to_float<Target>(&self) -> Edge<Target> where
Target: CoordinateType + NumCast + Float,
Target: CoordinateType + NumCast + Float,
pub fn distance_to_line<F>(&self, point: Point<T>) -> F where
F: Float,
F: 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.
pub fn distance<F>(&self, point: Point<T>) -> F where
F: Float,
F: Float,
Calculate distance from point to the edge.
pub fn projection_approx<F>(&self, point: Point<T>) -> Point<F> where
F: Float,
F: Float,
Find the perpendicular projection of a point onto the line of the edge.
pub fn reflection_approx<F>(&self, point: Point<T>) -> Point<F> where
F: Float,
F: Float,
Find the mirror image of point
.
pub fn distance_to_line_abs_approx<F>(&self, point: Point<T>) -> F where
F: Float,
F: Float,
Calculate the absolute distance from the point onto the unbounded line coincident with this edge.
pub fn contains_point_approx<F>(&self, point: Point<T>, tolerance: F) -> bool where
F: Float,
F: Float,
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).
impl<T> Edge<Ratio<T>> where
T: CoordinateType + Integer,
T: CoordinateType + Integer,
pub fn line_intersection_rational(
&self,
other: Edge<Ratio<T>>
) -> LineIntersection<Ratio<T>, Ratio<T>>
&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>>
&self,
other: &Edge<Ratio<T>>
) -> EdgeIntersection<Ratio<T>, Ratio<T>>
Compute the intersection with another edge.
impl<T> Edge<T> where
T: CoordinateType + Debug + PrimInt,
T: CoordinateType + Debug + PrimInt,
pub fn line_intersection_rounded(
&self,
other: Edge<T>
) -> LineIntersection<T, T>
&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)));
pub fn edge_intersection_rounded(
&self,
other: &Edge<T>
) -> EdgeIntersection<T, T>
&self,
other: &Edge<T>
) -> EdgeIntersection<T, 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.
Trait Implementations
impl<T> BoundingBox<T> for Edge<T> where
T: CoordinateType,
T: CoordinateType,
pub fn bounding_box(&self) -> Rect<T>
impl<T> Clone for Edge<T> where
T: CoordinateType + Clone,
T: CoordinateType + Clone,
pub fn clone(&self) -> Edge<T>
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T> Copy for Edge<T> where
T: CoordinateType + Copy,
T: CoordinateType + Copy,
impl<T> Debug for Edge<T> where
T: CoordinateType + Debug,
T: CoordinateType + Debug,
impl<T> Eq for Edge<T> where
T: CoordinateType + Eq,
T: CoordinateType + Eq,
impl<T> From<[Point<T>; 2]> for Edge<T> where
T: CoordinateType,
T: CoordinateType,
impl<T> From<(Point<T>, Point<T>)> for Edge<T> where
T: CoordinateType,
T: CoordinateType,
impl<T> From<Edge<T>> for Geometry<T> where
T: CoordinateType,
T: CoordinateType,
impl<T> Hash for Edge<T> where
T: CoordinateType + Hash,
T: CoordinateType + Hash,
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T> Into<(Point<T>, Point<T>)> for Edge<T> where
T: CoordinateType,
T: CoordinateType,
impl<'_, T> Into<(Point<T>, Point<T>)> for &'_ Edge<T> where
T: CoordinateType,
T: CoordinateType,
impl<'_, T> Into<Edge<T>> for &'_ REdge<T> where
T: CoordinateType,
T: CoordinateType,
impl<T> MapPointwise<T> for Edge<T> where
T: CoordinateType,
T: CoordinateType,
impl<T> PartialEq<Edge<T>> for Edge<T> where
T: CoordinateType + PartialEq<T>,
T: CoordinateType + PartialEq<T>,
impl<T> StructuralEq for Edge<T> where
T: CoordinateType,
T: CoordinateType,
impl<T> StructuralPartialEq for Edge<T> where
T: CoordinateType,
T: CoordinateType,
impl<T> TryBoundingBox<T> for Edge<T> where
T: CoordinateType,
T: CoordinateType,
pub fn try_bounding_box(&self) -> Option<Rect<T>>
Get bounding box of edge (always exists).
impl<T, Dst> TryCastCoord<T, Dst> for Edge<T> where
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
T: CoordinateType + NumCast,
Dst: CoordinateType + NumCast,
type Output = Edge<Dst>
Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more
pub fn try_cast(&self) -> Option<<Edge<T> as TryCastCoord<T, Dst>>::Output>
pub fn cast(&self) -> Self::Output
impl<'_, T> TryFrom<&'_ Edge<T>> for REdge<T> where
T: CoordinateType,
T: CoordinateType,
Auto Trait Implementations
impl<T> RefUnwindSafe for Edge<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Edge<T> where
T: Send,
T: Send,
impl<T> Sync for Edge<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Edge<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Edge<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<S, T> Mirror<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
S: MapPointwise<T>,
T: CoordinateType,
pub fn mirror_x(&self) -> S
Return the geometrical object mirrored at the x
axis.
pub fn mirror_y(&self) -> S
Return the geometrical object mirrored at the y
axis.
impl<S, T> RotateOrtho<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
S: MapPointwise<T>,
T: CoordinateType,
pub fn rotate_ortho(&self, a: Angle) -> S
impl<S, T> Scale<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
S: MapPointwise<T>,
T: CoordinateType,
pub fn scale(&self, factor: T) -> S
impl<T> TextType for T where
T: Clone + Eq + Debug + Hash,
T: Clone + Eq + Debug + Hash,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T
[src]
pub fn clone_into(&self, target: &mut T)
[src]
impl<S, T> Translate<T> for S where
S: MapPointwise<T>,
T: CoordinateType,
S: MapPointwise<T>,
T: CoordinateType,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,