~eliasnaur/gio#445: 
There is a weird line between the two triangles.

package main

import (
	"image"
	"image/color"

	"gioui.org/app"
	"gioui.org/f32"
	"gioui.org/io/system"
	"gioui.org/layout"
	"gioui.org/op"
	"gioui.org/op/clip"
	"gioui.org/op/paint"
)

func main() {
	go func() {
		var ops op.Ops
		w := app.NewWindow(app.Size(400, 400))
		for e := range w.Events() {
			switch e := e.(type) {
			case system.DestroyEvent:
				return
			case system.FrameEvent:
				gtx := layout.NewContext(&ops, e)

				triangles(gtx)
				e.Frame(gtx.Ops)
			}
		}
	}()
	app.Main()
}

func triangles(ctx layout.Context) layout.Dimensions {
	size := ctx.Dp(300.0)

	b := clip.Rect{Max: image.Pt(size, size)}
	x := b.Push(ctx.Ops)
	paint.ColorOp{
		Color: color.NRGBA{0, 0, 255, 255},
	}.Add(ctx.Ops)
	paint.PaintOp{}.Add(ctx.Ops)
	x.Pop()

	p := clip.Path{}
	p.Begin(ctx.Ops)
	p.MoveTo(f32.Pt(0, 0))
	p.LineTo(f32.Pt(float32(size), 0))
	p.LineTo(f32.Pt(0, float32(size)))
	p.Close()
	s := clip.Outline{
		Path: p.End(),
	}.Op().Push(ctx.Ops)

	paint.ColorOp{
		Color: color.NRGBA{255, 0, 0, 255},
	}.Add(ctx.Ops)
	paint.PaintOp{}.Add(ctx.Ops)
	s.Pop()

	p = clip.Path{}
	p.Begin(ctx.Ops)
	p.MoveTo(f32.Pt(float32(size), 0))
	p.LineTo(f32.Pt(float32(size), float32(size)))
	p.LineTo(f32.Pt(0, float32(size)))
	p.Close()
	s = clip.Outline{
		Path: p.End(),
	}.Op().Push(ctx.Ops)

	paint.ColorOp{
		Color: color.NRGBA{144, 0, 0, 255},
	}.Add(ctx.Ops)
	paint.PaintOp{}.Add(ctx.Ops)
	s.Pop()

	return layout.Dimensions{
		Size: image.Pt(size, size),
	}
}

weird line

Status
REPORTED
Submitter
~tangyang
Assigned to
No-one
Submitted
3 months ago
Updated
3 months ago
Labels
No labels applied.

~eliasnaur 3 months ago

This issue is likely a conflation artifact inherent to our implementation of anti-aliasing. See for example https://github.com/linebender/piet-gpu/issues/49 for a description of the general problem and possible solutions. The short story (for now) is: "don't overlap shape edges". Sorry.

~tangyang 3 months ago

Thank you!

Register here or Log in to comment, or comment via email.