The spica renderer
point3d.h
1 #ifdef _MSC_VER
2 #pragma once
3 #endif
4 
5 #ifndef _SPICA_POINT3D_H_
6 #define _SPICA_POINT3D_H_
7 
8 #include <string>
9 #include <type_traits>
10 
11 #include "common.h"
12 #include "core/vector3d.h"
13 
14 namespace spica {
15 
16  template <class T>
17  class Point3_ {
18  public:
19  Point3_();
20  Point3_(T x, T y, T z);
21  Point3_(const Point3_<T>& p);
22  explicit Point3_(const Vector3_<T>& v);
23  ~Point3_();
24 
25  template <class Fn>
26  static Point3_<T> binary_op(const Point3_<T>& p1, const Point3_<T>& p2, const Fn& f);
27 
28  static Point3_<T> maximum(const Point3_<T>& p1, const Point3_<T>& p2);
29  static Point3_<T> minimum(const Point3_<T>& p1, const Point3_<T>& p2);
30 
31  Point3_<T>& operator=(const Point3_<T>& p);
32  Point3_<T>& operator+=(const Point3_<T>& p);
33  Point3_<T>& operator*=(T s);
34  Point3_<T>& operator/=(T s);
35  bool operator==(const Point3_<T>& p) const;
36  bool operator!=(const Point3_<T>& p) const;
37  T operator[](int i) const;
38  operator Vector3_<T>() const;
39 
40  inline T x() const { return x_; }
41  inline T y() const { return y_; }
42  inline T z() const { return z_; }
43 
44  std::string toString() const;
45 
46  using type = T;
47 
48  private:
49  T x_, y_, z_;
50 
51  static_assert(std::is_arithmetic<T>::value, "Template type must be arithmetic!!");
52  };
53 
54  using Point3i = Point3_<int>;
55  using Point3f = Point3_<float>;
56  using Point3d = Point3_<double>;
57 
58 } // namespace spica
59 
60 template <class T>
61 std::ostream& operator<<(std::ostream& os, const spica::Point3_<T>& p);
62 
63 template <class T>
64 spica::Point3_<T> operator+(const spica::Point3_<T>& p1, const spica::Point3_<T>& p2);
65 
66 template <class T>
67 spica::Point3_<T> operator+(const spica::Point3_<T>& p, const spica::Vector3_<T>& v);
68 
69 template <class T>
70 spica::Point3_<T> operator-(const spica::Point3_<T>& p, const spica::Vector3_<T>& v);
71 
72 template <class T>
73 spica::Vector3_<T> operator-(const spica::Point3_<T>& p1, const spica::Point3_<T>& p2);
74 
75 template <class T>
76 spica::Point3_<T> operator*(const spica::Point3_<T>& p, T s);
77 
78 template <class T>
79 spica::Point3_<T> operator*(T s, const spica::Point3_<T>& p);
80 
81 template <class T>
82 spica::Point3_<T> operator/(const spica::Point3_<T>& p, T s);
83 
84 #include "point3d_detail.h"
85 
86 #endif // _SPICA_POINT3D_H_
Three-dimensional vector.
Definition: core.hpp:56
Definition: core.hpp:68