Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Point types

We have already discussed that certain conditions on the Point type template argument must be obeyed. The following shows a custom point type in 3D which can be used as a template argument to Catmull-Rom:

template<class Real>
class mypoint3d
{
public:
    // Must define a value_type:
    typedef Real value_type;

    // Regular constructor--need not be of this form.
    mypoint3d(Real x, Real y, Real z) {m_vec[0] = x; m_vec[1] = y; m_vec[2] = z; }

    // Must define a default constructor:
    mypoint3d() {}

    // Must define array access:
    Real operator[](size_t i) const
    {
        return m_vec[i];
    }

    // Must define array element assignment:
    Real& operator[](size_t i)
    {
        return m_vec[i];
    }

private:
    std::array<Real, 3> m_vec;
};


// Must define the free function "size()":
template<class Real>
constexpr size_t size(const mypoint3d<Real>& c)
{
    return 3;
}

These conditions are satisfied by both std::array and std::vector, but it may nonetheless be useful to define your own point class so that (say) you can define geometric distance between them.


PrevUpHomeNext