From 2d4671d5469116b05709bb1acb614d784d339964 Mon Sep 17 00:00:00 2001 From: Keuin Date: Fri, 15 Apr 2022 14:06:27 +0800 Subject: Make ray3::decay_ distinguishable between different color channels. --- vec.h | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'vec.h') 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) { -- cgit v1.2.3