mirror of
https://github.com/mpusz/mp-units.git
synced 2025-08-04 20:54:28 +02:00
Added luminance
This commit is contained in:
@@ -137,6 +137,9 @@ struct dim_current_density : derived_dimension<Child, U, exp<I, 1>, exp<L, -2>>
|
||||
template<typename Child, Unit U, DimensionOf<dim_substance> M, DimensionOf<dim_length> L>
|
||||
struct dim_concentration : derived_dimension<Child, U, exp<M, 1>, exp<L, -3>> {};
|
||||
|
||||
template<typename Child, Unit U, DimensionOf<dim_luminous_intensity> I, DimensionOf<dim_length> L>
|
||||
struct dim_luminance : derived_dimension<Child, U, exp<I, 1>, exp<L, -2>> {};
|
||||
|
||||
} // namespace physical
|
||||
|
||||
template<typename T>
|
||||
@@ -229,4 +232,7 @@ concept CurrentDensity = physical::QuantityOf<T, physical::dim_current_density>;
|
||||
template<typename T>
|
||||
concept Concentration = physical::QuantityOf<T, physical::dim_concentration>;
|
||||
|
||||
template<typename T>
|
||||
concept Luminance = physical::QuantityOf<T, physical::dim_luminance>;
|
||||
|
||||
} // namespace units
|
||||
|
@@ -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"
|
||||
|
47
src/include/units/physical/si/luminance.h
Normal file
47
src/include/units/physical/si/luminance.h
Normal file
@@ -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 <units/physical/dimensions.h>
|
||||
#include <units/physical/si/length.h>
|
||||
#include <units/physical/si/luminous_intensity.h>
|
||||
#include <units/quantity.h>
|
||||
|
||||
namespace units::si {
|
||||
|
||||
struct candela_per_metre_sq : unit<candela_per_metre_sq> {};
|
||||
struct dim_luminance : physical::dim_luminance<dim_luminance, candela_per_metre_sq, dim_luminous_intensity, dim_length> {};
|
||||
|
||||
template<Unit U, Scalar Rep = double>
|
||||
using luminance = quantity<dim_luminance, U, Rep>;
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// cd/m²
|
||||
constexpr auto operator"" q_cd_per_m2(unsigned long long l) { return luminance<candela_per_metre_sq, std::int64_t>(l); }
|
||||
constexpr auto operator"" q_cd_per_m2(long double l) { return luminance<candela_per_metre_sq, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
} // namespace units::si
|
||||
|
@@ -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³");
|
||||
|
@@ -304,4 +304,9 @@ static_assert(detail::unit_text<dim_current_density, ampere_per_metre_sq>() == b
|
||||
static_assert(1q_mol_per_m3 == 1q_kg_per_m3 * 1q_mol / 1q_kg);
|
||||
static_assert(detail::unit_text<dim_concentration, ampere_per_metre_sq>() == basic_symbol_text("mol/m³", "mol/m^2"));
|
||||
|
||||
// luminance
|
||||
|
||||
static_assert(1q_cd_per_m2 == 1q_cd / 1q_m2);
|
||||
static_assert(detail::unit_text<dim_luminance, candela_per_metre_sq>() == basic_symbol_text("cd/m²", "cd/m^2"));
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user