Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
26716e9
feat(benchmarks): establish benchmark suite and expand project-wide t…
cooler-king May 23, 2026
e0007f6
feat(dx): implement fluent quantity extensions and update example code
cooler-king May 23, 2026
91db1b3
refactor(dart3): apply sealed/final/base class modifiers and pattern …
cooler-king May 23, 2026
a76056c
perf(optimization): implement project-wide memory and math optimizati…
cooler-king May 23, 2026
a919f0a
feat(tree-shake): decouple dynamic registry, create quantity_core, an…
cooler-king May 23, 2026
ba80815
docs(roadmap): update ROADMAP.md to mark all v5.0.0 items as completed
cooler-king May 23, 2026
e019e65
docs(roadmap): expand v5.0.0 roadmap with quality, interop, and verif…
cooler-king May 23, 2026
bef8c79
feat(quality): format codebase, resolve NumberFormatSI gaps, and add …
cooler-king May 23, 2026
236a3d3
feat(interop): add JSON serialization and package:decimal interoperab…
cooler-king May 23, 2026
3449e3d
feat(automation): add property-based testing and automated NIST const…
cooler-king May 24, 2026
c1b269b
feat(ai-layout): implement AI-ready NLP parser, token, and display re…
cooler-king May 24, 2026
27c76f5
feat(synonyms): implement type aliases and dynamic registry mapping f…
cooler-king May 24, 2026
a753209
feat(domain): add 6 domain collections and corresponding unit tests
cooler-king May 24, 2026
66a549e
feat(coverage): boost package test coverage to 75.4% and add comprehe…
cooler-king May 24, 2026
5dd0fb4
test(coverage): expand test coverage to 90.7% targeting Level math, a…
cooler-king May 24, 2026
3dda34c
Raise test coverage further: add tests for Angle, Information, TimeIn…
cooler-king May 24, 2026
f93cd77
Raise test coverage to 95.5%: cover remaining core number math and qu…
cooler-king May 24, 2026
b431307
feat(coverage): achieve perfect 100.0% total package test coverage an…
cooler-king May 24, 2026
730c3a0
feat(canon): enforce 100% test coverage in CI and document code cover…
cooler-king May 24, 2026
820327d
doc(canon): establish 100% test coverage as project canon
cooler-king May 24, 2026
4a4f744
q5
cooler-king May 24, 2026
2587d2f
style: enforce alphabetized directives_ordering and format imports
cooler-king May 25, 2026
9c50176
build(git): stop tracking transient coverage files and add coverage/ …
cooler-king May 25, 2026
01bb388
build(git): stop tracking ROADMAP.md and add to .gitignore
cooler-king May 25, 2026
0135cb2
doc: delete CONTRIBUTING.md and remove references
cooler-king May 25, 2026
3278a50
feat(api): add Quantity.to(dynamic targetUnit) for dynamic unit conve…
cooler-king May 25, 2026
d374703
ci: opt into Node.js 24 for GitHub Actions; sync NIST CODATA constants
cooler-king May 25, 2026
7507a8a
ci: upgrade actions/checkout to v6.0.2 and setup-dart to v1.7.2
cooler-king May 25, 2026
f142466
style: apply dart format
cooler-king May 25, 2026
5ac0bed
docs: make pre-commit checklist explicit project canon in AGENTS.md
cooler-king May 25, 2026
30f5207
fix: resolve all dart analyze --fatal-infos warnings
cooler-king May 25, 2026
970753a
docs: add pana (160/160) to AGENTS.md useful commands
cooler-king May 25, 2026
b14616a
fix: use 'other' for operator== parameter throughout Number hierarchy
cooler-king May 25, 2026
28b0168
Fix unresolved doc references, add missing shortcut docs, and reorder…
cooler-king May 26, 2026
c226e11
Add common compound unit symbols to baseUnits for dynamic Quantity.to…
cooler-king May 26, 2026
ee483e8
Add repository, issue_tracker, and topics to pubspec.yaml
cooler-king May 26, 2026
ef301cd
Allow flexible spacing around carets in quantity unit parser
cooler-king May 26, 2026
3e5924a
update README; tweak tests
cooler-king Jun 1, 2026
7dfff49
fix format
cooler-king Jun 1, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Dart CI

on:
push:
branches: [ main, master, ai ]
pull_request:
branches: [ main, master, ai ]

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v6.0.2

- name: Setup Dart SDK
uses: dart-lang/setup-dart@v1.7.2
with:
sdk: stable

- name: Install dependencies
run: dart pub get

- name: Verify formatting
run: dart format --output=none --set-exit-if-changed .

- name: Analyze project source
run: dart analyze --fatal-infos

- name: Run tests with coverage
run: dart test --coverage=coverage

- name: Install coverage package
run: dart pub global activate coverage

