Functions
test_intersection.cxx File Reference
#include "WireCellUtil/Intersection.h"
#include "WireCellUtil/Testing.h"
#include <iostream>
#include <random>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

int main ( void  )

Definition at line 10 of file test_intersection.cxx.

11 {
12  {
13  Ray bounds(Point(-5, -500, -500), Point(5, 500, 500));
14  Ray line(Point(1, 0, -495), Point(1, 1, -495));
15  Ray hits;
16  int hitmask = box_intersection(bounds, line, hits);
17  cerr << "line: "<< line << " bounds:" << bounds << endl;
18  cerr << "got: " << hitmask << " " << hits<< endl;
19  Assert(hitmask == 3);
20  }
21 
22 
23  std::random_device rd;
24  std::default_random_engine re(rd());
25  std::uniform_real_distribution<> dist(-2, 2);
26 
27  Ray bounds(Point(-1,-1,-1), Point(1,1,1));
28  for (int ind = 0; ind<100; ++ind) {
29  Point p1(dist(re),dist(re),dist(re));
30  Point p2(dist(re),dist(re),dist(re));
31  Vector dir = (p2-p1).norm();
32 
33  cout << ind << " point=" << p1 << " dir=" << dir << endl;
34 
35  for (int axis=0; axis<3; ++axis) {
36  Ray hits;
37  int hitmask = hit_square(axis, bounds, p1, dir, hits);
38  cout << "\t axis=" << axis << " ["<<hitmask<<"]hits=" << hits << endl;
39  Assert(hitmask>=0);
40 
41  }
42 
43  {
44  Ray ray(p1,p2), hits;
45  int hitmask = box_intersection(bounds, ray, hits);
46  cout << "box: hitmask=" << hitmask << " ray=" << ray
47  << " hits=" << hits << endl;
49  AssertMsg(hitmask == 3, "Inside box, but not enough hits");
50  }
51  }
52  }
53 
54  return 0;
55 }
std::pair< Point, Point > Ray
A line segment running from a first (tail) to a second (head) point.
Definition: Point.h:21
string dir
#define Assert
Definition: Testing.h:7
int hit_square(int axis0, const Ray &bounds, const Point &point, const Vector &dir, Ray &hits)
Definition: Intersection.cxx:8
std::tuple< double, double, const reco::ClusterHit3D * > Point
Definitions used by the VoronoiDiagram algorithm.
Definition: DCEL.h:34
BoundingBox bounds(int x, int y, int w, int h)
Definition: main.cpp:37
auto norm(Vector const &v)
Return norm of the specified vector.
std::vector< float > Vector
#define AssertMsg
Definition: Testing.h:8
bool point_contained(const Point &point, const Ray &bounds)
Definition: Point.cxx:40
int box_intersection(const Ray &bounds, const Ray &ray, Ray &hits)
QTextStream & endl(QTextStream &s)