Skip to content

Commit c8231fc

Browse files
feat : Implement Heart Node
1 parent cd24109 commit c8231fc

2 files changed

Lines changed: 79 additions & 0 deletions

File tree

node-graph/libraries/vector-types/src/subpath/core.rs

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,54 @@ impl<PointId: Identifier> Subpath<PointId> {
379379

380380
Self::new(manipulator_groups, false)
381381
}
382+
383+
pub fn new_heart(
384+
center: DVec2,
385+
radius: f64,
386+
cleft_angle: f64,
387+
tip_angle: f64,
388+
left_bulb_height: f64,
389+
right_bulb_height: f64,
390+
left_bulb_expand: f64,
391+
right_bulb_expand: f64,
392+
cleft_depth: f64,
393+
tip_depth: f64,
394+
) -> Self {
395+
// Anchors
396+
let top_anchor = center - DVec2::new(0., radius * cleft_depth);
397+
let bottom_anchor = center + DVec2::new(0., radius * tip_depth);
398+
399+
let side_x = radius;
400+
// Offset is for less squat shape (-0.25).
401+
let right_anchor = DVec2::new(
402+
center.x + side_x * (1. + right_bulb_expand),
403+
(center.y + radius * (right_bulb_height - 0.25)) * (1. + right_bulb_expand) - center.y * right_bulb_expand,
404+
);
405+
let left_anchor = DVec2::new(
406+
center.x - side_x * (1. + left_bulb_expand),
407+
(center.y + radius * (left_bulb_height - 0.25)) * (1. + left_bulb_expand) - center.y * left_bulb_expand,
408+
);
409+
410+
// Handle Directions
411+
let (top_sin, top_cos) = cleft_angle.sin_cos();
412+
let top_dir = DVec2::new(top_sin, -top_cos) * radius * 0.5;
413+
414+
let (bot_sin, bot_cos) = tip_angle.sin_cos();
415+
let bot_dir = DVec2::new(bot_sin, -bot_cos) * radius * 0.45;
416+
417+
// Side Tangents
418+
let side_up = DVec2::new(0., -radius * 0.4);
419+
let side_down = DVec2::new(0., radius * 0.5);
420+
421+
let manipulator_groups = vec![
422+
ManipulatorGroup::new(top_anchor, Some(top_anchor + DVec2::new(-top_dir.x, top_dir.y)), Some(top_anchor + top_dir)),
423+
ManipulatorGroup::new(right_anchor, Some(right_anchor + side_up), Some(right_anchor + side_down)),
424+
ManipulatorGroup::new(bottom_anchor, Some(bottom_anchor + bot_dir), Some(bottom_anchor + DVec2::new(-bot_dir.x, bot_dir.y))),
425+
ManipulatorGroup::new(left_anchor, Some(left_anchor + side_down), Some(left_anchor + side_up)),
426+
];
427+
428+
Self::new(manipulator_groups, true)
429+
}
382430
}
383431

384432
pub fn calculate_b(a: f64, turns: f64, outer_radius: f64, spiral_type: SpiralType) -> f64 {

node-graph/nodes/vector/src/generator_nodes.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,37 @@ fn rectangle<T: CornerRadius>(
145145
corner_radius.generate(DVec2::new(width, height), clamped)
146146
}
147147

148+
/// Generates a heart shape with adjustable proportions.
149+
#[node_macro::node(category("Vector: Shape"))]
150+
fn heart(
151+
_: impl Ctx,
152+
_primary: (),
153+
#[unit(" px")]
154+
#[default(50.)]
155+
radius: f64,
156+
#[default(30.)] cleft_angle: f64,
157+
#[default(45.)] tip_angle: f64,
158+
#[default(0.4)] cleft_depth: f64,
159+
#[default(0.9)] tip_depth: f64,
160+
#[default(0.)] left_bulb_height: f64,
161+
#[default(0.)] right_bulb_height: f64,
162+
#[default(0.)] left_bulb_expand: f64,
163+
#[default(0.)] right_bulb_expand: f64,
164+
) -> Table<Vector> {
165+
Table::new_from_element(Vector::from_subpath(subpath::Subpath::new_heart(
166+
DVec2::splat(0.),
167+
radius,
168+
cleft_angle.to_radians(),
169+
tip_angle.to_radians(),
170+
left_bulb_height,
171+
right_bulb_height,
172+
left_bulb_expand,
173+
right_bulb_expand,
174+
cleft_depth,
175+
tip_depth,
176+
)))
177+
}
178+
148179
/// Generates an regular polygon shape like a triangle, square, pentagon, hexagon, heptagon, octagon, or any higher n-gon.
149180
#[node_macro::node(category("Vector: Shape"))]
150181
fn regular_polygon<T: AsU64>(

0 commit comments

Comments
 (0)