Add Heart shape tool

- Add new_heart() method
- Add Heart node to vector generator nodes
- Add Heart to ShapeType enum and UI dropdown
This commit is contained in:
Ashish Mohapatra 2025-11-26 19:23:46 +05:30
parent 5ebf6d6bc0
commit a78ee3c52a
7 changed files with 106 additions and 7 deletions

View file

@ -317,6 +317,18 @@ impl<PointId: Identifier> Subpath<PointId> {
Self::from_anchors([p1, p2], false)
}
/// Constructs a heart shape centered at the origin with the given radius.
pub fn new_heart(center: DVec2, radius: f64) -> Self {
let bottom = center + DVec2::new(0., radius);
let top = center + DVec2::new(0., -radius * 0.4);
let manipulator_groups = vec![
ManipulatorGroup::new(bottom, Some(bottom + DVec2::new(radius * 1.2, -radius * 0.9)), Some(bottom + DVec2::new(-radius * 1.2, -radius * 0.9))),
ManipulatorGroup::new(top, Some(top + DVec2::new(-radius * 1.2, -radius * 0.6)), Some(top + DVec2::new(radius * 1.2, -radius * 0.6))),
];
Self::new(manipulator_groups, true)
}
pub fn new_spiral(a: f64, outer_radius: f64, turns: f64, start_angle: f64, delta_theta: f64, spiral_type: SpiralType) -> Self {
let mut manipulator_groups = Vec::new();
let mut prev_in_handle = None;

View file

@ -201,6 +201,19 @@ fn line(
Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_line(start, end)))
}
/// Generates a heart shape with a chosen radius.
#[node_macro::node(category("Vector: Shape"))]
fn heart(
_: impl Ctx,
_primary: (),
#[unit(" px")]
#[default(50.)]
radius: f64,
) -> Table<Vector> {
let radius = radius.abs();
Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_heart(DVec2::ZERO, radius)))
}
trait GridSpacing {
fn as_dvec2(&self) -> DVec2;
}