-
Notifications
You must be signed in to change notification settings - Fork 204
vgx11: fix translate offset #188
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright ©2015 The gonum Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style | ||
| // license that can be found in the LICENSE file. | ||
|
|
||
| // +build !windows | ||
|
|
||
| package vgx11 | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "image/jpeg" | ||
| "io/ioutil" | ||
| "os" | ||
| "path/filepath" | ||
| "testing" | ||
|
|
||
| "github.com/gonum/plot" | ||
| "github.com/gonum/plot/plotter" | ||
| "github.com/gonum/plot/vg" | ||
| "github.com/gonum/plot/vg/draw" | ||
| ) | ||
|
|
||
| // hasX11 checks if X11 is available by looking at the DISPLAY environment variable | ||
| func hasX11() bool { | ||
| return os.Getenv("DISPLAY") != "" | ||
| } | ||
|
|
||
| func TestIssue179(t *testing.T) { | ||
| if !hasX11() { | ||
| t.Skip("no X11 environment") | ||
| } | ||
|
|
||
| scatter, err := plotter.NewScatter(plotter.XYs{{1, 1}, {0, 1}, {0, 0}}) | ||
| if err != nil { | ||
| t.Fatalf("error: %v\n", err) | ||
| } | ||
| p, err := plot.New() | ||
| if err != nil { | ||
| t.Fatalf("error: %v\n", err) | ||
| } | ||
| p.Add(scatter) | ||
| p.HideAxes() | ||
|
|
||
| c, err := New(5.08*vg.Centimeter, 5.08*vg.Centimeter, "test issue179") | ||
| if err != nil { | ||
| t.Fatalf("error: %v\n", err) | ||
| } | ||
|
|
||
| p.Draw(draw.New(c)) | ||
| b := bytes.NewBuffer([]byte{}) | ||
| err = jpeg.Encode(b, c.ximg, nil) | ||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
|
|
||
| f, err := os.Open(filepath.Join("..", "vgimg", "testdata", "issue179.jpg")) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It looks like we are going to be doing this boilerplate |
||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| defer f.Close() | ||
|
|
||
| want, err := ioutil.ReadAll(f) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. defer f.Close()
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. done.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (also fixed in vgimg_test) |
||
| if err != nil { | ||
| t.Error(err) | ||
| } | ||
| if !bytes.Equal(b.Bytes(), want) { | ||
| t.Error("Image mismatch") | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I get the joke, but we don't have to do it everywhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In this case we actually do - Seb is using the same image that Brendan created.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Haha. Fair enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah... at some point I was tinkering with the idea of folding vgx11 into vgimg directly so it could be handled like the JpegCanvas and co. (so the test could also be folded into vgimg_test...)