* Convert dash input into dashArray * * @param {DecalDashArrayX} dash dash input * @return {number[][]} normolized dash array
(dash)
| 27438 | |
| 27439 | |
| 27440 | function normalizeDashArrayX(dash) { |
| 27441 | if (!dash || dash.length === 0) { |
| 27442 | return [[0, 0]]; |
| 27443 | } |
| 27444 | |
| 27445 | if (typeof dash === 'number') { |
| 27446 | var dashValue = Math.ceil(dash); |
| 27447 | return [[dashValue, dashValue]]; |
| 27448 | } |
| 27449 | /** |
| 27450 | * [20, 5] should be normalized into [[20, 5]], |
| 27451 | * while [20, [5, 10]] should be normalized into [[20, 20], [5, 10]] |
| 27452 | */ |
| 27453 | |
| 27454 | |
| 27455 | var isAllNumber = true; |
| 27456 | |
| 27457 | for (var i = 0; i < dash.length; ++i) { |
| 27458 | if (typeof dash[i] !== 'number') { |
| 27459 | isAllNumber = false; |
| 27460 | break; |
| 27461 | } |
| 27462 | } |
| 27463 | |
| 27464 | if (isAllNumber) { |
| 27465 | return normalizeDashArrayX([dash]); |
| 27466 | } |
| 27467 | |
| 27468 | var result = []; |
| 27469 | |
| 27470 | for (var i = 0; i < dash.length; ++i) { |
| 27471 | if (typeof dash[i] === 'number') { |
| 27472 | var dashValue = Math.ceil(dash[i]); |
| 27473 | result.push([dashValue, dashValue]); |
| 27474 | } else { |
| 27475 | var dashValue = map(dash[i], function (n) { |
| 27476 | return Math.ceil(n); |
| 27477 | }); |
| 27478 | |
| 27479 | if (dashValue.length % 2 === 1) { |
| 27480 | // [4, 2, 1] means |---- - -- |---- - -- | |
| 27481 | // so normalize it to be [4, 2, 1, 4, 2, 1] |
| 27482 | result.push(dashValue.concat(dashValue)); |
| 27483 | } else { |
| 27484 | result.push(dashValue); |
| 27485 | } |
| 27486 | } |
| 27487 | } |
| 27488 | |
| 27489 | return result; |
| 27490 | } |
| 27491 | /** |
| 27492 | * Convert dash input into dashArray |
| 27493 | * |
no test coverage detected
searching dependent graphs…