Skip to content

Commit

Permalink
Bezier-rs: Make rectangle constructor produce linear segments (#2109)
Browse files Browse the repository at this point in the history
* fix(bezier-rs): new_rect constructor create linear segments

* refactor
  • Loading branch information
Sidharth-Singh10 authored Nov 18, 2024
1 parent 99cf8f0 commit 3b503cc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion libraries/bezier-rs/src/subpath/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,13 @@ impl<PointId: crate::Identifier> Subpath<PointId> {
Self::new(anchor_positions.into_iter().map(|anchor| ManipulatorGroup::new_anchor(anchor)).collect(), closed)
}

pub fn from_anchors_linear(anchor_positions: impl IntoIterator<Item = DVec2>, 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]`.
Expand Down
4 changes: 4 additions & 0 deletions libraries/bezier-rs/src/subpath/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ impl<PointId: crate::Identifier> ManipulatorGroup<PointId> {
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<DVec2>, out_handle: Option<DVec2>, id: PointId) -> Self {
Self { anchor, in_handle, out_handle, id }
Expand Down

0 comments on commit 3b503cc

Please sign in to comment.