-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Fluent speed unit conversion for .NET 10+ — metric, US customary, nautical, and scientific units, all built on a single strongly-typed Speed struct.
dotnet add package MarcusMedina.Units.SpeedThis one comes with a very specific, very embarrassing memory attached. Back in upper-secondary school, working through a problem involving a truck's weight, speed, road surface, and wind resistance, I somehow — through some mysterious chain of unit errors — calculated that the truck was travelling at 5 times the speed of light. My teacher was not impressed. Years later, teaching my own students, I still had flashbacks to that lesson. So I finally sat down and coded speed conversions properly, if only to explain it to myself, decades late. I wanted each unit conversion broken into the same small, obvious steps — precisely the steps that would have stopped that truck from ever breaking causality.
-
New to C#? A clean example of a fluent, extension-method-based conversion API —
120.KilometersPerHour().ToMilesPerHour(). -
Need real conversions? Every unit is backed by an explicit, documented conversion factor against metres per second — no guessing which raw
doublemeans what.
using MarcusMedina.Units.Speed.Metric;
using MarcusMedina.Units.Speed.Nautical;
using MarcusMedina.Units.Speed.Scientific;
Speed car = 120.KilometersPerHour();
Speed ship = 15.Knots();
Speed jet = 1.2.Mach();
double mph = car.ToMilesPerHour(); // ≈ 74.6
double ms = ship.ToMetersPerSecond(); // ≈ 7.72
Speed total = car + 10.KilometersPerHour();
bool faster = jet > car;