dimensional
Version:
Dimensional analysis and unit conversions
75 lines (74 loc) • 2.53 kB
TypeScript
/**
* Represents a compound number.
*/
export declare abstract class Compound<T extends Compound<T>> {
private readonly getChild;
/**
* The LaTeX representation of this compound
*/
protected readonly LaTeX?: string;
/**
* Terms and their exponents
*/
private readonly factors;
/**
* Terms in the numerator
*/
private readonly num;
/**
* Terms in the denominator
*/
private readonly den;
/**
* Either create a new "raw" compound with a variable to the power of one, or initialize a compound from factors and their exponents.
* @param getChild An internal method for the parent class to obtain the child class. Should return `this`
* @param data The LaTeX representation of this compound and a method to obtain the child class, or the factors and their exponents that make up this compound
*/
constructor(getChild: () => T, data?: string | Map<T, number>);
/**
* Defines a method to initialize a new child of `Compound` solely with a map of factors.
* @param factors The factors and exponents that make up this compound
*/
protected abstract fromMap(factors: Map<T, number>): T;
/**
* Return a map of factors in this compound.
* @returns The factors in this compound
*/
private getFactors;
/**
* Multiply this compound by another.
* @param factor Another term or compound of similar terms
* @returns The product of two compounds
*/
times(factor: T): T;
/**
* Raise this compound to an exponent.
* @param exponent The exponent to raise this compound by
* @returns The power of this compound and exponent
*/
pow(exponent: number): T;
/**
* Divide this compound by another.
* @param dividend The compound to divide by
* @returns The quotient of two compounds
*/
over(dividend: T): T;
/**
* Determine if this compound is made up of the same factors as another.
* @param other Another compound to compare to
* @returns Whether or not this compound matches another
*/
is(other: T): boolean;
/**
* Pretty-print this compound as a LaTeX formula.
* @returns The compound written as a LaTeX formula
*/
toString(): string;
/**
* Render a single factor in LaTeX markup.
* @param factor The factor to render
* @param exponent The exponent on this factor
* @returns A LaTeX representation of a factor
*/
private factorToString;
}