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

added rectangle package #76

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions rectangle /rectangle.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package rectangle

import (
"errors"
"image"
"image/color"

"github.com/anthonynsimon/bild/parallel"
)

//AddRectangle adds rectangle to the passes image
//it uses image to operate on
//definations of arguments are :
// img : input image
// xLeft : x value of top left most corner of rectangle to be drawn
// yLeft : y value of top left most corner of rectangle to be drawn
// xRight : x value of bottom right most corner of rectangle to be drawn
// yRight : y value of bottom right most corner of rectangle to be drawn
// c : color for the inner rectangle
func AddRectangle(img *image.RGBA, xLeft, yLeft, xRight, yRight int, c color.Color) error {

height, width := img.Rect.Dy(), img.Rect.Dx()
if xRight > width || yRight > height {
return errors.New("bottom right corner values exceed the limit")
} else if xLeft < 0 || yLeft < 0 {
return errors.New("top left corner values preceed the limit")
} else if xLeft > xRight || yLeft < yRight {
return errors.New("values must be in correct order")
}
height, width = yLeft-yRight, xRight-xLeft
parallel.Line(height, func(start, end int) {
for y := start; y < end; y++ {
for x := 0; x < width; x++ {
img.Set(x+xLeft, y+yRight, c)
}
}
})

return nil
}