Files
Graphite/bezier-rs/lib/src/subpath/structs.rs
T
Rob Nadal aeb9e85726 Added Subpaths to bezier-rs (#730)
* Added Subpath constructor, iterator and length

* Asserted that subpaths of len < 2 cannot be closed. Added len() and comments

* Added subpath to_svg(), made structs public, made quadratic use either in_handle or out_handle

* add bezier handles

* Added basic interactivity and index traits

* Added SubPath interactivity

* Added svg styling

* Broke subpath impl across multiple files. More sylistic changes per review

* Fixed format error

* Added closed subpath to documentation page

* Modified subpath to_svg to use functional style

* Stylistic changes per review

* Fixed build errors

* More sylistic changes per review

* Moved svg commands to constants

* Moved formatting for svg arguments to ToSVGOptions

* Renamed files in git

* Even more stylistic changes per review
2022-07-27 17:30:08 -04:00

84 lines
3.4 KiB
Rust

use glam::DVec2;
/// Structure used to represent a single anchor with up to two optional associated handles along a `Subpath`
pub struct ManipulatorGroup {
pub anchor: DVec2,
pub in_handle: Option<DVec2>,
pub out_handle: Option<DVec2>,
}
/// Structure to represent optional parameters that can be passed to the `into_svg` function.
pub struct ToSVGOptions {
/// Color of the line segments along the `Subpath`. Defaulted to `black`.
pub curve_stroke_color: String,
/// Width of the line segments along the `Subpath`. Defaulted to `2.`.
pub curve_stroke_width: f64,
/// Stroke color outlining circles marking anchors on the `Subpath`. Defaulted to `black`.
pub anchor_stroke_color: String,
/// Stroke width outlining circles marking anchors on the `Subpath`. Defaulted to `2.`.
pub anchor_stroke_width: f64,
/// Radius of the circles marking anchors on the `Subpath`. Defaulted to `4.`.
pub anchor_radius: f64,
/// Fill color of the circles marking anchors on the `Subpath`. Defaulted to `white`.
pub anchor_fill: String,
/// Color of the line segments connecting anchors to handle points. Defaulted to `gray`.
pub handle_line_stroke_color: String,
/// Width of the line segments connecting anchors to handle points. Defaulted to `1.`.
pub handle_line_stroke_width: f64,
/// Stroke color outlining circles marking the handles of `Subpath`. Defaulted to `gray`.
pub handle_point_stroke_color: String,
/// Stroke color outlining circles marking the handles of `Subpath`. Defaulted to `1.5`.
pub handle_point_stroke_width: f64,
/// Radius of the circles marking the handles of `Subpath`. Defaulted to `3.`.
pub handle_point_radius: f64,
/// Fill color of the circles marking the handles of `Subpath`. Defaulted to `white`.
pub handle_point_fill: String,
}
impl ToSVGOptions {
/// Combine and format curve styling options for an SVG path.
pub(crate) fn formatted_curve_arguments(&self) -> String {
format!(r#"stroke="{}" stroke-width="{}" fill="none""#, self.curve_stroke_color, self.curve_stroke_width)
}
/// Combine and format anchor styling options an SVG circle.
pub(crate) fn formatted_anchor_arguments(&self) -> String {
format!(
r#"r="{}", stroke="{}" stroke-width="{}" fill="{}""#,
self.anchor_radius, self.anchor_stroke_color, self.anchor_stroke_width, self.anchor_fill
)
}
/// Combine and format handle point styling options for an SVG circle.
pub(crate) fn formatted_handle_point_arguments(&self) -> String {
format!(
r#"r="{}", stroke="{}" stroke-width="{}" fill="{}""#,
self.handle_point_radius, self.handle_point_stroke_color, self.handle_point_stroke_width, self.handle_point_fill
)
}
/// Combine and format handle line styling options an SVG path.
pub(crate) fn formatted_handle_line_arguments(&self) -> String {
format!(r#"stroke="{}" stroke-width="{}" fill="none""#, self.handle_line_stroke_color, self.handle_line_stroke_width)
}
}
impl Default for ToSVGOptions {
fn default() -> Self {
ToSVGOptions {
curve_stroke_color: String::from("black"),
curve_stroke_width: 2.,
anchor_stroke_color: String::from("black"),
anchor_stroke_width: 2.,
anchor_radius: 4.,
anchor_fill: String::from("white"),
handle_line_stroke_color: String::from("gray"),
handle_line_stroke_width: 1.,
handle_point_stroke_color: String::from("gray"),
handle_point_stroke_width: 1.5,
handle_point_radius: 3.,
handle_point_fill: String::from("white"),
}
}
}