Raw strings in formulas, to avoid $$
This commit is contained in:
parent
ba6c761cee
commit
daa8b31879
7 changed files with 16 additions and 76 deletions
|
|
@ -182,7 +182,7 @@ class _FormulaScreenState extends State<FormulaScreen> {
|
|||
Text(widget.formula.output.name),
|
||||
const Spacer(),
|
||||
SizedBox(
|
||||
width: 100,
|
||||
width: 150,
|
||||
child: TextFormField(
|
||||
readOnly: true,
|
||||
enabled: false,
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class Corpus{
|
|||
|
||||
if( checkUnits ){
|
||||
for( final inputVar in formula.input + [formula.output] ){
|
||||
if( getUnit(inputVar.unit) == null ){
|
||||
if( !_allUnits.containsKey(inputVar.unit) ){
|
||||
throw ArgumentError( "Unit not found: ${inputVar.unit}");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
// Free fall distance (vertical)
|
||||
{
|
||||
"name": "Free Fall Distance",
|
||||
"description": '''
|
||||
"description": r"""
|
||||
Calculates vertical displacement under constant gravity
|
||||
|
||||
$$h = \\frac{1}{2}gt^2$$
|
||||
|
|
@ -11,7 +11,7 @@ Where:
|
|||
- $g$: Gravitational acceleration ($9.81\\ \\mathrm{m/s^2}$ on Earth)
|
||||
- $t$: Time in free fall (seconds)
|
||||
|
||||
''',
|
||||
""",
|
||||
"input": [
|
||||
{"name": "t", "unit": "second"}, // Time in seconds
|
||||
{"name": "g", "unit": "meters per second"} // Gravitational acceleration
|
||||
|
|
@ -24,7 +24,7 @@ Where:
|
|||
// Newton's Law of Universal Gravitation
|
||||
{
|
||||
"name": "Gravitational Force",
|
||||
"description": '''
|
||||
"description": r'''
|
||||
Newton's law of universal gravitation
|
||||
|
||||
$$F = G\\frac{m_1m_2}{r^2}$$
|
||||
|
|
@ -48,7 +48,7 @@ Where:
|
|||
// Kinetic Energy
|
||||
{
|
||||
"name": "Kinetic Energy",
|
||||
"description": '''
|
||||
"description": r'''
|
||||
Energy possessed by a moving object
|
||||
|
||||
$$KE = \\frac{1}{2}mv^2$$
|
||||
|
|
@ -70,13 +70,13 @@ Where:
|
|||
// Projectile Motion Range
|
||||
{
|
||||
"name": "Projectile Range",
|
||||
"description": "Calculates horizontal distance of projectile motion\n\n"
|
||||
"$$R = \\frac{v^2 \\sin(2\\theta)}{g}$$\n\n"
|
||||
"Where:\n"
|
||||
"- $v$: Initial velocity\n"
|
||||
"- $\\theta$: Launch angle\n"
|
||||
"- $g$: Gravitational acceleration\n\n"
|
||||
"",
|
||||
"description": r"""Calculates horizontal distance of projectile motion
|
||||
$$R = \\frac{v^2 \\sin(2\\theta)}{g}$$
|
||||
Where:
|
||||
- $v$: Initial velocity
|
||||
- $\\theta$: Launch angle
|
||||
- $g$: Gravitational acceleration
|
||||
""",
|
||||
"input": [
|
||||
{"name": "v", "unit": "meters per second"}, // Initial velocity
|
||||
{"name": "a", "unit": "degree"} // Launch angle
|
||||
|
|
@ -91,7 +91,7 @@ Where:
|
|||
|
||||
{
|
||||
"name": "Newton's Second Law",
|
||||
"description": '''
|
||||
"description": r'''
|
||||
Force equals mass times acceleration
|
||||
|
||||
$$F = m \\cdot a$$
|
||||
|
|
|
|||
|
|
@ -186,6 +186,7 @@ class Formula {
|
|||
buffer.write("main(){ return $arrayStringLiteral; }");
|
||||
final code = buffer.toString();
|
||||
|
||||
//print("fromArrayStringLiteral:$code");
|
||||
final List<Object?> list = d4rt.execute(source: code);
|
||||
|
||||
final formulas = list.map((set) => Formula.fromSet(set as Map));
|
||||
|
|
@ -214,6 +215,7 @@ class Formula {
|
|||
return Formula(
|
||||
name: name,
|
||||
description: description,
|
||||
tags: tags,
|
||||
input: input,
|
||||
output: output,
|
||||
d4rtCode: d4rtCode,
|
||||
|
|
|
|||
|
|
@ -1,10 +1,6 @@
|
|||
import 'package:d4rt_formulas/formula_models.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:resource_portable/resource.dart' show Resource;
|
||||
import 'dart:convert';
|
||||
|
||||
import 'ai/formula_screen.dart';
|
||||
import 'ai/formula_list.dart';
|
||||
import 'corpus.dart';
|
||||
import 'defaults/default_corpus.dart';
|
||||
|
|
|
|||
56
pubspec.lock
56
pubspec.lock
|
|
@ -299,14 +299,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.0"
|
||||
nested:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: nested
|
||||
sha256: "03bac4c528c64c95c722ec99280375a6f2fc708eec17c7b3f07253b626cd2a20"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.0.0"
|
||||
node_preamble:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -331,30 +323,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.9.1"
|
||||
path_drawing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_drawing
|
||||
sha256: "3bdd251dae9ffaef944450b73f168610db7e968e7b20daf0c3907f8b4aafc8a2"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.5.1+1"
|
||||
path_parsing:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path_parsing
|
||||
sha256: ee5c47c1058ad66b4a41746ec3996af9593d0858872807bcd64ac118f0700337
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.2.1"
|
||||
petitparser:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: petitparser
|
||||
sha256: cb3798bef7fc021ac45b308f4b51208a152792445cce0448c9a4ba5879dd8750
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.4.0"
|
||||
pool:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -363,14 +331,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.5.1"
|
||||
provider:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: provider
|
||||
sha256: "59471e0a4595e264625d3496af567ac85bdae1148ec985aff1e0555786f53ecf"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -504,14 +464,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "0.6.12"
|
||||
tuple:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: tuple
|
||||
sha256: a97ce2013f240b2f3807bcbaf218765b6f301c3eff91092bcfa23a039e7dd151
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "2.0.2"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -576,14 +528,6 @@ packages:
|
|||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.2.1"
|
||||
xml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: xml
|
||||
sha256: "80d494c09849dc3f899d227a78c30c5b949b985ededf884cb3f3bcd39f4b447a"
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "5.4.1"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
|
|||
|
|
@ -3,9 +3,7 @@ import 'package:d4rt_formulas/defaults/default_corpus.dart';
|
|||
import 'package:d4rt_formulas/formula_evaluator.dart';
|
||||
import 'package:test/test.dart';
|
||||
import 'package:d4rt_formulas/formula_models.dart';
|
||||
import 'dart:convert' show utf8;
|
||||
|
||||
import 'package:resource_portable/resource.dart' show Resource;
|
||||
|
||||
void main() {
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue