File: PlanesTest.cpp

package info (click to toggle)
vecgeom 1.2.8%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 24,016 kB
  • sloc: cpp: 88,803; ansic: 6,888; python: 1,035; sh: 582; sql: 538; makefile: 23
file content (52 lines) | stat: -rw-r--r-- 2,067 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include "VecGeom/base/Vector3D.h"
#include "VecGeom/base/Stopwatch.h"
#include "VecGeom/volumes/Box.h"
#include "VecGeom/volumes/Planes.h"
#include "VecGeom/volumes/utilities/VolumeUtilities.h"

using namespace vecgeom;

int StaticPlanes()
{
  Planes planes(6);
  planes.Set(0, Vector3D<Precision>(0, 0, 1), Vector3D<Precision>(0, 0, 1));
  planes.Set(1, Vector3D<Precision>(0, 0, -1), Vector3D<Precision>(0, 0, -1));
  planes.Set(2, Vector3D<Precision>(1, 0, 0), Vector3D<Precision>(1, 0, 0));
  planes.Set(3, Vector3D<Precision>(-1, 0, 0), Vector3D<Precision>(-1, 0, 0));
  planes.Set(4, Vector3D<Precision>(0, 1, 0), Vector3D<Precision>(0, 1, 0));
  planes.Set(5, Vector3D<Precision>(0, -1, 0), Vector3D<Precision>(0, -1, 0));
  SimpleBox die("die", 1, 1, 1);
  std::cout << planes;
  const Vector3D<Precision> sampleBounds(2., 2., 2.);
  constexpr int nPoints = 1024;
  int mismatches        = 0;
  for (int i = 0; i < nPoints; ++i) {
    Vector3D<Precision> point     = volumeUtilities::SamplePoint(sampleBounds);
    Vector3D<Precision> direction = volumeUtilities::SampleDirection();
    Inside_t insidePlanes         = planes.Inside<Precision, Inside_t>(point);
    Inside_t insideDie            = die.Inside(point);
    if (insidePlanes != insideDie) {
      ++mismatches;
      std::cout << "Inside mismatch for " << point << ": " << insidePlanes << " / " << insideDie << "\n";
    } else {
      if (insidePlanes == vecgeom::EInside::kInside) {
        Precision distancePlanes = planes.Distance<Precision>(point, direction);
        Precision distanceDie    = die.DistanceToOut(point, direction);
        if (Abs(distancePlanes - distanceDie) > kTolerance) {
          ++mismatches;
          std::cout << "DistanceToOut mismatch for " << point << "--" << direction << ": " << distancePlanes << " / "
                    << distanceDie << "\n";
        }
      }
    }
  }
  std::cout << "Mismatches: " << mismatches << " / " << nPoints << "\n";
  return mismatches > 0;
}

int main()
{
  bool error = false;
  error |= StaticPlanes();
  return error;
}