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
...@@ -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;
}; };
// //
......
...@@ -11,7 +11,8 @@ CommandLine::CommandLine(int argc, char ** argv) ...@@ -11,7 +11,8 @@ 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);
...@@ -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
...@@ -72,8 +75,10 @@ void CommandLine::addOption(const std::string &name ...@@ -72,8 +75,10 @@ void CommandLine::addOption(const std::string &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 << "> ";
} }
...@@ -185,7 +195,8 @@ void CommandLine::help(std::ostream &out) const ...@@ -185,7 +195,8 @@ void CommandLine::help(std::ostream &out) const
{ {
out << " -- " out << " -- "
<< mDeclArgs[i].second << std::endl; << mDeclArgs[i].second << std::endl;
} else }
else
{ {
out << std::endl; out << std::endl;
} }
...@@ -254,7 +265,9 @@ bool CommandLine::validate(std::vector<std::string> &errors) const ...@@ -254,7 +265,9 @@ 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)
{ {
...@@ -263,7 +276,8 @@ bool CommandLine::validate(std::vector<std::string> &errors) const ...@@ -263,7 +276,8 @@ bool CommandLine::validate(std::vector<std::string> &errors) const
{ {
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) { if (tx_min > ty_min)
{
t_near = tx_min; t_near = tx_min;
//face_in = (a >= 0.0) ? 0 : 3; //face_in = (a >= 0.0) ? 0 : 3;
} else { }
else
{
t_near = ty_min; t_near = ty_min;
//face_in = (b >= 0.0) ? 1 : 4; //face_in = (b >= 0.0) ? 1 : 4;
} }
if (tz_min > t_near) { if (tz_min > t_near)
{
t_near = tz_min; t_near = tz_min;
//face_in = (c >= 0.0) ? 2 : 5; //face_in = (c >= 0.0) ? 2 : 5;
} }
//find smallest exiting t value //find smallest exiting t value
if (tx_max < ty_max) { if (tx_max < ty_max)
{
t_far = tx_max; t_far = tx_max;
//face_out = (a >= 0.0) ? 3 : 0; //face_out = (a >= 0.0) ? 3 : 0;
} else { }
else
{
t_far = ty_max; t_far = ty_max;
//face_out = (b >= 0.0) ? 4 : 1; //face_out = (b >= 0.0) ? 4 : 1;
} }
if (tz_max < t_far) { if (tz_max < t_far)
{
t_far = tz_max; t_far = tz_max;
//face_out = (c >= 0.0) ? 5 : 2; //face_out = (c >= 0.0) ? 5 : 2;
} }
if (t_near < t_far && t_far > kEpsilon) { if (t_near < t_far && t_far > kEpsilon)
if (t_near > kEpsilon) { {
if (t_near > kEpsilon)
{
t = t_near; t = t_near;
}else{ }
else
{
t = t_far; t = t_far;
} }
return true; return true;
...@@ -186,12 +235,14 @@ bool AABB::hit(const Ray& ray, Real& t) const { ...@@ -186,12 +235,14 @@ bool AABB::hit(const Ray& ray, Real& t) const {
return false; return false;