- name: Format coverage report
run: dart pub global run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -i coverage -o coverage/coverage.lcov

- name: Verify 100% test coverage
run: dart run tool/verify_coverage.dart
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,12 @@ pubspec.lock
doc
.idea/
*.iml

# Coverage reports
coverage/
*.lcov

# Local Roadmap
ROADMAP.md


27 changes: 27 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Guidance for AI Coding Agents

This file provides rules, constraints, and commands for AI agents developing or modifying the `quantity` codebase.

## Pre-Commit Checklist

Run these commands in order before every commit. All must pass cleanly.

1. **Format**: `dart format .`
2. **Analyze**: `dart analyze --fatal-infos`
3. **Test**: `dart test`
4. **Verify 100% coverage**: `dart test --coverage=coverage && dart run coverage:format_coverage --packages=.dart_tool/package_config.json --report-on=lib --lcov -i coverage -o coverage/coverage.lcov && dart run tool/verify_coverage.dart`

CI enforces all four steps and will fail if any is skipped.

## Other Useful Commands
- **Sync NIST CODATA constants**: `dart run bin/update_nist_constants.dart`
- **Check pub.dev score (160/160 target)**: `dart pub global activate pana && dart pub global run pana --no-warning .`

## Architecture & Constraints
- **Code Coverage**: The codebase is at **100.0% code coverage**. Any and all code changes, additions, or refactorings MUST include corresponding unit tests to guarantee that overall project coverage remains at exactly **100.0%**.
- **Class Modifiers**: Keep the `sealed` modifier on `Number`, the `base` modifier on `Quantity`, and the `final` modifier on `Dimensions`.
- **Dynamic Registry**: Avoid hardcoding physical quantity instantiators in `utilities.dart`. Register new types using `registerQuantityType(...)`.
- **Constants**: If you define new fundamental physical constants, format them as:
`const <Type> <varName> = <Type>.constant(Double.constant(<value>), uncert: <relativeUncertainty>);`
This ensures they are discoverable and updatable automatically by the NIST synchronization script.
- **Imports**: Export public APIs in `lib/quantity.dart` and the tree-shaken `lib/quantity_core.dart`. Do not introduce circular public exports.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,23 @@
### 5.0.0
* **Dart 3+ Modernization**: Applied `sealed`, `base`, and `final` modifiers to `Number`, `Quantity`, and `Dimensions` classes. Refactored map parsing and type determination using modern pattern matching and switch expressions.
* **Fluent DX & Unit Shortcuts**: Added extension getters on `num` and `Number` (e.g., `5.meters`, `75.tps`) and unit shortcuts (`inKilometers`, `inTps`, `inCelsius`).
* **Registry Decoupling & Tree-Shaking**: Decoupled the physical quantity registry by registering subclasses dynamically, allowing for clean tree-shaking. Added a lightweight core entrypoint `lib/quantity_core.dart`.
* **JSON Serialization**: Added full `toJson()` and `fromJson()` support to `Quantity`, `Number`, and `Dimensions` hierarchies.
* **Decimal Interoperability**: Integrated the `decimal` package directly, introducing `valueSIAsDecimal`, `toDecimal()`, and `fromDecimal(Decimal)` to allow high-precision decimal operations.
* **NIST Constants Sync**: Added an automated script `bin/update_nist_constants.dart` to synchronize physical constants and uncertainties with the official NIST CODATA table.
* **AI Readiness & Natural Language Processing**:
* Added `Quantity.parse(String text)` for parsing natural language physical measurements (e.g., `'120 km/h'`, `'9.8 m/s^2'`).
* Added `Quantity.checkDimensionalConsistency` to symbolically check math formula consistency (e.g., `s = u * t + 0.5 * a * t^2`).
* Added `Dimensions.describe` returning human-readable dimensions (e.g. `'Length^1 / Time^2'`).
* Exposed structured JSON schemas (`Quantity.jsonSchema`) for structured LLM function calling.
* **Computational & Digital Layout Quantities**:
* Introduced `Token` and `TokenRate` classes to support modeling, parsing, and arithmetic for NLP/LLM context tracking and throughput metrics.
* Introduced `Pixel`, `Resolution` (pixels per length), and `PixelDensity` (pixels per area) classes to support spatial layout scaling, screen resolution calibration (PPI/DPI/DPCM), and graphics calculations with type-safe arithmetic operators.
* **Synonym Quantity Types**: Added compile-time typedef aliases and dynamic runtime name registry mapping for 19 physical quantity synonyms across 12 distinct classes (e.g. `Irradiance` / `EnergyFluxDensity` / `PowerFluxDensity` synonymizing `HeatFluxDensity`, `Stress` synonymizing `Pressure`, `Work` synonymizing `Energy`, etc.).
* **Domain Collections**: Added six domain library collections under `lib/domain/` to group quantity types, units, and constants commonly encountered in specific fields: `radiometry`, `atomic_nuclear`, `computing`, `chemistry`, `acoustics`, and `fluid_dynamics`. Added corresponding unit tests for each domain.
* **Algebraic Property Verification**: Established property-based testing for `Dimensions` algebra.
* **Test Coverage Boost**: Significantly expanded unit test coverage across the package. Wrote comprehensive tests for previously untested parts including the `Fraction` number representation class, trig functions and constants in `angle_ext`, fluent utility extensions on `num` and `Number`, and verified variable mappings across all 40+ extension libraries. Further expanded coverage by testing astronomical time scale conversions, range math, exception string serialization, logarithmic level operations, and dynamically generated Unit constructors/derivatives across all 75+ physical quantity classes. Raised overall repository code coverage to **90.7%** (surpassing the targets of 70% and 85%).

