diff --git a/src/include/units/physical/dimensions.h b/src/include/units/physical/dimensions.h index 350d0fcf..180f20cf 100644 --- a/src/include/units/physical/dimensions.h +++ b/src/include/units/physical/dimensions.h @@ -137,6 +137,9 @@ struct dim_current_density : derived_dimension, exp> template M, DimensionOf L> struct dim_concentration : derived_dimension, exp> {}; +template I, DimensionOf L> +struct dim_luminance : derived_dimension, exp> {}; + } // namespace physical template @@ -229,4 +232,7 @@ concept CurrentDensity = physical::QuantityOf; template concept Concentration = physical::QuantityOf; +template +concept Luminance = physical::QuantityOf; + } // namespace units diff --git a/src/include/units/physical/si.h b/src/include/units/physical/si.h index 4269572a..ba89a07d 100644 --- a/src/include/units/physical/si.h +++ b/src/include/units/physical/si.h @@ -33,6 +33,7 @@ #include "si/density.h" #include "si/frequency.h" #include "si/inductance.h" +#include "si/luminance.h" #include "si/magnetic_flux.h" #include "si/magnetic_induction.h" #include "si/momentum.h" diff --git a/src/include/units/physical/si/luminance.h b/src/include/units/physical/si/luminance.h new file mode 100644 index 00000000..1ef2a955 --- /dev/null +++ b/src/include/units/physical/si/luminance.h @@ -0,0 +1,47 @@ +// The MIT License (MIT) +// +// Copyright (c) 2018 Mateusz Pusz +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +#pragma once + +#include +#include +#include +#include + +namespace units::si { + +struct candela_per_metre_sq : unit {}; +struct dim_luminance : physical::dim_luminance {}; + +template +using luminance = quantity; + +inline namespace literals { + +// cd/m² +constexpr auto operator"" q_cd_per_m2(unsigned long long l) { return luminance(l); } +constexpr auto operator"" q_cd_per_m2(long double l) { return luminance(l); } + +} // namespace literals + +} // namespace units::si + diff --git a/test/unit_test/runtime/fmt_units_test.cpp b/test/unit_test/runtime/fmt_units_test.cpp index 0bfe6bbb..077774a6 100644 --- a/test/unit_test/runtime/fmt_units_test.cpp +++ b/test/unit_test/runtime/fmt_units_test.cpp @@ -245,6 +245,12 @@ TEST_CASE("fmt::format on synthesized unit symbols", "[text][fmt]") CHECK(fmt::format("{:%Q %Aq}", 1q_mol_per_m3) == "1 mol/m^3"); } + SECTION("luminance") + { + CHECK(fmt::format("{}", 1q_cd_per_m2) == "1 cd/m²"); + CHECK(fmt::format("{:%Q %Aq}", 1q_cd_per_m2) == "1 cd/m^2"); + } + SECTION("incoherent units with powers") { CHECK(fmt::format("{}", 1q_mi * 1q_mi * 1q_mi) == "1 [15900351812136/3814697265625 × 10⁹] m³"); diff --git a/test/unit_test/static/si_test.cpp b/test/unit_test/static/si_test.cpp index 422baa0f..f84fe9c2 100644 --- a/test/unit_test/static/si_test.cpp +++ b/test/unit_test/static/si_test.cpp @@ -304,4 +304,9 @@ static_assert(detail::unit_text() == b static_assert(1q_mol_per_m3 == 1q_kg_per_m3 * 1q_mol / 1q_kg); static_assert(detail::unit_text() == basic_symbol_text("mol/m³", "mol/m^2")); +// luminance + +static_assert(1q_cd_per_m2 == 1q_cd / 1q_m2); +static_assert(detail::unit_text() == basic_symbol_text("cd/m²", "cd/m^2")); + } // namespace