gpu,op/clip: implement stroked paths with miter joins

Signed-off-by: Sebastien Binet <s@sbinet.org>
This commit is contained in:
Sebastien Binet
2020-11-11 15:05:47 +00:00
committed by Elias Naur
parent 7de8ce51a5
commit 7eb32360e5
8 changed files with 145 additions and 3 deletions
+90
View File
@@ -211,6 +211,96 @@ func TestStrokedPathRoundRound(t *testing.T) {
})
}
func TestStrokedPathFlatMiter(t *testing.T) {
run(t, func(o *op.Ops) {
const width = 10
sty := clip.StrokeStyle{
Cap: clip.FlatCap,
Join: clip.BevelJoin,
Miter: 5,
}
beg := f32.Pt(40, 10)
{
p := new(clip.Path)
p.Begin(o)
p.Move(beg)
p.Line(f32.Pt(50, 0))
p.Line(f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Quad(f32.Pt(-50, 20), f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Stroke(width, sty).Add(o)
paint.Fill(o, colornames.Red)
}
{
p := new(clip.Path)
p.Begin(o)
p.Move(beg)
p.Line(f32.Pt(50, 0))
p.Line(f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Quad(f32.Pt(-50, 20), f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Stroke(2, clip.StrokeStyle{}).Add(o)
paint.Fill(o, colornames.Black)
}
}, func(r result) {
r.expect(0, 0, colornames.White)
r.expect(40, 10, colornames.Black)
r.expect(40, 12, colornames.Red)
})
}
func TestStrokedPathFlatMiterInf(t *testing.T) {
run(t, func(o *op.Ops) {
const width = 10
sty := clip.StrokeStyle{
Cap: clip.FlatCap,
Join: clip.BevelJoin,
Miter: float32(math.Inf(+1)),
}
beg := f32.Pt(40, 10)
{
p := new(clip.Path)
p.Begin(o)
p.Move(beg)
p.Line(f32.Pt(50, 0))
p.Line(f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Quad(f32.Pt(-50, 20), f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Stroke(width, sty).Add(o)
paint.Fill(o, colornames.Red)
}
{
p := new(clip.Path)
p.Begin(o)
p.Move(beg)
p.Line(f32.Pt(50, 0))
p.Line(f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Quad(f32.Pt(-50, 20), f32.Pt(-50, 50))
p.Line(f32.Pt(50, 0))
p.Stroke(2, clip.StrokeStyle{}).Add(o)
paint.Fill(o, colornames.Black)
}
}, func(r result) {
r.expect(0, 0, colornames.White)
r.expect(40, 10, colornames.Black)
r.expect(40, 12, colornames.Red)
})
}
func TestStrokedPathZeroWidth(t *testing.T) {
run(t, func(o *op.Ops) {
const width = 2
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 KiB