Skip to content

feat(generator): plural From{Unit} factory naming + form matrix docs (closes #49, partial #58)#72

Merged
matt-edmondson merged 1 commit intovectorsfrom
claude/issue-49-plural-units
May 10, 2026
Merged

feat(generator): plural From{Unit} factory naming + form matrix docs (closes #49, partial #58)#72
matt-edmondson merged 1 commit intovectorsfrom
claude/issue-49-plural-units

Conversation

@matt-edmondson
Copy link
Copy Markdown
Contributor

Summary

Closes #49 and addresses the documentation half of #58.

#49 — plural From{Unit} factory naming

UnitDefinition gets an optional FactoryName field. Every entry in units.json now sets it explicitly:

Group Examples
Regular (name + "s") MeterMeters, NewtonNewtons, JouleJoules, KilogramKilograms
Irregular plurals FootFeet, InchInches, SquareFootSquareFeet, PoundFootPoundFeet, HenryHenries
Mass nouns / no-plural Hertz, Lux, Siemens, Stokes, Psi, Horsepower, Celsius, Fahrenheit, Gauss, Poise, Dimensionless
"Per" compounds (already plural-reading) MetersPerSecond, KilometersPerHour, RadiansPerSecond, JoulePerKelvin, … all kept as-is

QuantitiesGenerator.AddUnitFactories reads FactoryName from the unit map and falls back to name + "s" when absent — correct for regulars and keeps unmigrated metadata building.

The new factory shape now matches what CLAUDE.md and docs/strategy-unified-vector-quantities.md have advertised all along (Speed.FromMetersPerSecond, Force1D.FromNewtons, etc.).

The V0 non-negativity guard from #50 and the V0 − V0 absolute subtraction operator from #52 are unchanged — only the factory name changed, not its body or argument shape.

#58 (part 1) — form coverage matrix

Added a "Form Coverage Matrix" section to docs/strategy-unified-vector-quantities.md writing down what was previously implicit:

  • Linear motion (Length / Velocity / Acceleration / Jerk / Snap / Force / Momentum / Displacement / ElectricField) → V0–V4
  • Angular motion (Angular* / Torque) → V0, V1, V3 (pseudovectors; no 2D / 4D forms)
  • Electric current → V0, V1, V3
  • Scalar-only (Mass / Energy / Area / Time / Frequency / …) → V0 (+ V1 when a signed delta makes sense)
  • Dimensionless → V0 Ratio + V1 SignedRatio

Plus a paragraph clarifying that the generator silently skips a relationship's form when either side doesn't declare it, so a new dimension has to declare every form it needs to participate in.

The SEM003 piece of #58 — a generator-time validator that fails fast when a relationship references a form the dimension doesn't declare — needs a metadata schema change first (current relationships are dimension-to-dimension, not form-specific). Not in this PR; comment on #58 explains.

Migration impact

Renames affect every call site of generated From{Unit} factories. Updated in this PR:

  • Semantics.Test/Quantities/{MultiUnitFactoryTests,Vector0InvariantTests,VectorQuantityTests,SemanticOverloadTests}.cs (call sites + method names)
  • docs/physics-domains-guide.md, docs/complete-library-guide.md (example call sites)

External consumers calling singular forms (FromMeter, FromKilogram, etc.) will need to switch to the plural — this is a deliberate breaking change to fix the inconsistency.

Test plan

  • dotnet build Semantics.SourceGenerators — clean
  • dotnet build Semantics.Quantities — generator runs cleanly (no SEM001/SEM002 warnings); 105 generated *.g.cs files updated to plural factory names; spot-checked Length / Mass / Temperature / Velocity1D / Frequency / Acceleration1D look right.
  • dotnet testSemantics.Test cannot restore in this sandbox (Microsoft.NETCore.App.Host.ubuntu.24.04-x64 not in feeds); CI will run the rewritten tests.

https://claude.ai/code/session_01Tj63Rddvs9frqLUgsjNEP5


Generated by Claude Code

…loses #49)

Issue #49 — every generated From{Unit} factory now uses the plural form,
matching the convention CLAUDE.md and docs/strategy-unified-vector-quantities.md
already advertise (Speed.FromMetersPerSecond, Force1D.FromNewtons, etc).

- UnitDefinition gets a new optional FactoryName field. units.json sets
  it explicitly on every unit, including:
    * regular: Meter -> Meters, Newton -> Newtons, Joule -> Joules, ...
    * irregular: Foot -> Feet, Inch -> Inches, SquareFoot -> SquareFeet,
      SquareInch -> SquareInches, PoundFoot -> PoundFeet, Henry -> Henries
    * mass nouns / no-plural: Hertz, Lux, Siemens, Stokes, Psi,
      Horsepower, Celsius, Fahrenheit, Gauss, Poise, Dimensionless
    * already-plural compounds (Per): MetersPerSecond, KilometersPerHour,
      RadiansPerSecond, JoulePerKelvin, etc. all keep their name.
- QuantitiesGenerator.AddUnitFactories looks up FactoryName from the unit
  map; falls back to Name + "s" when absent (correct for regular units,
  and lets dimensions.json that aren't migrated yet still build).
- Regenerated Semantics.Quantities/Generated/. Spot-checked Length
  (FromMeters / FromKilometers / FromCentimeters / FromMillimeters /
  FromNanometers / FromAngstroms / FromFeet / FromInches / FromYards /
  FromMiles), Velocity1D (FromMetersPerSecond / FromKilometersPerHour /
  FromMilesPerHour), Frequency (FromHertz), Temperature (FromKelvins /
  FromCelsius / FromFahrenheit). All preserve the V0 non-negativity
  guard from #50 and the V0 - V0 absolute subtraction from #52.

Updated tests in Semantics.Test/Quantities/{MultiUnitFactoryTests,
Vector0InvariantTests,VectorQuantityTests,SemanticOverloadTests}.cs to
use the new plural names (call sites + method names).

Updated docs:
- docs/physics-domains-guide.md, docs/complete-library-guide.md: example
  call sites switched to plural forms.
- CLAUDE.md: noted the plural-naming convention and that every new unit
  in units.json must set factoryName.

Issue #58 part 1 — added a "Form Coverage Matrix" section to
docs/strategy-unified-vector-quantities.md documenting the canonical
patterns (linear V0-V4, angular V0/V1/V3, scalar-only V0(+V1), etc.)
and explaining that the generator silently skips a relationship form
when either side is missing, so a new dimension must declare any form
it needs to participate in.

The SEM003 generator-time validator suggested in #58 needs a metadata
schema change first (relationships are dimension-to-dimension today,
not form-specific) — leaving that for a follow-up.
@sonarqubecloud
Copy link
Copy Markdown

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot
0.0% Coverage on New Code (required ≥ 80%)
C Security Rating on New Code (required ≥ A)
C Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

Catch issues before they fail your Quality Gate with our IDE extension SonarQube for IDE

@matt-edmondson matt-edmondson merged commit 1cc44e2 into vectors May 10, 2026
4 of 5 checks passed
@matt-edmondson matt-edmondson deleted the claude/issue-49-plural-units branch May 10, 2026 12:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants