Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x/image: LineTo has an unexpected behaviour, or is not enough documented #45723

Closed
owulveryck opened this issue Apr 23, 2021 · 3 comments
Closed
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@owulveryck
Copy link
Contributor

What version of Go are you using (go version)?

$ go version
go version go1.15.6 darwin/amd64

Does this issue reproduce with the latest release?

Yes

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GO111MODULE=""
GOARCH="amd64"
GOBIN=""
GOCACHE="/Users/olivierwulveryck/Library/Caches/go-build"
GOENV="/Users/olivierwulveryck/Library/Application Support/go/env"
GOEXE=""
GOFLAGS=""
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOINSECURE=""
GOMODCACHE="/Users/olivierwulveryck/GOPROJECTS/pkg/mod"
GONOPROXY="github.com/dktunited"
GONOSUMDB="github.com/dktunited"
GOOS="darwin"
GOPATH="/Users/olivierwulveryck/GOPROJECTS"
GOPRIVATE="github.com/dktunited"
GOPROXY="https://proxy.golang.org,direct"
GOROOT="/usr/local/go"
GOSUMDB="sum.golang.org"
GOTMPDIR=""
GOTOOLDIR="/usr/local/go/pkg/tool/darwin_amd64"
GCCGO="gccgo"
AR="ar"
CC="clang"
CXX="clang++"
CGO_ENABLED="1"
GOMOD="/Users/olivierwulveryck/GOPROJECTS/src/github.com/owulveryck/linesToGo/go.mod"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
PKG_CONFIG="pkg-config"
GOGCCFLAGS="-fPIC -m64 -pthread -fno-caret-diagnostics -Qunused-arguments -fmessage-length=0 -fdebug-prefix-map=/var/folders/j3/t2_lsqzd5mgbv7tqvxg9ty5r0000gn/T/go-build500293275=/tmp/go-build -gno-record-gcc-switches -fno-common"

What did you do?

I am trying to draw a simple line on a picture with the vector package.
I cannot figure out how the package work.

I made a trivial test and I expect it to see in the mask two identical values (representing the horizontal line) and two identical nil values.

func TestMe(t *testing.T) {
	z := vector.NewRasterizer(2, 2)
	z.DrawOp = draw.Src
	// . | .
	// -----
	// . | .

	z.MoveTo(0, 0)
	z.LineTo(1, 0)
	// x | x
	// -----
	// . | .

	dst := image.NewAlpha(z.Bounds())
	z.Draw(dst, dst.Bounds(), image.Opaque, image.Point{})
	expected := []uint8{255, 255, 0, 0}
	if !reflect.DeepEqual(dst.Pix, expected) {
		t.Fatal(dst.Pix)

	}
}

https://play.golang.org/p/RnHAWhUwP7K

I tried to debug the code without success. I may have completely misunderstood how to use the package. Therefore an example would help

What did you expect to see?

Eventually, the representation of a line

What did you see instead?

A blank mask or a black picture

@gopherbot gopherbot added this to the Unreleased milestone Apr 23, 2021
@cherrymui
Copy link
Member

cc @nigeltao

@cherrymui cherrymui added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Apr 26, 2021
@nigeltao
Copy link
Contributor

nigeltao commented May 2, 2021

There is an example at https://pkg.go.dev/golang.org/x/image/font/sfnt#example-package-RasterizeGlyph but I admit that that's not easily found from the golang.org/x/image/vector documentation. I'll add an example, as you suggested.

Calls like LineTo and QuadTo define the edges of the vector shape to fill, not the middle. There is no implicit stroke width. Your code does a single LineTo call, so your shape is infinitely thin and calling z.Draw touches no pixels.

z.MoveTo(0, 0)
z.LineTo(1, 0)

should instead be

z.MoveTo(0, 0)
z.LineTo(2, 0)
z.LineTo(2, 1)
z.LineTo(0, 1)
z.ClosePath()

@gopherbot
Copy link

Change https://golang.org/cl/316069 mentions this issue: vector: add example test

@golang golang locked and limited conversation to collaborators May 4, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Documentation FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants