Skip to main content

Line

Struct Line 

Source
pub struct Line {
    pub a: Point,
    pub b: Point,
}
Expand description

A two-point measurement: a ruler laid on the frozen image.

Not a Shape. A measure has no interior, no crop, no cutout contribution and no click point, so putting it through the selection path would make assert, emit, find, and the crop writer each grow a special case for a thing none of them can answer about.

Fields§

§a: Point§b: Point

Implementations§

Source§

impl Line

Source

pub const fn new(a: Point, b: Point) -> Self

Source

pub const fn delta(self) -> (i32, i32)

Signed horizontal and vertical extent, b - a.

Saturating, because the answer is an i32 and the true difference between two i32s need not be one. Screen coordinates never come close, but a session is a file a human can edit, and a bounded number beats a panic when the input was already meaningless. Self::length and Self::angle_deg do not go through this — they widen to f64 first and stay exact at any input.

Source

pub fn length(self) -> f64

Euclidean length in pixels.

Source

pub fn angle_deg(self) -> f64

Direction in degrees within [0, 360), 0 pointing right along +X and increasing clockwise.

Clockwise because screen Y grows downward: a ruler dragged visually down-and-right has to read as a positive angle, which the mathematical convention would report as negative.

A zero-length measure has no direction; it reports 0.0 rather than the NaN atan2(0, 0) would be entitled to.

Source

pub fn bbox(self) -> Rect

The smallest rect containing both endpoints — what the caption placement needs, since a line has no Shape::bbox.

Source

pub const fn translated(self, dx: i32, dy: i32) -> Self

Source

pub fn endpoint_grab(self, p: Point, tolerance: i32) -> Option<bool>

The endpoint p grabs, if either is within tolerance.

a wins a tie: the two coincide only on a zero-length measure, where the choice cannot matter, and preferring one keeps the pick deterministic.

Source

pub fn hit_test(self, p: Point, tolerance: i32) -> bool

Whether p is within tolerance of the segment — the whole-line grab, used after the endpoints have had their chance.

Source

pub fn distance_to(self, p: Point) -> f64

Shortest distance from p to the segment, clamped at the ends so a point beyond b measures to b rather than to the infinite line through it.

Source

pub fn constrained(self) -> Self

b snapped to the nearest horizontal, vertical, or 45° direction from a — what Shift does while dragging, matching the constraint the other tools apply.

The length along the chosen direction is preserved as the projection of the free endpoint onto it, so the ruler tracks the pointer instead of jumping to a fixed radius.

Trait Implementations§

Source§

impl Clone for Line

Source§

fn clone(&self) -> Line

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 Copy for Line

Source§

impl Debug for Line

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Eq for Line

Source§

impl From<Line> for LineRecord

Source§

fn from(line: Line) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Line

Source§

fn eq(&self, other: &Line) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Line

Auto Trait Implementations§

§

impl Freeze for Line

§

impl RefUnwindSafe for Line

§

impl Send for Line

§

impl Sync for Line

§

impl Unpin for Line

§

impl UnsafeUnpin for Line

§

impl UnwindSafe for Line

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<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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.