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)
if(std::fabs(z) > 1e-16)
{
sigma = 1.911515e-16 * (z * z * z * z)
- 9.857582e-13 * (z * z * z)
+ 5.3399174e-9 * (z * z)
- 1.180686e-4 * z
+ 1.22507;
- 9.857582e-13 * (z * z * z)
+ 5.3399174e-9 * (z * z)
- 1.180686e-4 * z
+ 1.22507;
}
// absorption/attenuation of gamma ray as it passes through air
......
......@@ -10,7 +10,8 @@ TEST(radixbug, Timer)
radix_timer_2(timer2);
radix_timer_3(timer3);
double value = 0;
auto func = [](double value)->double{
auto func = [](double value)->double
{
return value * value;
};
//
......@@ -29,17 +30,17 @@ TEST(radixbug, Timer)
}
radix_timer_stop(timer1);
radix_timer_block(std::cout << "First Timer duration: " << timer1.duration()
<< " nanoseconds with "
<< timer1.intervals()
<< " invervals" << std::endl);
<< " nanoseconds with "
<< timer1.intervals()
<< " invervals" << std::endl);
radix_timer_block_2(std::cout << "Second Timer duration: " << timer2.duration()
<< " nanoseconds with "
<< timer2.intervals()
<< " invervals" << std::endl);
<< " nanoseconds with "
<< timer2.intervals()
<< " invervals" << std::endl);
radix_timer_block_3(std::cout << "Third Timer duration: " << timer3.duration()
<< " nanoseconds with "
<< timer3.intervals()
<< " invervals" << std::endl);
<< " nanoseconds with "
<< timer3.intervals()
<< " invervals" << std::endl);
EXPECT_EQ(timer1.intervals(), 1);
EXPECT_EQ(timer2.intervals(), 100);
......
......@@ -11,10 +11,11 @@ CommandLine::CommandLine(int argc, char ** argv)
{
if(argc < 1) return;
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::tuple<std::string, std::string, bool> data
= std::make_tuple("", "", false);
= std::make_tuple("", "", false);
//
// Check for '-' as first character
//
......@@ -27,13 +28,15 @@ CommandLine::CommandLine(int argc, char ** argv)
//
size_t index = temp.find('=');
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
//
std::get<0>(data) = std::string("");
mData.insert(std::make_pair(temp.substr(1), data));
} else
}
else
{
//
// We found equal sign, so we must divide into flag and value
......@@ -70,10 +73,12 @@ void CommandLine::addOption(const std::string &name
// create a new tuple with no value
mData.insert(std::make_pair(name,
std::make_tuple(std::string("")
, description
, required)));
} else
{ // update existing entry
, description
, required)));
}
else
{
// update existing entry
std::get<1>(it->second) = description;
std::get<2>(it->second) = required;
}
......@@ -104,12 +109,14 @@ void CommandLine::printParsedLine(std::ostream &out) const
if(required)
{
out << "[" << it.first << "] " << value;
} else
}
else
{
out << "<" << it.first << "> " << value;
}
out << " -- " << std::get<1>(it.second) << std::endl;
} else
}
else
{
out << "*" << it.first << " " << value << std::endl;
}
......@@ -121,7 +128,8 @@ void CommandLine::printParsedLine(std::ostream &out) const
{
out << "\t" << mArgs[i] << std::endl;
}
} else
}
else
{
out << "No arguments." << std::endl;
}
......@@ -147,7 +155,8 @@ void CommandLine::help(std::ostream &out) const
if(required)
{
out << " [-" << it.first << "=var]";
} else
}
else
{
out << " <-" << it.first << "<=var>>";
}
......@@ -171,7 +180,8 @@ void CommandLine::help(std::ostream &out) const
if(required)
{
out << "[" << it.first << "] ";
} else
}
else
{
out << "<" << it.first << "> ";
}
......@@ -183,9 +193,10 @@ void CommandLine::help(std::ostream &out) const
out << "\t" << mDeclArgs[i].first;
if(!mDeclArgs[i].second.empty())
{
out << " -- "
<< mDeclArgs[i].second << std::endl;
} else
out << " -- "
<< mDeclArgs[i].second << std::endl;
}
else
{
out << std::endl;
}
......@@ -254,16 +265,19 @@ bool CommandLine::validate(std::vector<std::string> &errors) const
if((mDeclArgs.size() - mArgs.size())==1)
{
ss << " '" << mDeclArgs[mArgs.size()].first << "'";
} else {
}
else
{
ss << "s:" << std::endl;
for(size_t i = mArgs.size(); i < mDeclArgs.size(); ++i)
{
ss << "\t'" << mDeclArgs[i].first;
if(!mDeclArgs[i].second.empty())
{
ss << "' -- "
<< mDeclArgs[i].second << std::endl;
} else
ss << "' -- "
<< mDeclArgs[i].second << std::endl;
}
else
{
ss << "'" << std::endl;
}
......@@ -296,7 +310,8 @@ std::string CommandLine::get(const std::string& name) const
std::stringstream ss;
ss << "No such option: " << name;
throw std::logic_error(ss.str());
} else
}
else
{
std::string value = std::get<0>(it->second);
if(value.empty())
......
......@@ -17,7 +17,8 @@ return_type CommandLine::get(const std::string& name) const
std::stringstream ss;
ss << "No such option: " << name;
throw std::logic_error(ss.str());
} else
}
else
{
std::string value = std::get<0>(it->second);
if(value.empty())
......
......@@ -22,7 +22,8 @@ TEST(radixcommand, mixed)
(char*)"-M=machine.txt",
(char*)"-load=3.4",
(char*)"-flag",
(char*)"inputB"};
(char*)"inputB"
};
CommandLine line(fake_argc, fake_argv);
line.addOption("o"
, "Output filepath, whitespace must be escaped."
......@@ -50,7 +51,8 @@ TEST(radixcommand, declared)
{
int fake_argc = 2;
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);
line.declareArgument("input", "Path to input file.");
line.addOption("o"
......@@ -84,7 +86,8 @@ TEST(radixcommand, args)
(char*)"inputA",
(char*)"machine.txt",
(char*)"3.4",
(char*)"input 6"};
(char*)"input 6"
};
CommandLine line(fake_argc, fake_argv);
std::string a0 = line.arg<std::string>(0);
......
......@@ -14,24 +14,29 @@
namespace radix
{
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,
const Real _y0, const Real _y1,
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)
: 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)
: 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)
return (*this);
......@@ -45,76 +50,102 @@ AABB& AABB::operator=(const AABB& rhs) {
return (*this);
}//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_max, ty_max, tz_max;
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.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_max = (x1-ray.o.x) * ray.d.x;
}else{
}
else
{
tx_min = (x1-ray.o.x) * ray.d.x;
tx_max = (x0-ray.o.x) * ray.d.x;
}
if( tx_max < kEpsilon ) return false;
if( tx_min <= kEpsilon ){
if( tx_min <= kEpsilon )
{
t = tx_max;
}else{
}
else
{
t = tx_min;
}
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.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_max = (y1-ray.o.y) * ray.d.y;
}else{
}
else
{
ty_min = (y1-ray.o.y) * ray.d.y;
ty_max = (y0-ray.o.y) * ray.d.y;
}
if( ty_max < kEpsilon ) return false;
if( ty_min <= kEpsilon ){
if( ty_min <= kEpsilon )
{
t = ty_max;
}else{
}
else
{
t = ty_min;
}
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.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_max = (z1-ray.o.z) * ray.d.z;
}else{
}
else
{
tz_min = (z1-ray.o.z) * ray.d.z;
tz_max = (z0-ray.o.z) * ray.d.z;
}
if( tz_max < kEpsilon ) return false;
if( tz_min <= kEpsilon ){
if( tz_min <= kEpsilon )
{
t = tz_max;
}else{
}
else
{
t = tz_min;
}
return true;
}
Real a = 1.0 / ray.d.x;
if (a >= 0) {
if (a >= 0)
{
Real a1 = x0 - ray.o.x;
Real a2 = x1 - ray.o.x;
tx_min = (a1) * a;
tx_max = (a2) * a;
} else {
}
else
{
Real a1 = x0 - ray.o.x;
Real a2 = x1 - ray.o.x;
tx_min = (a2) * a;
......@@ -122,12 +153,15 @@ bool AABB::hit(const Ray& ray, Real& t) const {
}
Real b = 1.0 / ray.d.y;
if (b >= 0) {
if (b >= 0)
{
Real b1 = y0 - ray.o.y;
Real b2 = y1 - ray.o.y;
ty_min = (b1) * b;
ty_max = (b2) * b;
} else {
}
else
{
Real b1 = y0 - ray.o.y;
Real b2 = y1 - ray.o.y;
ty_min = (b2) * b;
......@@ -135,12 +169,15 @@ bool AABB::hit(const Ray& ray, Real& t) const {
}
Real c = 1.0 / ray.d.z;
if (c >= 0) {
if (c >= 0)
{
Real c1 = z0 - ray.o.z;
Real c2 = z1 - ray.o.z;
tz_min = (c1) * c;
tz_max = (c2) * c;
} else {
}
else
{
Real c1 = z0 - ray.o.z;
Real c2 = z1 - ray.o.z;
tz_min = (c2) * c;
......@@ -150,35 +187,47 @@ bool AABB::hit(const Ray& ray, Real& t) const {
//int face_in, face_out;
// find the largest entering t value
if (tx_min > ty_min) {
if (tx_min > ty_min)
{
t_near = tx_min;
//face_in = (a >= 0.0) ? 0 : 3;
} else {
}
else
{
t_near = ty_min;
//face_in = (b >= 0.0) ? 1 : 4;
}
if (tz_min > t_near) {
if (tz_min > t_near)
{
t_near = tz_min;
//face_in = (c >= 0.0) ? 2 : 5;
}
//find smallest exiting t value
if (tx_max < ty_max) {
if (tx_max < ty_max)
{
t_far = tx_max;
//face_out = (a >= 0.0) ? 3 : 0;
} else {
}
else
{
t_far = ty_max;
//face_out = (b >= 0.0) ? 4 : 1;
}
if (tz_max < t_far) {
if (tz_max < t_far)
{
t_far = tz_max;
//face_out = (c >= 0.0) ? 5 : 2;
}
if (t_near < t_far && t_far > kEpsilon) {
if (t_near > kEpsilon) {
if (t_near < t_far && t_far > kEpsilon)
{
if (t_near > kEpsilon)
{
t = t_near;
}else{
}
else
{
t = t_far;
}
return true;
......@@ -186,12 +235,14 @@ bool AABB::hit(const Ray& ray, Real& t) const {
return false;
}//hit
bool AABB::inside(const Point3D& p) const {
bool AABB::inside(const Point3D& p) const
{
return ((p.x > x0 && p.x < x1)
&& (p.y > y0 && p.y < y1)
&& (p.z > z0 && p.z < z1));
}//inside
bool AABB::on(const Point3D& p) const {
bool AABB::on(const Point3D& p) const
{
return ( ((p.x == x0 || p.x == x1)
&& (p.y >= y0 && p.y <= y1)
&& (p.z >= z0 && p.z <= z1))
......@@ -202,7 +253,8 @@ bool AABB::on(const Point3D& p) const {
&& (p.x >= x0 && p.x <= x1)
&& (p.y >= y0 && p.y <= y1)));
}
std::string AABB::toString()const{
std::string AABB::toString()const
{
std::stringstream stream;
stream << std::setprecision(15)
<< "aabb x0="<<x0<<",x1="<<x1
......@@ -210,14 +262,16 @@ std::string AABB::toString()const{
<< ",z0="<<z0<<",z1="<<z1;
return stream.str();
}
AABB AABB::operator+(const AABB& rhs){
AABB AABB::operator+(const AABB& rhs)
{
// union with a null AABB results in this
if( isNull(rhs) ) return *this;
return AABB(std::min(rhs.x0,this->x0), std::max(rhs.x1,this->x1)
,std::min(rhs.y0,this->y0), std::max(rhs.y1,this->y1)
,std::min(rhs.z0,this->z0), std::max(rhs.z1,this->z1));
}
AABB AABB::operator&(const AABB& rhs){
AABB AABB::operator&(const AABB& rhs)
{
// intersection with a null AABB results in null
if( isNull(rhs) ) return AABB(0,0,0,0,0,0);
Interval x,y,z;
......@@ -229,34 +283,37 @@ AABB AABB::operator&(const AABB& rhs){
,y.a,y.b
,z.a,z.b);
}
bool AABB::isNull(const AABB &aabb){
bool AABB::isNull(const AABB &aabb)
{
return !aabb.hasVolume();
}
Point3D AABB::origin() const{
Point3D AABB::origin() const
{
return Point3D((x0+x1)/2.0
,(y0+y1)/2.0
,(z0+z1)/2.0
);
);
}
bool AABB::intersects(const AABB& o)const
{
bool xIntersects = (x0 >= o.x0 && x0 < o.x1)
|| (x1 > o.x0 && x1 <= o.x1)
|| (o.x0 >= x0 && o.x0 < x1)
|| (o.x1 > x0 && o.x1 <= x1);
|| (x1 > o.x0 && x1 <= o.x1)
|| (o.x0 >= x0 && o.x0 < x1)
|| (o.x1 > x0 && o.x1 <= x1);
bool yIntersects = (y0 >= o.y0 && y0 < o.y1)
|| (y1 > o.y0 && y1 <= o.y1)
|| (o.y0 >= y0 && o.y0 < y1)
|| (o.y1 > y0 && o.y1 <= y1);
|| (y1 > o.y0 && y1 <= o.y1)
|| (o.y0 >= y0 && o.y0 < y1)
|| (o.y1 > y0 && o.y1 <= y1);
bool zIntersects = (z0 >= o.z0 && z0 < o.z1)
|| (z1 > o.z0 && z1 <= o.z1)
|| (o.z0 >= z0 && o.z0 < z1)
|| (o.z1 > z0 && o.z1 <= z1);
|| (z1 > o.z0 && z1 <= o.z1)
|| (o.z0 >= z0 && o.z0 < z1)
|| (o.z1 > z0 && o.z1 <= z1);
return (xIntersects && yIntersects && zIntersects);
}
AABB AABB::operator*(const Matrix & matrix)const{
AABB AABB::operator*(const Matrix & matrix)const
{
Point3D x0y0z0= matrix * Point3D(x0,y0,z0);
Point3D x1y0z0= matrix * Point3D(x1,y0,z0);
Point3D x0y1z0= matrix * Point3D(x0,y1,z0);
......@@ -270,61 +327,62 @@ AABB AABB::operator*(const Matrix & matrix)const{
result.x0 = std::min(x0y0z0.x
,std::min(x1y0z0.x
,std::min(x0y1z0.x
,std::min(x0y1z1.x
,std::min(x1y0z1.x
,std::min(x0y0z1.x
,std::min(x1y1z1.x,x1y1z0.x)))))));
,std::min(x0y1z1.x
,std::min(x1y0z1.x
,std::min(x0y0z1.x
,std::min(x1y1z1.x,x1y1z0.x)))))));
if (std::abs(result.x0) == infinity) result.x0 = (result.x0 < 0) ? -maxReal : maxReal;
result.x1 = std::max(x0y0z0.x
,std::max(x1y0z0.x
,std::max(x0y1z0.x
,std::max(x0y1z1.x
,std::max(x1y0z1.x
,std::max(x0y0z1.x
,std::max(x1y1z1.x,x1y1z0.x)))))));
,std::max(x0y1z1.x
,std::max(x1y0z1.x
,std::max(x0y0z1.x
,std::max(x1y1z1.x,x1y1z0.x)))))));
if (std::abs(result.x1) == infinity) result.x1 = (result.x1 < 0) ? -maxReal : maxReal;