C++ (Qt)class Triangle{public: Triangle(); Triangle(const QVector3D &a, const QVector3D &b, const QVector3D &c); QVector3D a() const; QVector3D b() const; QVector3D c() const; QVector3D ab() const; QVector3D bc() const; QVector3D ac() const; QVector3D normal() const; QVector3D normal(const QVector3D &pointUnderPlane) const; QVector3D perpendicular() const; float square() const; QVector3D center() const; private: std::array<QVector3D, nodeCountPerFace> vertices;}; using TriangleList = QVector<Triangle>;
C++ (Qt)struct VertexList { virtual size_t size( void ) const = 0; virtual arma::vec3 GetVertex( size_t index ) = 0; virtual void SetVertex( const arma::vec3 & val, size_t index ) = 0;}; template <class T> struct TVertexList<T> : public VertexList { virtual size_t size( void ) const { return mData.size(); } virtual arma::vec3 GetVertex( size_t index ) { return mData[index]; } virtual void SetVertex( const arma::vec3 & val, size_t index ) { mData[index] = val; } std::vector<T> mData;};
C++ (Qt)template <class T>class Triangle {public: Triangle(); Triangle(const T &a, const T &b, const T &c); T a() const;//....private: std::array<T, nodeCountPerFace> vertices;};
C++ (Qt)template<> class Triangle<QVector3D> {public: float square( void );};
C++ (Qt)template<class T> class TriangleQ : public Triangle<T> {public: TriangleQ(const T &a, const T &b, const T &c) : Triangle<T>(a, b, c) { } float square( void ) const { return 1; }};
C++ (Qt)template <class>point_traits{}; template <>point_traits<QVector3D>{ typedef float value_type; static value_type square(const QVector3D & p1, const QVector3D & p2, const QVector3D & p3) { return ...; }}; template <>point_traits<arma::vec3>{ typedef double value_type; static value_type square(const arma::vec3 & p1, const value_type & p2, const value_type & p3) { return ...; }}; template <class T, class PointTraits = point_traits<T>>class Triangle{public: typedef T point_type; typedef typename PointTraits::value_type value_type; ... value_type square() const { return PointTraits::square(p1, p2, p3); } private: point_type p1; point_type p2; point_type p3;};