Commit d5588bc2 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Applying formatting options.

parent f28d7334
Pipeline #7407 passed with stages
in 22 minutes and 14 seconds
...@@ -50,10 +50,10 @@ int main(int argc, char **argv) ...@@ -50,10 +50,10 @@ int main(int argc, char **argv)
if(std::fabs(z) > 1e-16) if(std::fabs(z) > 1e-16)
{ {
sigma = 1.911515e-16 * (z * z * z * z) sigma = 1.911515e-16 * (z * z * z * z)
- 9.857582e-13 * (z * z * z) - 9.857582e-13 * (z * z * z)
+ 5.3399174e-9 * (z * z) + 5.3399174e-9 * (z * z)
- 1.180686e-4 * z - 1.180686e-4 * z
+ 1.22507; + 1.22507;
} }
// absorption/attenuation of gamma ray as it passes through air // absorption/attenuation of gamma ray as it passes through air
......
...@@ -10,7 +10,8 @@ TEST(radixbug, Timer) ...@@ -10,7 +10,8 @@ TEST(radixbug, Timer)
radix_timer_2(timer2); radix_timer_2(timer2);
radix_timer_3(timer3); radix_timer_3(timer3);
double value = 0; double value = 0;
auto func = [](double value)->double{ auto func = [](double value)->double
{
return value * value; return value * value;
}; };
// //
...@@ -29,17 +30,17 @@ TEST(radixbug, Timer) ...@@ -29,17 +30,17 @@ TEST(radixbug, Timer)
} }
radix_timer_stop(timer1); radix_timer_stop(timer1);
radix_timer_block(std::cout << "First Timer duration: " << timer1.duration() radix_timer_block(std::cout << "First Timer duration: " << timer1.duration()
<< " nanoseconds with " << " nanoseconds with "
<< timer1.intervals() << timer1.intervals()
<< " invervals" << std::endl); << " invervals" << std::endl);
radix_timer_block_2(std::cout << "Second Timer duration: " << timer2.duration() radix_timer_block_2(std::cout << "Second Timer duration: " << timer2.duration()
<< " nanoseconds with " << " nanoseconds with "
<< timer2.intervals() << timer2.intervals()
<< " invervals" << std::endl); << " invervals" << std::endl);
radix_timer_block_3(std::cout << "Third Timer duration: " << timer3.duration() radix_timer_block_3(std::cout << "Third Timer duration: " << timer3.duration()
<< " nanoseconds with " << " nanoseconds with "
<< timer3.intervals() << timer3.intervals()
<< " invervals" << std::endl); << " invervals" << std::endl);
EXPECT_EQ(timer1.intervals(), 1); EXPECT_EQ(timer1.intervals(), 1);
EXPECT_EQ(timer2.intervals(), 100); EXPECT_EQ(timer2.intervals(), 100);
......
...@@ -11,10 +11,11 @@ CommandLine::CommandLine(int argc, char ** argv) ...@@ -11,10 +11,11 @@ CommandLine::CommandLine(int argc, char ** argv)
{ {
if(argc < 1) return; if(argc < 1) return;
mExecutable = argv[0]; mExecutable = argv[0];
for (int i = 1; i < argc; i++) { for (int i = 1; i < argc; i++)
{
std::string temp = std::string(argv[i]); std::string temp = std::string(argv[i]);
std::tuple<std::string, std::string, bool> data std::tuple<std::string, std::string, bool> data
= std::make_tuple("", "", false); = std::make_tuple("", "", false);
// //
// Check for '-' as first character // Check for '-' as first character
// //
...@@ -27,13 +28,15 @@ CommandLine::CommandLine(int argc, char ** argv) ...@@ -27,13 +28,15 @@ CommandLine::CommandLine(int argc, char ** argv)
// //
size_t index = temp.find('='); size_t index = temp.find('=');
if (index == std::string::npos) if (index == std::string::npos)
{//we didn't find equal sign {
//we didn't find equal sign
// //
// This is just a flag with empty value // This is just a flag with empty value
// //
std::get<0>(data) = std::string(""); std::get<0>(data) = std::string("");
mData.insert(std::make_pair(temp.substr(1), data)); mData.insert(std::make_pair(temp.substr(1), data));
} else }
else
{ {
// //
// We found equal sign, so we must divide into flag and value // We found equal sign, so we must divide into flag and value
...@@ -70,10 +73,12 @@ void CommandLine::addOption(const std::string &name ...@@ -70,10 +73,12 @@ void CommandLine::addOption(const std::string &name
// create a new tuple with no value // create a new tuple with no value
mData.insert(std::make_pair(name, mData.insert(std::make_pair(name,
std::make_tuple(std::string("") std::make_tuple(std::string("")
, description , description
, required))); , required)));
} else }
{ // update existing entry else
{
// update existing entry
std::get<1>(it->second) = description; std::get<1>(it->second) = description;
std::get<2>(it->second) = required; std::get<2>(it->second) = required;
} }
...@@ -104,12 +109,14 @@ void CommandLine::printParsedLine(std::ostream &out) const ...@@ -104,12 +109,14 @@ void CommandLine::printParsedLine(std::ostream &out) const
if(required) if(required)
{ {
out << "[" << it.first << "] " << value; out << "[" << it.first << "] " << value;
} else }
else
{ {
out << "<" << it.first << "> " << value; out << "<" << it.first << "> " << value;
} }
out << " -- " << std::get<1>(it.second) << std::endl; out << " -- " << std::get<1>(it.second) << std::endl;
} else }
else
{ {
out << "*" << it.first << " " << value << std::endl; out << "*" << it.first << " " << value << std::endl;
} }
...@@ -121,7 +128,8 @@ void CommandLine::printParsedLine(std::ostream &out) const ...@@ -121,7 +128,8 @@ void CommandLine::printParsedLine(std::ostream &out) const
{ {
out << "\t" << mArgs[i] << std::endl; out << "\t" << mArgs[i] << std::endl;
} }
} else }
else
{ {
out << "No arguments." << std::endl; out << "No arguments." << std::endl;
} }
...@@ -147,7 +155,8 @@ void CommandLine::help(std::ostream &out) const ...@@ -147,7 +155,8 @@ void CommandLine::help(std::ostream &out) const
if(required) if(required)
{ {
out << " [-" << it.first << "=var]"; out << " [-" << it.first << "=var]";
} else }
else
{ {
out << " <-" << it.first << "<=var>>"; out << " <-" << it.first << "<=var>>";
} }
...@@ -171,7 +180,8 @@ void CommandLine::help(std::ostream &out) const ...@@ -171,7 +180,8 @@ void CommandLine::help(std::ostream &out) const
if(required) if(required)
{ {
out << "[" << it.first << "] "; out << "[" << it.first << "] ";
} else }
else
{ {
out << "<" << it.first << "> "; out << "<" << it.first << "> ";
} }
...@@ -183,9 +193,10 @@ void CommandLine::help(std::ostream &out) const ...@@ -183,9 +193,10 @@ void CommandLine::help(std::ostream &out) const
out << "\t" << mDeclArgs[i].first; out << "\t" << mDeclArgs[i].first;
if(!mDeclArgs[i].second.empty()) if(!mDeclArgs[i].second.empty())
{ {
out << " -- " out << " -- "
<< mDeclArgs[i].second << std::endl; << mDeclArgs[i].second << std::endl;
} else }
else
{ {
out << std::endl; out << std::endl;
} }
...@@ -254,16 +265,19 @@ bool CommandLine::validate(std::vector<std::string> &errors) const ...@@ -254,16 +265,19 @@ bool CommandLine::validate(std::vector<std::string> &errors) const
if((mDeclArgs.size() - mArgs.size())==1) if((mDeclArgs.size() - mArgs.size())==1)
{ {
ss << " '" << mDeclArgs[mArgs.size()].first << "'"; ss << " '" << mDeclArgs[mArgs.size()].first << "'";
} else { }
else
{
ss << "s:" << std::endl; ss << "s:" << std::endl;
for(size_t i = mArgs.size(); i < mDeclArgs.size(); ++i) for(size_t i = mArgs.size(); i < mDeclArgs.size(); ++i)
{ {
ss << "\t'" << mDeclArgs[i].first; ss << "\t'" << mDeclArgs[i].first;
if(!mDeclArgs[i].second.empty()) if(!mDeclArgs[i].second.empty())
{ {
ss << "' -- " ss << "' -- "
<< mDeclArgs[i].second << std::endl; << mDeclArgs[i].second << std::endl;
} else }
else
{ {
ss << "'" << std::endl; ss << "'" << std::endl;
} }
...@@ -296,7 +310,8 @@ std::string CommandLine::get(const std::string& name) const ...@@ -296,7 +310,8 @@ std::string CommandLine::get(const std::string& name) const
std::stringstream ss; std::stringstream ss;
ss << "No such option: " << name; ss << "No such option: " << name;
throw std::logic_error(ss.str()); throw std::logic_error(ss.str());
} else }
else
{ {
std::string value = std::get<0>(it->second); std::string value = std::get<0>(it->second);
if(value.empty()) if(value.empty())
......
...@@ -17,7 +17,8 @@ return_type CommandLine::get(const std::string& name) const ...@@ -17,7 +17,8 @@ return_type CommandLine::get(const std::string& name) const
std::stringstream ss; std::stringstream ss;
ss << "No such option: " << name; ss << "No such option: " << name;
throw std::logic_error(ss.str()); throw std::logic_error(ss.str());
} else }
else
{ {
std::string value = std::get<0>(it->second); std::string value = std::get<0>(it->second);
if(value.empty()) if(value.empty())
......
...@@ -22,7 +22,8 @@ TEST(radixcommand, mixed) ...@@ -22,7 +22,8 @@ TEST(radixcommand, mixed)
(char*)"-M=machine.txt", (char*)"-M=machine.txt",
(char*)"-load=3.4", (char*)"-load=3.4",
(char*)"-flag", (char*)"-flag",
(char*)"inputB"}; (char*)"inputB"
};
CommandLine line(fake_argc, fake_argv); CommandLine line(fake_argc, fake_argv);
line.addOption("o" line.addOption("o"
, "Output filepath, whitespace must be escaped." , "Output filepath, whitespace must be escaped."
...@@ -50,7 +51,8 @@ TEST(radixcommand, declared) ...@@ -50,7 +51,8 @@ TEST(radixcommand, declared)
{ {
int fake_argc = 2; int fake_argc = 2;
char * fake_argv[] = {(char*)("/Users/jap/build/release/dummy"), char * fake_argv[] = {(char*)("/Users/jap/build/release/dummy"),
(char*)"-o=path/to a/file"}; (char*)"-o=path/to a/file"
};
CommandLine line(fake_argc, fake_argv); CommandLine line(fake_argc, fake_argv);
line.declareArgument("input", "Path to input file."); line.declareArgument("input", "Path to input file.");
line.addOption("o" line.addOption("o"
...@@ -84,7 +86,8 @@ TEST(radixcommand, args) ...@@ -84,7 +86,8 @@ TEST(radixcommand, args)
(char*)"inputA", (char*)"inputA",
(char*)"machine.txt", (char*)"machine.txt",
(char*)"3.4", (char*)"3.4",
(char*)"input 6"}; (char*)"input 6"
};
CommandLine line(fake_argc, fake_argv); CommandLine line(fake_argc, fake_argv);
std::string a0 = line.arg<std::string>(0); std::string a0 = line.arg<std::string>(0);
......
...@@ -14,24 +14,29 @@ ...@@ -14,24 +14,29 @@
namespace radix namespace radix
{ {
AABB::AABB(void) AABB::AABB(void)
: x0(-1), x1(1), y0(-1), y1(1), z0(-1), z1(1) { : x0(-1), x1(1), y0(-1), y1(1), z0(-1), z1(1)
{
} }
AABB::AABB(const Real _x0, const Real _x1, AABB::AABB(const Real _x0, const Real _x1,
const Real _y0, const Real _y1, const Real _y0, const Real _y1,
const Real _z0, const Real _z1) const Real _z0, const Real _z1)
: x0(_x0), x1(_x1), y0(_y0), y1(_y1), z0(_z0), z1(_z1) { : x0(_x0), x1(_x1), y0(_y0), y1(_y1), z0(_z0), z1(_z1)
{
} }
AABB::AABB(const Point3D p0, const Point3D p1) AABB::AABB(const Point3D p0, const Point3D p1)
: x0(p0.x), x1(p1.x), y0(p0.y), y1(p1.y), z0(p0.z), z1(p1.z) { : x0(p0.x), x1(p1.x), y0(p0.y), y1(p1.y), z0(p0.z), z1(p1.z)
{
} }
AABB::AABB(const AABB& aabb) AABB::AABB(const AABB& aabb)
: x0(aabb.x0), x1(aabb.x1), y0(aabb.y0), y1(aabb.y1), z0(aabb.z0), z1(aabb.z1) { : x0(aabb.x0), x1(aabb.x1), y0(aabb.y0), y1(aabb.y1), z0(aabb.z0), z1(aabb.z1)
{
} }
AABB& AABB::operator=(const AABB& rhs) { AABB& AABB::operator=(const AABB& rhs)
{
if (this == &rhs) if (this == &rhs)
return (*this); return (*this);
...@@ -45,76 +50,102 @@ AABB& AABB::operator=(const AABB& rhs) { ...@@ -45,76 +50,102 @@ AABB& AABB::operator=(const AABB& rhs) {
return (*this); return (*this);
}//operation= }//operation=
AABB::~AABB(void) { AABB::~AABB(void)
{
} }
bool AABB::hit(const Ray& ray, Real& t) const { bool AABB::hit(const Ray& ray, Real& t) const
{
Real tx_min, ty_min, tz_min; Real tx_min, ty_min, tz_min;
Real tx_max, ty_max, tz_max; Real tx_max, ty_max, tz_max;
Real t_near, t_far; Real t_near, t_far;
if( ray.d.x == 1 || ray.d.x == -1){ if( ray.d.x == 1 || ray.d.x == -1)
{
if( ray.o.y < y0 || ray.o.y > y1 ) return false; if( ray.o.y < y0 || ray.o.y > y1 ) return false;
if( ray.o.z < z0 || ray.o.z > z1 ) return false; if( ray.o.z < z0 || ray.o.z > z1 ) return false;
if( ray.d.x > 0 ){ if( ray.d.x > 0 )
{
tx_min = (x0-ray.o.x) * ray.d.x; tx_min = (x0-ray.o.x) * ray.d.x;
tx_max = (x1-ray.o.x) * ray.d.x; tx_max = (x1-ray.o.x) * ray.d.x;
}else{ }
else
{
tx_min = (x1-ray.o.x) * ray.d.x; tx_min = (x1-ray.o.x) * ray.d.x;
tx_max = (x0-ray.o.x) * ray.d.x; tx_max = (x0-ray.o.x) * ray.d.x;
} }
if( tx_max < kEpsilon ) return false; if( tx_max < kEpsilon ) return false;
if( tx_min <= kEpsilon ){ if( tx_min <= kEpsilon )
{
t = tx_max; t = tx_max;
}else{ }
else
{
t = tx_min; t = tx_min;
} }
return true; return true;
} }
if( ray.d.y == 1 || ray.d.y == -1){ if( ray.d.y == 1 || ray.d.y == -1)
{
if( ray.o.x < x0 || ray.o.x > x1 ) return false; if( ray.o.x < x0 || ray.o.x > x1 ) return false;
if( ray.o.z < z0 || ray.o.z > z1 ) return false; if( ray.o.z < z0 || ray.o.z > z1 ) return false;
if( ray.d.y > 0 ){ if( ray.d.y > 0 )
{
ty_min = (y0-ray.o.y) * ray.d.y; ty_min = (y0-ray.o.y) * ray.d.y;
ty_max = (y1-ray.o.y) * ray.d.y; ty_max = (y1-ray.o.y) * ray.d.y;
}else{ }
else
{
ty_min = (y1-ray.o.y) * ray.d.y; ty_min = (y1-ray.o.y) * ray.d.y;
ty_max = (y0-ray.o.y) * ray.d.y; ty_max = (y0-ray.o.y) * ray.d.y;
} }
if( ty_max < kEpsilon ) return false; if( ty_max < kEpsilon ) return false;
if( ty_min <= kEpsilon ){ if( ty_min <= kEpsilon )
{
t = ty_max; t = ty_max;
}else{ }
else
{
t = ty_min; t = ty_min;
} }
return true; return true;
} }
if( ray.d.z == 1 || ray.d.z == -1 ){ if( ray.d.z == 1 || ray.d.z == -1 )
{
if( ray.o.y < y0 || ray.o.y > y1 ) return false; if( ray.o.y < y0 || ray.o.y > y1 ) return false;
if( ray.o.x < x0 || ray.o.x > x1 ) return false; if( ray.o.x < x0 || ray.o.x > x1 ) return false;
if( ray.d.z > 0 ){ if( ray.d.z > 0 )
{
tz_min = (z0-ray.o.z) * ray.d.z; tz_min = (z0-ray.o.z) * ray.d.z;
tz_max = (z1-ray.o.z) * ray.d.z; tz_max = (z1-ray.o.z) * ray.d.z;
}else{ }
else
{
tz_min = (z1-ray.o.z) * ray.d.z; tz_min = (z1-ray.o.z) * ray.d.z;
tz_max = (z0-ray.o.z) * ray.d.z; tz_max = (z0-ray.o.z) * ray.d.z;
} }
if( tz_max < kEpsilon ) return false; if( tz_max < kEpsilon ) return false;
if( tz_min <= kEpsilon ){ if( tz_min <= kEpsilon )
{
t = tz_max; t = tz_max;
}else{ }
else
{
t = tz_min; t = tz_min;
} }
return true; return true;
} }
Real a = 1.0 / ray.d.x; Real a = 1.0 / ray.d.x;
if (a >= 0) { if (a >= 0)
{
Real a1 = x0 - ray.o.x; Real a1 = x0 - ray.o.x;
Real a2 = x1 - ray.o.x; Real a2 = x1 - ray.o.x;
tx_min = (a1) * a; tx_min = (a1) * a;
tx_max = (a2) * a; tx_max = (a2) * a;
} else { }
else
{
Real a1 = x0 - ray.o.x; Real a1 = x0 - ray.o.x;
Real a2 = x1 - ray.o.x; Real a2 = x1 - ray.o.x;
tx_min = (a2) * a; tx_min = (a2) * a;
...@@ -122,12 +153,15 @@ bool AABB::hit(const Ray& ray, Real& t) const { ...@@ -122,12 +153,15 @@ bool AABB::hit(const Ray& ray, Real& t) const {
} }
Real b = 1.0 / ray.d.y; Real b = 1.0 / ray.d.y;
if (b >= 0) { if (b >= 0)
{
Real b1 = y0 - ray.o.y; Real b1 = y0 - ray.o.y;
Real b2 = y1 - ray.o.y; Real b2 = y1 - ray.o.y;
ty_min = (b1) * b; ty_min = (b1) * b;
ty_max = (b2) * b; ty_max = (b2) * b;
} else { }
else
{
Real b1 = y0 - ray.o.y; Real b1 = y0 - ray.o.y;
Real b2 = y1 - ray.o.y; Real b2 = y1 - ray.o.y;
ty_min = (b2) * b; ty_min = (b2) * b;
...@@ -135,12 +169,15 @@ bool AABB::hit(const Ray& ray, Real& t) const { ...@@ -135,12 +169,15 @@ bool AABB::hit(const Ray& ray, Real& t) const {
} }
Real c = 1.0 / ray.d.z; Real c = 1.0 / ray.d.z;
if (c >= 0) { if (c >= 0)
{
Real c1 = z0 - ray.o.z; Real c1 = z0 - ray.o.z;
Real c2 = z1 - ray.o.z; Real c2 = z1 - ray.o.z;
tz_min = (c1) * c; tz_min = (c1) * c;
tz_max = (c2) * c; tz_max = (c2) * c;
} else { }
else
{
Real c1 = z0 - ray.o.z; Real c1 = z0 - ray.o.z;
Real c2 = z1 - ray.o.z; Real c2 = z1 - ray.o.z;
tz_min = (c2) * c; tz_min = (c2) * c;
...@@ -150,35 +187,47 @@ bool AABB::hit(const Ray& ray, Real& t) const { ...@@ -150,35 +187,47 @@ bool AABB::hit(const Ray& ray, Real& t) const {
//int face_in, face_out; //int face_in, face_out;
// find the largest entering t value // find the largest entering t value
if (tx_min > ty_min) {