pub struct Polygon { /* private fields */ }
Expand description
A polygon, with vertex coordinates given
Implementations§
source§impl Polygon
impl Polygon
sourcepub fn from_verts(vec: Vec<Point>) -> Self
pub fn from_verts(vec: Vec<Point>) -> Self
Creates a polygon with given vertices.
sourcepub fn bot(&self) -> i64
pub fn bot(&self) -> i64
Returns the bottom y-coordinate in the polygon.
§Example
let points = vec![
Point { x: 0, y: 0 },
Point { x: 1, y: 2 },
Point { x: -4, y: 5 },
];
let polygon = Polygon::from_verts(points);
assert_eq!(polygon.bot(), 0);
sourcepub fn top(&self) -> i64
pub fn top(&self) -> i64
Returns the top y-coordinate in the polygon.
§Example
let points = vec![
Point { x: 0, y: 0 },
Point { x: 1, y: 2 },
Point { x: -4, y: 5 },
];
let polygon = Polygon::from_verts(points);
assert_eq!(polygon.top(), 5);
sourcepub fn left(&self) -> i64
pub fn left(&self) -> i64
Returns the leftmost x-coordinate in the polygon.
§Example
let points = vec![
Point { x: 0, y: 0 },
Point { x: 1, y: 2 },
Point { x: -4, y: 5 },
];
let polygon = Polygon::from_verts(points);
assert_eq!(polygon.left(), -4);
sourcepub fn right(&self) -> i64
pub fn right(&self) -> i64
Returns the rightmost x-coordinate in the polygon.
§Example
let points = vec![
Point { x: 0, y: 0 },
Point { x: 1, y: 2 },
Point { x: -4, y: 5 },
];
let polygon = Polygon::from_verts(points);
assert_eq!(polygon.right(), 1);
sourcepub fn center(&self) -> Point
pub fn center(&self) -> Point
Returns the center point of the polygon.
Returns a point with x-coordinate equal to the average of all x-coordinates and y-coordinate equal to the average of all y-coordinates. Note that the current behavior is to round down.
§Example
let points = vec![
Point { x: 0, y: 0 },
Point { x: 1, y: 2 },
Point { x: -4, y: 5 },
];
let polygon = Polygon::from_verts(points);
assert_eq!(polygon.center(), Point::new(-1, 2));
Trait Implementations§
source§impl Contains<Point> for Polygon
impl Contains<Point> for Polygon
source§fn contains(&self, p: &Point) -> Containment
fn contains(&self, p: &Point) -> Containment
Determines if a point is contained within a polygon.
§Example
let points = vec![
Point { x: -4, y: 0 },
Point { x: 0, y: 0 },
Point { x: 1, y: 2 },
Point { x: 2, y: 2 },
Point { x: -4, y: 5 },
];
let p1 = Point::new(0,0);
let p2 = Point::new(0,4);
let p3 = Point::new(-5,3);
let p4 = Point::new(-2,4);
let p5 = Point::new(-2,2);
let polygon = Polygon::from_verts(points);
assert_eq!(polygon.contains(&p1), Containment::Full);
assert_eq!(polygon.contains(&p2), Containment::None);
assert_eq!(polygon.contains(&p3), Containment::None);
assert_eq!(polygon.contains(&p4), Containment::Full);
assert_eq!(polygon.contains(&p5), Containment::Full);
source§fn partially_intersects(&self, other: &T) -> bool
fn partially_intersects(&self, other: &T) -> bool
Returns true if
other
is fully or partially enclosed in this shape.source§impl<'de> Deserialize<'de> for Polygon
impl<'de> Deserialize<'de> for Polygon
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
source§impl Ord for Polygon
impl Ord for Polygon
source§impl PartialEq for Polygon
impl PartialEq for Polygon
source§impl PartialOrd for Polygon
impl PartialOrd for Polygon
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moresource§impl TransformMut for Polygon
impl TransformMut for Polygon
source§fn transform_mut(&mut self, trans: Transformation)
fn transform_mut(&mut self, trans: Transformation)
Applies matrix-vector
Transformation
trans
.source§impl TranslateMut for Polygon
impl TranslateMut for Polygon
source§fn translate_mut(&mut self, p: Point)
fn translate_mut(&mut self, p: Point)
Translates the shape by a
Point
through mutation.impl Eq for Polygon
impl StructuralPartialEq for Polygon
Auto Trait Implementations§
impl RefUnwindSafe for Polygon
impl Send for Polygon
impl Sync for Polygon
impl Unpin for Polygon
impl UnwindSafe for Polygon
Blanket Implementations§
source§impl<T> AlignBbox for Twhere
T: AlignBboxMut,
impl<T> AlignBbox for Twhere
T: AlignBboxMut,
source§impl<T> AlignBboxMut for Twhere
T: AlignRectMut + Bbox,
impl<T> AlignBboxMut for Twhere
T: AlignRectMut + Bbox,
source§impl<T> AlignRect for Twhere
T: AlignRectMut,
impl<T> AlignRect for Twhere
T: AlignRectMut,
source§impl<T> AlignRectMut for Twhere
T: Translate,
impl<T> AlignRectMut for Twhere
T: Translate,
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more