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 PartialOrd for Polygon
impl PartialOrd for Polygon
Source§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 TransformRef for Polygon
impl TransformRef for Polygon
Source§fn transform_ref(&self, trans: Transformation) -> Self
fn transform_ref(&self, trans: Transformation) -> Self
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.Source§impl TranslateRef for Polygon
impl TranslateRef for Polygon
Source§fn translate_ref(&self, p: Point) -> Self
fn translate_ref(&self, p: Point) -> Self
Translates the shape by
Point
, returning a new shape.impl Eq for Polygon
impl StructuralPartialEq for Polygon
Auto Trait Implementations§
impl Freeze for Polygon
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