Commit 7cd93df1 authored by LEFEBVREJP email's avatar LEFEBVREJP email
Browse files

Merge branch 'contribution_guide' into 'master'

Contribution guide

See merge request !3
parents 0a28680b fa13937a
Pipeline #7411 passed with stages
in 23 minutes and 14 seconds
# Topic-based branch development
A topic branch is a short-lived branch that you create for a single focus of work.
Generally, short-lived is less than 6 months. The work can be bug fixes, feature development or design testing.
It is good practice to always use a branch when introducing changes.
This allows the master to remain passing and all subsequent branches to start clean.
## In pratice
### Getting started
After you have cloned the project
```
git clone git@code.ornl.gov:jap/radix radix
Cloning into 'radix'...
remote: Counting objects: 893, done.
remote: Compressing objects: 100% (384/384), done.
remote: Total 893 (delta 523), reused 852 (delta 484)
Receiving objects: 100% (893/893), 247.71 KiB | 95.00 KiB/s, done.
Resolving deltas: 100% (523/523), done.
Checking connectivity... done.
```
Checkout and create a local branch
```
git checkout -b featurex
Switched to a new branch 'contribution_guide'
```
You now have a local branch `contribution_guide`
```
git branch -l
* contribution_guide
master
```
This branch is not in the originating repository.
```
git branch -r
origin/HEAD -> origin/master
origin/master
```
### Making the first push
When you are ready to push your changes, you will get a fatal error about `no upstream branch`.
```
git push
fatal: The current branch contribution_guide has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin contribution_guide
```
Follow the suggested command
```
git push --set-upstream origin contribution_guide
Counting objects: 6, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (6/6), done.
Writing objects: 100% (6/6), 1.25 KiB | 0 bytes/s, done.
Total 6 (delta 3), reused 0 (delta 0)
remote:
remote: Create merge request for contribution_guide:
remote: https://code.ornl.gov/jap/radix/merge_requests/new?merge_request%5Bsource_branch%5D=contribution_guide
remote:
To git@code.ornl.gov:jap/radix
* [new branch] contribution_guide -> contribution_guide
Branch contribution_guide set up to track remote branch contribution_guide from origin.
```
The remote server will return a quick link for creating a merge request if one hasn't already been created for this branch.
# Formatting
The use of the utility [astyle](http://astyle.sourceforge.net/) makes for a quick processing of the desired format.
From the root directory running the following command will load default options for style formatting.
```
astyle --options=options.astyle *.cc *.hh
```
# Naming convention
## File naming
C++ files should end in `.cc` and header files in `.hh`.
Template implementations should end in `.i.hh`.
**File names should be all lowercase with no underscores.**
## Class naming
Classes should be **CamelCase**.
```
class CommandLine
{
};
```
Class members should be prefixed with **m** and be **lazyCamelCase**.
```
class CommandLine
{
private:
int mArgc;
char ** mArgv;
};
```
Class methods should be **lazyCamelCase**.
Class member getter methods should be the members name **lazyCamelCase** `int argc() const`.
```
class Commandline
{
private:
int mArgc;
public:
int argc() const;
int myMethod() const;
};
```
--suffix=none
--lineend=linux
--indent=spaces=4
--convert-tabs
--style=bsd
--recursive
--exclude=testframework
--exclude=googletest
--exclude=TriBITS
......@@ -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)));