Skip to main content

SceneRegion

Struct SceneRegion 

Source
pub struct SceneRegion { /* private fields */ }
Expand description

The region a geometry query asks about.

Two forms, and the difference matters:

  • a rectangle — the rubber band under an unrotated view, and the one form that keeps a query on the same one-rect-compare fast path the pre-ItemShape marquee took;
  • a path — the exact quadrilateral of a rubber band under a rotated view (rather than its enlarged axis-aligned hull, which over-selects), a freehand lasso, or a stroked path for “what lies along this connector?”.

A region is in scene coordinates until SceneRegion::to_local maps it into an item’s frame; a rectangle that survives that map as a rectangle stays one, and one that does not becomes the exact transformed quadrilateral rather than being rounded up to an AABB.

Implementations§

Source§

impl SceneRegion

Source

pub fn rect(rect: Rect) -> Self

An axis-aligned box.

Source

pub fn empty() -> Self

A region that covers nothing. Every query against it is false.

Source

pub fn lasso(path: Path) -> Self

A closed freehand region, filled under [FillRule::Winding].

Source

pub fn lasso_with_rule(path: Path, rule: FillRule) -> Self

A closed freehand region under an explicit fill rule.

Source

pub fn stroke(path: Path, width: f32) -> Self

The stroke band of a path, width wide — “what lies along this line?” rather than “what lies inside this loop?”.

Source

pub fn from_geometry( geometry: Rc<ShapeGeometry>, fill: Option<FillRule>, band: Option<f32>, ) -> Self

A region from a shared geometry handle, with an explicit interior and/or band. The general constructor the others are sugar for; used to re-publish an item’s own shape as the region a collision query asks about.

Source

pub fn from_screen_rect( screen_rect: Rect, screen_to_scene: &Transform2D, ) -> Self

A screen-space rectangle mapped through screen_to_scene.

Stays a rectangle when the transform preserves axes, and becomes the exact transformed quadrilateral when it does not — which is what stops a rubber band under a rotated view from selecting everything in the enlarged hull of itself.

Source

pub fn bounding_rect(&self) -> Rect

Broad-phase AABB — what goes to the spatial index. Band-inflated.

Source

pub fn as_rect(&self) -> Option<Rect>

Some(rect) iff this region is an axis-aligned box with no band.

Source

pub fn is_empty(&self) -> bool

Whether the region covers nothing at all.

Source

pub fn to_local(&self, scene_to_local: &Transform2D) -> SceneRegion

Map into another coordinate frame — an item’s local space, via the inverse of its scene transform.

A rectangle survives as a rectangle only when the transform preserves axes; otherwise it becomes the exact transformed quadrilateral. A path goes through [Path::transformed], which is exact for every affine — including an arc, which it expands into cubics rather than moving the rectangle an arc is stored as and keeping its angles.

§A band under an anisotropic map

A band is a distance, and an affine that stretches one axis more than another does not carry a distance: the exact image of a round band is an elliptical one, which no single width can describe. A rotation, a uniform scale and a translation are all isotropic, so for every one of them the mapped width is exact and none of this applies.

Under a genuinely anisotropic map the width is scaled by the transform’s smallest stretch — its least singular value — which is the widest uniform band that fits inside the true image. Under scale(1, 10) the true band is between one and ten times as wide depending on the direction, and the mapped one claims one: it can under-reach along the stretched axis, and it never claims ground the true band does not cover. Transform2D::geometric_scale — the geometric mean of the two stretches — would err in both directions at once, over-reaching along one axis while under-reaching along the other, which is why it is not used here.

This is a one-sided approximation, and the framework’s own region queries do not rely on it. Under-reaching keeps IntersectsItemShape inside IntersectsItemBoundingRect, but it puts ContainsItemShape outside ContainsItemBoundingRect — the two families want opposite errors, so no scalar serves both. A query therefore never maps a banded region down into an anisotropic item’s frame: it lifts the item into scene space instead, where the band is still round. See ItemShape::contained_by_scene_region, which is the door Scene::items_in_region comes in by. What is left here is the honest answer for a caller who has asked for a mapped region and will measure distances in the target frame.

Source

pub fn contains_point(&self, p: Point) -> bool

Whether p — in the region’s own coordinate space — is inside it.

Source

pub fn has_area(&self) -> bool

Whether the region covers any area — false for a zero-width path (a bare line: the items_along_path query) and for a degenerate box. See ItemShape::intersects_region, which relaxes its rule for exactly this case.

A filled outline needs at least three points on some subpath to enclose anything; two points are a line, which [subpaths_contain_point] already declines to fill.

Source

pub fn clearance(&self, p: Point) -> f32

How far p is from leaving the region: positive inside, negative outside, in the region’s own units. Used by the containment modes to ask whether a band — not merely a centreline — fits inside.

Trait Implementations§

Source§

impl Clone for SceneRegion

Source§

fn clone(&self) -> SceneRegion

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SceneRegion

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> Downcast<T> for T

§

fn downcast(&self) -> &T

§

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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
§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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.
§

impl<T> Upcast<T> for T

§

fn upcast(&self) -> Option<&T>

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more