func (cg *Gen) fits(oc OffsetChunk) bool { // If a grid is defined, chunks must set in it. if cg.grid.X > 0 && num.AbsMod(oc.offset.X, cg.grid.X) != 0 { return false } if cg.grid.Y > 0 && num.AbsMod(oc.offset.Y, cg.grid.Y) != 0 { return false } inside := oc.chunk.InsideBounds() for pt, cell := range oc.chunk.cells { if pt.In(inside) { if _, ok := cg.cells[pt.Add(oc.offset)]; ok { return false } } else { if existingCell, ok := cg.cells[pt.Add(oc.offset)]; ok { // Non-peg cells in a chunk can overwrite peg cells in the // existing map. overwritingPeg := oc.chunk.isPegCell(existingCell) && !oc.chunk.isPegCell(cell) if !overwritingPeg && cell != existingCell { return false } } } } return true }
// HexCirclePoint returns a point along the edge of a radius sized hexagon // tile "circle" specified by windingIndex. The HexCircumference(radius) // consecutive clockwise points on the circle are denoted by consecutive // windingIndex values. func HexCirclePoint(radius int, windingIndex int) image.Point { if radius == 0 { return image.Pt(0, 0) } sector := num.AbsMod(windingIndex, HexCircumference(radius)) / radius offset := num.AbsMod(windingIndex, radius) return HexDirs[sector].Mul(radius).Add(HexDirs[(sector+2)%6].Mul(offset)) }