* Get minimum length that can make a repeatable pattern. * * @return {Object} pattern width and height
()
| 160 | * @return {Object} pattern width and height |
| 161 | */ |
| 162 | function getPatternSize(): { |
| 163 | width: number, |
| 164 | height: number |
| 165 | } { |
| 166 | /** |
| 167 | * For example, if dash is [[3, 2], [2, 1]] for X, it looks like |
| 168 | * |--- --- --- --- --- ... |
| 169 | * |-- -- -- -- -- -- -- -- ... |
| 170 | * |--- --- --- --- --- ... |
| 171 | * |-- -- -- -- -- -- -- -- ... |
| 172 | * So the minimum length of X is 15, |
| 173 | * which is the least common multiple of `3 + 2` and `2 + 1` |
| 174 | * |--- --- --- |--- --- ... |
| 175 | * |-- -- -- -- -- |-- -- -- ... |
| 176 | */ |
| 177 | let width = 1; |
| 178 | for (let i = 0, xlen = lineBlockLengthsX.length; i < xlen; ++i) { |
| 179 | width = getLeastCommonMultiple(width, lineBlockLengthsX[i]); |
| 180 | } |
| 181 | |
| 182 | let symbolRepeats = 1; |
| 183 | for (let i = 0, xlen = symbolArray.length; i < xlen; ++i) { |
| 184 | symbolRepeats = getLeastCommonMultiple(symbolRepeats, symbolArray[i].length); |
| 185 | } |
| 186 | width *= symbolRepeats; |
| 187 | |
| 188 | const height = lineBlockLengthY * lineBlockLengthsX.length * symbolArray.length; |
| 189 | |
| 190 | if (__DEV__) { |
| 191 | const warn = (attrName: string) => { |
| 192 | /* eslint-disable-next-line */ |
| 193 | console.warn(`Calculated decal size is greater than ${attrName} due to decal option settings so ${attrName} is used for the decal size. Please consider changing the decal option to make a smaller decal or set ${attrName} to be larger to avoid incontinuity.`); |
| 194 | }; |
| 195 | if (width > decalOpt.maxTileWidth) { |
| 196 | warn('maxTileWidth'); |
| 197 | } |
| 198 | if (height > decalOpt.maxTileHeight) { |
| 199 | warn('maxTileHeight'); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | return { |
| 204 | width: Math.max(1, Math.min(width, decalOpt.maxTileWidth)), |
| 205 | height: Math.max(1, Math.min(height, decalOpt.maxTileHeight)) |
| 206 | }; |
| 207 | } |
| 208 | |
| 209 | function brushDecal() { |
| 210 | if (ctx) { |
no test coverage detected
searching dependent graphs…