Explorar el Código

Cleans up distribution code

main
Steve Ruiz hace 4 años
padre
commit
f0afe62073
Se han modificado 1 ficheros con 18 adiciones y 26 borrados
  1. 18
    26
      state/commands/distribute.ts

+ 18
- 26
state/commands/distribute.ts Ver fichero

48
 
48
 
49
         switch (type) {
49
         switch (type) {
50
           case DistributeType.Horizontal: {
50
           case DistributeType.Horizontal: {
51
-            const sortedByCenter = entries.sort(
52
-              ([a], [b]) => centers[a][0] - centers[b][0]
53
-            )
54
-
55
-            const span = sortedByCenter.reduce((a, c) => a + c[1].width, 0)
51
+            const span = entries.reduce((a, c) => a + c[1].width, 0)
56
 
52
 
57
             if (span > commonBounds.width) {
53
             if (span > commonBounds.width) {
58
-              const left = sortedByCenter.sort(
59
-                (a, b) => a[1].minX - b[1].minX
60
-              )[0]
54
+              const left = entries.sort((a, b) => a[1].minX - b[1].minX)[0]
61
 
55
 
62
-              const right = sortedByCenter.sort(
63
-                (a, b) => b[1].maxX - a[1].maxX
64
-              )[0]
56
+              const right = entries.sort((a, b) => b[1].maxX - a[1].maxX)[0]
65
 
57
 
66
-              const entriesToMove = sortedByCenter
58
+              const entriesToMove = entries
67
                 .filter((a) => a !== left && a !== right)
59
                 .filter((a) => a !== left && a !== right)
68
                 .sort((a, b) => centers[a[0]][0] - centers[b[0]][0])
60
                 .sort((a, b) => centers[a[0]][0] - centers[b[0]][0])
69
 
61
 
81
                 ])
73
                 ])
82
               }
74
               }
83
             } else {
75
             } else {
84
-              const step = (commonBounds.width - span) / (len - 1)
76
+              const sortedByCenter = entries.sort(
77
+                (a, b) => centers[a[0]][0] - centers[b[0]][0]
78
+              )
79
+
85
               let x = commonBounds.minX
80
               let x = commonBounds.minX
81
+              const step = (commonBounds.width - span) / (len - 1)
86
 
82
 
87
               for (let i = 0; i < sortedByCenter.length - 1; i++) {
83
               for (let i = 0; i < sortedByCenter.length - 1; i++) {
88
                 const [id, bounds] = sortedByCenter[i]
84
                 const [id, bounds] = sortedByCenter[i]
94
             break
90
             break
95
           }
91
           }
96
           case DistributeType.Vertical: {
92
           case DistributeType.Vertical: {
97
-            const sortedByCenter = entries.sort(
98
-              ([a], [b]) => centers[a][1] - centers[b][1]
99
-            )
100
-
101
-            const span = sortedByCenter.reduce((a, c) => a + c[1].height, 0)
93
+            const span = entries.reduce((a, c) => a + c[1].height, 0)
102
 
94
 
103
             if (span > commonBounds.height) {
95
             if (span > commonBounds.height) {
104
-              const top = sortedByCenter.sort(
105
-                (a, b) => a[1].minY - b[1].minY
106
-              )[0]
96
+              const top = entries.sort((a, b) => a[1].minY - b[1].minY)[0]
107
 
97
 
108
-              const bottom = sortedByCenter.sort(
109
-                (a, b) => b[1].maxY - a[1].maxY
110
-              )[0]
98
+              const bottom = entries.sort((a, b) => b[1].maxY - a[1].maxY)[0]
111
 
99
 
112
-              const entriesToMove = sortedByCenter
100
+              const entriesToMove = entries
113
                 .filter((a) => a !== top && a !== bottom)
101
                 .filter((a) => a !== top && a !== bottom)
114
                 .sort((a, b) => centers[a[0]][1] - centers[b[0]][1])
102
                 .sort((a, b) => centers[a[0]][1] - centers[b[0]][1])
115
 
103
 
127
                 ])
115
                 ])
128
               }
116
               }
129
             } else {
117
             } else {
130
-              const step = (commonBounds.height - span) / (len - 1)
118
+              const sortedByCenter = entries.sort(
119
+                (a, b) => centers[a[0]][1] - centers[b[0]][1]
120
+              )
121
+
131
               let y = commonBounds.minY
122
               let y = commonBounds.minY
123
+              const step = (commonBounds.height - span) / (len - 1)
132
 
124
 
133
               for (let i = 0; i < sortedByCenter.length - 1; i++) {
125
               for (let i = 0; i < sortedByCenter.length - 1; i++) {
134
                 const [id, bounds] = sortedByCenter[i]
126
                 const [id, bounds] = sortedByCenter[i]

Loading…
Cancelar
Guardar