From 6d9db2b13c1b7edf502f983c11de94ffed340f15 Mon Sep 17 00:00:00 2001 From: Andy Balholm Date: Sat, 1 Jan 2022 19:01:48 -0800 Subject: [PATCH] internal/stroke: properly calculate maxDist The calculated value for maxDist (the maximum allowable error when converting cubic Beziers to quadratics) was way too small when the first control point was very close to the starting point of the segment. (f32.Rectangle.Add does not expand the rectangle to include the new point; it moves the rectangle by the point's X and Y coordinates.) Splitting the curve into such small pieces was resulting in very ugly output. Fixes: https://todo.sr.ht/~eliasnaur/gio/331 Signed-off-by: Andy Balholm --- internal/stroke/stroke.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/internal/stroke/stroke.go b/internal/stroke/stroke.go index f7cad17d..47db6cad 100644 --- a/internal/stroke/stroke.go +++ b/internal/stroke/stroke.go @@ -670,7 +670,10 @@ func SplitCubic(from, ctrl0, ctrl1, to f32.Point) []QuadSegment { hull := f32.Rectangle{ Min: from, Max: ctrl0, - }.Canon().Add(ctrl1).Add(to) + }.Canon().Union(f32.Rectangle{ + Min: ctrl1, + Max: to, + }.Canon()) l := hull.Dx() if h := hull.Dy(); h > l { l = h