~whereswaldon/gio-x

f3dbca58eb18ceb38d3c24790789e3325a4b3bff — Andy Balholm 7 months ago 0484e0d
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.

References: https://todo.sr.ht/~eliasnaur/gio/331
Signed-off-by: Andy Balholm <andy@balholm.com>
1 files changed, 4 insertions(+), 1 deletions(-)

M stroke/approx.go
M stroke/approx.go => stroke/approx.go +4 -1
@@ 789,7 789,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