forked from mpusz/mp-units
feat: solid angle support added
This commit is contained in:
@@ -45,6 +45,7 @@ add_library(
|
||||
include/units/exponent.h
|
||||
include/units/generic/angle.h
|
||||
include/units/generic/dimensionless.h
|
||||
include/units/generic/solid_angle.h
|
||||
include/units/kind.h
|
||||
include/units/magnitude.h
|
||||
include/units/math.h
|
||||
@@ -83,6 +84,7 @@ endif()
|
||||
if(DEFINED ${projectPrefix}DOWNCAST_MODE)
|
||||
set(downcast_mode_options OFF ON AUTO)
|
||||
list(FIND downcast_mode_options "${${projectPrefix}DOWNCAST_MODE}" downcast_mode)
|
||||
|
||||
if(downcast_mode EQUAL -1)
|
||||
message(FATAL_ERROR
|
||||
"'${projectPrefix}DOWNCAST_MODE' should be one of ${downcast_mode_options} ('${${projectPrefix}DOWNCAST_MODE}' received)"
|
||||
|
104
src/core/include/units/generic/solid_angle.h
Normal file
104
src/core/include/units/generic/solid_angle.h
Normal file
@@ -0,0 +1,104 @@
|
||||
// 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
|
||||
|
||||
// IWYU pragma: begin_exports
|
||||
#include <units/generic/angle.h>
|
||||
#include <units/quantity.h>
|
||||
#include <units/reference.h>
|
||||
#include <units/symbol_text.h>
|
||||
// IWYU pragma: end_exports
|
||||
|
||||
#include <units/isq/si/prefixes.h>
|
||||
|
||||
namespace units {
|
||||
|
||||
struct steradian : named_unit<steradian, "sr"> {};
|
||||
|
||||
template<Unit U = steradian>
|
||||
struct dim_solid_angle : derived_dimension<dim_solid_angle<U>, U, exponent<dim_angle<>, 2>> {};
|
||||
|
||||
struct square_degree : derived_scaled_unit<square_degree, dim_solid_angle<>, degree> {};
|
||||
|
||||
template<typename T>
|
||||
concept SolidAngle = QuantityOfT<T, dim_solid_angle>;
|
||||
|
||||
template<UnitOf<dim_solid_angle<>> U, Representation Rep = double>
|
||||
using solid_angle = quantity<dim_solid_angle<>, U, Rep>;
|
||||
|
||||
#ifndef UNITS_NO_LITERALS
|
||||
|
||||
inline namespace literals {
|
||||
|
||||
// sr
|
||||
constexpr auto operator"" _q_sr(unsigned long long l)
|
||||
{
|
||||
gsl_ExpectsAudit(std::in_range<std::int64_t>(l));
|
||||
return solid_angle<steradian, std::int64_t>(static_cast<std::int64_t>(l));
|
||||
}
|
||||
constexpr auto operator"" _q_sr(long double l) { return solid_angle<steradian, long double>(l); }
|
||||
|
||||
// deg2
|
||||
constexpr auto operator"" _q_deg2(unsigned long long l)
|
||||
{
|
||||
gsl_ExpectsAudit(std::in_range<std::int64_t>(l));
|
||||
return solid_angle<square_degree, std::int64_t>(static_cast<std::int64_t>(l));
|
||||
}
|
||||
constexpr auto operator"" _q_deg2(long double l) { return solid_angle<square_degree, long double>(l); }
|
||||
|
||||
} // namespace literals
|
||||
|
||||
#endif // UNITS_NO_LITERALS
|
||||
|
||||
#ifndef UNITS_NO_REFERENCES
|
||||
|
||||
namespace solid_angle_references {
|
||||
|
||||
inline constexpr auto sr = reference<dim_solid_angle<>, steradian>{};
|
||||
inline constexpr auto deg2 = reference<dim_solid_angle<>, square_degree>{};
|
||||
|
||||
} // namespace solid_angle_references
|
||||
|
||||
namespace references {
|
||||
|
||||
using namespace solid_angle_references;
|
||||
|
||||
} // namespace references
|
||||
|
||||
#endif // UNITS_NO_REFERENCES
|
||||
|
||||
} // namespace units
|
||||
|
||||
#ifndef UNITS_NO_ALIASES
|
||||
|
||||
namespace units::aliases::inline solid_angle {
|
||||
|
||||
template<Representation Rep = double>
|
||||
using sr = units::solid_angle<units::steradian, Rep>;
|
||||
|
||||
template<Representation Rep = double>
|
||||
using deg2 = units::solid_angle<units::square_degree, Rep>;
|
||||
|
||||
} // namespace units::aliases::inline solid_angle
|
||||
|
||||
#endif // UNITS_NO_ALIASES
|
@@ -21,18 +21,20 @@
|
||||
// SOFTWARE.
|
||||
|
||||
#include <units/generic/angle.h>
|
||||
#include <units/generic/solid_angle.h>
|
||||
#include <numbers>
|
||||
|
||||
namespace {
|
||||
|
||||
// plane angle
|
||||
|
||||
using namespace units::references;
|
||||
using namespace units::literals;
|
||||
|
||||
static_assert(360 * deg == 1 * rot);
|
||||
static_assert(400 * grad == 1 * rot);
|
||||
static_assert(std::numbers::pi * 2 * rad == 1. * rot);
|
||||
|
||||
using namespace units::literals;
|
||||
|
||||
static_assert(360_q_deg == 1_q_rot);
|
||||
static_assert(400_q_grad == 1_q_rot);
|
||||
static_assert(std::numbers::pi * quantity_cast<double>(2._q_rad) == quantity_cast<double>(1._q_rot));
|
||||
@@ -42,4 +44,9 @@ static_assert(units::aliases::deg<int>(360) == units::aliases::rot<int>(1));
|
||||
static_assert(units::aliases::grad<int>(400) == units::aliases::rot<int>(1));
|
||||
static_assert(std::numbers::pi * units::aliases::rad<>(2.) == units::aliases::rot<>(1.));
|
||||
|
||||
// solid angle
|
||||
|
||||
static_assert(1_q_rad * 1_q_rad == 1_q_sr);
|
||||
static_assert(1_q_deg * 1_q_deg == 1_q_deg2);
|
||||
|
||||
} // namespace
|
||||
|
Reference in New Issue
Block a user