|
Phyth v0.1.0
A dimensional safe C++ header-only mechanics and electromagnetics simulation library.
|
Physical unit with dimension and scale factor relative to SI base. More...
#include <Unit.hpp>
Public Types | |
| using | DimensionT = DimT |
| using | ScaleT = Scale |
Public Member Functions | |
| Unit ()=default | |
| Default constructor. | |
Static Public Attributes | |
| static constexpr double | scale = static_cast<double>(Scale::num) / Scale::den |
| Scale factor relative to the SI base unit. | |
Physical unit with dimension and scale factor relative to SI base.
Unit is the compile-time representation of a unit. It combines:
| DimT | The dimension type (e.g., Length, Mass, Velocity) |
| Scale | std::ratio scale relative to base unit (default: 1) |
| TagT | An optional tag type to distinguish units with same dimension and scale (e.g., radians vs. degrees) |
Example: using Meter = Unit<Length, std::ratio<1>>; using Kilometer = Unit<Length, std::ratio<1000>>; using Second = Unit<Time, std::ratio<1>>; using MilliSecond = Unit<Time, std::ratio<1, 1000>>;
// Same dimension, different scale, no tag static_assert(std::is_same_v<Meter::DimensionT, Length>); static_assert(Meter::scale == 1.0); static_assert(Kilometer::scale == 1000.0);
// Differentiating units with the same dimension and scale via TagT: struct RadianTag {}; struct DegreeTag {}; using Radian = Unit<Dimensionless, std::ratio<1>, RadianTag>; using Degree = Unit<Dimensionless, std::ratio<1>, DegreeTag>; // Radian and Degree are distinct types despite having the same // DimensionT and scale, because their TagT differ. static_assert(!stdis_same_v<Radian, Degree>);
|
default |
Default constructor.
|
staticconstexpr |