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>
impl<'a, G: Preparable + ?Sized> Prepared<'a, G>
Sourcepub fn locate(&self, p: Point) -> Location
pub fn locate(&self, p: Point) -> Location
Location of p relative to the prepared geometry: locate(g, p).
Sourcepub fn intersects<B: Geometry + ?Sized>(&self, b: &B) -> bool
pub fn intersects<B: Geometry + ?Sized>(&self, b: &B) -> bool
true when the prepared geometry and b share a point:
intersects(g, b).
Sourcepub fn distance_less_than<B: Geometry + ?Sized>(&self, b: &B, d: i64) -> bool
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).
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>
impl<'a, G> Sync for Prepared<'a, G>
impl<'a, G> Unpin for Prepared<'a, G>
impl<'a, G> UnsafeUnpin for Prepared<'a, G>
impl<'a, G> UnwindSafe for Prepared<'a, G>
Blanket Implementations§
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
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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