Skip to main content

Prepared

Struct Prepared 

Source
pub struct Prepared<'a, G: Preparable + ?Sized> { /* private fields */ }
Expand description

A geometry prepared for repeated queries: a spatial index over its segments and rings.

Build it once for a geometry queried many times (a zone fill checked against every pad, track and via in DRC); every method returns exactly what the free function of the same name returns with the prepared geometry as first argument, closest points included, at a cost that follows the size of the other operand and of the prepared geometry near it rather than the size of the whole prepared geometry.

Building costs about as much as a few free-function queries (O(n log n) for n segments); contains and distance also compute a little more on their first call. A Prepared is Send + Sync when the geometry is.

use polyclip::*;
let zone = Polygon::new(
    Ring::from([(0, 0), (1000, 0), (1000, 1000), (0, 1000)]),
    vec![Ring::from([(400, 400), (400, 600), (600, 600), (600, 400)])],
);
let prepared = Prepared::new(&zone);
let pad = Ring::from([(450, 450), (550, 450), (550, 550), (450, 550)]);
assert!(!prepared.intersects(&pad));
assert!(prepared.distance_less_than(&pad, 51));
assert!(!prepared.distance_less_than(&pad, 50));
assert_eq!(prepared.locate(Point::new(500, 500)), Location::Outside);
assert_eq!(prepared.distance_less_than(&pad, 51), distance_less_than(&zone, &pad, 51));

Implementations§

Source§

impl<'a, G: Preparable + ?Sized> Prepared<'a, G>

Source

pub fn new(geom: &'a G) -> Self

Indexes geom.

Source

pub fn geometry(&self) -> &'a G

The prepared geometry.

Source

pub fn locate(&self, p: Point) -> Location

Location of p relative to the prepared geometry: locate(g, p).

Source

pub fn intersects<B: Geometry + ?Sized>(&self, b: &B) -> bool

true when the prepared geometry and b share a point: intersects(g, b).

Source

pub fn distance_less_than<B: Geometry + ?Sized>(&self, b: &B, d: i64) -> bool

true when the distance between the prepared geometry and b is less than d: distance_less_than(g, b, d).

Source

pub fn contains<B: Geometry + ?Sized>(&self, b: &B) -> bool

true when every point of b belongs to the prepared geometry: contains(g, b).

Source

pub fn distance<B: Geometry + ?Sized>(&self, b: &B) -> Option<Closest>

Exact minimum distance between the prepared geometry and b, with a pair of closest points: distance(g, b), the same pair included.

Auto Trait Implementations§

§

impl<'a, G> !Freeze for Prepared<'a, G>

§

impl<'a, G> RefUnwindSafe for Prepared<'a, G>

§

impl<'a, G> Send for Prepared<'a, G>
where &'a G: Send, G: ?Sized,

§

impl<'a, G> Sync for Prepared<'a, G>
where &'a G: Sync, G: ?Sized,

§

impl<'a, G> Unpin for Prepared<'a, G>
where &'a G: Unpin, G: ?Sized,

§

impl<'a, G> UnsafeUnpin for Prepared<'a, G>
where &'a G: UnsafeUnpin, G: ?Sized,

§

impl<'a, G> UnwindSafe for Prepared<'a, G>
where &'a G: UnwindSafe, G: ?Sized,

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> 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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.