feat: add description field to Formula and example formulas
This commit is contained in:
parent
e08474a7eb
commit
ba5175b6be
2 changed files with 53 additions and 2 deletions
|
|
@ -123,12 +123,14 @@ class VariableSpec {
|
|||
|
||||
class Formula {
|
||||
final String name;
|
||||
final String? description;
|
||||
final List<VariableSpec> input;
|
||||
final VariableSpec output;
|
||||
final String d4rtCode;
|
||||
|
||||
Formula({
|
||||
required this.name,
|
||||
this.description,
|
||||
required this.input,
|
||||
required this.output,
|
||||
required this.d4rtCode,
|
||||
|
|
@ -144,7 +146,7 @@ class Formula {
|
|||
|
||||
@override
|
||||
String toString() =>
|
||||
'Formula(name: $name, input: $input, output: $output, d4rtCode: $d4rtCode)';
|
||||
'Formula(name: $name, description: $description, input: $input, output: $output, d4rtCode: $d4rtCode)';
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) =>
|
||||
|
|
@ -152,13 +154,14 @@ class Formula {
|
|||
other is Formula &&
|
||||
runtimeType == other.runtimeType &&
|
||||
name == other.name &&
|
||||
description == other.description &&
|
||||
output == other.output &&
|
||||
ListEquality().equals(input, other.input) &&
|
||||
d4rtCode == other.d4rtCode;
|
||||
|
||||
@override
|
||||
int get hashCode =>
|
||||
Object.hash(name, ListEquality().hash(input), output, d4rtCode);
|
||||
Object.hash(name, description, ListEquality().hash(input), output, d4rtCode);
|
||||
|
||||
List<String> inputVarNames() =>
|
||||
input.map((v) => v.name).toList(growable: false);
|
||||
|
|
@ -195,6 +198,7 @@ class Formula {
|
|||
}
|
||||
|
||||
String name = SetUtils.stringValue(theSet, "name");
|
||||
String? description = theSet ["description"] as String?;
|
||||
final List<Object?> inputSet = SetUtils.listValue(theSet, "input");
|
||||
List<VariableSpec> input = inputSet
|
||||
.map((v) => parseVar(v as Map))
|
||||
|
|
@ -205,6 +209,7 @@ class Formula {
|
|||
|
||||
return Formula(
|
||||
name: name,
|
||||
description: description,
|
||||
input: input,
|
||||
output: output,
|
||||
d4rtCode: d4rtCode,
|
||||
|
|
|
|||
46
lib/formulas.d4rt
Normal file
46
lib/formulas.d4rt
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
[
|
||||
// Free fall distance (vertical)
|
||||
{
|
||||
name: "Free Fall Distance",
|
||||
input: [
|
||||
{name: "t", magnitude: "s"}, // Time in seconds
|
||||
{name: "g", magnitude: "m/s²"} // Gravitational acceleration
|
||||
],
|
||||
output: {name: "h", magnitude: "m"}, // Height in meters
|
||||
d4rtCode: "0.5 * g * pow(t, 2)"
|
||||
},
|
||||
|
||||
// Newton's Law of Universal Gravitation
|
||||
{
|
||||
name: "Gravitational Force",
|
||||
input: [
|
||||
{name: "m1", magnitude: "kg"}, // Mass 1
|
||||
{name: "m2", magnitude: "kg"}, // Mass 2
|
||||
{name: "r", magnitude: "m"} // Distance between masses
|
||||
],
|
||||
output: {name: "F", magnitude: "N"}, // Force in newtons
|
||||
d4rtCode: "(6.67430e-11 * m1 * m2) / pow(r, 2)"
|
||||
},
|
||||
|
||||
// Kinetic Energy
|
||||
{
|
||||
name: "Kinetic Energy",
|
||||
input: [
|
||||
{name: "m", magnitude: "kg"}, // Mass
|
||||
{name: "v", magnitude: "m/s"} // Velocity
|
||||
],
|
||||
output: {name: "KE", magnitude: "J"}, // Energy in joules
|
||||
d4rtCode: "0.5 * m * pow(v, 2)"
|
||||
},
|
||||
|
||||
// Projectile Motion Range
|
||||
{
|
||||
name: "Projectile Range",
|
||||
input: [
|
||||
{name: "v", magnitude: "m/s"}, // Initial velocity
|
||||
{name: "θ", magnitude: "deg"} // Launch angle
|
||||
],
|
||||
output: {name: "R", magnitude: "m"}, // Horizontal distance
|
||||
d4rtCode: "(pow(v, 2) * sin(2 * radians(θ))) / 9.80665"
|
||||
}
|
||||
]
|
||||
Loading…
Reference in a new issue