From f0d40b4e1fc57c82f142fb483c8b0618369b7aa7 Mon Sep 17 00:00:00 2001 From: Hajime Hoshi Date: Sat, 17 Jan 2015 23:31:09 +0900 Subject: [PATCH] Revert rectangles' vetices (float64 -> int) --- example/shapes/main.go | 2 +- image.go | 6 ++++-- internal/graphics/framebuffer.go | 2 +- internal/graphics/internal/shader/draw.go | 2 +- shapes.go | 11 ++++++----- 5 files changed, 13 insertions(+), 10 deletions(-) diff --git a/example/shapes/main.go b/example/shapes/main.go index df273bb2f..22e730b8b 100644 --- a/example/shapes/main.go +++ b/example/shapes/main.go @@ -27,7 +27,7 @@ const ( func update(screen *ebiten.Image) error { for i := 0; i < 6; i++ { - screen.DrawRect(float64(2*i), float64(2*i), 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80}) + screen.DrawRect(2*i, 2*i, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80}) } screen.FillRect(10, 10, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80}) screen.FillRect(20, 20, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80}) diff --git a/image.go b/image.go index 9d0b9d1c0..df6c5d693 100644 --- a/image.go +++ b/image.go @@ -108,16 +108,18 @@ func (i *Image) DrawLines(lines Lines) (err error) { return } -func (i *Image) DrawRect(x, y, width, height float64, clr color.Color) error { +// DrawRect draws a rectangle. +func (i *Image) DrawRect(x, y, width, height int, clr color.Color) error { return i.DrawLines(&rectsAsLines{&rect{x, y, width, height, clr}}) } +// DrawRect draws rectangles. func (i *Image) DrawRects(rects Rects) error { return i.DrawLines(&rectsAsLines{rects}) } // FillRect draws a filled rectangle. -func (i *Image) FillRect(x, y, width, height float64, clr color.Color) error { +func (i *Image) FillRect(x, y, width, height int, clr color.Color) error { return i.FillRects(&rect{x, y, width, height, clr}) } diff --git a/internal/graphics/framebuffer.go b/internal/graphics/framebuffer.go index 4a271d55b..1872aa1b4 100644 --- a/internal/graphics/framebuffer.go +++ b/internal/graphics/framebuffer.go @@ -130,7 +130,7 @@ func (f *Framebuffer) DrawLines(c *opengl.Context, lines Lines) error { type Rects interface { Len() int - Rect(i int) (x, y, width, height float64) + Rect(i int) (x, y, width, height int) Color(i int) color.Color } diff --git a/internal/graphics/internal/shader/draw.go b/internal/graphics/internal/shader/draw.go index 68ef5eba7..27a37fda2 100644 --- a/internal/graphics/internal/shader/draw.go +++ b/internal/graphics/internal/shader/draw.go @@ -135,7 +135,7 @@ func DrawLines(c *opengl.Context, projectionMatrix *[4][4]float64, lines Lines) type Rects interface { Len() int - Rect(i int) (x, y, width, height float64) + Rect(i int) (x, y, width, height int) Color(i int) color.Color } diff --git a/shapes.go b/shapes.go index 5174e3d31..fa4e34009 100644 --- a/shapes.go +++ b/shapes.go @@ -52,7 +52,8 @@ func (r *rectsAsLines) Len() int { } func (r *rectsAsLines) Points(i int) (x0, y0, x1, y1 float64) { - x, y, w, h := r.Rects.Rect(i / 4) + ix, iy, iw, ih := r.Rects.Rect(i / 4) + x, y, w, h := float64(ix), float64(iy), float64(iw), float64(ih) switch i % 4 { case 0: return x, y, x + w, y @@ -73,13 +74,13 @@ func (r *rectsAsLines) Color(i int) color.Color { // A Rects represents the set of rectangles. type Rects interface { Len() int - Rect(i int) (x, y, width, height float64) + Rect(i int) (x, y, width, height int) Color(i int) color.Color } type rect struct { - x, y float64 - width, height float64 + x, y int + width, height int color color.Color } @@ -87,7 +88,7 @@ func (r *rect) Len() int { return 1 } -func (r *rect) Rect(i int) (x, y, width, height float64) { +func (r *rect) Rect(i int) (x, y, width, height int) { return r.x, r.y, r.width, r.height }