Added model::segment (preparing model namespace)

[SVN r65213]
This commit is contained in:
Barend Gehrels
2010-09-03 10:24:41 +00:00
parent 3a5e4ebdf1
commit 63199bfe5d
2 changed files with 90 additions and 2 deletions

View File

@@ -26,8 +26,7 @@ namespace boost { namespace geometry
/*!
\brief Basic point class, having coordinates defined in a neutral way
\ingroup geometries
\tparam CoordinateType \template_numerical
\tparam CoordinateType \tparam_numeric
\tparam DimensionCount number of coordinates, usually 2 or 3
\tparam CoordinateSystem coordinate system, for example cs::cartesian

View File

@@ -58,6 +58,45 @@ public:
{}
};
// Namespace model
// Anticipates for all geometries, which will be moved to namespace "model":
/*
Bruno:
However maybe an even better name
would be "model", since those geometries model the concepts GGL
defines. It would state more clearly that those shapes are not mere
shapes but are also examples of models for our concepts.
Barend:
I agree that model is a better name. Very good.
So that is the new proposal :-)
*/
namespace model
{
/*!
\brief segment: segment owning two points
\note Might be merged with "segment", while "segment" be used as segment<P&>
*/
template<typename Point>
struct segment : public std::pair<Point, Point>
{
inline segment()
{}
inline segment(Point const& p1, Point const& p2)
{
this->first = p1;
this->second = p2;
}
};
} // namespace model
// Traits specializations for segment above
#ifndef DOXYGEN_NO_TRAITS_SPECIALIZATIONS
namespace traits
@@ -110,6 +149,56 @@ struct indexed_access<segment<ConstOrNonConstPoint>, 1, Dimension>
}
};
template <typename Point>
struct tag<model::segment<Point> >
{
typedef segment_tag type;
};
template <typename Point>
struct point_type<model::segment<Point> >
{
typedef Point type;
};
template <typename Point, std::size_t Dimension>
struct indexed_access<model::segment<Point>, 0, Dimension>
{
typedef model::segment<Point> segment_type;
typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
static inline coordinate_type get(segment_type const& s)
{
return geometry::get<Dimension>(s.first);
}
static inline void set(segment_type& s, coordinate_type const& value)
{
geometry::set<Dimension>(s.first, value);
}
};
template <typename Point, std::size_t Dimension>
struct indexed_access<model::segment<Point>, 1, Dimension>
{
typedef model::segment<Point> segment_type;
typedef typename geometry::coordinate_type<segment_type>::type coordinate_type;
static inline coordinate_type get(segment_type const& s)
{
return geometry::get<Dimension>(s.second);
}
static inline void set(segment_type& s, coordinate_type const& value)
{
geometry::set<Dimension>(s.second, value);
}
};
} // namespace traits
#endif // DOXYGEN_NO_TRAITS_SPECIALIZATIONS