Skip to content

Commit

Permalink
Unexport unneeded functions & variables.
Browse files Browse the repository at this point in the history
Add a comment to Mask().
Remove unneeded comment.
  • Loading branch information
psidex committed Oct 30, 2019
1 parent 4e66424 commit 1bda291
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 19 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ See the example folder for a fully working implementation.
Most wordclouds should take a few seconds to be generated. A spatial hashmap is used to find potential collisions.

There are two possible placement algorithm choices:
1. Random: the algorithms randomly tries to place the word anywhere in the image space.
If it can't find a spot after 500000 tries, it gives up and moves on to the next word.
1. Random: the algorithms randomly tries to place the word anywhere in the image space.
- If it can't find a spot after 500000 tries, it gives up and moves on to the next word.
2. Spiral: the algorithm starts to place the words on concentric circles starting at the center of the image.

# Contributing
Expand Down
12 changes: 6 additions & 6 deletions circle.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package wordclouds

import "math"

type Circle struct {
type circle struct {
cx float64
cy float64
radius float64
step int
maxSteps int
}
type Point struct {
type point struct {
x float64
y float64
}

func NewCircle(cx float64, cy float64, radius float64, maxSteps int) *Circle {
return &Circle{
func newCircle(cx float64, cy float64, radius float64, maxSteps int) *circle {
return &circle{
cx: cx,
cy: cy,
radius: radius,
Expand All @@ -24,8 +24,8 @@ func NewCircle(cx float64, cy float64, radius float64, maxSteps int) *Circle {
}
}

func (c *Circle) positions() []Point {
pts := make([]Point, c.maxSteps, c.maxSteps)
func (c *circle) positions() []point {
pts := make([]point, c.maxSteps, c.maxSteps)
for i := 0; i < c.maxSteps; i++ {
pts[i].x = c.cx + c.radius*math.Cos(float64(i)*(2*math.Pi/float64(c.maxSteps)))
pts[i].y = c.cy + c.radius*math.Sin(float64(i)*(2*math.Pi/float64(c.maxSteps)))
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ go 1.13
require (
github.com/fogleman/gg v1.3.0
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 // indirect
github.com/psykhi/wordclouds v0.0.0-20190618172152-830cdaec919c
github.com/satori/go.uuid v1.2.0
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 // indirect
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ github.com/fogleman/gg v1.3.0 h1:/7zJX8F6AaYQc57WQCyN9cAIz+4bCJGO9B+dyW29am8=
github.com/fogleman/gg v1.3.0/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0 h1:DACJavvAHhabrF08vX0COfcOBJRhZ8lUbR+ZWIs0Y5g=
github.com/golang/freetype v0.0.0-20170609003504-e2365dfdc4a0/go.mod h1:E/TSTwGwJL78qG/PmXZO1EjYhfJinVAhrmmHX6Z8B9k=
github.com/psykhi/wordclouds v0.0.0-20190618172152-830cdaec919c h1:18rUGfk1gaSF1/KAz/zyg1JHfDiT5bTF1I/ogk+ywCg=
github.com/psykhi/wordclouds v0.0.0-20190618172152-830cdaec919c/go.mod h1:BWMHnlxidqejfhTejWRvLTYY0qw0AzPqSMMd4vXi+QQ=
github.com/satori/go.uuid v1.2.0 h1:0uYX9dsZ2yD7q2RtLRtPSdGDWzjeM3TbMJP9utgA0ww=
github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0=
golang.org/x/image v0.0.0-20191009234506-e7c1f5e7dbb8 h1:hVwzHzIUGRjiF7EcUjqNxk3NCfkPxbDKRdnNE1Rpg0U=
Expand Down
4 changes: 3 additions & 1 deletion mask.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package wordclouds

import (
"github.com/fogleman/gg"
"image/color"
"math"

"github.com/fogleman/gg"
)

// Mask creates a slice of box structs from a given mask image to be passed to wordclouds.MaskBoxes.
func Mask(path string, width int, height int, exclude color.RGBA) []*Box {
res := make([]*Box, 0)

Expand Down
9 changes: 1 addition & 8 deletions spatialHashmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ type spatialHashMap struct {
gridSize int
}

//func (s *spatialHashMap) Len() int {
// total := 0
// for i := 0; i < len(s.mat); i++ {
//
// }
//}

func (s *spatialHashMap) TestCollision(b *Box, test func(a *Box, b *Box) bool) (bool, int) {
overlaps := 0
top, left, right, bottom := s.toGridCoords(b)
Expand All @@ -49,7 +42,7 @@ func (s *spatialHashMap) Add(b *Box) {
}
}

func NewSpatialHashMap(windowWidth float64, windowHeight float64, gridSize int) *spatialHashMap {
func newSpatialHashMap(windowWidth float64, windowHeight float64, gridSize int) *spatialHashMap {
rw := windowWidth / float64(gridSize)
rh := windowHeight / float64(gridSize)

Expand Down
4 changes: 2 additions & 2 deletions wordcloud.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ func NewWordcloud(wordList map[string]int, options ...Option) *Wordcloud {
dc.SetRGB(1, 1, 1)
dc.Clear()
dc.SetRGB(0, 0, 0)
grid := NewSpatialHashMap(float64(opts.Width), float64(opts.Height), opts.Height/10)
grid := newSpatialHashMap(float64(opts.Width), float64(opts.Height), opts.Height/10)

for _, b := range opts.mask {
//dc.DrawRectangle(b.x(), b.y(), b.w(), b.h())
Expand Down Expand Up @@ -301,7 +301,7 @@ func (w *Wordcloud) nextPos(width float64, height float64) (x float64, y float64

for searching && radius < maxRadius {
radius = radius + 5
c := NewCircle(w.width/2, w.height/2, radius, 512)
c := newCircle(w.width/2, w.height/2, radius, 512)
pts := c.positions()

for _, p := range pts {
Expand Down

0 comments on commit 1bda291

Please sign in to comment.