mirror of
https://github.com/esjeon/krohnkite.git
synced 2024-10-04 07:18:09 +03:00
simply LayoutUtils.splitAreaHalfWeighted
This is just a wrapper for splitAreaWeighted now.
This commit is contained in:
parent
5d5f9521a2
commit
c134e60fcd
@ -68,19 +68,7 @@ class LayoutUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static splitAreaHalfWeighted(area: Rect, weight: number, gap?: number, horizontal?: boolean): Rect[] {
|
public static splitAreaHalfWeighted(area: Rect, weight: number, gap?: number, horizontal?: boolean): Rect[] {
|
||||||
gap = (gap !== undefined) ? gap : 0;
|
return LayoutUtils.splitAreaWeighted(area, [weight, 1 - weight], gap, horizontal);
|
||||||
horizontal = (horizontal !== undefined) ? horizontal : false;
|
|
||||||
|
|
||||||
const [lineBase, lineLength] = (horizontal) ? [area.x, area.width] : [area.y, area.height];
|
|
||||||
const part1: [number, number] = [lineBase, Math.floor((lineLength - gap) * weight)];
|
|
||||||
const part2: [number, number] = [lineBase + (part1[1] + gap), lineLength - (part1[1] + gap)];
|
|
||||||
const parts: Array<[number, number]> = [part1, part2];
|
|
||||||
|
|
||||||
return parts.map(([begin, length]) =>
|
|
||||||
(horizontal)
|
|
||||||
? new Rect(begin, area.y, length, area.height)
|
|
||||||
: new Rect(area.x, begin, area.width, length),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static calculateWeights(parts: number[]): number[] {
|
public static calculateWeights(parts: number[]): number[] {
|
||||||
|
Loading…
Reference in New Issue
Block a user