ROOT logo
// $Id: PSRectangle.cxx 2118 2009-01-11 21:31:58Z matevz $

// Copyright (C) 1999-2008, Matevz Tadel. All rights reserved.
// This file is part of GLED, released under GNU General Public License version 2.
// For the licensing terms see $GLEDSYS/LICENSE or http://www.gnu.org/.

//__________________________________________________________________________
// PSRectangle
//
//

#include "PSRectangle.h"
#include "PSRectangle.c7"
#include <Stones/GravData.h>

#include <Opcode/Opcode.h>

#include <TRandom.h>

ClassImp(PSRectangle);

/**************************************************************************/

void PSRectangle::_init()
{
  mMinX = 0; mMaxX = 1;
  mMinY = 0; mMaxY = 1;

  mEdgePlanes = new Opcode::Plane[4];
}

PSRectangle::PSRectangle(const Text_t* n, const Text_t* t) :
  ParaSurf(n,t)
{
  _init();
}

PSRectangle::~PSRectangle()
{
  delete [] mEdgePlanes;
}

/**************************************************************************/

void PSRectangle::SetupEdgePlanes()
{
  // !!! should be called from AdEnlightenment

  mEdgePlanes[0].Set( 0, -1, 0,  mMinY);
  mEdgePlanes[1].Set(-1,  0, 0,  mMinX);
  mEdgePlanes[2].Set( 0,  1, 0, -mMaxY);
  mEdgePlanes[3].Set( 1,  0, 0, -mMaxX);
}

/**************************************************************************/

Float_t PSRectangle::Surface()
{
  return (mMaxX - mMinX) * (mMaxY - mMinY);
}

/******************************************************************************/

void PSRectangle::origin_fgh(Float_t* f)
{
  f[0] = mMinX + 0.5f*(mMaxX - mMinX);
  f[1] = mMinY + 0.5f*(mMaxY - mMinY);
  f[2] = 0;
}

void PSRectangle::origin_pos(Float_t* x)
{
  x[0] = mMinX + 0.5f*(mMaxX - mMinX);
  x[1] = mMinY + 0.5f*(mMaxY - mMinY);
  x[2] = 0;
}

/**************************************************************************/

void PSRectangle::pos2fgh(const Float_t* x, Float_t* f)
{
  f[0] = x[0];
  f[1] = x[1];
  f[2] = x[2];
}

void PSRectangle::fgh2pos(const Float_t* f, Float_t* x)
{
  x[0] = f[0];
  x[1] = f[1];
  x[2] = f[2];
}

void PSRectangle::fgh2fdir(const Float_t* f, Float_t* d)
{
  d[0] = 1;
  d[1] = 0;
  d[2] = 0;
}

void PSRectangle::fgh2gdir(const Float_t* f, Float_t* d)
{
  d[0] = 0;
  d[1] = 1;
  d[2] = 0;
}

void PSRectangle::fgh2hdir(const Float_t* f, Float_t* d)
{
  d[0] = 0;
  d[1] = 0;
  d[2] = 1;
}

/**************************************************************************/

void PSRectangle::pos2hdir(const Float_t* x, Float_t* d)
{
  // Return 'up' direction.

  d[0] = 0;
  d[1] = 0;
  d[2] = 1;
}

Float_t PSRectangle::pos2hray(const Float_t* x, Opcode::Ray& r)
{
  // Setup ray r for given postition x so that the ray origin is above
  // the surface and its direction/lenght ascertain the surface will
  // be intersected.
  // Returns distance the ray-origin was shifted from initial pos.

  pos2hdir(x, r.mDir);
  Float_t dist = mMaxH - x[2] + mEpsilon;
  r.mOrig.Set(x);
  r.mOrig.TMac(r.mDir, dist);
  r.mDir.Neg();
  return dist;
}

/**************************************************************************/

