mirror of
https://github.com/GraphiteEditor/Graphite.git
synced 2026-10-10 04:20:55 +08:00
Bezier-rs: Subpath offset and bezier offset improvements (#1039)
* Added subpath offset * Enhanced offset to produce smooth curves * Lots of outline bugfixes * Fixed failing unit tests * Added subpath outline * Refactor bezier offset and outline to return Subpaths * Fix outline bug due to smooth joining and removed reduce optimization that causes jumping approximations * Bugfix when subpath angle is acute but doesn't intersect * Stylistic changes per review * Stylistic changes per review and updated doc comments --------- Co-authored-by: Hannah Li <hannahli2010@gmail.com> Co-authored-by: Keavon Chambers <keavon@keavon.com>
This commit is contained in:
co-authored by
Hannah Li
Keavon Chambers
parent
0512cb249f
commit
2fd5c26450
@@ -1,6 +1,4 @@
|
||||
use bezier_rs::Bezier;
|
||||
use glam::DVec2;
|
||||
use std::fmt::Write;
|
||||
|
||||
// SVG drawing constants
|
||||
pub const SVG_OPEN_TAG: &str = r#"<svg xmlns="http://www.w3.org/2000/svg" width="200px" height="200px">"#;
|
||||
@@ -48,19 +46,6 @@ pub fn draw_line(start_x: f64, start_y: f64, end_x: f64, end_y: f64, stroke: &st
|
||||
format!(r#"<line x1="{start_x}" y1="{start_y}" x2="{end_x}" y2="{end_y}" stroke="{stroke}" stroke-width="{stroke_width}"/>"#)
|
||||
}
|
||||
|
||||
/// Helper function to draw a list of beziers.
|
||||
pub fn draw_beziers(beziers: Vec<Bezier>, options: String) -> String {
|
||||
let start_point = beziers.first().unwrap().start();
|
||||
let mut svg = format!("<path d=\"M {} {}", start_point.x, start_point.y);
|
||||
|
||||
beziers.iter().for_each(|bezier| {
|
||||
let _ = write!(svg, " {}", bezier.svg_curve_argument());
|
||||
});
|
||||
|
||||
let _ = write!(svg, " Z\" {}/>", options);
|
||||
svg
|
||||
}
|
||||
|
||||
// Helper function to convert polar to cartesian coordinates
|
||||
fn polar_to_cartesian(center_x: f64, center_y: f64, radius: f64, angle_in_rad: f64) -> [f64; 2] {
|
||||
let x = center_x + radius * angle_in_rad.cos();
|
||||
|
||||
Reference in New Issue
Block a user