Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:29

0001 #pragma once
0002 /**
0003 s_pa.h
0004 ========
0005 
0006 * ctor adds to the pool
0007 * dtor removes from the pool
0008 
0009 Note that the meaning of the six param
0010 depends on typecode, so must do anything
0011 typecode specific (such as zmin() set_zmin ... )
0012 within sn.h
0013 
0014 Q: Could the number of param be increased slightly ? eg for CutCylinder ?
0015 A: Possibly could manage two more param (ie total of 8) by bitwise combination
0016    of two fields in CSGNode. An alternative way would be to reference planes of 4 param
0017    each to give unlimited additional params.
0018 
0019 */
0020 
0021 #include <cassert>
0022 #include <string>
0023 #include <sstream>
0024 #include <iomanip>
0025 
0026 #include "s_pool.h"
0027 
0028 struct _s_pa
0029 {
0030     static constexpr const char* ITEM = "6" ;
0031 
0032     double x0, y0, z0, w0, x1, y1 ;
0033 };
0034 
0035 #include "SYSRAP_API_EXPORT.hh"
0036 
0037 struct SYSRAP_API s_pa
0038 {
0039     static constexpr const char* NAME = "s_pa.npy" ;
0040     static constexpr const bool LEAK = false ;
0041 
0042     typedef s_pool<s_pa,_s_pa> POOL ;
0043     static POOL* pool ;
0044     static void SetPOOL( POOL* pool_ );
0045     static int level() ;
0046     static void Serialize( _s_pa& p, const s_pa* o );
0047     static s_pa* Import(  const _s_pa* p, const std::vector<_s_pa>& buf );
0048 
0049     s_pa();
0050     ~s_pa();
0051     s_pa* copy() const ;
0052 
0053     int pid ;
0054 
0055     double x0, y0, z0, w0, x1, y1 ;
0056 
0057     const double* data() const { return &x0 ; }
0058     double* data_() {            return &x0 ; }
0059     bool is_root() const { return true ; }
0060 
0061     double value(int i) const {       assert( i >=0 && i < 6 ) ; return  *(data() + i) ; }
0062     void set_value(int i, double v ) { assert( i >=0 && i < 6 ) ; *(data_()+i) = v ; }
0063 
0064 
0065     std::string desc() const ;
0066 };
0067 
0068 inline void s_pa::SetPOOL( POOL* pool_ ){ pool = pool_ ; }
0069 inline int s_pa::level() {  return pool ? pool->level : ssys::getenvint("sn__level",-1) ; } // static
0070 
0071 inline void s_pa::Serialize( _s_pa& p, const s_pa* o )
0072 {
0073     p.x0 = o->x0 ;
0074     p.y0 = o->y0 ;
0075     p.z0 = o->z0 ;
0076     p.w0 = o->w0 ;
0077     p.x1 = o->x1 ;
0078     p.y1 = o->y1 ;
0079 }
0080 inline s_pa* s_pa::Import( const _s_pa* p, const std::vector<_s_pa>& )
0081 {
0082     s_pa* o = new s_pa ;
0083     o->x0 = p->x0 ;
0084     o->y0 = p->y0 ;
0085     o->z0 = p->z0 ;
0086     o->w0 = p->w0 ;
0087     o->x1 = p->x1 ;
0088     o->y1 = p->y1 ;
0089     return o ;
0090 }
0091 
0092 
0093 inline s_pa::s_pa()
0094     :
0095     pid(pool ? pool->add(this) : -1),
0096     x0(0.),
0097     y0(0.),
0098     z0(0.),
0099     w0(0.),
0100     x1(0.),
0101     y1(0.)
0102 {
0103     if(level() > 1) std::cerr << "s_pa::s_pa pid " << pid << std::endl ;
0104 }
0105 inline s_pa::~s_pa()
0106 {
0107     if(level() > 1) std::cerr << "s_pa::~s_pa pid " << pid << std::endl ;
0108     if(pool) pool->remove(this);
0109 }
0110 
0111 
0112 /**
0113 s_pa::copy
0114 -----------
0115 
0116 Note that *pid* is not copied, it gets set by s_pool::add from ctor,
0117 as it is part of the persistency plumbing, not the payload.
0118 
0119 **/
0120 
0121 inline s_pa* s_pa::copy() const
0122 {
0123     s_pa* n = new s_pa ;
0124     n->x0 = x0 ;
0125     n->y0 = y0 ;
0126     n->z0 = z0 ;
0127     n->w0 = w0 ;
0128     n->x1 = x1 ;
0129     n->y1 = y1 ;
0130     return n ;
0131 }
0132 
0133 
0134 
0135 
0136 
0137 inline std::string s_pa::desc() const
0138 {
0139     std::stringstream ss ;
0140     ss
0141        << " x0 " << std::setw(10) << std::fixed << std::setprecision(3) << x0
0142        << " y0 " << std::setw(10) << std::fixed << std::setprecision(3) << y0
0143        << " z0 " << std::setw(10) << std::fixed << std::setprecision(3) << z0
0144        << " w0 " << std::setw(10) << std::fixed << std::setprecision(3) << w0
0145        << " x1 " << std::setw(10) << std::fixed << std::setprecision(3) << x1
0146        << " y1 " << std::setw(10) << std::fixed << std::setprecision(3) << y1
0147        ;
0148 
0149     std::string str = ss.str();
0150     return str ;
0151 }
0152 
0153