void PSRectangle::pos2grav(const Float_t* x, GravData& gd)
{
  gd.fPos[0] = x[0]; gd.fPos[1] = x[1]; gd.fPos[2] = x[2];
  gd.fDir[0] = 0;    gd.fDir[1] = 0;    gd.fDir[2] = -1;
  gd.fMag  = mGravAtSurface;
  gd.fLDer = 0;
  gd.fTDer = 0;
  gd.fH    = x[2];
  gd.fDown[0] = gd.fDown[1] = 0; gd.fDown[2] = -1;
}

/**************************************************************************/

void PSRectangle::random_fgh(TRandom& rnd, Float_t* f)
{
  f[0] = rnd.Uniform(mMinY, mMaxY);
  f[1] = rnd.Uniform(mMinY, mMaxY);
  f[2] = 0;
}

void PSRectangle::random_pos(TRandom& rnd, Float_t* x)
{
  x[0] = rnd.Uniform(mMinX, mMaxX);
  x[1] = rnd.Uniform(mMinY, mMaxY);
  x[2] = 0;
}

/**************************************************************************/

void PSRectangle::wrap(Float_t* x, Int_t plane, Float_t dist)
{
  using namespace Opcode;

  Point& pos = *(Point*)x;

  Int_t opp_plane = (plane + 2) % 4;
  Plane& P = mEdgePlanes[plane];
  Plane& O = mEdgePlanes[opp_plane];

  Float_t opp_dist = O.Distance(pos);
  pos += dist * P.n - opp_dist * O.n;
}

