mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-09-19 19:08:05 +08:00
Port all remaining Subpath producers to BezPath and delete the legacy subpath module (#4457)
* Port all remaining Subpath producers to BezPath and delete the legacy subpath module * Reset contour state at each MoveTo so an open contour's segments don't leak into the next region * Give the polygon and star constructors a true center and radius instead of compensated arguments
This commit is contained in:
@@ -4,7 +4,9 @@ use core_types::{CacheHash, Ctx};
|
||||
use dyn_any::DynAny;
|
||||
use glam::DVec2;
|
||||
use graphic_types::Vector;
|
||||
use vector_types::subpath;
|
||||
use vector_types::vector::VectorExt;
|
||||
use vector_types::vector::algorithms::shapes;
|
||||
use vector_types::vector::misc::BezierHandles;
|
||||
use vector_types::vector::misc::{ArcType, AsU64, BoxCorners, GridType};
|
||||
use vector_types::vector::misc::{HandleId, SpiralType};
|
||||
use vector_types::vector::{PointId, SegmentId, StrokeId};
|
||||
@@ -19,7 +21,7 @@ fn circle(
|
||||
radius: Item<f64>,
|
||||
) -> Item<Vector> {
|
||||
let radius = radius.element().abs();
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_ellipse(DVec2::splat(-radius), DVec2::splat(radius))))
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::ellipse_bezpath(DVec2::splat(-radius), DVec2::splat(radius))))
|
||||
}
|
||||
|
||||
/// Generates an arc shape forming a portion of a circle which may be open, closed, or a pie slice.
|
||||
@@ -38,7 +40,7 @@ fn arc(
|
||||
arc_type: Item<ArcType>,
|
||||
) -> Item<Vector> {
|
||||
let (radius, start_angle, sweep_angle, arc_type) = (*radius.element(), *start_angle.element(), *sweep_angle.element(), arc_type.into_element());
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_arc(
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::arc_bezpath(
|
||||
radius,
|
||||
start_angle / 360. * std::f64::consts::TAU,
|
||||
sweep_angle / 360. * std::f64::consts::TAU,
|
||||
@@ -65,7 +67,7 @@ fn spiral(
|
||||
*outer_radius.element(),
|
||||
*angular_resolution.element(),
|
||||
);
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_spiral(
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::spiral_bezpath(
|
||||
inner_radius,
|
||||
outer_radius,
|
||||
turns,
|
||||
@@ -91,7 +93,7 @@ fn ellipse(
|
||||
let corner1 = -radius;
|
||||
let corner2 = radius;
|
||||
|
||||
let mut ellipse = Vector::from_subpath(subpath::Subpath::new_ellipse(corner1, corner2));
|
||||
let mut ellipse = Vector::from_bezpath(shapes::ellipse_bezpath(corner1, corner2));
|
||||
|
||||
let len = ellipse.segment_domain.ids().len();
|
||||
for i in 0..len {
|
||||
@@ -139,7 +141,7 @@ fn rectangle(
|
||||
radii
|
||||
};
|
||||
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_rounded_rectangle(size / -2., size / 2., radii)))
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::rounded_rectangle_bezpath(size / -2., size / 2., radii)))
|
||||
}
|
||||
|
||||
/// Builds a set of four corner values, such as a rectangle's corner radii, from a list of one, two, three, or four values.
|
||||
@@ -167,8 +169,7 @@ fn regular_polygon<T: AsU64>(
|
||||
radius: Item<f64>,
|
||||
) -> Item<Vector> {
|
||||
let points = sides.element().as_u64();
|
||||
let radius: f64 = *radius.element() * 2.;
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_regular_polygon(DVec2::splat(-radius), points, radius)))
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::regular_polygon_bezpath(DVec2::ZERO, points, *radius.element())))
|
||||
}
|
||||
|
||||
/// Generates an n-pointed star shape with inner and outer points at chosen radii from the center.
|
||||
@@ -188,10 +189,7 @@ fn star<T: AsU64>(
|
||||
radius_2: Item<f64>,
|
||||
) -> Item<Vector> {
|
||||
let points = sides.element().as_u64();
|
||||
let diameter: f64 = *radius_1.element() * 2.;
|
||||
let inner_diameter = *radius_2.element() * 2.;
|
||||
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_star_polygon(DVec2::splat(-diameter), points, diameter, inner_diameter)))
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::star_polygon_bezpath(DVec2::ZERO, points, *radius_1.element(), *radius_2.element())))
|
||||
}
|
||||
|
||||
#[cfg_attr(feature = "wasm", derive(tsify::Tsify))]
|
||||
@@ -249,11 +247,7 @@ fn qr_code(
|
||||
for x in 0..dimension {
|
||||
if qr_code.get_module(x as i32, y as i32) {
|
||||
let corner1 = DVec2::new(x as f64, y as f64);
|
||||
let corner2 = corner1 + DVec2::splat(1.);
|
||||
vector.append_subpath(
|
||||
subpath::Subpath::from_anchors([corner1, DVec2::new(corner2.x, corner1.y), corner2, DVec2::new(corner1.x, corner2.y)], true),
|
||||
false,
|
||||
);
|
||||
vector.append_bezpath(shapes::rectangle_bezpath(corner1, corner1 + DVec2::splat(1.)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -281,12 +275,12 @@ fn arrow(
|
||||
#[default(20)] head_length: Item<PixelLength>,
|
||||
) -> Item<Vector> {
|
||||
let (arrow_to, shaft_width, head_width, head_length) = (*arrow_to.element(), *shaft_width.element(), *head_width.element(), *head_length.element());
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_arrow(DVec2::ZERO, arrow_to, shaft_width, head_width, head_length)))
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::arrow_bezpath(DVec2::ZERO, arrow_to, shaft_width, head_width, head_length)))
|
||||
}
|
||||
|
||||
#[node_macro::node(category("Vector: Shape"))]
|
||||
fn line(_: impl Ctx, _primary: (), #[default(100., 100.)] line_to: Item<PixelSize>) -> Item<Vector> {
|
||||
Item::new_from_element(Vector::from_subpath(subpath::Subpath::new_line(DVec2::ZERO, *line_to.element())))
|
||||
Item::new_from_element(Vector::from_bezpath(shapes::line_bezpath(DVec2::ZERO, *line_to.element())))
|
||||
}
|
||||
|
||||
trait GridSpacing {
|
||||
@@ -370,9 +364,7 @@ fn grid<T: GridSpacing>(
|
||||
// Helper function to connect points with line segments.
|
||||
let mut push_segment = |to_index: Option<usize>| {
|
||||
if let Some(other_index) = to_index {
|
||||
vector
|
||||
.segment_domain
|
||||
.push(segment_id.next_id(), other_index, current_index, subpath::BezierHandles::Linear, StrokeId::ZERO);
|
||||
vector.segment_domain.push(segment_id.next_id(), other_index, current_index, BezierHandles::Linear, StrokeId::ZERO);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user