Skip to content

Commit

Permalink
Remove some Partial<...> and prefer using ? instead.
Browse files Browse the repository at this point in the history
Cast some fields "as number" for now.
More to come in a future PR.
  • Loading branch information
ronyeh committed Sep 30, 2021
1 parent f3553d3 commit 7d633c9
Show file tree
Hide file tree
Showing 39 changed files with 436 additions and 496 deletions.
7 changes: 4 additions & 3 deletions src/chordsymbol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -492,9 +492,10 @@ export class ChordSymbol extends Modifier {
// eslint-disable-next-line
getSymbolBlock(parameters?: any): any {
parameters = parameters ?? {};
const symbolType = parameters.symbolType ? parameters.symbolType : ChordSymbol.symbolTypes.TEXT;
const text = parameters.text ? parameters.text : '';
const symbolModifier = parameters.symbolModifier ? parameters.symbolModifier : ChordSymbol.symbolModifiers.NONE;
const symbolType = parameters.symbolType ?? ChordSymbol.symbolTypes.TEXT;
const text = parameters.text ?? '';
const symbolModifier = parameters.symbolModifier ?? ChordSymbol.symbolModifiers.NONE;

const xShift = 0;
const yShift = 0;
const vAlign = 0;
Expand Down
26 changes: 14 additions & 12 deletions src/curve.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import { Element } from './element';
import { Note } from './note';

export interface CurveOptions {
thickness: number;
x_shift: number;
y_shift: number;
position: string | number;
position_end: string | number;
invert: boolean;
cps: { x: number; y: number }[];
/** Two control points for the bezier curves. */
cps?: { x: number; y: number }[];
thickness?: number;
x_shift?: number;
y_shift?: number;
position?: string | number;
position_end?: string | number;
invert?: boolean;
}

export enum CurvePosition {
Expand Down Expand Up @@ -88,16 +89,17 @@ export class Curve extends Element {

renderCurve(params: { last_y: number; last_x: number; first_y: number; first_x: number; direction: number }): void {
const ctx = this.checkContext();
const cps = this.render_options.cps;
// eslint-disable-next-line
const cps = this.render_options.cps!;

const x_shift = this.render_options.x_shift;
const y_shift = this.render_options.y_shift * params.direction;
const x_shift = this.render_options.x_shift as number;
const y_shift = (this.render_options.y_shift as number) * params.direction;

const first_x = params.first_x + x_shift;
const first_y = params.first_y + y_shift;
const last_x = params.last_x - x_shift;
const last_y = params.last_y + y_shift;
const thickness = this.render_options.thickness;
const thickness = this.render_options.thickness as number;

const cp_spacing = (last_x - first_x) / (cps.length + 2);

Expand Down Expand Up @@ -139,7 +141,7 @@ export class Curve extends Element {
let metric = 'baseY';
let end_metric = 'baseY';

function getPosition(position: string | number) {
function getPosition(position?: string | number) {
return typeof position === 'string' ? Curve.PositionString[position] : position;
}
const position = getPosition(this.render_options.position);
Expand Down
Loading

0 comments on commit 7d633c9

Please sign in to comment.