<commit_before>// @(#)root/geom:$Id$
// Author: <NAME>   26/09/05

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/


#include "Riostream.h"

#include "TGeoManager.h"
#include "TGeoMatrix.h"
#include "TGeoVolume.h"
#include "TGeoNode.h"
#include "TGeoScaledShape.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TMath.h"

//_____________________________________________________________________________
// TGeoScaledShape - A shape scaled by a TGeoScale transformation
//    
//Begin_Html
/*
<img src="gif/TGeoScaledShape.gif">
*/
//End_Html
//_____________________________________________________________________________


ClassImp(TGeoScaledShape)
   
//_____________________________________________________________________________
TGeoScaledShape::TGeoScaledShape()
{
// Default constructor
   fShape = 0;
   fScale = 0;
}   


//_____________________________________________________________________________
TGeoScaledShape::TGeoScaledShape(const char *name, TGeoShape *shape, TGeoScale *scale)
                :TGeoBBox(name,0,0,0)
{
// Constructor
   fShape = shape;
   fScale = scale;
   if (!fScale->IsRegistered()) fScale->RegisterYourself();
   ComputeBBox();
}

//_____________________________________________________________________________
TGeoScaledShape::TGeoScaledShape(TGeoShape *shape, TGeoScale *scale)
{
// Constructor
   fShape = shape;
   fScale = scale;
   if (!fScale->IsRegistered()) fScale->RegisterYourself();
   ComputeBBox();
}

//_____________________________________________________________________________
TGeoScaledShape::~TGeoScaledShape()
{
// destructor
}

//_____________________________________________________________________________
Double_t TGeoScaledShape::Capacity() const
{
// Computes capacity of this shape [length^3]
   Double_t capacity = fShape->Capacity();
   const Double_t *scale = fScale->GetScale();
   capacity *= scale[0]*scale[1]*scale[2];
   return capacity;
}   
   
//_____________________________________________________________________________   
void TGeoScaledShape::ComputeBBox()
{
// Compute bounding box of the scaled shape
   if (!fShape) {
      Error("ComputeBBox", "Scaled shape %s without shape", GetName());
      return;
   } 
   TGeoBBox *box = (TGeoBBox*)fShape;
   const Double_t *orig = box->GetOrigin();
   Double_t point[3], master[3];
   point[0] = box->GetDX();
   point[1] = box->GetDY();
   point[2] = box->GetDZ();
   
   fScale->LocalToMaster(orig, fOrigin);
   fScale->LocalToMaster(point, master);
   fDX = TMath::Abs(master[0]);
   fDY = TMath::Abs(master[1]);
   fDZ = TMath::Abs(master[2]);
}   

//_____________________________________________________________________________   
void TGeoScaledShape::ComputeNormal(Double_t *point, Double_t *dir, Double_t *norm)
{
// Compute normal to closest surface from POINT.
   Double_t local[3], ldir[3], lnorm[3];
   fScale->MasterToLocal(point,local);
   fScale->MasterToLocalVect(dir,ldir);
   TGeoMatrix::Normalize(ldir);
   fShape->ComputeNormal(local,ldir,lnorm);
   fScale->LocalToMasterVect(lnorm, norm);
   TGeoMatrix::Normalize(norm);
}

//_____________________________________________________________________________
Bool_t TGeoScaledShape::Contains(Double_t *point) const
{
// Test if point is inside the scaled shape
   Double_t local[3];
   fScale->MasterToLocal(point,local);
   return fShape->Contains(local);
}

//_____________________________________________________________________________
Int_t TGeoScaledShape::DistancetoPrimitive(Int_t px, Int_t py)
{
// compute closest distance from point px,py to each vertex. Should not be called.
   Int_t n = fShape->GetNmeshVertices();
   return ShapeDistancetoPrimitive(n, px, py);
}

