作者 linmadan

修复布局算法

@@ -62,17 +62,18 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) { @@ -62,17 +62,18 @@ func CellsLocationAdjust(cells []*domain.LayoutCell) {
62 if len(cells) > 0 { 62 if len(cells) > 0 {
63 addedRows := 0 63 addedRows := 0
64 addedColumns := 0 64 addedColumns := 0
65 - preRowMaxDownLength := 0 65 + preRowMaxDownLength := 1
66 preRawCellX := 0 66 preRawCellX := 0
67 for _, cell := range cells { 67 for _, cell := range cells {
68 if preRawCellX != cell.X { 68 if preRawCellX != cell.X {
69 addedColumns = 0 69 addedColumns = 0
70 addedRows = addedRows + preRowMaxDownLength - 1 70 addedRows = addedRows + preRowMaxDownLength - 1
71 - preRowMaxDownLength = 0 71 + preRowMaxDownLength = 1
72 preRawCellX = cell.X 72 preRawCellX = cell.X
73 } 73 }
74 cell.X = addedRows + cell.X 74 cell.X = addedRows + cell.X
75 cell.Y = addedColumns + cell.Y 75 cell.Y = addedColumns + cell.Y
  76 + println("=======")
76 switch cell.Direction { 77 switch cell.Direction {
77 case domain.DirectionRight: 78 case domain.DirectionRight:
78 addedColumns = addedColumns + cell.Length - 1 79 addedColumns = addedColumns + cell.Length - 1
@@ -97,6 +97,75 @@ func TestNewDataLayout(t *testing.T) { @@ -97,6 +97,75 @@ func TestNewDataLayout(t *testing.T) {
97 }, 97 },
98 flag: Location{X: 2, Y: 2}, 98 flag: Location{X: 2, Y: 2},
99 }, 99 },
  100 + {
  101 + title: "全部无方向",
  102 + cells: []*domain.LayoutCell{
  103 + {
  104 + X: 0,
  105 + Y: 0,
  106 + Length: 1,
  107 + ImageData: "1",
  108 + Direction: domain.DirectionNone,
  109 + },
  110 + {
  111 + X: 0,
  112 + Y: 1,
  113 + Length: 1,
  114 + ImageData: "2",
  115 + Direction: domain.DirectionNone,
  116 + },
  117 + {
  118 + X: 0,
  119 + Y: 2,
  120 + Length: 1,
  121 + ImageData: "3",
  122 + Direction: domain.DirectionNone,
  123 + },
  124 + {
  125 + X: 1,
  126 + Y: 0,
  127 + Length: 1,
  128 + ImageData: "4",
  129 + Direction: domain.DirectionNone,
  130 + },
  131 + {
  132 + X: 1,
  133 + Y: 1,
  134 + Length: 1,
  135 + ImageData: "5",
  136 + Direction: domain.DirectionNone,
  137 + },
  138 + {
  139 + X: 1,
  140 + Y: 2,
  141 + Length: 1,
  142 + ImageData: "6",
  143 + Direction: domain.DirectionNone,
  144 + },
  145 + {
  146 + X: 2,
  147 + Y: 0,
  148 + Length: 1,
  149 + ImageData: "7",
  150 + Direction: domain.DirectionNone,
  151 + },
  152 + {
  153 + X: 2,
  154 + Y: 1,
  155 + Length: 1,
  156 + ImageData: "8",
  157 + Direction: domain.DirectionDown,
  158 + },
  159 + {
  160 + X: 2,
  161 + Y: 2,
  162 + Length: 1,
  163 + ImageData: "9",
  164 + Direction: domain.DirectionNone,
  165 + },
  166 + },
  167 + flag: Location{X: 2, Y: 2},
  168 + },
100 } 169 }
101 padding := func(cells []*domain.LayoutCell) { 170 padding := func(cells []*domain.LayoutCell) {
102 for _, cell := range cells { 171 for _, cell := range cells {