|
1 | 1 | use super::*;
|
| 2 | +use utils::format_point; |
| 3 | + |
2 | 4 | use std::fmt::Write;
|
3 | 5 |
|
4 | 6 | /// Functionality relating to core `Bezier` operations, such as constructors and `abs_diff_eq`.
|
@@ -122,32 +124,38 @@ impl Bezier {
|
122 | 124 | pub fn write_curve_argument(&self, svg: &mut String) -> std::fmt::Result {
|
123 | 125 | match self.handles {
|
124 | 126 | BezierHandles::Linear => svg.push_str(SVG_ARG_LINEAR),
|
125 |
| - BezierHandles::Quadratic { handle } => write!(svg, "{SVG_ARG_QUADRATIC}{:.6},{:.6}", handle.x, handle.y)?, |
126 |
| - BezierHandles::Cubic { handle_start, handle_end } => write!(svg, "{SVG_ARG_CUBIC}{:.6},{:.6} {:.6},{:.6}", handle_start.x, handle_start.y, handle_end.x, handle_end.y)?, |
| 127 | + BezierHandles::Quadratic { handle } => { |
| 128 | + format_point(svg, SVG_ARG_QUADRATIC, handle.x, handle.y)?; |
| 129 | + } |
| 130 | + BezierHandles::Cubic { handle_start, handle_end } => { |
| 131 | + format_point(svg, SVG_ARG_CUBIC, handle_start.x, handle_start.y)?; |
| 132 | + format_point(svg, " ", handle_end.x, handle_end.y)?; |
| 133 | + } |
127 | 134 | }
|
128 |
| - write!(svg, " {:.6},{:.6}", self.end.x, self.end.y) |
| 135 | + format_point(svg, " ", self.end.x, self.end.y) |
129 | 136 | }
|
130 | 137 |
|
131 | 138 | /// Return the string argument used to create the lines connecting handles to endpoints in an SVG `path`
|
132 | 139 | pub(crate) fn svg_handle_line_argument(&self) -> Option<String> {
|
| 140 | + let mut result = String::new(); |
| 141 | + |
133 | 142 | match self.handles {
|
134 |
| - BezierHandles::Linear => None, |
| 143 | + BezierHandles::Linear => {} |
135 | 144 | BezierHandles::Quadratic { handle } => {
|
136 |
| - let handle_line = format!("{SVG_ARG_LINEAR}{:.6} {:.6}", handle.x, handle.y); |
137 |
| - Some(format!( |
138 |
| - "{SVG_ARG_MOVE}{:.6} {:.6} {handle_line} {SVG_ARG_MOVE}{:.6} {:.6} {handle_line}", |
139 |
| - self.start.x, self.start.y, self.end.x, self.end.y |
140 |
| - )) |
| 145 | + let _ = format_point(&mut result, SVG_ARG_MOVE, self.start.x, self.start.y); |
| 146 | + let _ = format_point(&mut result, SVG_ARG_LINEAR, handle.x, handle.y); |
| 147 | + let _ = format_point(&mut result, SVG_ARG_MOVE, self.end.x, self.end.y); |
| 148 | + let _ = format_point(&mut result, SVG_ARG_LINEAR, handle.x, handle.y); |
141 | 149 | }
|
142 | 150 | BezierHandles::Cubic { handle_start, handle_end } => {
|
143 |
| - let handle_start_line = format!("{SVG_ARG_LINEAR}{:.6} {:.6}", handle_start.x, handle_start.y); |
144 |
| - let handle_end_line = format!("{SVG_ARG_LINEAR}{} {}", handle_end.x, handle_end.y); |
145 |
| - Some(format!( |
146 |
| - "{SVG_ARG_MOVE}{:.6} {:.6} {handle_start_line} {SVG_ARG_MOVE}{:.6} {:.6} {handle_end_line}", |
147 |
| - self.start.x, self.start.y, self.end.x, self.end.y |
148 |
| - )) |
| 151 | + let _ = format_point(&mut result, SVG_ARG_MOVE, self.start.x, self.start.y); |
| 152 | + let _ = format_point(&mut result, SVG_ARG_LINEAR, handle_start.x, handle_start.y); |
| 153 | + let _ = format_point(&mut result, SVG_ARG_MOVE, self.end.x, self.end.y); |
| 154 | + let _ = format_point(&mut result, SVG_ARG_LINEAR, handle_end.x, handle_end.y); |
149 | 155 | }
|
150 | 156 | }
|
| 157 | + |
| 158 | + (!result.is_empty()).then_some(result) |
151 | 159 | }
|
152 | 160 |
|
153 | 161 | /// Appends to the `svg` mutable string with an SVG shape representation of the curve.
|
|
0 commit comments