Skip to content

Commit

Permalink
[C] change to distance modulus
Browse files Browse the repository at this point in the history
  • Loading branch information
alexgoff authored and blnkt committed Apr 4, 2024
1 parent 9b8b89c commit 5c9ef56
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 9 deletions.
2 changes: 1 addition & 1 deletion components/calculators/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const Config: Record<Equation, EquationConfig> = {
inputs: [Variables.m15],
result: Variables.peakAbsoluteMagnitude,
},
distanceMly: {
distanceModulus: {
latex: ({ result, constants, variables }) =>
`${result} = \\left (${constants.A}\\right )${constants.B}^{\\frac{${variables.peakApparentMagnitude} - ${variables.peakAbsoluteMagnitude}}{${constants.C}}} + ${constants.D}`,
constants: {
Expand Down
4 changes: 2 additions & 2 deletions components/calculators/lib/equations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ const peakAbsoluteMagnitude: EquationComposer = ({ m15 }, { A, B }) => {
return undefined;
};

const distanceMly: EquationComposer = (
const distanceModulus: EquationComposer = (
{ peakApparentMagnitude, peakAbsoluteMagnitude },
{ A, B, C, D }
) => {
Expand All @@ -31,7 +31,7 @@ const distanceMly: EquationComposer = (

const Equations: Record<Equation, EquationComposer> = {
peakAbsoluteMagnitude,
distanceMly,
distanceModulus,
};

export default Equations;
9 changes: 4 additions & 5 deletions components/calculators/lib/latex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Result,
EquationConfig,
} from "@/types/calculators";
import { Variables } from "./config";

const withClass = (value: string) => `\\class{calc-output}{${value}}`;

Expand Down Expand Up @@ -63,7 +62,7 @@ const LaTeXComposer = (
values: { result?: number; variables: Record<string, number | undefined> },
locale = fallbackLng
) => {
const { latex, constants, result: resultConfig } = equation;
const { latex, constants, inputs, result: resultConfig } = equation;
const { result, variables } = values;

const formattedConstants: Record<string, string> = {};
Expand All @@ -73,10 +72,10 @@ const LaTeXComposer = (
formattedConstants[key] = formatConstant(constant, locale);
});

Object.entries(variables).map(([key, variable]) => {
inputs.map(({ key, ...rest }) => {
formattedVariables[key] = formatVariable({
variable,
config: Variables[key],
variable: variables[key],
config: { key, ...rest },
locale,
});
});
Expand Down
2 changes: 1 addition & 1 deletion types/calculators.d.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type Equation = "peakAbsoluteMagnitude" | "distanceMly";
export type Equation = "peakAbsoluteMagnitude" | "distanceModulus";
export type CalculatorValues = Record<string, number | null | undefined>;
export type NonNullableCalculatorValues = Record<string, number | undefined>;

Expand Down

0 comments on commit 5c9ef56

Please sign in to comment.