Skip to content

Commit

Permalink
chore: break up a nested ternary
Browse files Browse the repository at this point in the history
  • Loading branch information
monfera committed Apr 29, 2020
1 parent 91013f9 commit 6d3acea
Showing 1 changed file with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* under the License. */

import { wrapToTau } from '../geometry';
import { Coordinate, Distance, Pixels, Radian, Radius, RingSector } from '../types/geometry_types';
import { Coordinate, Distance, Pixels, Radian, Radius, Ratio, RingSector } from '../types/geometry_types';
import { Config } from '../types/config_types';
import { logarithm, TAU, trueBearingToStandardPositionAngle } from '../utils/math';
import {
Expand Down Expand Up @@ -172,6 +172,26 @@ export function getSectorRowGeometry(
return { rowCentroidX, rowCentroidY, maximumRowLength };
}

function getVerticalAlignment(
container: RectangleConstruction,
verticalAlignment: VerticalAlignment,
linePitch: Pixels,
totalRowCount: number,
rowIndex: number,
padding: Pixels,
fontSize: Pixels,
overhang: Ratio,
) {
switch (verticalAlignment) {
case VerticalAlignments.top:
return -(container.y0 + linePitch * rowIndex + padding + fontSize * overhang);
case VerticalAlignments.bottom:
return -(container.y1 - linePitch * (totalRowCount - 1 - rowIndex) - fontSize * overhang);
default:
return -((container.y0 + container.y1) / 2 + (linePitch * (rowIndex - totalRowCount)) / 2);
}
}

/** @internal */
export function getRectangleRowGeometry(
container: RectangleConstruction,
Expand All @@ -193,12 +213,16 @@ export function getRectangleRowGeometry(
maximumRowLength: 0,
};
}
const rowCentroidY =
verticalAlignment === VerticalAlignments.top
? -(container.y0 + linePitch * rowIndex + padding + fontSize * overhang)
: verticalAlignment === VerticalAlignments.bottom
? -(container.y1 - linePitch * (totalRowCount - 1 - rowIndex) - fontSize * overhang)
: -((container.y0 + container.y1) / 2 + (linePitch * (rowIndex - totalRowCount)) / 2);
const rowCentroidY = getVerticalAlignment(
container,
verticalAlignment,
linePitch,
totalRowCount,
rowIndex,
padding,
fontSize,
overhang,
);
return {
rowCentroidX: cx,
rowCentroidY,
Expand Down

0 comments on commit 6d3acea

Please sign in to comment.