summaryrefslogtreecommitdiff
path: root/vec.h
diff options
context:
space:
mode:
authorKeuin <[email protected]>2022-04-15 14:06:27 +0800
committerKeuin <[email protected]>2022-04-15 14:06:27 +0800
commit2d4671d5469116b05709bb1acb614d784d339964 (patch)
treeafa839deea5e01ab3cd062968eae30ca56310370 /vec.h
parent50cd8dd3dd029ce432f8e517b4c054e75b5cfe8e (diff)
Make ray3::decay_ distinguishable between different color channels.
Diffstat (limited to 'vec.h')
-rw-r--r--vec.h13
1 files changed, 13 insertions, 0 deletions
diff --git a/vec.h b/vec.h
index 5050065..99004d6 100644
--- a/vec.h
+++ b/vec.h
@@ -36,12 +36,20 @@ struct vec3 {
return vec3{0, 0, 0};
}
+ static vec3 one() {
+ return vec3{1, 1, 1};
+ }
+
bool is_zero() const {
#define EPS (1e-8)
return x >= -EPS && y >= -EPS && z >= -EPS && x <= EPS && y <= EPS && z <= EPS;
#undef EPS
}
+ bool is_one() const {
+ return (*this - vec3::one()).is_zero();
+ }
+
vec3 operator+(const vec3 &b) const {
return vec3{.x=x + b.x, .y=y + b.y, .z=z + b.z};
}
@@ -68,6 +76,11 @@ struct vec3 {
return vec3{.x=y * b.z - z * b.y, .y=x * b.z - z * b.x, .z=x * b.y - y * b.x};
}
+ // Multiply with b on every dimension.
+ vec3 scale(const vec3 &b) const {
+ return vec3{.x=x * b.x, .y=y * b.y, .z=z * b.z};
+ }
+
// norm value
double norm(const int level = 2) const {
if (level == 2) {