DLG4::VolumeBuilders
A fluent interface for Geant4 geometry definition.
Loading...
Searching...
No Matches
VolumeBuildersUnitTypes.hh
Go to the documentation of this file.
1// VolumeBuilderUnitTypes.hh
2// A bridge to bring DLG4Units.hh into VolumeBuilders without a header loop
3// Created by D.S. Leonard on 5/11/26.
4//
5
6#ifndef HPGESIM_VOLUMEBUIDLERSUNITTYPES_HH
7#define HPGESIM_VOLUMEBUIDLERSUNITTYPES_HH
8#include "DLG4Units.hh"
9
10namespace DLG4::VolumeBuilders {
16 template <class T>
24
25
35 public:
36 double x, y, z;
38
40
42
44 : Unit3Vec(v) { Sync(); }
45
46 ThreeVecDimensioner(G4ThreeVector v, const Length &u)
47 : Unit3Vec(v, u) { Sync(); }
48
49 ThreeVecDimensioner(double x, double y, double z, const Length &u)
50 : Unit3Vec(x, y, z, u) { Sync(); }
51
52 ThreeVecDimensioner(double x, double y, double z) {
53 NativeVec_ = G4ThreeVector(x, y, z);
54 is_dimensioned_ = false;
55 Sync();
56 }
57
58 ThreeVecDimensioner(G4ThreeVector v)
59 : ThreeVecDimensioner(v.x(), v.y(), v.z()) {
60 }
61
62 [[nodiscard]] G4ThreeVector apply_units(const Length dflt_unit) const {
63 auto vec = G4ThreeVector(x, y, z);
64 if (!is_dimensioned_) {
65 vec *= dflt_unit.Native();
66 }
67 return vec;
68 }
69
70 private:
71 void Sync() {
72 x = NativeVec_->x();
73 y = NativeVec_->y();
74 z = NativeVec_->z();
75 }
76
77 bool is_dimensioned_ = true;
78 };
79
80
81}
82
83
84
85#endif //HPGESIM_VOLUMEBUIDLERSUNITTYPES_HH
Typesafe units, for VolumeBuilders, Geant, ETC !! No accidental mixing values and units.
A 3 vector that is scalable with/to Units.
Definition DLG4Units.hh:452
std::optional< G4ThreeVector > NativeVec_
Definition DLG4Units.hh:516
CRTP base methods for Unit classes.
Definition DLG4Units.hh:154
PropertySetter Native
Definition DLG4Units.hh:182
A 3D vector that manages unit policy for parameter passing If constructed with a unit,...
ThreeVecDimensioner(double x, double y, double z, const Length &u)
ThreeVecDimensioner(G4ThreeVector v, const Length &u)
ThreeVecDimensioner(const ThreeVecDimensioner &)=delete
G4ThreeVector apply_units(const Length dflt_unit) const
ThreeVecDimensioner & operator=(const ThreeVecDimensioner &)=delete
void SetGlobalDefaultUnit(T unit)
Set the default unit for all VolumeBuilder methods.
Definition DLG4Units.hh:553