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-
ItemShapemarquee 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
impl SceneRegion
Sourcepub fn lasso_with_rule(path: Path, rule: FillRule) -> Self
pub fn lasso_with_rule(path: Path, rule: FillRule) -> Self
A closed freehand region under an explicit fill rule.
Sourcepub fn stroke(path: Path, width: f32) -> Self
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?”.
Sourcepub fn from_geometry(
geometry: Rc<ShapeGeometry>,
fill: Option<FillRule>,
band: Option<f32>,
) -> Self
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.
Sourcepub fn from_screen_rect(
screen_rect: Rect,
screen_to_scene: &Transform2D,
) -> Self
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.
Sourcepub fn bounding_rect(&self) -> Rect
pub fn bounding_rect(&self) -> Rect
Broad-phase AABB — what goes to the spatial index. Band-inflated.
Sourcepub fn as_rect(&self) -> Option<Rect>
pub fn as_rect(&self) -> Option<Rect>
Some(rect) iff this region is an axis-aligned box with no band.
Sourcepub fn to_local(&self, scene_to_local: &Transform2D) -> SceneRegion
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.
Sourcepub fn contains_point(&self, p: Point) -> bool
pub fn contains_point(&self, p: Point) -> bool
Whether p — in the region’s own coordinate space — is inside it.
Sourcepub fn has_area(&self) -> bool
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.
Trait Implementations§
Source§impl Clone for SceneRegion
impl Clone for SceneRegion
Source§fn clone(&self) -> SceneRegion
fn clone(&self) -> SceneRegion
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl !RefUnwindSafe for SceneRegion
impl !Send for SceneRegion
impl !Sync for SceneRegion
impl !UnwindSafe for SceneRegion
impl Freeze for SceneRegion
impl Unpin for SceneRegion
impl UnsafeUnpin for SceneRegion
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.impl<T> ErasedDestructor for Twhere
T: 'static,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
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