mirror of
https://github.com/iib0011/omni-tools.git
synced 2025-09-19 05:59:34 +02:00
Allow manually derived formulas for things nerdimer can't handl
This commit is contained in:
@@ -15,6 +15,7 @@ export const areaSphere: GenericCalcType = {
|
|||||||
{
|
{
|
||||||
name: 'r',
|
name: 'r',
|
||||||
title: 'Radius',
|
title: 'Radius',
|
||||||
|
formula: 'r = sqrt(A/pi) / 2',
|
||||||
unit: 'mm',
|
unit: 'mm',
|
||||||
default: 1
|
default: 1
|
||||||
}
|
}
|
||||||
|
@@ -36,6 +36,10 @@ export interface GenericCalcType {
|
|||||||
// If present and false, don't allow user to select this as output
|
// If present and false, don't allow user to select this as output
|
||||||
solvable?: boolean;
|
solvable?: boolean;
|
||||||
|
|
||||||
|
// Alternate rearrangement of the formula, to be used when calculating this.
|
||||||
|
// If missing, the main formula is used with auto derivation.
|
||||||
|
formula?: string;
|
||||||
|
|
||||||
// Alternates are alternate ways of entering the exact same thing,
|
// Alternates are alternate ways of entering the exact same thing,
|
||||||
// like the diameter or radius. The formula for an alternate
|
// like the diameter or radius. The formula for an alternate
|
||||||
// can use only one variable, always called v, which is the main
|
// can use only one variable, always called v, which is the main
|
||||||
|
@@ -25,6 +25,7 @@ import 'nerdamer-prime/Algebra';
|
|||||||
import 'nerdamer-prime/Solve';
|
import 'nerdamer-prime/Solve';
|
||||||
import 'nerdamer-prime/Calculus';
|
import 'nerdamer-prime/Calculus';
|
||||||
import Qty from 'js-quantities';
|
import Qty from 'js-quantities';
|
||||||
|
import { error } from 'console';
|
||||||
|
|
||||||
function numericSolveEquationFor(
|
function numericSolveEquationFor(
|
||||||
equation: string,
|
equation: string,
|
||||||
@@ -444,10 +445,29 @@ export default async function makeTool(
|
|||||||
setResult('Please select a solve for variable');
|
setResult('Please select a solve for variable');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
let expr = nerdamer(calcData.formula);
|
let expr: nerdamer.Expression | null = null;
|
||||||
|
|
||||||
|
for (const i of calcData.variables) {
|
||||||
|
if (i.name === values.outputVariable) {
|
||||||
|
if (i.formula !== undefined) {
|
||||||
|
expr = nerdamer(i.formula);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (expr == null) {
|
||||||
|
expr = nerdamer(calcData.formula);
|
||||||
|
}
|
||||||
|
if (expr == null) {
|
||||||
|
throw new Error('No formula found');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
Object.keys(values.vars).forEach((key) => {
|
Object.keys(values.vars).forEach((key) => {
|
||||||
if (key === values.outputVariable) return;
|
if (key === values.outputVariable) return;
|
||||||
|
if (expr === null) {
|
||||||
|
throw new Error('Math fail');
|
||||||
|
}
|
||||||
expr = expr.sub(key, values.vars[key].value.toString());
|
expr = expr.sub(key, values.vars[key].value.toString());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user