Point Concept

The point concept tag is point_concept

To register a user defined type as a model of point concept, specialize the geometry concept meta-function for that type.  In the example below CPoint is registered as a model of point  concept.

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

The semantic of a point is that it has an x and y coordinate.  A std::pair<int, int>, boost::tuple<int, int> or boost::array<int, 2> could all be made models of point by simply providing indirect access to their elements through traits, however, these objects cannot be made a model of both point and interval in the same compilation unit, for obvious reason that duplicate specialization of the geometry_concept struct is illegal, but also because it would make overloading generic function by concept ambiguous if a type modeled more than one concept.

Below is shown the default point traits.  Specialization of these traits is required for types that don't conform to the default behavior.

template <typename T>
struct point_traits {
     typedef typename T::coordinate_type coordinate_type;

     static coordinate_type get(const T& point, orientation_2d orient) {
          return point.get(orient);
     }
};

template <typename T>
struct point_mutable_traits {
     typedef typename T::coordinate_type coordinate_type;

     static void set(T& point, orientation_2d orient, typename point_traits<T>::coordinate_type value) {
          point.set(orient, value);
     }
     static T construct(typename point_traits<T>::coordinate_type x_value,
                        typename point_traits<T>::coordinate_type y_value) {
          return T(x_value, y_value);
     }
};

Example code custom_point.cpp demonstrates how to map a user defined point class to the library point_concept

Functions

template <typename PointType>
coordinate_type get(const PointType& point,
                    orientation_2d)
Expects a model of point. Returns the x or y coordinate of the point, depending on the orientation_2d value.
 
template <typename PointType>
void set(PointType& point, orientation_2d,
         coordinate_type)
Expects a model of point. Sets the x or y coordinate of the point to the coordinate, depending on the orientation_2d  value.
template <typename PointType>
PointType construct(coordinate_type x,
                    coordinate_type y)
Construct an object that is a model of point given x and y coordinate values.
template <typename PointType1, typename PointType2>
PointType1& assign(PointType1& left,
                   const PointType2& right)
Copies data from right object that models point into left object that models point.
template <typename PointType1, typename PointType2>
bool equivalence(const
PointType1& point1,
                 const
PointType2& point2)
Given two objects that model point, compares and returns true if their x and y values are respectively equal to each other.
template <typename PointType>
coordinate_type x(const
PointType& point)
Returns the x coordinate of an object that models point.
template <typename PointType>
coordinate_type y(const
PointType& point)
Returns the y coordinate of an object that models point.
template <typename PointType>
void x(p
PointType& point, coordinate_type )
Sets the x coordinate of the object that models point to the coordinate value. 
template <typename PointType>
void y(
PointType& point, coordinate_type )
Sets the y coordinate of the object that models point to the coordinate value. 
template <typename PointType>
point_type& scale_up(
PointType& point,
                     unsigned_area_type factor)
Multiplies x and y coordinate of an object that models point by unsigned factor.
template <typename PointType>
point_type& scale_down(
PointType& point,
                       unsigned_area_type factor)
Divides x and y coordinate of an object that models point by unsigned factor.
template <typename PointType, typename scaling_type>
point_type& scale(
PointType& point,
                  const scaling_type& factor)
Calls the scale member function of scaling type on the x and y value of an object that models point and sets the point to the scaled values.
template <typename PointType, typename transform_type>
point_type& transform(
PointType& point,
                      const transform_type& transform)
Calls the transform member function of transform type on the x and y value of an object that models point and sets the point to the transformed values.
template <typename PointType>
point_type& move(
PointType& point, orientation_2d,
                 coordinate_difference displacement)
Adds displacement value to the coordinate of an object that models point indicated by the orientation_2d.
template <typename PointType1, typename PointType2>
PointType1& convolve(PointType1& a,
                     const
PointType2& b)
Adds x coordinate of b to x coordinate of a and adds y coordinate of b to y coordinate of a.
template <typename PointType1, typename PointType2>
PointType1,& deconvolve(PointType1& a,
                        const
PointType2>& b)
Subtracts x coordinate of b from x coordinate of a and subtracts y coordinate of b from y coordinate of a.
template <typename PointType1, typename PointType2>
distance_type euclidean_distance(
    const
PointType1&, const PointType2&)
Returns the distance from an object that models point to a second object that models point.
template <typename PointType1, typename PointType2>
coordinate_difference euclidean_distance(
    const
PointType1&, const PointType2&, orientation_2d)
Returns the distance from an object that models point to a coordinate in the given orientation_2d.
template <typename PointType1, typename PointType2>
coordinate_difference manhattan_distance(
   
const PointType1&, const PointType2&)
Returns the distance in x plus the distance in y from an object that models point to a second object that models point.
template <typename PointType1, typename PointType2>
coordinate_difference distance_squared(
   
const PointType1&, const PointType2&)
Returns the square of the distance in x plus the square of the distance in y from an object that models point to a second object that models point.

Point Data

The library provides a model of point concept declared template<typename T> point_data where T is the coordinate type.

This data type is used internally when a point is needed and is available to the library user who finds it convenient to use a library point data type instead of providing their own.  The data type is implemented to be convenient to use with the library traits.

Example code point_usage.cpp demonstrates using the library provided point data type and functions

Members

coordinate_type T
point_data() Default constructs the two coordinate values of the point.
point_data(T x, T y) Constructs an interval with two coordinates.
point_data(const point_data& that) Copy construct
point_data& operator=(const point_data& that) Assignment operator.
template <typename PointType>
point_data& operator=(const PointType& that) const
Assign from an object that is a model of point.
bool operator==(const point_data& that) const Equality operator overload.
bool operator!=(const point_data& that) const Inequality operator overload.
bool operator<(const point_data& that) const Compares y coordinates then x coordinates to break ties.
bool operator<=(const point_data& that) const Compares y coordinates then x coordinates to break ties.
bool operator>(const point_data& that) const Compares low coordinates then high coordinates to break ties.
bool operator>=(const point_data& that) const Compares low coordinates then high coordinates to break ties.
T get(orientation_2d orient) const Get the coordinate in the given orientation.
T x() const Get the coordinate in the horizontal orientation.
T y() const Get the coordinate in the vertical orientation.
void set(orientation_2d orient, T value) Sets the coordinate in the given orientation to the value.
void x(T value) Sets the coordinate in the horizontal orientation to the value.
void y(T value) Sets the coordinate in the vertical orientation to the value.
 
Copyright: Copyright © Intel Corporation 2008-2010.
License: Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)