Skip to content

Commit

Permalink
responded to comments
Browse files Browse the repository at this point in the history
  • Loading branch information
ctessum committed Aug 7, 2015
1 parent 2e432e6 commit 5b41e65
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
8 changes: 0 additions & 8 deletions plotter/main.go
Expand Up @@ -59,14 +59,6 @@ var formats = []string{
}

func main() {
//for _, ex := range examples {
// for _, f := range formats {
// err := ex.p.Save(4*vg.Inch, 4*vg.Inch, ex.name+"."+f)
// if err != nil {
// log.Fatalf("failed to save %s.%s: %v", ex.name, f, err)
// }
// }
//}
const (
nrows = 4
ncols = 5
Expand Down
32 changes: 15 additions & 17 deletions vg/draw/canvas.go
Expand Up @@ -318,18 +318,18 @@ func (c *Canvas) Y(y float64) vg.Length {
// area with the given number of inches added to the minimum
// and maximum x and y values of the Canvas's Rectangle.
// Note that cropping the right and top sides of the canvas
// requires specifying negative values of xmaxcrop and ymaxcrop.
func (c Canvas) Crop(xmincrop, ymincrop, xmaxcrop, ymaxcrop vg.Length) Canvas {
// requires specifying negative values of right and top.
func (c Canvas) Crop(right, bottom, left, top vg.Length) Canvas {
minpt := Point{
X: c.Min.X + xmincrop,
Y: c.Min.Y + ymincrop,
X: c.Min.X + right,
Y: c.Min.Y + bottom,
}
maxpt := Point{
X: c.Max.X + xmaxcrop,
Y: c.Max.Y + ymaxcrop,
X: c.Max.X + left,
Y: c.Max.Y + top,
}
return Canvas{
Canvas: vg.Canvas(c),
Canvas: c,
Rectangle: Rectangle{Min: minpt, Max: maxpt},
}
}
Expand All @@ -345,34 +345,32 @@ func (t Tiles) At(row, col int) Canvas {
return t.Values[row*t.Cols+col]
}

// Tile returns new Canvases corresponding to the reciever canvas tiled
// Tiles returns new Canvases corresponding to the reciever canvas tiled
// into the given number of rows and columns (row major, starting from the
// top left corner) where t, b, l, r, h,
// and w are the padding above, below, to the left, to the right, between rows,
// and between columns of the tiles, respectively.
func (c Canvas) Tile(rows, cols int, top, bottom, left, right, padx, pady vg.Length) *Tiles {
// top left corner) where top, bottom, left, right, padx,
// and pady are the padding above, below, to the left, to the right, between columns,
// and between rows of the tiles, respectively.
func (c Canvas) Tiles(rows, cols int, top, bottom, left, right, padx, pady vg.Length) *Tiles {
o := &Tiles{
Values: make([]Canvas, rows*cols),
Values: make([]Canvas, 0, rows*cols),
Rows: rows,
Cols: cols,
}
tileH := (c.Max.Y - c.Min.Y - top - bottom - vg.Length(rows-1)*pady) / vg.Length(rows)
tileW := (c.Max.X - c.Min.X - left - right - vg.Length(cols-1)*padx) / vg.Length(cols)
ii := 0
for j := 0; j < rows; j++ {
ymax := c.Max.Y - top - vg.Length(j)*(pady+tileH)
ymin := ymax - tileH
for i := 0; i < cols; i++ {
xmin := c.Min.X + left + vg.Length(i)*(padx+tileW)
xmax := xmin + tileW
o.Values[ii] = Canvas{
o.Values = append(o.Values, Canvas{
Canvas: vg.Canvas(c),
Rectangle: Rectangle{
Min: Point{X: xmin, Y: ymin},
Max: Point{X: xmax, Y: ymax},
},
}
ii++
})
}
}
return o
Expand Down
2 changes: 1 addition & 1 deletion vg/draw/draw_test.go
Expand Up @@ -60,7 +60,7 @@ func TestCrop(t *testing.T) {
func TestTile(t *testing.T) {
r := recorder.New(96)
c := NewCanvas(r, 13, 7)
tiles := c.Tile(2, 3, 1, 1, 1, 1, 1, 1)
tiles := c.Tiles(2, 3, 1, 1, 1, 1, 1, 1)
rectangles := [][]Rectangle{
{
Rectangle{
Expand Down

0 comments on commit 5b41e65

Please sign in to comment.