Loading controllers/isogrids/hexa16.go +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ import ( "github.com/taironas/tinygraphs/write" ) // Hexa is the handler for /isogrids/hexa16/:key // Hexa16 is the handler for /isogrids/hexa16/:key // builds an hexagon with alternate colors. func Hexa16(w http.ResponseWriter, r *http.Request) { var err error Loading draw/isogrids/hexa16.go +6 −4 Original line number Diff line number Diff line Loading @@ -9,7 +9,9 @@ import ( "github.com/taironas/tinygraphs/draw" ) // Hexa builds an image with lines x lines grids of half diagonals in the form of an hexagon // Hexa16 builds an image with lines x lines grids of half diagonals in the form of an hexagon // it draws 6 triangles, triangle 1 to 5 are all rotations of triangle 0. // triangle zero triangle on the center left. func Hexa16(w http.ResponseWriter, key string, colors []color.RGBA, size, lines int) { canvas := svg.New(w) canvas.Start(size, size) Loading Loading @@ -116,11 +118,11 @@ func canFill(x, y int, fills []string, isLeft func(x int) bool, isRight func(x i r := newTrianglePosition(x, y, right) if isLeft(x) && l.isInTriangle() { rid := l.rotationId() rid := l.rotationID() return fills[rid], nil } else if isRight(x) && r.isInTriangle() { rid := r.rotationId() rid := r.rotationID() return fills[rid], nil } return "", errors.New("cannot find svg fill for given position.") return "", errors.New("cannot find svg fill for given position") } draw/isogrids/trianglePositions.go +10 −10 Original line number Diff line number Diff line Loading @@ -96,10 +96,10 @@ func (tp *trianglePosition) isInTriangle() bool { return tp.triangleId() != -1 } // triangleId returns the triangle id (from 0 to 5) // triangleID returns the triangle id (from 0 to 5) // that has a match with the position given as param. // returns -1 if a match is not found. func (tp *trianglePosition) triangleId() int { func (tp *trianglePosition) triangleID() int { for i, t := range triangles { for _, ti := range t { Loading @@ -111,10 +111,10 @@ func (tp *trianglePosition) triangleId() int { return -1 } // subTriangleId returns the sub triangle id (from 0 to 8) // subTriangleID returns the sub triangle id (from 0 to 8) // that has a match with the position given as param. // returns -1 if a match is not found. func (tp *trianglePosition) subTriangleId() int { func (tp *trianglePosition) subTriangleID() int { for _, t := range triangles { for i, ti := range t { Loading @@ -126,7 +126,7 @@ func (tp *trianglePosition) subTriangleId() int { return -1 } func subTriangleRotations(lookforSubTriangleId int) []int { func subTriangleRotations(lookforSubTriangleID int) []int { m := map[int][]int{ 0: []int{0, 6, 8, 8, 2, 0}, Loading @@ -139,7 +139,7 @@ func subTriangleRotations(lookforSubTriangleId int) []int { 7: []int{7, 5, 4, 1, 3, 4}, 8: []int{8, 8, 2, 0, 0, 6}, } if v, ok := m[lookforSubTriangleId]; ok { if v, ok := m[lookforSubTriangleID]; ok { return v } return nil Loading @@ -147,13 +147,13 @@ func subTriangleRotations(lookforSubTriangleId int) []int { // rotationId returns the original sub triangle id // if the current triangle was rotated to position 0. func (tp *trianglePosition) rotationId() int { current_tid := tp.triangleId() current_stid := tp.subTriangleId() func (tp *trianglePosition) rotationID() int { currentTID := tp.triangleID() currentSTID := tp.subTriangleID() numberOfSubTriangles := 9 for i := 0; i < numberOfSubTriangles; i++ { rotations := subTriangleRotations(i) if rotations[current_tid] == current_stid { if rotations[currentTID] == currentSTID { return i } } Loading extract/colors.go +2 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ func swap(pColors *[]color.RGBA) { colors[1] = tmp } // reOrder will change the order of the color array passed as param // ReOrder will change the order of the color array passed as param // with respect to the 'order' array of integers. // both array have to have the same length. // will ignore any change if the indexes in the order array are out of range. Loading @@ -79,7 +79,7 @@ func ReOrder(order []int, pColors *[]color.RGBA) { if len(order) == len(colors) { tmp := []color.RGBA{} reOrder := true for i, _ := range order { for i := range order { if order[i] >= 0 && order[i] < len(colors) { tmp = append(tmp, colors[order[i]]) } else { Loading extract/colors_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -353,7 +353,7 @@ func areArrayOfColorsEqual(a, b []color.RGBA) bool { return false } for i, _ := range a { for i := range a { if a[i] != b[i] { return false } Loading Loading
controllers/isogrids/hexa16.go +1 −1 Original line number Diff line number Diff line Loading @@ -12,7 +12,7 @@ import ( "github.com/taironas/tinygraphs/write" ) // Hexa is the handler for /isogrids/hexa16/:key // Hexa16 is the handler for /isogrids/hexa16/:key // builds an hexagon with alternate colors. func Hexa16(w http.ResponseWriter, r *http.Request) { var err error Loading
draw/isogrids/hexa16.go +6 −4 Original line number Diff line number Diff line Loading @@ -9,7 +9,9 @@ import ( "github.com/taironas/tinygraphs/draw" ) // Hexa builds an image with lines x lines grids of half diagonals in the form of an hexagon // Hexa16 builds an image with lines x lines grids of half diagonals in the form of an hexagon // it draws 6 triangles, triangle 1 to 5 are all rotations of triangle 0. // triangle zero triangle on the center left. func Hexa16(w http.ResponseWriter, key string, colors []color.RGBA, size, lines int) { canvas := svg.New(w) canvas.Start(size, size) Loading Loading @@ -116,11 +118,11 @@ func canFill(x, y int, fills []string, isLeft func(x int) bool, isRight func(x i r := newTrianglePosition(x, y, right) if isLeft(x) && l.isInTriangle() { rid := l.rotationId() rid := l.rotationID() return fills[rid], nil } else if isRight(x) && r.isInTriangle() { rid := r.rotationId() rid := r.rotationID() return fills[rid], nil } return "", errors.New("cannot find svg fill for given position.") return "", errors.New("cannot find svg fill for given position") }
draw/isogrids/trianglePositions.go +10 −10 Original line number Diff line number Diff line Loading @@ -96,10 +96,10 @@ func (tp *trianglePosition) isInTriangle() bool { return tp.triangleId() != -1 } // triangleId returns the triangle id (from 0 to 5) // triangleID returns the triangle id (from 0 to 5) // that has a match with the position given as param. // returns -1 if a match is not found. func (tp *trianglePosition) triangleId() int { func (tp *trianglePosition) triangleID() int { for i, t := range triangles { for _, ti := range t { Loading @@ -111,10 +111,10 @@ func (tp *trianglePosition) triangleId() int { return -1 } // subTriangleId returns the sub triangle id (from 0 to 8) // subTriangleID returns the sub triangle id (from 0 to 8) // that has a match with the position given as param. // returns -1 if a match is not found. func (tp *trianglePosition) subTriangleId() int { func (tp *trianglePosition) subTriangleID() int { for _, t := range triangles { for i, ti := range t { Loading @@ -126,7 +126,7 @@ func (tp *trianglePosition) subTriangleId() int { return -1 } func subTriangleRotations(lookforSubTriangleId int) []int { func subTriangleRotations(lookforSubTriangleID int) []int { m := map[int][]int{ 0: []int{0, 6, 8, 8, 2, 0}, Loading @@ -139,7 +139,7 @@ func subTriangleRotations(lookforSubTriangleId int) []int { 7: []int{7, 5, 4, 1, 3, 4}, 8: []int{8, 8, 2, 0, 0, 6}, } if v, ok := m[lookforSubTriangleId]; ok { if v, ok := m[lookforSubTriangleID]; ok { return v } return nil Loading @@ -147,13 +147,13 @@ func subTriangleRotations(lookforSubTriangleId int) []int { // rotationId returns the original sub triangle id // if the current triangle was rotated to position 0. func (tp *trianglePosition) rotationId() int { current_tid := tp.triangleId() current_stid := tp.subTriangleId() func (tp *trianglePosition) rotationID() int { currentTID := tp.triangleID() currentSTID := tp.subTriangleID() numberOfSubTriangles := 9 for i := 0; i < numberOfSubTriangles; i++ { rotations := subTriangleRotations(i) if rotations[current_tid] == current_stid { if rotations[currentTID] == currentSTID { return i } } Loading
extract/colors.go +2 −2 Original line number Diff line number Diff line Loading @@ -70,7 +70,7 @@ func swap(pColors *[]color.RGBA) { colors[1] = tmp } // reOrder will change the order of the color array passed as param // ReOrder will change the order of the color array passed as param // with respect to the 'order' array of integers. // both array have to have the same length. // will ignore any change if the indexes in the order array are out of range. Loading @@ -79,7 +79,7 @@ func ReOrder(order []int, pColors *[]color.RGBA) { if len(order) == len(colors) { tmp := []color.RGBA{} reOrder := true for i, _ := range order { for i := range order { if order[i] >= 0 && order[i] < len(colors) { tmp = append(tmp, colors[order[i]]) } else { Loading
extract/colors_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -353,7 +353,7 @@ func areArrayOfColorsEqual(a, b []color.RGBA) bool { return false } for i, _ := range a { for i := range a { if a[i] != b[i] { return false } Loading