Sewlore Measurement Baselines
A small, dependency-free Dart library for length comparisons whose percentage must retain its meaning. It requires a unit when creating a length and requires the caller to choose the percentage denominator. The returned immutable report keeps the normalized pair, signed difference, denominator, formula and percentage together.
This is useful when a sewing or fabric measurement app receives centimetres and
inches from different inputs, or exports a before/after result to a log. An
unlabelled 20% can otherwise lose the denominator that made it meaningful.
Use
Add sewlore_measurement_baselines as a dependency to your Dart or Flutter app.
The library uses Dart core only; it has no Flutter, network or storage dependency.
import 'package:sewlore_measurement_baselines/sewlore_measurement_baselines.dart';
final report = LengthChange.between(
before: Length.centimetres(10),
after: Length.millimetres(120),
baseline: PercentageBaseline.before,
);
report.percent; // 20.0
report.formula; // (after - before) / before * 100
report.toMap(unit: LengthUnit.millimetres);
The map includes before: 100.0, after: 120.0, difference: 20.0,
baseline: 'before', denominator: 100.0, the formula and percent: 20.0.
All length-valued fields in the exported map share the selected length unit;
percent is dimensionless.
Changing the required baseline to PercentageBaseline.after gives approximately
16.6667% for the same pair. That is a different question, not a rounding fix.
No baseline is selected by default. A positive result means an increase; a
negative result means a decrease. For a 100 mm to 90 mm change, the before-based
result is -10%; this library does not silently relabel it as positive shrinkage.
Valid input and errors
- Lengths must be nonnegative and finite.
NaN, infinity and negative values throwArgumentError. - Zero length is permitted, but a zero selected denominator throws
ArgumentError. Thus 100 mm to zero is-100%with the before baseline; it has no valid after-based percentage. - Non-finite normalized lengths or percentage results throw
RangeError. Positive values that underflow to zero during display conversion are rejected. - The comparison uses binary floating-point arithmetic, not arbitrary precision. Round the final user-facing display as needed; keep this report for audit.
What the report can establish
The library normalizes length units and records a chosen arithmetic definition. The caller must still establish that the measurements refer to the intended endpoints, seam/cut/fold line, path, direction and measurement states. It does not validate physical measurement technique, infer a treatment protocol, estimate uncertainty or decide a fabric's suitability.
General-purpose unit-conversion libraries already exist. This package's narrow purpose is to keep a length-change percentage attached to its named denominator and formula at the app/export boundary, with explicit rejection of invalid arithmetic. It is not a catalogue of sewing calculators.
For the recording context, see the Sewlore Fabric Measurement Methods Guide. The package example and all numbers in this README are hypothetical; no fabric specimens were tested. Source and documentation were prepared with AI assistance for Sewlore. Automated code checks do not constitute a physical experiment or independent expert review.
Development
dart pub get
dart format --output=none --set-exit-if-changed lib example test
dart analyze
dart test
dart run example/sewlore_measurement_baselines_example.dart
dart doc
dart pub publish --dry-run
MIT licensed.
Libraries
- sewlore_measurement_baselines
- Length comparisons that preserve the chosen percentage denominator.