/**************************************************************************/
 PSRectangle.cxx:1
 PSRectangle.cxx:2
 PSRectangle.cxx:3
 PSRectangle.cxx:4
 PSRectangle.cxx:5
 PSRectangle.cxx:6
 PSRectangle.cxx:7
 PSRectangle.cxx:8
 PSRectangle.cxx:9
 PSRectangle.cxx:10
 PSRectangle.cxx:11
 PSRectangle.cxx:12
 PSRectangle.cxx:13
 PSRectangle.cxx:14
 PSRectangle.cxx:15
 PSRectangle.cxx:16
 PSRectangle.cxx:17
 PSRectangle.cxx:18
 PSRectangle.cxx:19
 PSRectangle.cxx:20
 PSRectangle.cxx:21
 PSRectangle.cxx:22
 PSRectangle.cxx:23
 PSRectangle.cxx:24
 PSRectangle.cxx:25
 PSRectangle.cxx:26
 PSRectangle.cxx:27
 PSRectangle.cxx:28
 PSRectangle.cxx:29
 PSRectangle.cxx:30
 PSRectangle.cxx:31
 PSRectangle.cxx:32
 PSRectangle.cxx:33
 PSRectangle.cxx:34
 PSRectangle.cxx:35
 PSRectangle.cxx:36
 PSRectangle.cxx:37
 PSRectangle.cxx:38
 PSRectangle.cxx:39
 PSRectangle.cxx:40
 PSRectangle.cxx:41
 PSRectangle.cxx:42
 PSRectangle.cxx:43
 PSRectangle.cxx:44
 PSRectangle.cxx:45
 PSRectangle.cxx:46
 PSRectangle.cxx:47
 PSRectangle.cxx:48
 PSRectangle.cxx:49
 PSRectangle.cxx:50
 PSRectangle.cxx:51
 PSRectangle.cxx:52
 PSRectangle.cxx:53
 PSRectangle.cxx:54
 PSRectangle.cxx:55
 PSRectangle.cxx:56
 PSRectangle.cxx:57
 PSRectangle.cxx:58
 PSRectangle.cxx:59
 PSRectangle.cxx:60
 PSRectangle.cxx:61
 PSRectangle.cxx:62
 PSRectangle.cxx:63
 PSRectangle.cxx:64
 PSRectangle.cxx:65
 PSRectangle.cxx:66
 PSRectangle.cxx:67
 PSRectangle.cxx:68
 PSRectangle.cxx:69
 PSRectangle.cxx:70
 PSRectangle.cxx:71
 PSRectangle.cxx:72
 PSRectangle.cxx:73
 PSRectangle.cxx:74
 PSRectangle.cxx:75
 PSRectangle.cxx:76
 PSRectangle.cxx:77
 PSRectangle.cxx:78
 PSRectangle.cxx:79
 PSRectangle.cxx:80
 PSRectangle.cxx:81
 PSRectangle.cxx:82
 PSRectangle.cxx:83
 PSRectangle.cxx:84
 PSRectangle.cxx:85
 PSRectangle.cxx:86
 PSRectangle.cxx:87
 PSRectangle.cxx:88
 PSRectangle.cxx:89
 PSRectangle.cxx:90
 PSRectangle.cxx:91
 PSRectangle.cxx:92
 PSRectangle.cxx:93
 PSRectangle.cxx:94
 PSRectangle.cxx:95
 PSRectangle.cxx:96
 PSRectangle.cxx:97
 PSRectangle.cxx:98
 PSRectangle.cxx:99
 PSRectangle.cxx:100
 PSRectangle.cxx:101
 PSRectangle.cxx:102
 PSRectangle.cxx:103
 PSRectangle.cxx:104
 PSRectangle.cxx:105
 PSRectangle.cxx:106
 PSRectangle.cxx:107
 PSRectangle.cxx:108
 PSRectangle.cxx:109
 PSRectangle.cxx:110
 PSRectangle.cxx:111
 PSRectangle.cxx:112
 PSRectangle.cxx:113
 PSRectangle.cxx:114
 PSRectangle.cxx:115
 PSRectangle.cxx:116
 PSRectangle.cxx:117
 PSRectangle.cxx:118
 PSRectangle.cxx:119
 PSRectangle.cxx:120
 PSRectangle.cxx:121
 PSRectangle.cxx:122
 PSRectangle.cxx:123
 PSRectangle.cxx:124
 PSRectangle.cxx:125
 PSRectangle.cxx:126
 PSRectangle.cxx:127
 PSRectangle.cxx:128
 PSRectangle.cxx:129
 PSRectangle.cxx:130
 PSRectangle.cxx:131
 PSRectangle.cxx:132
 PSRectangle.cxx:133
 PSRectangle.cxx:134
 PSRectangle.cxx:135
 PSRectangle.cxx:136
 PSRectangle.cxx:137
 PSRectangle.cxx:138
 PSRectangle.cxx:139
 PSRectangle.cxx:140
 PSRectangle.cxx:141
 PSRectangle.cxx:142
 PSRectangle.cxx:143
 PSRectangle.cxx:144
 PSRectangle.cxx:145
 PSRectangle.cxx:146
 PSRectangle.cxx:147
 PSRectangle.cxx:148
 PSRectangle.cxx:149
 PSRectangle.cxx:150
 PSRectangle.cxx:151
 PSRectangle.cxx:152
 PSRectangle.cxx:153
 PSRectangle.cxx:154
 PSRectangle.cxx:155
 PSRectangle.cxx:156
 PSRectangle.cxx:157
 PSRectangle.cxx:158
 PSRectangle.cxx:159
 PSRectangle.cxx:160
 PSRectangle.cxx:161
 PSRectangle.cxx:162
 PSRectangle.cxx:163
 PSRectangle.cxx:164
 PSRectangle.cxx:165
 PSRectangle.cxx:166
 PSRectangle.cxx:167
 PSRectangle.cxx:168
 PSRectangle.cxx:169
 PSRectangle.cxx:170
 PSRectangle.cxx:171
 PSRectangle.cxx:172
 PSRectangle.cxx:173
 PSRectangle.cxx:174
 PSRectangle.cxx:175
 PSRectangle.cxx:176
 PSRectangle.cxx:177
 PSRectangle.cxx:178
 PSRectangle.cxx:179
 PSRectangle.cxx:180
 PSRectangle.cxx:181
 PSRectangle.cxx:182
 PSRectangle.cxx:183
 PSRectangle.cxx:184
 PSRectangle.cxx:185
 PSRectangle.cxx:186