Struct libreda_db::prelude::Edge
source · [−]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
sourceimpl<T> Edge<T> where
T: PartialEq<T>,
impl<T> Edge<T> where
T: PartialEq<T>,
sourcepub fn is_degenerate(&self) -> bool
pub fn is_degenerate(&self) -> bool
Check if edge is degenerate. An edge is degenerate if start point and end point are equal.
sourcepub fn is_rectilinear(&self) -> bool
pub fn is_rectilinear(&self) -> bool
Test if this edge is either horizontal or vertical.
sourcepub fn is_horizontal(&self) -> bool
pub fn is_horizontal(&self) -> bool
Test if this edge is horizontal.
sourcepub fn is_vertical(&self) -> bool
pub fn is_vertical(&self) -> bool
Test if this edge is vertical.
sourceimpl<T> Edge<T> where
T: CoordinateType,
impl<T> Edge<T> where
T: CoordinateType,
sourcepub fn side_of(&self, point: Point<T>) -> Side
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.
sourcepub fn contains_point(&self, point: Point<T>) -> ContainsResult
pub fn contains_point(&self, point: Point<T>) -> ContainsResult
Test if point lies on the edge. Includes start and end points of edge.
sourcepub fn line_contains_point(&self, point: Point<T>) -> bool
pub fn line_contains_point(&self, point: Point<T>) -> bool
Test if point lies on the line defined by the edge.
sourcepub fn is_parallel(&self, other: &Edge<T>) -> bool
pub fn is_parallel(&self, other: &Edge<T>) -> bool
Test if two edges are parallel.
sourcepub fn is_collinear(&self, other: &Edge<T>) -> bool where
T: CoordinateType,
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.
sourcepub fn is_coincident(&self, other: &Edge<T>) -> bool
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).
sourcepub fn is_parallel_approx(&self, other: &Edge<T>, epsilon_squared: T) -> bool
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”.
sourcepub fn is_collinear_approx(&self, other: &Edge<T>, epsilon_squared: T) -> bool
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”.
sourcepub fn lines_intersect_approx(&self, other: &Edge<T>, epsilon_squared: T) -> bool
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.
sourcepub fn crossed_by_line(&self, other: &Edge<T>) -> ContainsResult
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.
sourcepub fn lines_intersect(&self, other: &Edge<T>) -> bool
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.
sourcepub fn edges_intersect(&self, other: &Edge<T>) -> ContainsResult
pub fn edges_intersect(&self, other: &Edge<T>) -> ContainsResult
Test if two edges intersect. If the edges coincide, they also intersect.
sourceimpl<T> Edge<T> where
T: CoordinateType + NumCast,
impl<T> Edge<T> where
T: CoordinateType + NumCast,
sourcepub fn line_contains_point_approx<F>(&self, point: Point<T>, tolerance: F) -> bool where
F: Float + NumCast,
pub fn line_contains_point_approx<F>(&self, point: Point<T>, tolerance: F) -> bool where
F: Float + NumCast,
Test if point lies on the line defined by the edge.
sourcepub 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.));
sourcepub fn edge_intersection_approx<F>(
&self,
other: &Edge<T>,
tolerance: F
) -> EdgeIntersection<F, T, Edge<T>> where
F: Float,
pub fn edge_intersection_approx<F>(
&self,
other: &Edge<T>,
tolerance: F
) -> EdgeIntersection<F, T, Edge<T>> where
F: Float,
Compute the intersection with another edge.
sourceimpl<T> Edge<T> where
T: CoordinateType + NumCast,
impl<T> Edge<T> where
T: CoordinateType + NumCast,
sourcepub fn try_cast<Target>(&self) -> Option<Edge<Target>> where
Target: NumCast + CoordinateType,
pub fn try_cast<Target>(&self) -> Option<Edge<Target>> where
Target: NumCast + CoordinateType,
Try to cast into other data type.
When the conversion fails None
is returned.
sourcepub fn cast<Target>(&self) -> Edge<Target> where
Target: CoordinateType + NumCast,
pub fn cast<Target>(&self) -> Edge<Target> where
Target: CoordinateType + NumCast,
sourcepub 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,
sourcepub fn distance_to_line<F>(&self, point: Point<T>) -> F where
F: Float,
pub fn distance_to_line<F>(&self, point: Point<T>) -> F where
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.
sourcepub fn distance<F>(&self, point: Point<T>) -> F where
F: Float,
pub fn distance<F>(&self, point: Point<T>) -> F where
F: Float,
Calculate distance from point to the edge.
sourcepub fn projection_approx<F>(&self, point: Point<T>) -> Point<F> where
F: Float,
pub fn projection_approx<F>(&self, point: Point<T>) -> Point<F> where
F: Float,
Find the perpendicular projection of a point onto the line of the edge.
sourcepub fn reflection_approx<F>(&self, point: Point<T>) -> Point<F> where
F: Float,
pub fn reflection_approx<F>(&self, point: Point<T>) -> Point<F> where
F: Float,
Find the mirror image of point
.
sourcepub fn distance_to_line_abs_approx<F>(&self, point: Point<T>) -> F where
F: Float,
pub fn distance_to_line_abs_approx<F>(&self, point: Point<T>) -> F where
F: Float,
Calculate the absolute distance from the point onto the unbounded line coincident with this edge.
sourcepub fn contains_point_approx<F>(&self, point: Point<T>, tolerance: F) -> bool where
F: Float,
pub fn contains_point_approx<F>(&self, point: Point<T>, tolerance: F) -> bool where
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).
sourceimpl<T> Edge<T> where
T: CoordinateType + PrimInt + Debug,
impl<T> Edge<T> where
T: CoordinateType + PrimInt + Debug,
sourcepub fn line_intersection_rounded(&self, other: Edge<T>) -> LineIntersection<T, T>
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)));
sourcepub fn edge_intersection_rounded(
&self,
other: &Edge<T>
) -> EdgeIntersection<T, T, Edge<T>>
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.
sourceimpl<T> Edge<Ratio<T>> where
T: CoordinateType + Integer,
impl<T> Edge<Ratio<T>> where
T: CoordinateType + Integer,
sourcepub 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))));
sourcepub fn edge_intersection_rational(
&self,
other: &Edge<Ratio<T>>
) -> EdgeIntersection<Ratio<T>, Ratio<T>, Edge<Ratio<T>>>
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
sourceimpl<T> BoundingBox<T> for Edge<T> where
T: Copy + PartialOrd<T>,
impl<T> BoundingBox<T> for Edge<T> where
T: Copy + PartialOrd<T>,
sourcefn bounding_box(&self) -> Rect<T>
fn bounding_box(&self) -> Rect<T>
Return the bounding box of this geometry.
sourceimpl<'de, T> Deserialize<'de> for Edge<T> where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Edge<T> where
T: Deserialize<'de>,
sourcefn deserialize<__D>(
__deserializer: __D
) -> Result<Edge<T>, <__D as Deserializer<'de>>::Error> where
__D: Deserializer<'de>,
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
sourceimpl<T> EdgeEndpoints<T> for Edge<T> where
T: Copy,
impl<T> EdgeEndpoints<T> for Edge<T> where
T: Copy,
sourceimpl<T> Into<Edge<T>> for &REdge<T> where
T: CoordinateType,
impl<T> Into<Edge<T>> for &REdge<T> where
T: CoordinateType,
sourceimpl<T> Into<Edge<T>> for REdge<T> where
T: CoordinateType,
impl<T> Into<Edge<T>> for REdge<T> where
T: CoordinateType,
sourceimpl<T> MapPointwise<T> for Edge<T> where
T: Copy,
impl<T> MapPointwise<T> for Edge<T> where
T: Copy,
sourceimpl<T> Serialize for Edge<T> where
T: Serialize,
impl<T> Serialize for Edge<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 Edge<T> where
T: Copy + PartialOrd<T>,
impl<T> TryBoundingBox<T> for Edge<T> where
T: Copy + PartialOrd<T>,
sourcefn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
Get bounding box of edge (always exists).
sourceimpl<T, Dst> TryCastCoord<T, Dst> for Edge<T> where
T: Copy + NumCast,
Dst: Copy + NumCast,
impl<T, Dst> TryCastCoord<T, Dst> for Edge<T> where
T: Copy + NumCast,
Dst: Copy + NumCast,
sourceimpl<T> TryFrom<&Edge<T>> for REdge<T> where
T: CoordinateType,
impl<T> TryFrom<&Edge<T>> for REdge<T> where
T: CoordinateType,
impl<T> Copy for Edge<T> where
T: Copy,
impl<T> Eq for Edge<T> where
T: Eq,
impl<T> StructuralEq for Edge<T>
impl<T> StructuralPartialEq for Edge<T>
Auto Trait Implementations
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
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
sourceimpl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
impl<S, T> RotateOrtho<T> for S where
T: Copy + Zero + Sub<T, Output = T>,
S: MapPointwise<T>,
sourcefn rotate_ortho(&self, a: Angle) -> S
fn rotate_ortho(&self, a: Angle) -> S
Rotate the geometrical shape by a multiple of 90 degrees.