From 88f1d3f10842add73598e06f557643e0b00a97a5 Mon Sep 17 00:00:00 2001 From: Patrick Walton Date: Fri, 22 Sep 2017 13:40:41 -0700 Subject: [PATCH] Fix de Casteljau subdivision when a curve has two inflection points --- demo/server/src/main.rs | 1 + path-utils/src/curve.rs | 10 +++++----- path-utils/src/monotonic.rs | 10 +++------- 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/demo/server/src/main.rs b/demo/server/src/main.rs index b4a98bee..017b016d 100644 --- a/demo/server/src/main.rs +++ b/demo/server/src/main.rs @@ -506,6 +506,7 @@ fn partition_svg_paths(request: Json) PartitionSvgPathKind::Stroke(stroke_width) => { let mut temp_path_buffer = PathBuffer::new(); stroke::stroke(&mut temp_path_buffer, stream.into_iter(), stroke_width); + let stream = PathBufferStream::new(&temp_path_buffer); let stream = MonotonicPathSegmentStream::new(stream); path_buffer.add_stream(stream) diff --git a/path-utils/src/curve.rs b/path-utils/src/curve.rs index a701b8ca..a07b3c80 100644 --- a/path-utils/src/curve.rs +++ b/path-utils/src/curve.rs @@ -54,11 +54,11 @@ impl Curve { pub fn inflection_points(&self) -> (Option, Option) { let inflection_point_x = Curve::inflection_point_x(self.endpoints[0].x, - self.endpoints[1].x, - self.control_point.x); + self.control_point.x, + self.endpoints[1].x); let inflection_point_y = Curve::inflection_point_x(self.endpoints[0].y, - self.endpoints[1].y, - self.control_point.y); + self.control_point.y, + self.endpoints[1].y); (inflection_point_x, inflection_point_y) } @@ -68,7 +68,7 @@ impl Curve { } #[inline] - fn inflection_point_x(endpoint_x_0: f32, endpoint_x_1: f32, control_point_x: f32) + fn inflection_point_x(endpoint_x_0: f32, control_point_x: f32, endpoint_x_1: f32) -> Option { let num = endpoint_x_0 - control_point_x; let denom = endpoint_x_0 - 2.0 * control_point_x + endpoint_x_1; diff --git a/path-utils/src/monotonic.rs b/path-utils/src/monotonic.rs index 406bc00f..d3471612 100644 --- a/path-utils/src/monotonic.rs +++ b/path-utils/src/monotonic.rs @@ -52,15 +52,12 @@ impl Iterator for MonotonicPathSegmentStream where I: Iterator { let curve = Curve::new(&self.prev_point, &control_point, &endpoint); + self.prev_point = endpoint; match curve.inflection_points() { - (None, None) => { - self.prev_point = endpoint; - Some(PathSegment::CurveTo(control_point, endpoint)) - } + (None, None) => Some(PathSegment::CurveTo(control_point, endpoint)), (Some(t), None) | (None, Some(t)) => { let (prev_curve, next_curve) = curve.subdivide(t); self.queue.push(next_curve.to_path_segment()); - self.prev_point = prev_curve.endpoints[1]; Some(prev_curve.to_path_segment()) } (Some(mut t0), Some(mut t1)) => { @@ -69,11 +66,10 @@ impl Iterator for MonotonicPathSegmentStream where I: Iterator