//_____________________________________________________________________________
Double_t TGeoScaledShape::DistFromInside(Double_t *point, Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
{
// Compute distance from inside point to surface of the scaled shape.
   Double_t local[3], ldir[3];
   Double_t lstep;
   fScale->MasterToLocal(point,local);
   lstep = fScale->MasterToLocal(step, dir);
   fScale->MasterToLocalVect(dir,ldir);
   TGeoMatrix::Normalize(ldir);
   Double_t dist = fShape->DistFromInside(local,ldir, iact, lstep, safe);
   if (safe) *safe = fScale->LocalToMaster(*safe);
   dist = fScale->LocalToMaster(dist, ldir);
   return dist;
}


//_____________________________________________________________________________
Double_t TGeoScaledShape::DistFromOutside(Double_t *point, Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
{
// Compute distance from outside point to surface of the scaled shape.
   Double_t local[3], ldir[3];
   Double_t lstep;
//   printf("DistFromOutside(%f,%f,%f,  %f,%f,%f)\n", point[0], point[1], point[2], dir[0], dir[1],dir[2]);
   fScale->MasterToLocal(point,local);
//   printf("local: %f,%f,%f\n", local[0],local[1], local[2]);
   lstep = fScale->MasterToLocal(step, dir);
   fScale->MasterToLocalVect(dir,ldir);
   TGeoMatrix::Normalize(ldir);
//   printf("localdir: %f,%f,%f\n",ldir[0],ldir[1],ldir[2]);
   Double_t dist = fShape->DistFromOutside(local,ldir, iact, lstep, safe);
//   printf("local distance: %f\n", dist);
   if (safe) *safe = fScale->LocalToMaster(*safe);<commit_msg>From Andrei: protection for an uninitialized variable.<commit_after>// @(#)root/geom:$Id$
// Author: <NAME>   26/09/05

/*************************************************************************
 * Copyright (C) 1995-2000, <NAME> and <NAME>.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/


#include "Riostream.h"

#include "TGeoManager.h"
#include "TGeoMatrix.h"
#include "TGeoVolume.h"
#include "TGeoNode.h"
#include "TGeoScaledShape.h"
#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include "TMath.h"

//_____________________________________________________________________________
// TGeoScaledShape - A shape scaled by a TGeoScale transformation
//    
//Begin_Html
/*
<img src="gif/TGeoScaledShape.gif">
*/
//End_Html
//_____________________________________________________________________________


ClassImp(TGeoScaledShape)
   
//_____________________________________________________________________________
TGeoScaledShape::TGeoScaledShape()
{
// Default constructor
   fShape = 0;
   fScale = 0;
}   


//_____________________________________________________________________________
TGeoScaledShape::TGeoScaledShape(const char *name, TGeoShape *shape, TGeoScale *scale)
                :TGeoBBox(name,0,0,0)
{
// Constructor
   fShape = shape;
   fScale = scale;
   if (!fScale->IsRegistered()) fScale->RegisterYourself();
   ComputeBBox();
}

//_____________________________________________________________________________
TGeoScaledShape::TGeoScaledShape(TGeoShape *shape, TGeoScale *scale)
{
// Constructor
   fShape = shape;
   fScale = scale;
   if (!fScale->IsRegistered()) fScale->RegisterYourself();
   ComputeBBox();
}

//_____________________________________________________________________________
TGeoScaledShape::~TGeoScaledShape()
{
// destructor
}

//_____________________________________________________________________________
Double_t TGeoScaledShape::Capacity() const
{
// Computes capacity of this shape [length^3]
   Double_t capacity = fShape->Capacity();
   const Double_t *scale = fScale->GetScale();
   capacity *= scale[0]*scale[1]*scale[2];
   return capacity;
}   
   
//_____________________________________________________________________________   
void TGeoScaledShape::ComputeBBox()
{
// Compute bounding box of the scaled shape
   if (!fShape) {
      Error("ComputeBBox", "Scaled shape %s without shape", GetName());
      return;
   } 
   TGeoBBox *box = (TGeoBBox*)fShape;
   const Double_t *orig = box->GetOrigin();
   Double_t point[3], master[3];
   point[0] = box->GetDX();
   point[1] = box->GetDY();
   point[2] = box->GetDZ();
   
   fScale->LocalToMaster(orig, fOrigin);
   fScale->LocalToMaster(point, master);
   fDX = TMath::Abs(master[0]);
   fDY = TMath::Abs(master[1]);
   fDZ = TMath::Abs(master[2]);
}   

//_____________________________________________________________________________   
void TGeoScaledShape::ComputeNormal(Double_t *point, Double_t *dir, Double_t *norm)
{
// Compute normal to closest surface from POINT.
   Double_t local[3], ldir[3], lnorm[3];
   fScale->MasterToLocal(point,local);
   fScale->MasterToLocalVect(dir,ldir);
   TGeoMatrix::Normalize(ldir);
   fShape->ComputeNormal(local,ldir,lnorm);
   fScale->LocalToMasterVect(lnorm, norm);
   TGeoMatrix::Normalize(norm);
}

//_____________________________________________________________________________
Bool_t TGeoScaledShape::Contains(Double_t *point) const
{
// Test if point is inside the scaled shape
   Double_t local[3];
   fScale->MasterToLocal(point,local);
   return fShape->Contains(local);
}

//_____________________________________________________________________________
Int_t TGeoScaledShape::DistancetoPrimitive(Int_t px, Int_t py)
{
// compute closest distance from point px,py to each vertex. Should not be called.
   Int_t n = fShape->GetNmeshVertices();
   return ShapeDistancetoPrimitive(n, px, py);
}

//_____________________________________________________________________________
Double_t TGeoScaledShape::DistFromInside(Double_t *point, Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
{
// Compute distance from inside point to surface of the scaled shape.
   Double_t local[3], ldir[3];
   Double_t lstep;
   fScale->MasterToLocal(point,local);
   lstep = fScale->MasterToLocal(step, dir);
   fScale->MasterToLocalVect(dir,ldir);
   TGeoMatrix::Normalize(ldir);
   Double_t dist = fShape->DistFromInside(local,ldir, iact, lstep, safe);
   if (iact<3 && safe) *safe = fScale->LocalToMaster(*safe);
   dist = fScale->LocalToMaster(dist, ldir);
   return dist;
}


//_____________________________________________________________________________
Double_t TGeoScaledShape::DistFromOutside(Double_t *point, Double_t *dir, Int_t iact, Double_t step, Double_t *safe) const
{
// Compute distance from outside point to surface of the scaled shape.
   Double_t local[3], ldir[3];
   Double_t lstep;
//   printf("DistFromOutside(%f,%f,%f,  %f,%f,%f)\n", point[0], point[1], point[2], dir[0], dir[1],dir[2]);
   fScale->MasterToLocal(point,local);
//   printf("local: %f,%f,%f\n", local[0],local[1], local[2]);
   lstep = fScale->MasterToLocal(step, dir);
   fScale->MasterToLocalVect(dir,ldir);
   TGeoMatrix::Normalize(ldir);
//   printf("localdir: %f,%f,%f\n",ldir[0],ldir[1],ldir[2]);
   Double_t dist = fShape->DistFromOutside(local,ldir, iact, lstep, safe);
//   printf("local distance: %f\n", dist);
   if (safe) *safe = fScale->LocalToMaster(*safe);
{'fraction_non_alphanumeric': 0.14832535885167464, 'fraction_numerical': 0.009308394954327968, 'mean_word_length': 4.713717693836978, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 71, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 10, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2742762', 'n_tokens_mistral': 3489, 'n_tokens_neox': 3383, 'n_words': 684}