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
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.
Triangle
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.
Implementations§
Source§impl Shape
impl Shape
Sourcepub fn compute_preview(
tool: ToolKind,
start: Point,
current: Point,
region: Rect,
lock: bool,
) -> Option<Self>
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.
pub const fn kind(&self) -> ToolKind
Sourcepub fn bbox(&self) -> Rect
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.
Sourcepub fn hit_test(&self, p: Point) -> bool
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.
Sourcepub fn covers(&self, x: i32, y: i32) -> bool
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.
Sourcepub fn click_point(&self) -> Point
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.
Sourcepub fn grab_origin(&self) -> Point
pub fn grab_origin(&self) -> Point
The reference point a drag-move grabs: bbox origin, or a circle’s center.
Sourcepub fn clamp_move(
&self,
grab_offset: Point,
cursor: Point,
region: Rect,
) -> Self
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.
Sourcepub fn resize_grab(&self, p: Point, tolerance: i32) -> Option<ResizeHandle>
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.
Sourcepub fn resize_to(
&self,
handle: ResizeHandle,
cursor: Point,
region: Rect,
keep_aspect: bool,
) -> Self
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.
Sourcepub fn translated(&self, dx: i32, dy: i32) -> Self
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
impl Shape
Sourcepub fn rotated_bbox(&self, deg: i32) -> Rect
pub fn rotated_bbox(&self, deg: i32) -> Rect
AABB of the shape after rotating it deg about its pivot.
Sourcepub fn hit_test_rotated(&self, deg: i32, p: Point) -> bool
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.
Sourcepub fn resize_grab_rotated(
&self,
deg: i32,
p: Point,
tolerance: i32,
) -> Option<ResizeHandle>
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.
Sourcepub fn resize_to_rotated(
&self,
deg: i32,
handle: ResizeHandle,
cursor: Point,
region: Rect,
keep_aspect: bool,
) -> Self
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.
Sourcepub fn clamp_move_rotated(
&self,
deg: i32,
grab_offset: Point,
cursor: Point,
region: Rect,
) -> Self
pub fn clamp_move_rotated( &self, deg: i32, grab_offset: Point, cursor: Point, region: Rect, ) -> Self
clamp_move keeping the rotated silhouette on screen.
Sourcepub fn grab_origin_rotated(&self, deg: i32) -> Point
pub fn grab_origin_rotated(&self, deg: i32) -> Point
The grab reference for a rotated move: the rotated AABB origin.
Sourcepub fn with_rotation_baked(&self, deg: i32) -> Self
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<'de> Deserialize<'de> for Shape
impl<'de> Deserialize<'de> for Shape
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl Eq for Shape
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> 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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
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.