<commit_before>#include "NLTProjector.h"
#include "ReveManager.h"
#include "NLTBases.h"

#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include <TVirtualPad.h>
#include <TVirtualViewer3D.h>

#include <list>

using namespace Reve;

ClassImp(Reve::NLTProjection)

Float_t NLTProjection::fgEps = 0.005f;
 
NLTProjection::NLTProjection(Vector& center) : 
  fType(PT_Unknown),
  fGeoMode(GM_Unknown),
  fName(0),
  fCenter(center.x, center.y, center.z),
  fDistortion(0.0f), 
  fFixedRadius(300), 
  fScale(1.0f)
{}

//______________________________________________________________________________
void NLTProjection::ProjectVector(Vector& v)
{
  ProjectPoint(v.x, v.y, v.z);
}

//______________________________________________________________________________
Vector* NLTProjection::Project(Vector* origPnts, Int_t Npnts, Bool_t copy)
{
  Vector* pnts = 0; 
  if(copy) 
  {
    pnts = new Vector[Npnts];
    memcpy(pnts, origPnts, Npnts*sizeof(Vector));
  }
  else
  { 
    pnts =  origPnts;
  }

  for(Int_t i = 0; i<Npnts; i++)
  {
    ProjectPoint(pnts[i].x, pnts[i].y, pnts[i].z);
  }
  return pnts;
}

//______________________________________________________________________________
void NLTProjection::UpdateLimit()
{
  if ( fDistortion == 0.0f )
    return;
 
  Float_t lim =  1.0f/fDistortion + fFixedRadius;
  Float_t* c = GetProjectedCenter();
  fUpLimit.Set(lim + c[0], lim + c[1], c[2]);
  fLowLimit.Set(-lim + c[0], -lim + c[1], c[2]);
}

//______________________________________________________________________________
void NLTProjection::SetDistortion(Float_t d)
{
  // Prevent scaling down whole projected scene.
  // Point at fixe distance shold be on constant screen coorinate. 

  fDistortion=d; 
  fScale = 1+fFixedRadius*fDistortion;
  UpdateLimit();
}

//______________________________________________________________________________
void NLTProjection::SetFixedRadius(Float_t r)
{

  fFixedRadius=r;
  fScale = 1+fFixedRadius*fDistortion;
  UpdateLimit();
}

//______________________________________________________________________________
void NLTProjection::SetDirectionalVector(Int_t screenAxis, Vector& vec)
{
  for(Int_t i=0; i<3; i++)
  {
    vec[i] = (i==screenAxis) ? 1. : 0.;
  }
}

