Boost logo

Boost :

Subject: Re: [boost] Geometry and spatial indexes, my opinion
From: Simonson, Lucanus J (lucanus.j.simonson_at_[hidden])
Date: 2008-10-09 14:00:58


Brandon wrote:
>I posted this to clarify how I implemented the ideas for Patrick or
anyone
>else who was confused by my post. I think it is relevant because a)
there
>are many long threads in the archive on geometry which are difficult to

>follow (so the points may be hard to uncover.) and b) I couldn't find
any
>where someone has committed to this exact mechanism.

You have access to the boost svn sandbox, which has my recent code. My
library in the vault is fairly out of date. Below I am registering
legacy point and polygon classes with my geometry library so that I know
their conceptual type for tag dispatching purposes:

  template <>
  struct geometry_concept<CCGCoordPoint> {
    typedef point_concept type;
  };

  template <>
  struct geometry_concept<CPolygonQuery> {
    typedef polygon_concept type;
  };

And here I specify the traits of the legacy point type such that I know
what coordinate type it uses and how to access its data. I have runtime
accessor instead of compile time because we like to use orientation as
runtime data instead of compile time constant in our code. Construct is
not strictly necessary because I could use default construction and set
x and y.

  template <>
  struct point_traits<CCGCoordPoint> {
    typedef intDC coordinate_type;
    
    static inline coordinate_type get(const CCGCoordPoint& point,
orientation_2d orient) {
      return point.Coord()[orient.to_int()];
    }
    static inline void set(CCGCoordPoint& point, orientation_2d orient,
coordinate_type value) {
      point.Coord()[orient.to_int()] = value;
    }
    static inline CCGCoordPoint construct(coordinate_type x_value,
coordinate_type y_value) {
      return CCGCoordPoint(x_value, y_value);
    }
  };

And here I'm defining the traits for the legacy polygon which uses the
legacy point as part of its interface. Specifically, pointer to legacy
point type models an iterator semantic of objects that are conceptually
points.

  template <>
  struct polygon_traits<CPolygonQuery> {
    typedef intDC coordinate_type;
    typedef const CCGCoordPoint* iterator_type;

    /// Get the begin iterator
    static inline iterator_type begin(const CPolygonQuery& t) {
      return t.Data();
    }
  
    /// Get the end iterator
    static inline iterator_type end(const CPolygonQuery& t) {
      return t.Data() + t.GetSize();
    }
  
    /// Set the data of a polygon with the unique coordinates in an
iterator, starting with an x
    template <typename iT>
    static inline CPolygonQuery& set(CPolygonQuery& t, iT input_begin,
iT input_end) {
      std::vector<intDC> pts;
      for(; input_begin != input_end; ++input_begin) {
        pts.push_back(point_concept::get((*input_begin),
gtl::HORIZONTAL));
        pts.push_back(point_concept::get((*input_begin),
gtl::VERTICAL));
      }
      t.SetPolygon(t.GetLayer(), pts.size()/2, &(pts[0]));
      return t;
    }

    /// Get the number of sides of the polygon
    static inline unsigned int size(const CPolygonQuery& t) {
      return t.GetSize();
    }
  
    /// Get the winding direction of the polygon
    static inline winding_direction winding(const CPolygonQuery& t) {
      return unknown_winding;
    }
  };

I did the interface this way for exactly the same reason that you did.
I have to interact with a large number of legacy geometry type systems
in proprietary code. By the way, I have every respect for what you have
done, if there is anyone in the world who can really appreciate your
library you have found them here.

Luke


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk