Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ pub fn rounded_rectangle_path(corner1: DVec2, corner2: DVec2, radii: [f64; 4]) -
/// Ellipse inscribed in the box spanning the two opposite corners.
pub fn ellipse_path(corner1: DVec2, corner2: DVec2) -> BezPath {
let rect = kurbo::Rect::from_points(dvec2_to_point(corner1), dvec2_to_point(corner2));
kurbo::Ellipse::new(rect.center(), (rect.width() / 2., rect.height() / 2.), 0.).to_path(DEFAULT_ACCURACY)
let mut path = kurbo::Ellipse::new(rect.center(), (rect.width() / 2., rect.height() / 2.), 0.).to_path(DEFAULT_ACCURACY);

// Kurbo emits the ellipse as an unclosed 360 degree arc, but hit testing only fills explicitly closed contours
path.close_path();
path
}

#[derive(PartialEq)]
Expand Down Expand Up @@ -888,3 +892,23 @@ pub(crate) fn collect_input_resource(input: &NodeInput, out: &mut HashSet<Resour
out.insert(*id);
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn port_click_targets_are_clickable_at_their_center() {
let center = DVec2::new(100., 50.);
let mut ports = Ports::new();
ports.insert_input_port_at_center(0, center);
ports.insert_output_port_at_center(0, center + DVec2::new(200., 0.));

assert_eq!(ports.clicked_input_port_from_point(center), Some(0));
assert_eq!(ports.clicked_input_port_from_point(center + DVec2::new(5., 5.)), Some(0));
assert_eq!(ports.clicked_input_port_from_point(center + DVec2::new(20., 0.)), None);

assert_eq!(ports.clicked_output_port_from_point(center + DVec2::new(200., 0.)), Some(0));
assert_eq!(ports.clicked_output_port_from_point(center), None);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ fn straight_wire_to_bezpath(locations: Vec<IVec2>) -> BezPath {
if locations.len() == 2 {
let p1 = to_point(locations[0]);
let p2 = to_point(locations[1]);
Line::new(p1, p2).to_path(DEFAULT_ACCURACY);
return Line::new(p1, p2).to_path(DEFAULT_ACCURACY);
}

let corner_radius = 10;
Expand Down
10 changes: 2 additions & 8 deletions node-graph/libraries/rendering/src/renderer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1522,7 +1522,7 @@ fn render_vector_shape_svg(item: ItemRef<'_, Vector>, vector: &Vector, render: &
});

if use_face_fill {
for mut face_path in vector.construct_faces().filter(|face| face.area() >= 0.) {
for mut face_path in vector.construct_faces() {
face_path.apply_affine(Affine::new(applied_stroke_transform.to_cols_array()));
let face_d = face_path.to_svg();

Expand Down Expand Up @@ -1612,10 +1612,6 @@ fn render_vector_shape_svg(item: ItemRef<'_, Vector>, vector: &Vector, render: &
attributes.push_val(stroke_shape_attribute);
attributes.push_val(stroke_attribute);

if vector.is_branching() && !use_face_fill {
attributes.push("fill-rule", "evenodd");
}

let opacity = (opacity_attr * if render_params.for_mask { 1. } else { opacity_fill_attr }) as f32;
if opacity < 1. {
attributes.push("opacity", opacity.to_string());
Expand Down Expand Up @@ -1851,16 +1847,14 @@ fn render_vector_item_to_vello(
let use_face_fill = element.use_face_fill();
let do_fill = |scene: &mut Scene, context: &mut RenderContext| {
if use_face_fill {
for mut face_path in element.construct_faces().filter(|face| face.area() >= 0.) {
for mut face_path in element.construct_faces() {
face_path.apply_affine(Affine::new(applied_stroke_transform.to_cols_array()));
let mut kurbo_path = kurbo::BezPath::new();
for element in face_path {
kurbo_path.push(element);
}
do_fill_path(scene, context, &kurbo_path, peniko::Fill::NonZero);
}
} else if element.is_branching() {
do_fill_path(scene, context, &path, peniko::Fill::EvenOdd);
} else {
do_fill_path(scene, context, &path, peniko::Fill::NonZero);
}
Expand Down
Loading
Loading