SHiP Geometry
SHiP experiment geometry implementation using GeoModel.
Loading...
Searching...
No Matches
SHiP::geometry::checks Namespace Reference

Constexpr predicates for compile-time geometry consistency checks. More...

Classes

struct  Span
 Closed interval along one axis. More...
struct  Box
 Axis-aligned box. More...

Typedefs

using LengthMm
 Spellings for struct members and function parameters.

Functions

constexpr Span span (LengthMm centre, LengthMm half)
 Interval of a volume with the given centre and half-length.
constexpr bool contains (Span outer, Span inner, LengthMm tol=0.0 *units::mm)
 inner lies within outer, allowing tol of slack at either end.
constexpr bool overlaps (Span a, Span b)
 The intervals share more than a boundary. Touching ends do not overlap.
constexpr Box box (LengthMm cx, LengthMm cy, LengthMm cz, LengthMm hx, LengthMm hy, LengthMm hz)
 Box with centre (cx, cy, cz) and the given half-lengths.
constexpr Box box (LengthMm hx, LengthMm hy, LengthMm hz)
 Box centred on the origin.
constexpr bool contains (const Box &outer, const Box &inner, LengthMm tol=0.0 *units::mm)
constexpr bool overlaps (const Box &a, const Box &b)
 Boxes overlap only if they overlap along every axis.
constexpr Box bounds (double x0, double x1, double y0, double y1, double z0, double z1)
 Box from its bounds in mm, for writing a known region down literally.
constexpr Box intersection (const Box &a, const Box &b)
 The region two boxes share. Only meaningful if they overlap.
constexpr bool overlapsWithin (const Box &a, const Box &b, const Box &region, LengthMm tol=1e-6 *units::mm)
 The boxes overlap, and only within region.
constexpr Box shrunk (const Box &b, LengthMm d)
 b with every face moved inwards by d.
template<typename Range, typename Pred>
constexpr std::size_t firstFailure (const Range &range, Pred ok)
 Index of the first element of range for which ok is false, or npos.
template<typename Range, typename Pred>
constexpr std::size_t firstPairFailure (const Range &range, Pred ok)
 Index i of the first neighbouring pair (range[i], range[i+1]) for which ok is false, or npos.
template<std::size_t N>
constexpr bool coveredBy (const Box &inner, const std::array< Box, N > &outers)
 Whether inner lies within the union of outers.

Variables

constexpr std::size_t npos = std::numeric_limits<std::size_t>::max()
 Returned by the first*() searches when every element passes.

Detailed Description

Constexpr predicates for compile-time geometry consistency checks.

The geometry constants are all constexpr quantities, so containment, ordering and non-overlap can be checked with static_assert instead of building volumes in a test. The predicates are plain constexpr functions so tests can also feed them bad inputs as negative controls.

Only comparisons and +/- are used: no <cmath>, whose functions Clang does not fold in constant expressions (clang-tidy parses the tree with Clang).

Typedef Documentation

◆ LengthMm

Spellings for struct members and function parameters.

Constants instead use static constexpr auto x = 1.0 * units::mm; and deduce their type.

Function Documentation

◆ bounds()

Box SHiP::geometry::checks::bounds ( double x0,
double x1,
double y0,
double y1,
double z0,
double z1 )
nodiscardconstexpr

Box from its bounds in mm, for writing a known region down literally.

◆ box() [1/2]

Box SHiP::geometry::checks::box ( LengthMm cx,
LengthMm cy,
LengthMm cz,
LengthMm hx,
LengthMm hy,
LengthMm hz )
nodiscardconstexpr

Box with centre (cx, cy, cz) and the given half-lengths.

◆ box() [2/2]

Box SHiP::geometry::checks::box ( LengthMm hx,
LengthMm hy,
LengthMm hz )
nodiscardconstexpr

Box centred on the origin.

◆ contains() [1/2]

bool SHiP::geometry::checks::contains ( const Box & outer,
const Box & inner,
LengthMm tol = 0.0 * units::mm )
nodiscardconstexpr

◆ contains() [2/2]

bool SHiP::geometry::checks::contains ( Span outer,
Span inner,
LengthMm tol = 0.0 * units::mm )
nodiscardconstexpr

inner lies within outer, allowing tol of slack at either end.

◆ coveredBy()

template<std::size_t N>
bool SHiP::geometry::checks::coveredBy ( const Box & inner,
const std::array< Box, N > & outers )
nodiscardconstexpr

Whether inner lies within the union of outers.

Every bound of an outer box that falls inside inner cuts it into cells; each cell lies either wholly inside or wholly outside each outer box, so testing the cell centres decides coverage exactly.

◆ firstFailure()

template<typename Range, typename Pred>
std::size_t SHiP::geometry::checks::firstFailure ( const Range & range,
Pred ok )
nodiscardconstexpr

Index of the first element of range for which ok is false, or npos.

Asserting firstFailure(...) == npos instead of a plain all-of makes the compiler print the offending index when the assertion fails.

◆ firstPairFailure()

template<typename Range, typename Pred>
std::size_t SHiP::geometry::checks::firstPairFailure ( const Range & range,
Pred ok )
nodiscardconstexpr

Index i of the first neighbouring pair (range[i], range[i+1]) for which ok is false, or npos.

◆ intersection()

Box SHiP::geometry::checks::intersection ( const Box & a,
const Box & b )
nodiscardconstexpr

The region two boxes share. Only meaningful if they overlap.

◆ overlaps() [1/2]

bool SHiP::geometry::checks::overlaps ( const Box & a,
const Box & b )
nodiscardconstexpr

Boxes overlap only if they overlap along every axis.

◆ overlaps() [2/2]

bool SHiP::geometry::checks::overlaps ( Span a,
Span b )
nodiscardconstexpr

The intervals share more than a boundary. Touching ends do not overlap.

◆ overlapsWithin()

bool SHiP::geometry::checks::overlapsWithin ( const Box & a,
const Box & b,
const Box & region,
LengthMm tol = 1e-6 * units::mm )
nodiscardconstexpr

The boxes overlap, and only within region.

Bounds a known overlap: it fails both when the overlap is removed and when it grows.

◆ shrunk()

Box SHiP::geometry::checks::shrunk ( const Box & b,
LengthMm d )
nodiscardconstexpr

b with every face moved inwards by d.

A box sticks out of a region by at most d exactly when shrunk(box, d) lies within it.

◆ span()

Span SHiP::geometry::checks::span ( LengthMm centre,
LengthMm half )
nodiscardconstexpr

Interval of a volume with the given centre and half-length.

Variable Documentation

◆ npos

std::size_t SHiP::geometry::checks::npos = std::numeric_limits<std::size_t>::max()
inlineconstexpr

Returned by the first*() searches when every element passes.