Commit fe72c2da authored by Kendrick, Coleman's avatar Kendrick, Coleman Committed by Peterson, Peter
Browse files

Link sum function, changed sphere tests to use it

parent 3662271b
......@@ -171,6 +171,8 @@ public:
const Kernel::V3D &startPoint() const { return m_line.getOrigin(); }
/// Returns the direction as a unit vector
const Kernel::V3D &direction() const { return m_line.getDirect(); }
/// Returns the sum of all the links distInsideObject in the track
double totalDistInsideObject() const;
/// Returns an interator to the start of the set of links
LType::iterator begin() { return m_links.begin(); }
/// Returns an interator to one-past-the-end of the set of links
......
......@@ -235,6 +235,13 @@ void Track::buildLink() {
m_surfPoints.clear();
}
double Track::totalDistInsideObject() const {
return std::accumulate(m_links.begin(), m_links.end(), 0.,
[](double total, const auto &link) {
return total + link.distInsideObject;
});
}
std::ostream &operator<<(std::ostream &os, TrackDirection direction) {
switch (direction) {
case TrackDirection::ENTERING:
......
......@@ -859,41 +859,41 @@ public:
// Test center of sphere
Track origin(V3D{0.0, 0.0, 0.0}, BEAM_X);
sphere->interceptSurface(origin);
TS_ASSERT_EQUALS(origin.front().distInsideObject, RADIUS);
TS_ASSERT_EQUALS(origin.totalDistInsideObject(), RADIUS);
Track front_midpoint(V3D{0.5*RADIUS, 0.0, 0.0}, BEAM_X);
sphere->interceptSurface(front_midpoint);
TS_ASSERT_EQUALS(front_midpoint.front().distInsideObject, 0.5*RADIUS);
TS_ASSERT_EQUALS(front_midpoint.totalDistInsideObject(), 0.5*RADIUS);
Track back_midpoint(V3D{-0.5*RADIUS, 0.0, 0.0}, BEAM_X);
sphere->interceptSurface(back_midpoint);
TS_ASSERT_EQUALS(back_midpoint.front().distInsideObject, 1.5*RADIUS);
TS_ASSERT_EQUALS(back_midpoint.totalDistInsideObject(), 1.5*RADIUS);
// Y axis tests
origin = Track(V3D{0.0, 0.0, 0.0}, BEAM_Y);
sphere->interceptSurface(origin);
TS_ASSERT_EQUALS(origin.front().distInsideObject, RADIUS);
TS_ASSERT_EQUALS(origin.totalDistInsideObject(), RADIUS);
front_midpoint = Track(V3D{0.0, 0.5*RADIUS, 0.0}, BEAM_Y);
sphere->interceptSurface(front_midpoint);
TS_ASSERT_EQUALS(front_midpoint.front().distInsideObject, 0.5*RADIUS);
TS_ASSERT_EQUALS(front_midpoint.totalDistInsideObject(), 0.5*RADIUS);
back_midpoint = Track(V3D{0.0, -0.5*RADIUS, 0.0}, BEAM_Y);
sphere->interceptSurface(back_midpoint);
TS_ASSERT_EQUALS(back_midpoint.front().distInsideObject, 1.5*RADIUS);
TS_ASSERT_EQUALS(back_midpoint.totalDistInsideObject(), 1.5*RADIUS);
// Z axis tests
origin = Track(V3D{0.0, 0.0, 0.0}, BEAM_Z);
sphere->interceptSurface(origin);
TS_ASSERT_EQUALS(origin.front().distInsideObject, RADIUS);
TS_ASSERT_EQUALS(origin.totalDistInsideObject(), RADIUS);
front_midpoint = Track(V3D{0.0, 0.0, 0.5*RADIUS}, BEAM_Z);
sphere->interceptSurface(front_midpoint);
TS_ASSERT_EQUALS(front_midpoint.front().distInsideObject, 0.5*RADIUS);
TS_ASSERT_EQUALS(front_midpoint.totalDistInsideObject(), 0.5*RADIUS);
back_midpoint = Track(V3D{0.0, 0.0, -0.5*RADIUS}, BEAM_Z);
sphere->interceptSurface(back_midpoint);
TS_ASSERT_EQUALS(back_midpoint.front().distInsideObject, 1.5*RADIUS);
TS_ASSERT_EQUALS(back_midpoint.totalDistInsideObject(), 1.5*RADIUS);
}
void testGeneratePointInsideSphere() {
......
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