### 4.0.0
* Breaking changes:
* Changed some compound unit constructor names to be more descriptive.
Expand Down
82 changes: 82 additions & 0 deletions MIGRATION.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
# Migration Guide: Quantity 4.x to 5.0.0

Quantity 5.0.0 is a major release containing API modernization, modern Dart 3 feature adoption, comprehensive tree-shaking support, and significant performance optimizations.

This guide outlines the breaking changes and new APIs introduced in this version and how to migrate your code.

---

## 1. Class Modifiers (Dart 3+)

To ensure structural integrity and correct mathematical equivalence:
* `Number` is now a `sealed class`. You cannot extend, implement, or mix in `Number` outside of the package. All subclasses (`Integer`, `Double`, `Precise`, `Imaginary`, `Complex`) are exhaustive.
* `Quantity` is now a `base class`. Outside of the package, you can `extend` `Quantity` to define custom physical quantities, but you can no longer `implement` `Quantity` as an interface.
* `Dimensions` is now a `final class`. You cannot extend or implement `Dimensions`.

### Migration Action
If you were using custom classes that implemented `Quantity` or `Number`, update them to extend `Quantity` or use the predefined `Number` subclasses instead.

```diff
-class CustomQuantity implements Quantity {
+base class CustomQuantity extends Quantity {
```

---

## 2. Dynamic SI Registry & Core Entrypoint (Tree-Shaking)

Previously, importing the core classes of the library transitively imported all 75+ physical quantity subclasses (like `Length`, `Volume`, etc.) due to a monolithic static type mapping registry in `utilities.dart`.

In 5.0.0:
* The static registry has been decoupled into a lazy dynamic registry (`registerStandardSIQuantities`).
* A new entrypoint `package:quantity/quantity_core.dart` has been created containing only the core mathematical and quantity classes (`Quantity`, `Dimensions`, `Units`, `Number`, `Double`, `Integer`, `Precise`, etc.), but **none** of the 75+ subclasses.
* `package:quantity/quantity.dart` and `package:quantity/quantity_si.dart` continue to export all standard SI quantities and automatically trigger registration when used or imported.

### Migration Action
* For applications needing only core dimensions and operations (e.g. custom dimensions or custom math without SI subclasses), import the core entrypoint for clean compiler tree-shaking:
```dart
import 'package:quantity/quantity_core.dart';
```
* For standard SI quantities, continue importing:
```dart
import 'package:quantity/quantity.dart'; // or package:quantity/quantity_si.dart
```

---

## 3. Fluent Quantity Extensions & Unit Shortcuts (DX)

New extension methods on `num` and `Number` allow for much cleaner syntax for constructing quantities and converting units.

### Creating Quantities
Instead of using constructors or helper methods, you can construct quantities directly on numbers:

```dart
// Before
var distance = Length(m: 5);
var duration = Time(s: 10);

// After
var distance = 5.meters;
var duration = 10.seconds;
var speed = 2.5.metersPerSecond;
```

### Converting Units
Shortcut getters are provided for unit conversions on quantity instances:

```dart
// Before
var valueInKm = distance.valueInUnits(Length.kilometers);

// After
var valueInKm = distance.inKilometers;
```

---

## 4. Performance & Memory Optimizations

* **Flat Precise Representation:** The internal representation of arbitrary precision `Precise` arithmetic has been rewritten to use a flat `List<int>` instead of allocating a custom wrapper object per digit. This eliminates garbage collection overhead and accelerates arithmetic operations by up to 35%.
* **Dimensions Cache:** `Dimensions.determineQuantityType` is now cached, preventing unnecessary switch-expression checks on hot paths (e.g., repeating dimension operations).
* **Constant Re-use:** `simplifyType` has been optimized to return pre-allocated static constants (`Integer.zero`, `Integer.one`, `Integer.negOne`) instead of allocating new instances for trivial integer values.
Loading