Skip to main content

EdgeMap

Struct EdgeMap 

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

Per-pixel edge strength for one frozen frame, precomputed once.

Two maps, one per axis, quantized to u8 — a frame’s worth of f32 pairs is tens of megabytes per monitor, and the extra precision buys nothing when the answer is an integer pixel column.

Implementations§

Source§

impl EdgeMap

Source

pub fn new(gray: &GrayImage) -> Self

Detect edges in a frozen frame.

The operator is a forward difference — I(x) - I(x-1) — weighted 3:10:3 across the neighbouring rows in the Scharr manner. The weighting rejects single-pixel noise without smearing the edge’s position; the forward difference is what makes the position unambiguous. A centered difference peaks equally on both pixels of a one-pixel step, and a snap that lands on whichever of the two the cursor happened to approach from is not an answer a user can rely on. Position is the whole product here: an edge detected one pixel off is worse than no edge at all, because the user trusted it.

The convention this fixes is that a boundary sits on the first pixel of the new region. Snapping both sides of a 40px-wide button therefore gives 20 and 60, and the rect drawn between them is 40 wide — the button’s true width, not one pixel short.

Source

pub const fn threshold(&self) -> u8

The strength a gradient must reach to count as an edge: the [EDGE_PERCENT] percentile of this frame’s own gradients, floored at MIN_GRADIENT.

Relative, because an absolute cut that works on a light theme finds nothing on a dark one. Floored, because a nearly blank screen’s 98th percentile is noise, and snapping to noise is worse than not snapping.

Source

pub fn snap(&self, p: Point, radius: i32) -> Snap

Where p wants to go, searching radius pixels either way on each axis independently.

A non-positive radius disables snapping outright rather than searching a degenerate window.

Source

pub fn snap_x(&self, p: Point, radius: i32) -> Option<SnapHit>

Just the vertical-edge search, for callers that move one axis at a time — sliding a shape sideways onto an alignment, say.

Source

pub fn snap_y(&self, p: Point, radius: i32) -> Option<SnapHit>

Just the horizontal-edge search. See Self::snap_x.

Trait Implementations§

Source§

impl Clone for EdgeMap

Source§

fn clone(&self) -> EdgeMap

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 EdgeMap

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
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.