Skip to main content

Shape

Enum Shape 

Source
pub enum Shape {
    Rect(Rect),
    Circle {
        cx: i32,
        cy: i32,
        r: i32,
    },
    Ellipse {
        cx: i32,
        cy: i32,
        rx: i32,
        ry: i32,
    },
    Triangle {
        ax: i32,
        ay: i32,
        bx: i32,
        by: i32,
        cx: i32,
        cy: i32,
    },
    Poly {
        points: Vec<Point>,
    },
}
Expand description

A committed or in-progress selection shape.

Serializes untagged: a rect is {x, y, w, h}, a circle is {cx, cy, r}, a triangle is its three vertices {ax, ay, bx, by, cx, cy} (apex, then base-left, then base-right as drawn — though any triangle is representable). The field sets are disjoint, so deserialization is unambiguous; the session schema also stores the discriminant in a sibling shape field.

Variants§

§

Rect(Rect)

§

Circle

Fields

§cx: i32
§cy: i32
§

Ellipse

Axis-aligned ellipse; rotation, like a rect’s, is metadata. The field set is disjoint from every other variant, so the untagged serde representation stays unambiguous.

Fields

§cx: i32
§cy: i32
§rx: i32
§ry: i32
§

Triangle

Fields

§ax: i32
§ay: i32
§bx: i32
§by: i32
§cx: i32
§cy: i32
§

Poly

An arbitrary closed polygon — regular N-gons and freehand paths alike. Rotation is baked into the vertices, triangle-style, and the winding may be either direction.

Fields

§points: Vec<Point>

Implementations§

Source§

impl Shape

Source

pub fn compute_preview( tool: ToolKind, start: Point, current: Point, region: Rect, lock: bool, ) -> Option<Self>

Shape previewed while dragging from start to current, or None while the drag is still degenerate. current is clamped into bounds so dragging off-screen keeps the preview on-screen. lock constrains the proportions (Shift held): an ellipse locks to a perfect circle.

Source

pub const fn kind(&self) -> ToolKind

Source

pub fn bbox(&self) -> Rect

Axis-aligned bounding box. Saturating math so absurd deserialized values (e.g. r near i32::MAX) misreport rather than panic.

Source

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

Whether p lies inside the shape (used for cursor hit-testing). Distance math is done in i64 so extreme coordinates cannot overflow.

Source

pub fn covers(&self, x: i32, y: i32) -> bool

Whether the shape covers pixel (x, y) — identical to hit_test, named separately because it is the crop/mask predicate.

Source

pub fn click_point(&self) -> Point

The point a click should aim for: the bbox center for rects (the rotation pivot, so it holds for rotated rects unchanged), a circle’s center, and the centroid for triangles — always interior, where a thin diagonal triangle’s bbox center may fall outside. i64 arithmetic so extreme deserialized vertices cannot overflow.

Source

pub fn grab_origin(&self) -> Point

The reference point a drag-move grabs: bbox origin, or a circle’s center.

Source

pub fn clamp_move( &self, grab_offset: Point, cursor: Point, region: Rect, ) -> Self

New shape position for a drag-move, clamped so the shape cannot leave bounds. grab_offset is cursor-at-grab minus grab_origin.

Source

pub fn resize_grab(&self, p: Point, tolerance: i32) -> Option<ResizeHandle>

Which resize handle, if any, p grabs: the rim of a circle, or an edge/corner of a rect, within tolerance pixels on either side of the border.

Source

pub fn resize_to( &self, handle: ResizeHandle, cursor: Point, region: Rect, keep_aspect: bool, ) -> Self

The shape resized by dragging handle to cursor (clamped into bounds), anchored on the parts not being dragged: a circle keeps its center, a rect keeps its ungrabbed edges. Dimensions never drop below 2, so a resize can’t destroy a shape.

keep_aspect (Shift held) preserves self’s width:height ratio — the ratio at drag start, so it stays stable through the whole drag. On a corner the opposite corner anchors and the dominant cursor axis sets the scale; on a single edge the perpendicular axis scales with it, centered. Circles are inherently proportional and ignore it.

Source

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

The same shape translated by (dx, dy) — used to derive global desktop coordinates from monitor-local ones.

Source§

impl Shape

Source

pub fn pivot(&self) -> Point

The pivot every rotation turns around: the unrotated bbox center.

Source

pub fn rotated_bbox(&self, deg: i32) -> Rect

AABB of the shape after rotating it deg about its pivot.

Source

pub fn hit_test_rotated(&self, deg: i32, p: Point) -> bool

hit_test/covers for the shape rotated deg about its pivot: the point is inverse-rotated into the shape’s local space.

Source

pub fn resize_grab_rotated( &self, deg: i32, p: Point, tolerance: i32, ) -> Option<ResizeHandle>

resize_grab in the rotated frame: the cursor is inverse-rotated, so grips sit on the shape as the user sees it.

Source

pub fn resize_to_rotated( &self, deg: i32, handle: ResizeHandle, cursor: Point, region: Rect, keep_aspect: bool, ) -> Self

resize_to in the rotated frame; rotation itself is unchanged.

Source

pub fn clamp_move_rotated( &self, deg: i32, grab_offset: Point, cursor: Point, region: Rect, ) -> Self

clamp_move keeping the rotated silhouette on screen.

Source

pub fn grab_origin_rotated(&self, deg: i32) -> Point

The grab reference for a rotated move: the rotated AABB origin.

Source

pub fn with_rotation_baked(&self, deg: i32) -> Self

A triangle with the rotation baked into its vertices (exact, single rounding); other shapes are returned unchanged — rects carry their rotation as metadata instead.

Trait Implementations§

Source§

impl Clone for Shape

Source§

fn clone(&self) -> Shape

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 Shape

Source§

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

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

impl<'de> Deserialize<'de> for Shape

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Eq for Shape

Source§

impl PartialEq for Shape

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl Serialize for Shape

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Shape

Auto Trait Implementations§

§

impl Freeze for Shape

§

impl RefUnwindSafe for Shape

§

impl Send for Shape

§

impl Sync for Shape

§

impl Unpin for Shape

§

impl UnsafeUnpin for Shape

§

impl UnwindSafe for Shape

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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.