RPolygon

Struct RPolygon 

Source
pub struct RPolygon<T> {
    pub origin: Point<T, T>,
    /* private fields */
}
Expand description

The RPolygon struct represents a rectilinear polygon with an origin point and a vector of 2D vectors.

Properties:

  • origin: The origin property represents the starting point or the reference point of the rectilinear polygon. It is of type Point<T, T>, where T is the type of the coordinates of the point (e.g., integer or floating-point).
  • vecs: vecs is a vector that stores the vectors representing the sides of the rectilinear polygon.

Fields§

§origin: Point<T, T>

Implementations§

Source§

impl<T: Clone + Num + Copy + AddAssign + Ord> RPolygon<T>

Source

pub fn new(coords: &[Point<T, T>]) -> Self

The new function constructs a new RPolygon object by calculating the origin and vectors based on the given coordinates.

Arguments:

  • coords: The coords parameter is an array of Point<T, T> objects. It represents the coordinates of the points that define the polygon. The first element of the array (coords[0]) is considered as the origin of the polygon, and the remaining elements represent the vectors from the origin to the

Returns:

The new function is returning an instance of the RPolygon struct.

Source

pub fn from_origin_and_vectors( origin: Point<T, T>, vecs: Vec<Vector2<T, T>>, ) -> Self

Constructs a new Polygon from origin and displacement vectors

§Arguments
  • origin - The origin point of the polygon
  • vecs - Vector of displacement vectors from origin
Source

pub fn from_pointset(pointset: &[Point<T, T>]) -> Self

Constructs a new Polygon from a point set

The first point in the set is used as the origin, and the remaining points are used to construct displacement vectors relative to the origin.

Source

pub fn add_assign(&mut self, rhs: Vector2<T, T>)
where T: AddAssign,

Translates the polygon by adding a vector to its origin

Source

pub fn sub_assign(&mut self, rhs: Vector2<T, T>)
where T: SubAssign,

Translates the polygon by subtracting a vector from its origin

Source

pub fn signed_area(&self) -> T

The signed_area function calculates the signed area of a polygon.

Returns:

The function signed_area returns a value of type T.

Source

pub fn vertices(&self) -> Vec<Point<T, T>>

Gets all vertices of the polygon as points

Source

pub fn bounding_box(&self) -> (Point<T, T>, Point<T, T>)

Gets the bounding box of the polygon

Source

pub fn is_rectilinear(&self) -> bool

Checks if the polygon is rectilinear

A polygon is rectilinear if all its edges are either horizontal or vertical.

§Returns

true if the polygon is rectilinear, false otherwise

§Examples
use physdes::point::Point;
use physdes::rpolygon::RPolygon;

let p1 = Point::new(0, 0);
let p2 = Point::new(0, 1);
let p3 = Point::new(1, 1);
let p4 = Point::new(1, 0);
let poly = RPolygon::new(&[p1, p2, p3, p4]);
assert!(poly.is_rectilinear());

let p5 = Point::new(0, 0);
let p6 = Point::new(1, 1);
let p7 = Point::new(0, 2);
let poly2 = RPolygon::new(&[p5, p6, p7]);
assert!(poly2.is_rectilinear());
Source

pub fn is_anticlockwise(&self) -> bool
where T: PartialOrd,

Checks if the polygon is oriented anticlockwise

Source§

impl<T: Clone + Num + Ord + Copy> RPolygon<T>

Source

pub fn create_mono_rpolygon<F>( pointset: &[Point<T, T>], f: F, ) -> (Vec<Point<T, T>>, bool)
where F: Fn(&Point<T, T>) -> (T, T),

The create_mono_rpolygon function creates a monotone polygon from a given set of points based on a provided comparison function.

Arguments:

  • pointset: pointset is a slice of Point<T, T> elements. It represents a set of points in a two-dimensional space.
  • f: The parameter f is a closure that takes a reference to a reference of a Point<T, T> and returns a tuple of two values of type T. The closure is used to determine the ordering of the points in the pointset. The first value of the tuple represents the x-coordinate
Source

pub fn create_xmono_rpolygon( pointset: &[Point<T, T>], ) -> (Vec<Point<T, T>>, bool)

The function create_xmono_rpolygon creates a monotone RPolygon object using a given point set, with the x-coordinate as the primary sorting criterion.

Arguments:

  • pointset: A slice of Point objects
Source

pub fn create_ymono_rpolygon( pointset: &[Point<T, T>], ) -> (Vec<Point<T, T>>, bool)

The function create_ymono_rpolygon creates a y-monotone RPolygon object from a given point set.

Arguments:

  • pointset: A slice of Point objects, where each Point object has two fields: ycoord and xcoord.
Source

pub fn point_in_rpolygon(pointset: &[Point<T, T>], q: &Point<T, T>) -> bool

The function point_in_rpolygon determines if a given point is within a polygon.

The code below is from Wm. Randolph Franklin wrf@ecse.rpi.edu (see URL below) with some minor modifications for integer. It returns true for strictly interior points, false for strictly exterior, and ub for points on the boundary. The boundary behavior is complex but determined; in particular, for a partition of a region into polygons, each Point is “in” exactly one Polygon. (See p.243 of [O’Rourke (C)] for a discussion of boundary behavior.)

See http://www.faqs.org/faqs/graphics/algorithms-faq/ Subject 2.03

Arguments:

  • pointset: A slice of points representing the vertices of the polygon. Each point has x and y coordinates.
  • q: The parameter q represents the point that we want to determine if it is within the polygon or not.

Returns:

The function point_in_polygon returns a boolean value. It returns true if the given point q is strictly inside the polygon defined by the pointset array, false if the point is strictly outside the polygon, and ub (undefined behavior) if the point lies on the boundary of the polygon.

Trait Implementations§

Source§

impl<T: Clone> Clone for RPolygon<T>

Source§

fn clone(&self) -> RPolygon<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for RPolygon<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Default> Default for RPolygon<T>

Source§

fn default() -> RPolygon<T>

Returns the “default value” for a type. Read more
Source§

impl<T: PartialEq> PartialEq for RPolygon<T>

Source§

fn eq(&self, other: &Self) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<T: Eq> Eq for RPolygon<T>

Auto Trait Implementations§

§

impl<T> Freeze for RPolygon<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for RPolygon<T>
where T: RefUnwindSafe,

§

impl<T> Send for RPolygon<T>
where T: Send,

§

impl<T> Sync for RPolygon<T>
where T: Sync,

§

impl<T> Unpin for RPolygon<T>
where T: Unpin,

§

impl<T> UnwindSafe for RPolygon<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.