Boost logo

Geometry :

Subject: [ggl] box_range is not a valid range
From: zzsj (feverzsj)
Date: 2011-05-02 21:37:29


hi,Barend
 
> Did you work out your suggestion in your solution? If so, could you send
> it such that we might replace it?

That's fairly easy. Almost just copy and paste code of box_rang/box_iterator. I've also removed some unnecessary test since it seems iterator is always compared with other iterator of same range.

namespace ggl = boost::geometry;

template<typename Box>
class box2d_range
{
public :
    typedef typename ggl::point_type<Box>::type point_type;

    struct box2d_iterator
        : public boost::iterator_facade<
            box2d_iterator,
            point_type const, // read only
            boost::random_access_traversal_tag
>
    {
        // begin iterator
        box2d_iterator(point_type const* p)
            : m_points(p), m_index(0) {}

        // end iterator
        box2d_iterator()
            : m_points(0), m_index(5) {}

        typedef std::ptrdiff_t difference_type;

    private:
        friend class boost::iterator_core_access;

        point_type const& dereference() const
        {
            assert(m_points);

            if (m_index >= 0 && m_index <= 3)
            {
                return m_points[m_index];
            }
            // If it index is 4, or other, return first point
            return m_points[0];
        }

        bool equal(box2d_iterator const& other) const
        {
            return other.m_index == m_index;
        }

        void increment()
        {
            m_index++;
        }

        void decrement()
        {
            m_index--;
        }

        void advance(difference_type n)
        {
            m_index += n;
        }

        difference_type distance_to(box2d_iterator const& other) const
        {
            return other.m_index - m_index;
        }

        int m_index;
        point_type const* m_points;
    };

    typedef box2d_iterator const_iterator;
    typedef box2d_iterator iterator; // must be defined

    explicit box2d_range(Box const& box)
    {
        init(box);
    }

    const_iterator begin() const { return const_iterator(m_points); }
    const_iterator end() const { return const_iterator(); }

    // It may not be used non-const, so comment this:
    //iterator begin() { return m_begin; }
    //iterator end() { return m_end; }

    void init(Box const& box)
    {
        ggl::detail::assign_box_corners_oriented<false>(box, m_points);
    }

private :
    point_type m_points[4];
};


Geometry list run by mateusz at loskot.net