#ifndef RADIX_RADIXMATH_RAY_HH_ #define RADIX_RADIXMATH_RAY_HH_ #include #include "radixmath/constants.hh" #include "radixmath/point3d.hh" #include "radixmath/vector3d.hh" #include "radixcore/visibility.hh" namespace radix { class RADIX_PUBLIC Ray { // public member variables public: /** * @brief the origin of the ray */ Point3D o; /** * @brief the direction of the ray */ Vector3D d; // constructor/deconstructor public: Ray(void); Ray(const Point3D &origin, const Vector3D &dir); Ray(const Ray &ray); ~Ray(void); // operators public: /** * operator= * @param rhs * @return this */ Ray &operator=(const Ray &rhs); bool operator==(const Ray &rhs) const; bool operator!=(const Ray &rhs) const; /** * Move the ray position by {@code tmin} * @param tmin * @return this updated */ Ray &operator+=(const Real t); Ray &operator-=(const Real t); void move(Real t) { this->o.x += d.x * t; this->o.y += d.y * t; this->o.z += d.z * t; } void backup(Real t) { this->o.x -= d.x * t; this->o.y -= d.y * t; this->o.z -= d.z * t; } // public methods public: inline Point3D getIntersection(const Real &t) const; std::string toString() const; }; inline Point3D Ray::getIntersection(const Real &t) const { return Point3D(o.x + d.x * t, o.y + d.y * t, o.z + d.z * t); } inline Ray &Ray::operator+=(const Real t) { this->o.x += d.x * t; this->o.y += d.y * t; this->o.z += d.z * t; return *this; } // operator+ inline Ray &Ray::operator-=(const Real t) { this->o.x -= d.x * t; this->o.y -= d.y * t; this->o.z -= d.z * t; return *this; } // operator+ inline bool Ray::operator==(const Ray &rhs) const { if (o == rhs.o && d == rhs.d) return true; return false; } inline bool Ray::operator!=(const Ray &rhs) const { if (o == rhs.o && d == rhs.d) return false; return true; } /** * Allow for printing a Ray to stream * @param os - the stream to receive the string representation of the ray * @param r - the ray to be stringified * @return the stream */ RADIX_PUBLIC std::ostream &operator<<(std::ostream &os, const Ray &r); } // namespace radix #endif