Commit 5fcf362a authored by Peterson, Peter's avatar Peterson, Peter
Browse files

Copy files from master

parent eb9b841e
......@@ -129,9 +129,19 @@ void Track::addPoint(const TrackDirection direction, const V3D &endPoint,
const IObject &obj, const ComponentID compID) {
IntersectionPoint newPoint(
direction, endPoint, endPoint.distance(m_line.getOrigin()), obj, compID);
auto lowestPtr =
std::lower_bound(m_surfPoints.begin(), m_surfPoints.end(), newPoint);
m_surfPoints.insert(lowestPtr, newPoint);
if (m_surfPoints.empty()) {
m_surfPoints.push_back(newPoint);
} else {
auto lowestPtr =
std::lower_bound(m_surfPoints.begin(), m_surfPoints.end(), newPoint);
// Make sure same point isn't added twice
if (newPoint == *lowestPtr) {
return;
}
m_surfPoints.insert(lowestPtr, newPoint);
}
}
/**
......
......@@ -896,6 +896,133 @@ public:
TS_ASSERT_EQUALS(back_midpoint.totalDistInsideObject(), 1.5 * RADIUS);
}
void testTracksForSolidCylinder() {
// solid cylinder at the origin with the symmetry axis along y
// using PAC06 dimensions: 2.95mm radius x 5.68cm height
constexpr double RADIUS{0.00295};
constexpr double HEIGHT{0.0568};
V3D BOTTOM_CENTRE{0., -.5 * HEIGHT, 0.};
V3D AXIS_SYMM{0., 1., 0.};
auto cylinder = ComponentCreationHelper::createCappedCylinder(
RADIUS, HEIGHT, BOTTOM_CENTRE, AXIS_SYMM, "cyl");
const V3D BEAM_DIRECTION{0., 0., 1.}; // along z-axis
// centre of sample
Track origin(V3D{0., 0., 0.}, BEAM_DIRECTION);
cylinder->interceptSurface(origin);
TS_ASSERT_EQUALS(origin.totalDistInsideObject(), RADIUS);
constexpr double HALF_RADIUS{0.5 * RADIUS};
// Right midpoint between origin and radius (front wrt beam dir)
Track front_midpt(V3D{0., 0., HALF_RADIUS}, BEAM_DIRECTION);
cylinder->interceptSurface(front_midpt);
TS_ASSERT_EQUALS(front_midpt.totalDistInsideObject(), 0.5 * RADIUS);
// Left midpoint between origin and radius (back wrt beam dir)
Track back_midpt(V3D{0., 0., -HALF_RADIUS}, BEAM_DIRECTION);
cylinder->interceptSurface(back_midpt);
TS_ASSERT_EQUALS(back_midpt.totalDistInsideObject(), 1.5 * RADIUS);
// Put the cylinder with the symmetry axis along Z and repeat tests
AXIS_SYMM = V3D{0.0, 0.0, 1.0};
BOTTOM_CENTRE = V3D{0.0, 0.0, -0.5 * HEIGHT};
cylinder = ComponentCreationHelper::createCappedCylinder(
RADIUS, HEIGHT, BOTTOM_CENTRE, AXIS_SYMM, "cyl");
origin = Track(V3D{0.0, 0.0, 0.0}, BEAM_DIRECTION);
cylinder->interceptSurface(origin);
TS_ASSERT_EQUALS(origin.totalDistInsideObject(), 0.5 * HEIGHT);
// Front midpoint between origin and top (height/2)
front_midpt = Track(V3D{0., 0., 0.25 * HEIGHT}, BEAM_DIRECTION);
cylinder->interceptSurface(front_midpt);
TS_ASSERT_EQUALS(front_midpt.totalDistInsideObject(), 0.25 * HEIGHT);
// Back midpoint between origin and bottom (-height/2)
back_midpt = Track(V3D{0., 0., -0.25 * HEIGHT}, BEAM_DIRECTION);
cylinder->interceptSurface(back_midpt);
TS_ASSERT_EQUALS(back_midpt.totalDistInsideObject(), 0.75 * HEIGHT);
}
void testTracksForSolidCylinderAngle() {
// solid cylinder at origin with symmetry along y axis
// using PAC06 dimensions: 2.95mm radius x 5.68cm height
// Beam is hitting surface at 30, 45, and 60 degrees from the y-z axis
constexpr double RADIUS{0.00295};
constexpr double HEIGHT{0.05680};
constexpr double TOLERANCE{1.0e-10};
V3D BOTTOM_CENTRE{0., -.5 * HEIGHT, 0.};
V3D AXIS_SYMM{0., 1., 0.};
auto cylinder = ComponentCreationHelper::createCappedCylinder(
RADIUS, HEIGHT, BOTTOM_CENTRE, AXIS_SYMM, "cyl");
// Test sample at 30 degrees
V3D BEAM_DIRECTION{0.0, sin(30.0 * (M_PI / 180.0)),
cos(30.0 * (M_PI / 180.0))};
BEAM_DIRECTION.normalize();
double ANGLE{atan((BEAM_DIRECTION.Y()) / BEAM_DIRECTION.Z())};
// centre of sample
Track origin(V3D{0., 0., 0.}, BEAM_DIRECTION);
int nsegments = cylinder->interceptSurface(origin);
TS_ASSERT_EQUALS(nsegments, 1);
double base = origin.totalDistInsideObject() * (BEAM_DIRECTION.Z());
double height = base * tan(ANGLE);
TS_ASSERT_DELTA(origin.totalDistInsideObject(),
sqrt(pow(height, 2) + pow(base, 2)), TOLERANCE);
// Test sample at 45 degrees
BEAM_DIRECTION =
V3D{0.0, sin(45.0 * (M_PI / 180.0)), cos(45.0 * (M_PI / 180.0))};
BEAM_DIRECTION.normalize();
ANGLE = atan((BEAM_DIRECTION.Y()) / BEAM_DIRECTION.Z());
origin = Track(V3D{0., 0., 0.}, BEAM_DIRECTION);
nsegments = cylinder->interceptSurface(origin);
TS_ASSERT_EQUALS(nsegments, 1);
base = origin.totalDistInsideObject() * (BEAM_DIRECTION.Z());
height = base * tan(ANGLE);
TS_ASSERT_DELTA(origin.totalDistInsideObject(),
sqrt(pow(height, 2) + pow(base, 2)), TOLERANCE);
// Test sample at 60 degrees
BEAM_DIRECTION =
V3D{0.0, sin(60.0 * (M_PI / 180.0)), cos(60.0 * (M_PI / 180.0))};
BEAM_DIRECTION.normalize();
ANGLE = atan((BEAM_DIRECTION.Y()) / BEAM_DIRECTION.Z());
origin = Track(V3D{0., 0., 0.}, BEAM_DIRECTION);
nsegments = cylinder->interceptSurface(origin);
TS_ASSERT_EQUALS(nsegments, 1);
base = origin.totalDistInsideObject() * (BEAM_DIRECTION.Z());
height = base * tan(ANGLE);
TS_ASSERT_DELTA(origin.totalDistInsideObject(),
sqrt(pow(height, 2) + pow(base, 2)), TOLERANCE);
// Test sample at the top corner
BEAM_DIRECTION = V3D{0.0, HEIGHT * 0.5, RADIUS};
BEAM_DIRECTION.normalize();
ANGLE = atan((BEAM_DIRECTION.Y()) / BEAM_DIRECTION.Z());
origin = Track(V3D{0., 0., 0.}, BEAM_DIRECTION);
nsegments = cylinder->interceptSurface(origin);
TS_ASSERT_EQUALS(nsegments, 1);
// Since this is at the corner, triangle sides should be the same as the
// cylinder dimensions
TS_ASSERT_DELTA(origin.totalDistInsideObject(),
sqrt(pow(HEIGHT * 0.5, 2) + pow(RADIUS, 2)), TOLERANCE);
}
void testTracksForHollowCylinder() {
// hollow cylinder at the origin with the symmetry axis along y
// using PAC06 dimensions: 2.95mm inner radius, 3.15mm outer radius
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment