Skip to content

Commit 3b503cc

Browse files
Bezier-rs: Make rectangle constructor produce linear segments (#2109)
* fix(bezier-rs): new_rect constructor create linear segments * refactor
1 parent 99cf8f0 commit 3b503cc

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

libraries/bezier-rs/src/subpath/core.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,13 @@ impl<PointId: crate::Identifier> Subpath<PointId> {
225225
Self::new(anchor_positions.into_iter().map(|anchor| ManipulatorGroup::new_anchor(anchor)).collect(), closed)
226226
}
227227

228+
pub fn from_anchors_linear(anchor_positions: impl IntoIterator<Item = DVec2>, closed: bool) -> Self {
229+
Self::new(anchor_positions.into_iter().map(|anchor| ManipulatorGroup::new_anchor_linear(anchor)).collect(), closed)
230+
}
231+
228232
/// Constructs a rectangle with `corner1` and `corner2` as the two corners.
229233
pub fn new_rect(corner1: DVec2, corner2: DVec2) -> Self {
230-
Self::from_anchors([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true)
234+
Self::from_anchors_linear([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true)
231235
}
232236

233237
/// 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]`.

libraries/bezier-rs/src/subpath/structs.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,10 @@ impl<PointId: crate::Identifier> ManipulatorGroup<PointId> {
7676
Self::new(anchor, Some(anchor), Some(anchor))
7777
}
7878

79+
pub fn new_anchor_linear(anchor: DVec2) -> Self {
80+
Self::new(anchor, None, None)
81+
}
82+
7983
/// Construct a new manipulator group from an anchor, in handle, out handle and an id
8084
pub fn new_with_id(anchor: DVec2, in_handle: Option<DVec2>, out_handle: Option<DVec2>, id: PointId) -> Self {
8185
Self { anchor, in_handle, out_handle, id }

0 commit comments

Comments
 (0)