Skip to content

Commit

Permalink
chroe: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
wenlng committed Sep 21, 2024
1 parent 60487af commit 8ad0fdf
Show file tree
Hide file tree
Showing 29 changed files with 74 additions and 73 deletions.
4 changes: 2 additions & 2 deletions v2/base/canvas/canvas.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"image/color"
)

// CreatePaletteCanvas is the canvas that creates the palette
// CreatePaletteCanvas is to the canvas that creates the palette
func CreatePaletteCanvas(width, height int, colour []color.RGBA) Palette {
p := []color.Color{
color.RGBA{R: 0xFF, G: 0xFF, B: 0xFF, A: 0x00},
Expand All @@ -24,7 +24,7 @@ func CreatePaletteCanvas(width, height int, colour []color.RGBA) Palette {
return NewPalette(image.Rect(0, 0, width, height), p)
}

// CreateNRGBACanvas is the canvas that creates the NRGBA
// CreateNRGBACanvas is to the canvas that creates the NRGBA
func CreateNRGBACanvas(width, height int, isAlpha bool) NRGBA {
return NewNRGBA(image.Rect(0, 0, width, height), isAlpha)
}
4 changes: 2 additions & 2 deletions v2/base/canvas/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import (
"math"
)

// RotatePoint is the point of rotation
// RotatePoint is to the point of rotation
func RotatePoint(x, y, sin, cos float64) (float64, float64) {
return x*cos - y*sin, x*sin + y*cos
}

// RotatedSize is the size of rotation
// RotatedSize is to the size of rotation
func RotatedSize(w, h int, angle float64) (int, int) {
if w <= 0 || h <= 0 {
return 0, 0
Expand Down
6 changes: 3 additions & 3 deletions v2/base/canvas/matrix.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ type Matrix struct {
XX, YX, XY, YY, X0, Y0 float64
}

// Translate is the matrix calculation of translate
// Translate is to the matrix calculation of translate
func (a Matrix) Translate(x, y float64) Matrix {
return Matrix{
1, 0,
Expand All @@ -22,7 +22,7 @@ func (a Matrix) Translate(x, y float64) Matrix {
}.Multiply(a)
}

// Multiply is the matrix calculation of multiply
// Multiply is to the matrix calculation of multiply
func (a Matrix) Multiply(b Matrix) Matrix {
return Matrix{
a.XX*b.XX + a.YX*b.XY,
Expand All @@ -34,7 +34,7 @@ func (a Matrix) Multiply(b Matrix) Matrix {
}
}

// Rotate is the matrix calculation of rotation
// Rotate is to the matrix calculation of rotation
func (a Matrix) Rotate(angle float64) Matrix {
c := math.Cos(angle)
s := math.Sin(angle)
Expand Down
12 changes: 6 additions & 6 deletions v2/base/canvas/nrgba.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func (n *nRGBA) Get() *image.NRGBA {
return n.NRGBA
}

// DrawString draws a string
// DrawString is to draws a string
func (n *nRGBA) DrawString(params *DrawStringParams, pt fixed.Point26_6) error {
dc := freetype.NewContext()
dc.SetDPI(float64(params.FontDPI))
Expand All @@ -84,7 +84,7 @@ func (n *nRGBA) DrawString(params *DrawStringParams, pt fixed.Point26_6) error {
return nil
}

// DrawImage draws a picture
// DrawImage is to draws a picture
func (n *nRGBA) DrawImage(img Palette, dotRect *PositionRect, posRect *AreaRect) {
nW := img.Bounds().Max.X
nH := img.Bounds().Max.Y
Expand All @@ -110,7 +110,7 @@ func (n *nRGBA) DrawImage(img Palette, dotRect *PositionRect, posRect *AreaRect)
}
}

// CalcMarginBlankArea is the calculation of margin space
// CalcMarginBlankArea is to the calculation of margin space
func (n *nRGBA) CalcMarginBlankArea() *AreaRect {
nW := n.Bounds().Max.X
nH := n.Bounds().Max.Y
Expand Down Expand Up @@ -152,7 +152,7 @@ func (n *nRGBA) CalcMarginBlankArea() *AreaRect {
}
}

// Rotate is rotation at any Angle
// Rotate is to rotation at any Angle
func (n *nRGBA) Rotate(a int) {
if a == 0 {
return
Expand Down Expand Up @@ -186,7 +186,7 @@ func (n *nRGBA) Rotate(a int) {
n.NRGBA = im
}

// CropCircle is cut the circle
// CropCircle is to cut the circle
func (n *nRGBA) CropCircle(x, y, radius, zoom int) {
bounds := n.Bounds()
mask := image.NewNRGBA(bounds)
Expand All @@ -212,7 +212,7 @@ func (n *nRGBA) CropCircle(x, y, radius, zoom int) {
n.NRGBA = mask
}

// SubImage is captured the image
// SubImage is to capture the image
func (n *nRGBA) SubImage(r image.Rectangle) {
n.NRGBA = n.Get().SubImage(r).(*image.NRGBA)
}
14 changes: 7 additions & 7 deletions v2/base/canvas/palette.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func (p *palette) Get() *image.Paletted {
return p.Paletted
}

// Rotate is rotation at any Angle
// Rotate is to rotation at any Angle
func (p *palette) Rotate(angle int) {
if angle == 0 {
return
Expand Down Expand Up @@ -105,14 +105,14 @@ func (p *palette) DrawCircle(x, y, radius int, c color.RGBA) {
}
}

// DrawHorizLine is drawing horiz line
// DrawHorizLine is to draw horiz line
func (p *palette) DrawHorizLine(fromX, toX, y int, c color.RGBA) {
for x := fromX; x <= toX; x++ {
p.Set(x, y, c)
}
}

// Distort is distorting the image
// Distort is to distort the image
func (p *palette) Distort(amplude float64, period float64) {
w := p.Bounds().Max.X
h := p.Bounds().Max.Y
Expand All @@ -137,7 +137,7 @@ func (p *palette) Distort(amplude float64, period float64) {
newP.Get().Palette = nil
}

// DrawBeeline is drawing beelines
// DrawBeeline is to draw beelines
func (p *palette) DrawBeeline(point1 image.Point, point2 image.Point, lineColor color.RGBA) {
dx := math.Abs(float64(point1.X - point2.X))
dy := math.Abs(float64(point2.Y - point1.Y))
Expand Down Expand Up @@ -170,7 +170,7 @@ func (p *palette) DrawBeeline(point1 image.Point, point2 image.Point, lineColor
}
}

// AngleSwapPoint is the angular conversion point coordinate
// AngleSwapPoint is to the angular conversion point coordinate
func (p *palette) AngleSwapPoint(x, y, r, angle float64) (tarX, tarY float64) {
x -= r
y = r - y
Expand All @@ -183,7 +183,7 @@ func (p *palette) AngleSwapPoint(x, y, r, angle float64) (tarX, tarY float64) {
return
}

// CalcMarginBlankArea is the calculation of margin space
// CalcMarginBlankArea is to the calculation of margin space
func (p *palette) CalcMarginBlankArea() *AreaRect {
nW := p.Bounds().Max.X
nH := p.Bounds().Max.Y
Expand Down Expand Up @@ -225,7 +225,7 @@ func (p *palette) CalcMarginBlankArea() *AreaRect {
}
}

// DrawString draws a string
// DrawString is to draw a string
func (p *palette) DrawString(params *DrawStringParams, pt fixed.Point26_6) error {
dc := freetype.NewContext()
dc.SetDPI(float64(params.FontDPI))
Expand Down
6 changes: 3 additions & 3 deletions v2/base/helper/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func t2x(t int64) string {
return result
}

// FormatAlpha is formatting transparent
// FormatAlpha is to formatting transparent
func FormatAlpha(val float32) uint8 {
a := math.Min(float64(val), 1)
alpha := a * 255
Expand Down Expand Up @@ -119,12 +119,12 @@ func IsChineseChar(str string) bool {
return false
}

// LenChineseChar is calc Chinese and letter length
// LenChineseChar is to calc Chinese and letter length
func LenChineseChar(str string) int {
return utf8.RuneCountInString(str)
}

// RandIndex is the random length range value
// RandIndex is to the random length range value
func RandIndex(length int) int {
if length == 0 {
return -1
Expand Down
1 change: 1 addition & 0 deletions v2/base/imagedata/base.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
"path"
)

// saveToFile .
func saveToFile(img image.Image, filepath string, isTransparent bool, quality int) error {
var file *os.File
var err error
Expand Down
2 changes: 1 addition & 1 deletion v2/base/imagedata/jpegdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func NewJPEGImageData(img image.Image) JPEGImageData {
}
}

// Get is get the original picture
// Get is to get the original picture
func (c *jpegImageDta) Get() image.Image {
return c.image
}
Expand Down
2 changes: 1 addition & 1 deletion v2/base/imagedata/pngdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func NewPNGImageData(img image.Image) PNGImageData {
}
}

// Get is get the original picture
// Get is to get the original picture
func (c *pngImageDta) Get() image.Image {
return c.image
}
Expand Down
12 changes: 6 additions & 6 deletions v2/base/randgen/randgen.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"github.com/wenlng/go-captcha/v2/base/random"
)

// RandFont is a random font
// RandFont is to random font
func RandFont(fonts []*truetype.Font) *truetype.Font {
index := helper.RandIndex(len(fonts))
if index < 0 {
Expand All @@ -26,7 +26,7 @@ func RandFont(fonts []*truetype.Font) *truetype.Font {
return fonts[index]
}

// RandHexColor is a random color
// RandHexColor is to random color
func RandHexColor(colors []string) string {
index := helper.RandIndex(len(colors))
if index < 0 {
Expand All @@ -36,7 +36,7 @@ func RandHexColor(colors []string) string {
return colors[index]
}

// RandImage is a random image
// RandImage is to random image
func RandImage(images []image.Image) image.Image {
index := helper.RandIndex(len(images))
if index < 0 {
Expand All @@ -46,13 +46,13 @@ func RandImage(images []image.Image) image.Image {
return images[index]
}

// RandString is a random string
// RandString is to random string
func RandString(chars []string) string {
k := rand.Intn(len(chars))
return chars[k]
}

// RandColor is a random RGBA color
// RandColor is to random RGBA color
func RandColor(co []color.Color) color.RGBA {
colorLen := len(co)
index := random.RandInt(0, colorLen)
Expand All @@ -64,7 +64,7 @@ func RandColor(co []color.Color) color.RGBA {
return color.RGBA{R: uint8(r), G: uint8(g), B: uint8(b), A: uint8(a)}
}

// RangCutImagePos is a random image position
// RangCutImagePos is to random image position
func RangCutImagePos(width int, height int, img image.Image) image.Point {
b := img.Bounds()
iW := b.Max.X
Expand Down
2 changes: 1 addition & 1 deletion v2/base/random/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func Perm(n int) []int {
return rand.Perm(n)
}

// RandInt is the safe random number of the interval [n, m]
// RandInt is to the safe random number of the interval [n, m]
func RandInt(min, max int) int {
if min > max {
return max
Expand Down
4 changes: 2 additions & 2 deletions v2/click/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,14 +42,14 @@ func (b *builder) Clear() {
b.resources = make([]Resource, 0)
}

// SetOptions is the set option
// SetOptions is to the set option
func (b *builder) SetOptions(opts ...Option) {
if len(opts) > 0 {
b.opts = append(b.opts, opts...)
}
}

// SetResources is the set resource
// SetResources is to the set resource
func (b *builder) SetResources(resources ...Resource) {
if len(resources) > 0 {
b.resources = append(b.resources, resources...)
Expand Down
2 changes: 1 addition & 1 deletion v2/click/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"math"
)

// CheckPoint is the position of the detection point
// CheckPoint is to the position of the detection point
func CheckPoint(sx, sy, dx, dy, width, height, padding int64) bool {
newWidth := width + (padding * 2)
newHeight := height + (padding * 2)
Expand Down
8 changes: 4 additions & 4 deletions v2/click/click.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,14 @@ func newWithMode(mode Mode, opts ...Option) *captcha {
return capt
}

// setOptions is the set option
// setOptions is to set option
func (c *captcha) setOptions(opts ...Option) {
for _, opt := range opts {
opt(c.opts)
}
}

// setResources is the set resource
// setResources is to set resource
func (c *captcha) setResources(resources ...Resource) {
for _, resource := range resources {
resource(c.resources)
Expand Down Expand Up @@ -313,7 +313,7 @@ func (c *captcha) rangeCheckDots(dots map[int]*Dot) (map[int]*Dot, []string) {
return chkDots, values
}

// genMasterImage is the master image of drawing captcha
// genMasterImage is to the master image of drawing captcha
func (c *captcha) genMasterImage(size *option.Size, dots map[int]*Dot) (image.Image, error) {
var drawDots = make([]*DrawDot, 0, len(dots))

Expand Down Expand Up @@ -360,7 +360,7 @@ func (c *captcha) genMasterImage(size *option.Size, dots map[int]*Dot) (image.Im
})
}

// genThumbImage is the thumbnail image of drawing captcha
// genThumbImage is to the thumbnail image of drawing captcha
func (c *captcha) genThumbImage(size *option.Size, dots map[int]*Dot) (image.Image, error) {
var drawDots = make([]*DrawDot, 0, len(dots))

Expand Down
4 changes: 2 additions & 2 deletions v2/click/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func getDefaultChars() []string {
return defaultChars
}

// defaultOptions is the default configuration
// defaultOptions is to the default configuration
func defaultOptions() Option {
return func(opts *Options) {
opts.fontDPI = 72
Expand Down Expand Up @@ -92,7 +92,7 @@ func defaultOptions() Option {
}
}

// defaultResource is the default resource
// defaultResource is to the default resource
func defaultResource() Resource {
return func(resources *Resources) {
resources.chars = getDefaultChars()
Expand Down
Loading

0 comments on commit 8ad0fdf

Please sign in to comment.