Revert rectangles' vetices (float64 -> int)

This commit is contained in:
Hajime Hoshi 2015-01-17 23:31:09 +09:00
parent 1659e9abab
commit f0d40b4e1f
5 changed files with 13 additions and 10 deletions

View File

@ -27,7 +27,7 @@ const (
func update(screen *ebiten.Image) error { func update(screen *ebiten.Image) error {
for i := 0; i < 6; i++ { 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(10, 10, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})
screen.FillRect(20, 20, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80}) screen.FillRect(20, 20, 100, 100, color.NRGBA{0x80, 0x80, 0xff, 0x80})

View File

@ -108,16 +108,18 @@ func (i *Image) DrawLines(lines Lines) (err error) {
return 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}}) return i.DrawLines(&rectsAsLines{&rect{x, y, width, height, clr}})
} }
// DrawRect draws rectangles.
func (i *Image) DrawRects(rects Rects) error { func (i *Image) DrawRects(rects Rects) error {
return i.DrawLines(&rectsAsLines{rects}) return i.DrawLines(&rectsAsLines{rects})
} }
// FillRect draws a filled rectangle. // 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}) return i.FillRects(&rect{x, y, width, height, clr})
} }

View File

@ -130,7 +130,7 @@ func (f *Framebuffer) DrawLines(c *opengl.Context, lines Lines) error {
type Rects interface { type Rects interface {
Len() int Len() int
Rect(i int) (x, y, width, height float64) Rect(i int) (x, y, width, height int)
Color(i int) color.Color Color(i int) color.Color
} }

View File

@ -135,7 +135,7 @@ func DrawLines(c *opengl.Context, projectionMatrix *[4][4]float64, lines Lines)
type Rects interface { type Rects interface {
Len() int Len() int
Rect(i int) (x, y, width, height float64) Rect(i int) (x, y, width, height int)
Color(i int) color.Color Color(i int) color.Color
} }

View File

@ -52,7 +52,8 @@ func (r *rectsAsLines) Len() int {
} }
func (r *rectsAsLines) Points(i int) (x0, y0, x1, y1 float64) { 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 { switch i % 4 {
case 0: case 0:
return x, y, x + w, y 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. // A Rects represents the set of rectangles.
type Rects interface { type Rects interface {
Len() int Len() int
Rect(i int) (x, y, width, height float64) Rect(i int) (x, y, width, height int)
Color(i int) color.Color Color(i int) color.Color
} }
type rect struct { type rect struct {
x, y float64 x, y int
width, height float64 width, height int
color color.Color color color.Color
} }
@ -87,7 +88,7 @@ func (r *rect) Len() int {
return 1 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 return r.x, r.y, r.width, r.height
} }