(
portion: Portion,
ratio: Rectangular = { x: 0, y: 0, width: 1, height: 1 }
)
| 343 | } |
| 344 | |
| 345 | getRatioForPortion( |
| 346 | portion: Portion, |
| 347 | ratio: Rectangular = { x: 0, y: 0, width: 1, height: 1 } |
| 348 | ): Rectangular { |
| 349 | const basisTotal = this.children.reduce( |
| 350 | (sum, child) => sum + child.basis, |
| 351 | 0 |
| 352 | ); |
| 353 | let basisSum = 0; |
| 354 | |
| 355 | for (let i = 0; i < this.children.length; i++) { |
| 356 | const child = this.children[i]; |
| 357 | const hasPortion = child.hasPortion(portion); |
| 358 | |
| 359 | if (child !== portion && !hasPortion) { |
| 360 | basisSum += child.basis; |
| 361 | |
| 362 | continue; |
| 363 | } |
| 364 | |
| 365 | const [position, size] = this.vertical |
| 366 | ? (['y', 'height'] as const) |
| 367 | : (['x', 'width'] as const); |
| 368 | |
| 369 | ratio[position] += ratio[size] * (basisSum / basisTotal); |
| 370 | ratio[size] *= child.basis / basisTotal; |
| 371 | |
| 372 | if (hasPortion) { |
| 373 | return child.getRatioForPortion(portion, ratio); |
| 374 | } |
| 375 | |
| 376 | break; |
| 377 | } |
| 378 | |
| 379 | return ratio; |
| 380 | } |
| 381 | |
| 382 | convert() { |
| 383 | this.vertical = !this.vertical; |
no test coverage detected