Struct iron_shapes::simple_rpolygon::SimpleRPolygon
source · [−]pub struct SimpleRPolygon<T> { /* private fields */ }
Expand description
A SimpleRPolygon
is a rectilinear polygon. It does not contain holes but can be self-intersecting.
The vertices are stored in an implicit format (one coordinate of two neighbour vertices is always the same
for rectilinear polygons). This reduces memory usage but has the drawback that edges must
alternate between horizontal and vertical. Vertices between two edges of the same orientation will
be dropped.
Implementations
sourceimpl<T> SimpleRPolygon<T>
impl<T> SimpleRPolygon<T>
sourceimpl<T: Clone> SimpleRPolygon<T>
impl<T: Clone> SimpleRPolygon<T>
sourceimpl<T: Copy> SimpleRPolygon<T>
impl<T: Copy> SimpleRPolygon<T>
sourcepub fn edges(&self) -> impl Iterator<Item = REdge<T>> + '_
pub fn edges(&self) -> impl Iterator<Item = REdge<T>> + '_
Get all exterior edges of the polygon.
Examples
use iron_shapes::simple_rpolygon::SimpleRPolygon;
use iron_shapes::redge::REdge;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];
let poly = SimpleRPolygon::try_new(coords).unwrap();
let edges: Vec<_> = poly.edges().collect();
assert_eq!(edges, vec![
REdge::new((0, 0), (1, 0)),
REdge::new((1, 0), (1, 1)),
REdge::new((1, 1), (0, 1)),
REdge::new((0, 1), (0, 0)),
]);
sourceimpl<T: CoordinateType> SimpleRPolygon<T>
impl<T: CoordinateType> SimpleRPolygon<T>
sourcepub fn try_new<P>(points: Vec<P>) -> Option<Self> where
P: Copy + Into<Point<T>>,
pub fn try_new<P>(points: Vec<P>) -> Option<Self> where
P: Copy + Into<Point<T>>,
Create new rectilinear polygon from points.
Returns None
if the polygon defined by the points is not rectilinear.
use iron_shapes::simple_rpolygon::SimpleRPolygon;
let poly1 = SimpleRPolygon::try_new(vec![(0, 0), (1, 0), (1, 1), (0, 1)]);
assert!(poly1.is_some());
// A triangle cannot be rectilinear.
let poly1 = SimpleRPolygon::try_new(vec![(0, 0), (1, 0), (1, 1)]);
assert!(poly1.is_none());
sourcepub fn transformed(&self, tf: &SimpleTransform<T>) -> Self
pub fn transformed(&self, tf: &SimpleTransform<T>) -> Self
Apply the transformation to this rectilinear polygon.
sourcepub fn to_simple_polygon(&self) -> SimplePolygon<T>
pub fn to_simple_polygon(&self) -> SimplePolygon<T>
Convert to a SimplePolygon
.
sourcepub fn convex_hull(&self) -> SimplePolygon<T> where
T: Ord,
pub fn convex_hull(&self) -> SimplePolygon<T> where
T: Ord,
Get the convex hull of the polygon.
Implements Andrew’s Monotone Chain algorithm. See: http://geomalgorithms.com/a10-_hull-1.html
sourcepub fn lower_left_vertex(&self) -> Point<T>
pub fn lower_left_vertex(&self) -> Point<T>
Get the vertex with lowest x-coordinate. Prefer lower y-coordinates to break ties.
Examples
use iron_shapes::simple_rpolygon::SimpleRPolygon;
use iron_shapes::point::Point;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];
let poly = SimpleRPolygon::try_new(coords).unwrap();
assert_eq!(poly.lower_left_vertex(), Point::new(0, 0));
sourcepub fn orientation(&self) -> Orientation
pub fn orientation(&self) -> Orientation
Get the orientation of the polygon, i.e. check if it is wound clock-wise or counter-clock-wise.
Examples
use iron_shapes::simple_rpolygon::SimpleRPolygon;
use iron_shapes::point::Point;
use iron_shapes::types::Orientation;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];
let poly = SimpleRPolygon::try_new(coords).unwrap();
assert_eq!(poly.orientation(), Orientation::CounterClockWise);
sourceimpl<T> SimpleRPolygon<T> where
T: Copy + PartialOrd,
impl<T> SimpleRPolygon<T> where
T: Copy + PartialOrd,
Trait Implementations
sourceimpl<T: Clone> Clone for SimpleRPolygon<T>
impl<T: Clone> Clone for SimpleRPolygon<T>
sourcefn clone(&self) -> SimpleRPolygon<T>
fn clone(&self) -> SimpleRPolygon<T>
Returns a copy of the value. Read more
1.0.0 · sourcefn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from source
. Read more
sourceimpl<T: Debug> Debug for SimpleRPolygon<T>
impl<T: Debug> Debug for SimpleRPolygon<T>
sourceimpl<T: CoordinateType> DoubledOrientedArea<T> for SimpleRPolygon<T>
impl<T: CoordinateType> DoubledOrientedArea<T> for SimpleRPolygon<T>
sourcefn area_doubled_oriented(&self) -> T
fn area_doubled_oriented(&self) -> T
Calculates the doubled oriented area.
Using doubled area allows to compute in the integers because the area of a polygon with integer coordinates is either integer or half-integer.
The area will be positive if the vertices are listed counter-clockwise, negative otherwise.
Complexity: O(n)
Examples
use iron_shapes::traits::DoubledOrientedArea;
use iron_shapes::simple_rpolygon::SimpleRPolygon;
let coords = vec![(0, 0), (1, 0), (1, 1), (0, 1)];
let poly = SimpleRPolygon::try_new(coords).unwrap();
assert_eq!(poly.area_doubled_oriented(), 2);
sourceimpl<T: CoordinateType> From<Rect<T>> for SimpleRPolygon<T>
impl<T: CoordinateType> From<Rect<T>> for SimpleRPolygon<T>
sourceimpl<T> From<SimpleRPolygon<T>> for Geometry<T>
impl<T> From<SimpleRPolygon<T>> for Geometry<T>
sourcefn from(x: SimpleRPolygon<T>) -> Geometry<T>
fn from(x: SimpleRPolygon<T>) -> Geometry<T>
Converts to this type from the input type.
sourceimpl<T: Hash> Hash for SimpleRPolygon<T>
impl<T: Hash> Hash for SimpleRPolygon<T>
sourceimpl<T: PartialEq> PartialEq<SimpleRPolygon<T>> for SimpleRPolygon<T>
impl<T: PartialEq> PartialEq<SimpleRPolygon<T>> for SimpleRPolygon<T>
sourceimpl<T> TryBoundingBox<T> for SimpleRPolygon<T> where
T: Copy + PartialOrd,
impl<T> TryBoundingBox<T> for SimpleRPolygon<T> where
T: Copy + PartialOrd,
sourcefn try_bounding_box(&self) -> Option<Rect<T>>
fn try_bounding_box(&self) -> Option<Rect<T>>
Return the bounding box of this geometry if a bounding box is defined.
sourceimpl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for SimpleRPolygon<T>
impl<T: CoordinateType + NumCast, Dst: CoordinateType + NumCast> TryCastCoord<T, Dst> for SimpleRPolygon<T>
type Output = SimpleRPolygon<Dst>
type Output = SimpleRPolygon<Dst>
Output type of the cast. This is likely the same geometrical type just with other coordinate types. Read more
sourceimpl<T> WindingNumber<T> for SimpleRPolygon<T> where
T: CoordinateType,
impl<T> WindingNumber<T> for SimpleRPolygon<T> where
T: CoordinateType,
sourcefn winding_number(&self, point: Point<T>) -> isize
fn winding_number(&self, point: Point<T>) -> isize
Calculate the winding number of the polygon around this point.
TODO: Define how point on edges and vertices is handled.
sourcefn contains_point_non_oriented(&self, point: Point<T>) -> bool
fn contains_point_non_oriented(&self, point: Point<T>) -> bool
Check if point
is inside the polygon, i.e. the polygons winds around the point
a non-zero number of times. Read more
sourcefn contains_point(&self, point: Point<T>) -> bool
fn contains_point(&self, point: Point<T>) -> bool
Check if point
is inside the polygon, i.e. the polygon winds around the point
an odd number of times. Read more
impl<T: PartialEq> Eq for SimpleRPolygon<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for SimpleRPolygon<T> where
T: RefUnwindSafe,
impl<T> Send for SimpleRPolygon<T> where
T: Send,
impl<T> Sync for SimpleRPolygon<T> where
T: Sync,
impl<T> Unpin for SimpleRPolygon<T> where
T: Unpin,
impl<T> UnwindSafe for SimpleRPolygon<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