From daa8b31879abba23af117fb081edbf4a9c9a527a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Gonz=C3=A1lez?= Date: Sun, 5 Oct 2025 16:53:46 +0200 Subject: [PATCH] Raw strings in formulas, to avoid $$ --- lib/ai/formula_screen.dart | 2 +- lib/corpus.dart | 2 +- lib/defaults/formulas.d4rt | 24 +++++++-------- lib/formula_models.dart | 2 ++ lib/main.dart | 4 --- pubspec.lock | 56 ----------------------------------- test/formula_models_test.dart | 2 -- 7 files changed, 16 insertions(+), 76 deletions(-) diff --git a/lib/ai/formula_screen.dart b/lib/ai/formula_screen.dart index fe4757c..72ec462 100644 --- a/lib/ai/formula_screen.dart +++ b/lib/ai/formula_screen.dart @@ -182,7 +182,7 @@ class _FormulaScreenState extends State { Text(widget.formula.output.name), const Spacer(), SizedBox( - width: 100, + width: 150, child: TextFormField( readOnly: true, enabled: false, diff --git a/lib/corpus.dart b/lib/corpus.dart index 5d782ac..fc735b4 100644 --- a/lib/corpus.dart +++ b/lib/corpus.dart @@ -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}"); } } diff --git a/lib/defaults/formulas.d4rt b/lib/defaults/formulas.d4rt index da40891..c173128 100644 --- a/lib/defaults/formulas.d4rt +++ b/lib/defaults/formulas.d4rt @@ -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) -![Free Fall Diagram](https://altcalculator.com/wp-content/uploads/2023/08/Free-Fall.png)''', +![Free Fall Diagram](https://altcalculator.com/wp-content/uploads/2023/08/Free-Fall.png)""", "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" - "![Projectile Motion](https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Projectile_motion_diagram.png/800px-Projectile_motion_diagram.png)", + "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 + ![Projectile Motion](https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Projectile_motion_diagram.png/800px-Projectile_motion_diagram.png)""", "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$$ diff --git a/lib/formula_models.dart b/lib/formula_models.dart index dd75a82..541a21c 100644 --- a/lib/formula_models.dart +++ b/lib/formula_models.dart @@ -186,6 +186,7 @@ class Formula { buffer.write("main(){ return $arrayStringLiteral; }"); final code = buffer.toString(); + //print("fromArrayStringLiteral:$code"); final List 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, diff --git a/lib/main.dart b/lib/main.dart index 4ccbd35..f21f76c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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'; diff --git a/pubspec.lock b/pubspec.lock index 3b77547..b1879fe 100644 --- a/pubspec.lock +++ b/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: diff --git a/test/formula_models_test.dart b/test/formula_models_test.dart index bbc79a2..3979a2b 100644 --- a/test/formula_models_test.dart +++ b/test/formula_models_test.dart @@ -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() {