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: PointImplementations§
Source§impl Line
impl Line
pub const fn new(a: Point, b: Point) -> Self
Sourcepub const fn delta(self) -> (i32, i32)
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.
Sourcepub fn angle_deg(self) -> f64
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.
Sourcepub fn bbox(self) -> Rect
pub fn bbox(self) -> Rect
The smallest rect containing both endpoints — what the caption
placement needs, since a line has no Shape::bbox.
pub const fn translated(self, dx: i32, dy: i32) -> Self
Sourcepub fn endpoint_grab(self, p: Point, tolerance: i32) -> Option<bool>
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.
Sourcepub fn hit_test(self, p: Point, tolerance: i32) -> bool
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.
Sourcepub fn distance_to(self, p: Point) -> f64
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.
Sourcepub fn constrained(self) -> Self
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§
impl Copy for Line
impl Eq for Line
Source§impl From<Line> for LineRecord
impl From<Line> for LineRecord
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> 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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.