//______________________________________________________________________________
Float_t NLTProjection::GetValForScreenPos(Int_t i, Float_t sv)
{
  // move on unprojected axis, find when projected value is geiven screen values(sv)
  static const Exc_t eH("NLTProjector::GetValForScreenPos ");

  Float_t xL, xM, xR;
  Vector V, DirVec;
  SetDirectionalVector(i, DirVec);
  if((sv > 0 && sv > fUpLimit[i]) || (sv < 0 && sv < fLowLimit[i]) )
    throw(eH + Form("screen value '%f' out of limit '%f'.", sv, sv > 0 ? fUpLimit[i] : fLowLimit[i]));

  Vector zero; ProjectVector(zero);
  // printf("NLTProjection::GetValForScreenPos %d sv %f , zero %f\n",i,  sv, zero[i]);
  // search from -/+ infinity according to sign of screen value
  if (sv > zero[i])
  {
    xL = 0; xR = 1000;
    while (1)
    {
      V.Mult(DirVec, xR); ProjectVector(V);
      // printf("positive projected %f, value %f,xL, xR ( %f, %f)\n", V[i], sv, xL, xR);
      if (V[i] > sv || V[i] == sv) break;
      xL = xR; xR *= 2;
    }
  }
  else if (sv < zero[i])
  {
    xR = 0; xL = -1000;<commit_msg>Bugfix: in GetValForScreenPos() check if distortion exist before checking the limit.<commit_after>#include "NLTProjector.h"
#include "ReveManager.h"
#include "NLTBases.h"

#include "TBuffer3D.h"
#include "TBuffer3DTypes.h"
#include <TVirtualPad.h>
#include <TVirtualViewer3D.h>

#include <list>

using namespace Reve;

ClassImp(Reve::NLTProjection)

Float_t NLTProjection::fgEps = 0.005f;
 
NLTProjection::NLTProjection(Vector& center) : 
  fType(PT_Unknown),
  fGeoMode(GM_Unknown),
  fName(0),
  fCenter(center.x, center.y, center.z),
  fDistortion(0.0f), 
  fFixedRadius(300), 
  fScale(1.0f)
{}

//______________________________________________________________________________
void NLTProjection::ProjectVector(Vector& v)
{
  ProjectPoint(v.x, v.y, v.z);
}

//______________________________________________________________________________
Vector* NLTProjection::Project(Vector* origPnts, Int_t Npnts, Bool_t copy)
{
  Vector* pnts = 0; 
  if(copy) 
  {
    pnts = new Vector[Npnts];
    memcpy(pnts, origPnts, Npnts*sizeof(Vector));
  }
  else
  { 
    pnts =  origPnts;
  }

  for(Int_t i = 0; i<Npnts; i++)
  {
    ProjectPoint(pnts[i].x, pnts[i].y, pnts[i].z);
  }
  return pnts;
}

//______________________________________________________________________________
void NLTProjection::UpdateLimit()
{
  if ( fDistortion == 0.0f )
    return;
 
  Float_t lim =  1.0f/fDistortion + fFixedRadius;
  Float_t* c = GetProjectedCenter();
  fUpLimit.Set(lim + c[0], lim + c[1], c[2]);
  fLowLimit.Set(-lim + c[0], -lim + c[1], c[2]);
}

//______________________________________________________________________________
void NLTProjection::SetDistortion(Float_t d)
{
  // Prevent scaling down whole projected scene.
  // Point at fixe distance shold be on constant screen coorinate. 

  fDistortion=d; 
  fScale = 1+fFixedRadius*fDistortion;
  UpdateLimit();
}

//______________________________________________________________________________
void NLTProjection::SetFixedRadius(Float_t r)
{

  fFixedRadius=r;
  fScale = 1+fFixedRadius*fDistortion;
  UpdateLimit();
}

//______________________________________________________________________________
void NLTProjection::SetDirectionalVector(Int_t screenAxis, Vector& vec)
{
  for (Int_t i=0; i<3; i++)
  {
    vec[i] = (i==screenAxis) ? 1. : 0.;
  }
}

//______________________________________________________________________________
Float_t NLTProjection::GetValForScreenPos(Int_t i, Float_t sv)
{
  // move on unprojected axis, find when projected value is geiven screen values(sv)
  static const Exc_t eH("NLTProjector::GetValForScreenPos ");

  Float_t xL, xM, xR;
  Vector V, DirVec;
  SetDirectionalVector(i, DirVec);
  if (fDistortion > 0.0f && ((sv > 0 && sv > fUpLimit[i]) || (sv < 0 && sv < fLowLimit[i])))
    throw(eH + Form("screen value '%f' out of limit '%f'.", sv, sv > 0 ? fUpLimit[i] : fLowLimit[i]));

  Vector zero; ProjectVector(zero);
  // printf("NLTProjection::GetValForScreenPos %d sv %f , zero %f\n",i,  sv, zero[i]);
  // search from -/+ infinity according to sign of screen value
  if (sv > zero[i])
  {
    xL = 0; xR = 1000;
    while (1)
    {
      V.Mult(DirVec, xR); ProjectVector(V);
      // printf("positive projected %f, value %f,xL, xR ( %f, %f)\n", V[i], sv, xL, xR);
      if (V[i] > sv || V[i] == sv) break;
      xL = xR; xR *= 2;
    }
  }
  else if (sv < zero[i])
  {
    xR = 0; xL = -1000;
{'fraction_non_alphanumeric': 0.138872225554889, 'fraction_numerical': 0.014697060587882423, 'mean_word_length': 4.466393442622951, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6926775', 'n_tokens_mistral': 2445, 'n_tokens_neox': 2328, 'n_words': 511}