raytracer
Parallel Ray Tracer written from scratch (no graphics API).
Loading...
Searching...
No Matches
complex.h
Go to the documentation of this file.
1#pragma once
2#include <cmath>
3
4namespace raytracer::common
5{
6
10struct Complex
11{
12 double re;
13 double im;
14
15 constexpr Complex(const double _re, const double _im) : re(_re), im(_im)
16 {
17 }
18
22 static const Complex ZERO;
23
29 [[nodiscard]] constexpr double real_part() const
30 {
31 return re;
32 }
33
39 [[nodiscard]] constexpr double imaginary_part() const
40 {
41 return im;
42 }
43
49 [[nodiscard]] constexpr Complex squared() const
50 {
51 return {re * re - im * im, 2 * re * im};
52 }
53
59 [[nodiscard]] constexpr Complex conjugate() const
60 {
61 return {re, -im};
62 }
63
69 [[nodiscard]] double magnitude() const
70 {
71 return std::sqrt(re * re + im * im);
72 }
73
79 [[nodiscard]] constexpr double magnitude_squared() const
80 {
81 return re * re + im * im;
82 }
83
84 constexpr Complex operator-() const
85 {
86 return {-re, -im};
87 }
88
89 constexpr Complex operator+(Complex const &other) const
90 {
91 return {re + other.re, im + other.im};
92 }
93
94 constexpr Complex operator-(Complex const &other) const
95 {
96 return {re - other.re, im - other.im};
97 }
98};
99
100inline constexpr Complex Complex::ZERO = {0, 0};
101} // namespace raytracer::common
Definition raytracer.cpp:24
double im
Definition complex.h:13
constexpr Complex squared() const
Definition complex.h:49
constexpr double imaginary_part() const
Definition complex.h:39
constexpr Complex operator+(Complex const &other) const
Definition complex.h:89
constexpr Complex operator-() const
Definition complex.h:84
constexpr Complex conjugate() const
Definition complex.h:59
constexpr Complex(const double _re, const double _im)
Definition complex.h:15
static const Complex ZERO
Definition complex.h:22
constexpr Complex operator-(Complex const &other) const
Definition complex.h:94
constexpr double real_part() const
Definition complex.h:29
double magnitude() const
Definition complex.h:69
constexpr double magnitude_squared() const
Definition complex.h:79
double re
Definition complex.h:12