diff --git a/lib/formula_models.dart b/lib/formula_models.dart index 7e33e8c..bec3b4c 100644 --- a/lib/formula_models.dart +++ b/lib/formula_models.dart @@ -123,12 +123,14 @@ class VariableSpec { class Formula { final String name; + final String? description; final List 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 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 inputSet = SetUtils.listValue(theSet, "input"); List 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, diff --git a/lib/formulas.d4rt b/lib/formulas.d4rt new file mode 100644 index 0000000..70dbd2f --- /dev/null +++ b/lib/formulas.d4rt @@ -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" + } +]