From 18991045368d653f8050d1b4033bd7060ec58b93 Mon Sep 17 00:00:00 2001 From: Egon Elbre Date: Fri, 20 Nov 2020 20:14:53 +0200 Subject: [PATCH] op/clip: expose LineTo and QuadTo Using delta position with Line and Quad can drift over successive calls. Also, in some cases it's much more convenient to use absolute coordinates rather than relative. Signed-off-by: Egon Elbre --- internal/rendertest/clip_test.go | 20 +++++++++++ .../rendertest/refs/TestPaintAbsolute.png | Bin 0 -> 920 bytes op/clip/clip.go | 32 +++++++++++------- 3 files changed, 40 insertions(+), 12 deletions(-) create mode 100644 internal/rendertest/refs/TestPaintAbsolute.png diff --git a/internal/rendertest/clip_test.go b/internal/rendertest/clip_test.go index 7746156d..91eafaef 100644 --- a/internal/rendertest/clip_test.go +++ b/internal/rendertest/clip_test.go @@ -78,6 +78,26 @@ func TestPaintArc(t *testing.T) { }) } +func TestPaintAbsolute(t *testing.T) { + run(t, func(o *op.Ops) { + p := new(clip.Path) + p.Begin(o) + p.Move(f32.Pt(100, 100)) // offset the initial pen position to test "MoveTo" + + p.MoveTo(f32.Pt(20, 20)) + p.LineTo(f32.Pt(80, 20)) + p.QuadTo(f32.Pt(80, 80), f32.Pt(20, 80)) + p.Outline().Add(o) + + paint.FillShape(o, red, clip.Rect(image.Rect(0, 0, 128, 128)).Op()) + }, func(r result) { + r.expect(0, 0, colornames.White) + r.expect(30, 30, colornames.Red) + r.expect(79, 79, colornames.White) + r.expect(90, 90, colornames.White) + }) +} + func TestPaintTexture(t *testing.T) { run(t, func(o *op.Ops) { squares.Add(o) diff --git a/internal/rendertest/refs/TestPaintAbsolute.png b/internal/rendertest/refs/TestPaintAbsolute.png new file mode 100644 index 0000000000000000000000000000000000000000..f8680aacab6519a33c38e8133213d6c8a0074e21 GIT binary patch literal 920 zcmeAS@N?(olHy`uVBq!ia0vp^4Is?H1SEZ8zRh7^V2<~6aSW-L^XATZuSJ0p$3GtL z==hhR^;JyNk;_#~X$waTOW;MfC=U_cMWF&0)n1%871{ccYfsZUhm7mHT7QSdI+#Bw zNRVhVewER+zxdqe-v%dg*yPTYpZi!FfBK=@V#OBY7C8rNHil#d10snH59j?W)w#Ca zk?q*V^9Ob^ACO?^VFVIBkqu8%zp$94GH%;;LHNcL))OgUYQ|hw|Ab(%gfuqWM&HPW z5H2v~!eran%XnZ4>x?-r{t1^w6y&CNa()po^JVPoPtD=6ZSf6mIP1%9f8c_M!faRn z3oXkSxVc|&&blCSVDEE*Sxj^0&t9$YeFf)+-QDvRSei0kyM9sFMEv#3)m(RWugZS; z`}V=x38vN$9v(bEiQhcc#E@&-Nw#p->-%58_xSjMmh0+lz;fH;d%P^ zaQi#50dn5gq^*6 z?F2_v-@gx8>_CUCKYcUOVDu+FLzaY0x)}IHqxP9|!*p>=+pkZ5)@{GT_u-3* zyL(*CrXR_EY$u*SedhM<``tfF7yT>JIq-L{B^b?3sf&sFET z`5R~KU=SDIv{!fMoRrN*c6`#zxdDt}VNV_$&?#3_?(R0SU;lhU=KALhfhqU2CVLiF zExG(mf8~^)#-?9?o6a;@-`T=bS$f%AV=rsLo9Y?0NB&Pu;9)q%Kxbk= maxSplits { - p.quadTo(c, to) + p.QuadTo(c, to) return splits } // The maximum distance between the cubic P and its approximation Q given t @@ -301,7 +309,7 @@ func (p *Path) approxCubeTo(splits int, maxDist float32, ctrl0, ctrl1, to f32.Po v := to.Sub(ctrl1.Mul(3)).Add(ctrl0.Mul(3)).Sub(p.pen) d2 := (v.X*v.X + v.Y*v.Y) * 3 / (36 * 36) if d2 <= maxDist*maxDist { - p.quadTo(c, to) + p.QuadTo(c, to) return splits } // De Casteljau split the curve and approximate the halves.