Skip to content

Commit

Permalink
fix constexpr
Browse files Browse the repository at this point in the history
  • Loading branch information
vitor-k committed Apr 9, 2020
1 parent 378d094 commit 4faf100
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
16 changes: 16 additions & 0 deletions src/v3d.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,21 @@
#include "v3d.h"

//Euclidian norm
float v3d::norm() const {
return std::sqrt(norm2());
}
//Returns normalized vector
v3d v3d::normalized() const {
return *this / norm();
}
//Normalizes vector
void v3d::normalize() {
*this /= norm();
}

v3d normalized(const v3d& vect){
return vect.normalized();
}
std::ostream& operator<<(std::ostream& os, v3d vec) {
return os << vec.x << ", " << vec.y << ", " << vec.z;
}
17 changes: 4 additions & 13 deletions src/v3d.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,21 +56,15 @@ struct v3d {
constexpr v3d cross(const v3d& vec) const {
return v3d(y*vec.z - z*vec.y, z*vec.x - x*vec.z, x*vec.y - y*vec.x);
}
//Euclidian norm
float norm() const {
return std::sqrt(norm2());
}
constexpr float norm2() const {
return x*x + y*y + z*z;
}
//Euclidian norm
float norm() const;
//Returns normalized vector
constexpr v3d normalized() const {
return *this / norm();
}
v3d normalized() const;
//Normalizes vector
constexpr void normalize() {
*this /= norm();
}
void normalize();
};

//More operators
Expand All @@ -87,9 +81,6 @@ constexpr v3d cross(const v3d& vec1, const v3d& vec2){
constexpr float dot(const v3d& vec1, const v3d& vec2){
return vec1.dot(vec2);
}
constexpr v3d normalized(const v3d& vect){
return vect.normalized();
}


struct State3d {
Expand Down

0 comments on commit 4faf100

Please sign in to comment.