MCPcopy Create free account
hub / github.com/material-shell/material-shell / getRatioForPortion

Method getRatioForPortion

src/layout/msWorkspace/portion.ts:345–380  ·  view source on GitHub ↗
(
        portion: Portion,
        ratio: Rectangular = { x: 0, y: 0, width: 1, height: 1 }
    )

Source from the content-addressed store, hash-verified

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;

Callers 3

getRatioForIndexMethod · 0.95
updateBordersPositionMethod · 0.80

Calls 1

hasPortionMethod · 0.80

Tested by

no test coverage detected