* Convert dash input into dashArray * * @param {DecalDashArrayX} dash dash input * @return {number[][]} normolized dash array
(dash: DecalDashArrayX)
| 349 | * @return {number[][]} normolized dash array |
| 350 | */ |
| 351 | function normalizeDashArrayX(dash: DecalDashArrayX): number[][] { |
| 352 | if (!dash || (dash as number[]).length === 0) { |
| 353 | return [[0, 0]]; |
| 354 | } |
| 355 | if (isNumber(dash)) { |
| 356 | const dashValue = Math.ceil(dash); |
| 357 | return [[dashValue, dashValue]]; |
| 358 | } |
| 359 | |
| 360 | /** |
| 361 | * [20, 5] should be normalized into [[20, 5]], |
| 362 | * while [20, [5, 10]] should be normalized into [[20, 20], [5, 10]] |
| 363 | */ |
| 364 | let isAllNumber = true; |
| 365 | for (let i = 0; i < dash.length; ++i) { |
| 366 | if (!isNumber(dash[i])) { |
| 367 | isAllNumber = false; |
| 368 | break; |
| 369 | } |
| 370 | } |
| 371 | if (isAllNumber) { |
| 372 | return normalizeDashArrayX([dash as number[]]); |
| 373 | } |
| 374 | |
| 375 | const result: number[][] = []; |
| 376 | for (let i = 0; i < dash.length; ++i) { |
| 377 | if (isNumber(dash[i])) { |
| 378 | const dashValue = Math.ceil(dash[i] as number); |
| 379 | result.push([dashValue, dashValue]); |
| 380 | } |
| 381 | else { |
| 382 | const dashValue = map(dash[i] as number[], n => Math.ceil(n)); |
| 383 | if (dashValue.length % 2 === 1) { |
| 384 | // [4, 2, 1] means |---- - -- |---- - -- | |
| 385 | // so normalize it to be [4, 2, 1, 4, 2, 1] |
| 386 | result.push(dashValue.concat(dashValue)); |
| 387 | } |
| 388 | else { |
| 389 | result.push(dashValue); |
| 390 | } |
| 391 | } |
| 392 | } |
| 393 | return result; |
| 394 | } |
| 395 | |
| 396 | /** |
| 397 | * Convert dash input into dashArray |
no test coverage detected