From 7238a601fc0e074543e3fa1b1912bf7afa9d32bf Mon Sep 17 00:00:00 2001 From: Richard Piazza Date: Tue, 20 Jun 2023 06:29:23 -0500 Subject: [PATCH] Smooth Curves (#13) --- Sources/SwiftSVG/Path.ComponentParser.swift | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Sources/SwiftSVG/Path.ComponentParser.swift b/Sources/SwiftSVG/Path.ComponentParser.swift index 56a6580..807b8e4 100644 --- a/Sources/SwiftSVG/Path.ComponentParser.swift +++ b/Sources/SwiftSVG/Path.ComponentParser.swift @@ -79,11 +79,19 @@ public extension Path { command = .cubicBezierCurve(cp1: currentPoint, cp2: currentPoint, point: currentPoint) coordinates = .relative case .smoothCubicBezierCurve: - command = .cubicBezierCurve(cp1: currentPoint, cp2: .nan, point: .nan) + if case .cubicBezierCurve(_, let cp, _) = lastCommand { + command = .cubicBezierCurve(cp1: cp.reflection(using: currentPoint), cp2: .nan, point: .nan) + } else { + command = .cubicBezierCurve(cp1: currentPoint, cp2: .nan, point: .nan) + } coordinates = .absolute position = 2 case .relativeSmoothCubicBezierCurve: - command = .cubicBezierCurve(cp1: currentPoint, cp2: currentPoint, point: currentPoint) + if case .cubicBezierCurve(_, let cp, _) = lastCommand { + command = .cubicBezierCurve(cp1: cp.reflection(using: cp.reflection(using: currentPoint)), cp2: currentPoint, point: currentPoint) + } else { + command = .cubicBezierCurve(cp1: currentPoint, cp2: currentPoint, point: currentPoint) + } coordinates = .relative position = 2 case .quadraticBezierCurve: @@ -102,9 +110,9 @@ public extension Path { position = 2 case .relativeSmoothQuadraticBezierCurve: if case .quadraticBezierCurve(let cp, _) = lastCommand { - command = .quadraticBezierCurve(cp: cp.reflection(using: currentPoint), point: .nan) + command = .quadraticBezierCurve(cp: cp.reflection(using: currentPoint), point: currentPoint) } else { - command = .quadraticBezierCurve(cp: currentPoint, point: .nan) + command = .quadraticBezierCurve(cp: currentPoint, point: currentPoint) } coordinates = .relative position = 2