func valid(x, y, dimension int) bool {
	if (x-2) < 7 && (y-2) < 7 {
		return false
	}
	if (x+2) > dimension-7 && (y-2) < 7 {
		return false
	}
	if (x-2) < 7 && (y+2) > dimension-7 {
		return false
	}
	return true
}
x, y center position x,y so
package qrcode
import (
	"errors"
	"log"
	"strconv"
	"github.com/yeqown/reedsolomon/binary"
)
type ecLevel int
const (
	ErrorCorrectionLow ecLevel = iota + 1
	ErrorCorrectionMedium
	ErrorCorrectionQuart
	ErrorCorrectionHighest
	formatInfoBitsNum = 15  
	verInfoBitsNum    = 18  
)
var (
	errMissMatchedVersion    = errors.New("could not match version! check the versionCfg.json file")
	errMissMatchedEncodeType = errors.New("could not match the encode type")
	formatBitSequence = []struct {
		regular uint32
		micro   uint32
	}{
		{0x5412, 0x4445}, {0x5125, 0x4172}, {0x5e7c, 0x4e2b}, {0x5b4b, 0x4b1c},
		{0x45f9, 0x55ae}, {0x40ce, 0x5099}, {0x4f97, 0x5fc0}, {0x4aa0, 0x5af7},
		{0x77c4, 0x6793}, {0x72f3, 0x62a4}, {0x7daa, 0x6dfd}, {0x789d, 0x68ca},
		{0x662f, 0x7678}, {0x6318, 0x734f}, {0x6c41, 0x7c16}, {0x6976, 0x7921},
		{0x1689, 0x06de}, {0x13be, 0x03e9}, {0x1ce7, 0x0cb0}, {0x19d0, 0x0987},
		{0x0762, 0x1735}, {0x0255, 0x1202}, {0x0d0c, 0x1d5b}, {0x083b, 0x186c},
		{0x355f, 0x2508}, {0x3068, 0x203f}, {0x3f31, 0x2f66}, {0x3a06, 0x2a51},
		{0x24b4, 0x34e3}, {0x2183, 0x31d4}, {0x2eda, 0x3e8d}, {0x2bed, 0x3bba},
	}
	versionBitSequence = []uint32{
		0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x00000, 0x07c94,
		0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, 0x0f928,
		0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, 0x177ec,
		0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, 0x1f250,
		0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, 0x27541, 0x28c69,
	}
)
func init() {
}
type capacity struct {
	Numeric      int `json:"n"`  
	AlphaNumeric int `json:"a"`  
	Byte         int `json:"b"`  
	JP           int `json:"j"`  
}
type group struct {
	NumBlocks int `json:"nbs"`
	NumDataCodewords int `json:"ndcs"`
	ECBlockwordsPerBlock int `json:"ecbs_pb"`
}
type version struct {
	Ver int `json:"ver"`
	ECLevel ecLevel `json:"eclv"`
	Cap capacity `json:"cap"`
	RemainderBits int `json:"rembits"`
	Groups []group `json:"groups"`
}
func (v version) Dimension() int {
	return v.Ver*4 + 17
}
func (v version) NumTotalCodewrods() int {
	var total int
	for _, g := range v.Groups {
		total = total + (g.NumBlocks * g.NumDataCodewords)
	}
	return total
}
func (v version) NumGroups() int {
	return len(v.Groups)
}
func (v version) TotalNumBlocks() int {
	var total int
	for _, g := range v.Groups {
		total = total + g.NumBlocks
	}
	return total
}
func (v version) verInfo() *binary.Binary {
	if v.Ver < 7 {
		return nil
	}
	result := binary.New()
	result.AppendUint32(versionBitSequence[v.Ver], verInfoBitsNum)
	return result
}
func (v version) formatInfo(maskPattern int) *binary.Binary {
	formatID := 0
	switch v.ECLevel {
	case ErrorCorrectionLow:
		formatID = 0x08  
	case ErrorCorrectionMedium:
		formatID = 0x00  
	case ErrorCorrectionQuart:
		formatID = 0x18  
	case ErrorCorrectionHighest:
		formatID = 0x10  
	default:
		log.Panicf("Invalid level %d", v.ECLevel)
	}
	if maskPattern < 0 || maskPattern > 7 {
		log.Panicf("Invalid maskPattern %d", maskPattern)
	}
	formatID |= maskPattern & 0x7
	result := binary.New()
	result.AppendUint32(formatBitSequence[formatID].regular, formatInfoBitsNum)
	return result
}
func loadVersion(lv int, ecLv ecLevel) version {
	for _, v := range versions {
		if v.Ver == lv && v.ECLevel == ecLv {
			return v
		}
	}
	panic(errMissMatchedVersion)
}
func analyzeVersion(raw []byte, ecLv ecLevel, eMode encMode) (*version, error) {
	if len(versions) == 0 {
		panic("did not loaded the versions config success")
	}
	var (
		length = len(raw)
		c      int
	)
	for _, v := range versions {
		if v.ECLevel == ecLv {
			switch eMode {
			case EncModeNumeric:
				c = v.Cap.Numeric
			case EncModeAlphanumeric:
				c = v.Cap.AlphaNumeric
			case EncModeByte:
				c = v.Cap.Byte
			case EncModeJP:
				c = v.Cap.JP
			default:
				return nil, errMissMatchedEncodeType
			}
			if c > length {
				return &v, nil
			}
		}
	}
	debugLogf("mismatched version, version's length: %d, ecLv: %v", len(versions), ecLv)
	return nil, errMissMatchedVersion
}
var (
	alignPatternLocation = map[int][]int{
		2:  {6, 18},
		3:  {6, 22},
		4:  {6, 26},
		5:  {6, 30},
		6:  {6, 34},
		7:  {6, 22, 38},
		8:  {6, 24, 42},
		9:  {6, 26, 46},
		10: {6, 28, 50},
		11: {6, 30, 54},
		12: {6, 32, 58},
		13: {6, 34, 62},
		14: {6, 26, 46, 66},
		15: {6, 26, 48, 70},
		16: {6, 26, 50, 74},
		17: {6, 30, 54, 78},
		18: {6, 30, 56, 82},
		19: {6, 30, 58, 86},
		20: {6, 34, 62, 90},
		21: {6, 28, 50, 72, 94},
		22: {6, 26, 50, 74, 98},
		23: {6, 30, 54, 78, 102},
		24: {6, 28, 54, 80, 106},
		25: {6, 32, 58, 84, 110},
		26: {6, 30, 58, 86, 114},
		27: {6, 34, 62, 90, 118},
		28: {6, 26, 50, 74, 98, 122},
		29: {6, 30, 54, 78, 102, 126},
		30: {6, 26, 52, 78, 104, 130},
		31: {6, 30, 56, 82, 108, 134},
		32: {6, 34, 60, 86, 112, 138},
		33: {6, 30, 58, 86, 114, 142},
		34: {6, 34, 62, 90, 118, 146},
		35: {6, 30, 54, 78, 102, 126, 150},
		36: {6, 24, 50, 76, 102, 128, 154},
		37: {6, 28, 54, 80, 106, 132, 158},
		38: {6, 32, 58, 84, 110, 136, 162},
		39: {6, 26, 54, 82, 110, 138, 166},
		40: {6, 30, 58, 86, 114, 142, 170},
	}
	alignPatternCache = map[int][]loc{}
)
type loc struct {
	X int  
	Y int  
}
func loadAlignmentPatternLoc(ver int) (locs []loc) {
	if ver < 2 {
		return
	}
	var ok bool
	if locs, ok = alignPatternCache[ver]; ok {
		return
	}
	dimension := ver*4 + 17
	positions, ok := alignPatternLocation[ver]
	if !ok {
		panic("could not found align at version: " + strconv.Itoa(ver))
	}
	for _, pos1 := range positions {
		for _, pos2 := range positions {
			if !valid(pos1, pos2, dimension) {
				continue
			}
			locs = append(locs, loc{X: pos1, Y: pos2})
		}
	}
	alignPatternCache[ver] = locs
	return
}