From 3b503ccde26c49a29bac16510362d8bbd666c444 Mon Sep 17 00:00:00 2001 From: Sidharth-Singh10 <70999945+Sidharth-Singh10@users.noreply.github.com> Date: Tue, 19 Nov 2024 02:40:08 +0530 Subject: [PATCH] Bezier-rs: Make rectangle constructor produce linear segments (#2109) * fix(bezier-rs): new_rect constructor create linear segments * refactor --- libraries/bezier-rs/src/subpath/core.rs | 6 +++++- libraries/bezier-rs/src/subpath/structs.rs | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/libraries/bezier-rs/src/subpath/core.rs b/libraries/bezier-rs/src/subpath/core.rs index 323853d9c9..90f2818c86 100644 --- a/libraries/bezier-rs/src/subpath/core.rs +++ b/libraries/bezier-rs/src/subpath/core.rs @@ -225,9 +225,13 @@ impl Subpath { Self::new(anchor_positions.into_iter().map(|anchor| ManipulatorGroup::new_anchor(anchor)).collect(), closed) } + pub fn from_anchors_linear(anchor_positions: impl IntoIterator, closed: bool) -> Self { + Self::new(anchor_positions.into_iter().map(|anchor| ManipulatorGroup::new_anchor_linear(anchor)).collect(), closed) + } + /// Constructs a rectangle with `corner1` and `corner2` as the two corners. pub fn new_rect(corner1: DVec2, corner2: DVec2) -> Self { - Self::from_anchors([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true) + Self::from_anchors_linear([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true) } /// Constructs a rounded rectangle with `corner1` and `corner2` as the two corners and `corner_radii` as the radii of the corners: `[top_left, top_right, bottom_right, bottom_left]`. diff --git a/libraries/bezier-rs/src/subpath/structs.rs b/libraries/bezier-rs/src/subpath/structs.rs index b0cc300779..63912bf421 100644 --- a/libraries/bezier-rs/src/subpath/structs.rs +++ b/libraries/bezier-rs/src/subpath/structs.rs @@ -76,6 +76,10 @@ impl ManipulatorGroup { Self::new(anchor, Some(anchor), Some(anchor)) } + pub fn new_anchor_linear(anchor: DVec2) -> Self { + Self::new(anchor, None, None) + } + /// Construct a new manipulator group from an anchor, in handle, out handle and an id pub fn new_with_id(anchor: DVec2, in_handle: Option, out_handle: Option, id: PointId) -> Self { Self { anchor, in_handle, out_handle, id }