Boost Polygon Library: Point Concept

### Contents

- Boost.Polygon Main Page
- Design Overview
- Isotropy
- Coordinate Concept
- Interval Concept
- Point Concept
- Rectangle Concept
- Polygon 90 Concept
- Polygon 90 With Holes Concept
- Polygon 45 Concept
- Polygon 45 With Holes Concept
- Polygon Concept
- Polygon With Holes Concept
- Polygon 90 Set Concept
- Polygon 45 Set Concept
- Polygon Set Concept
- Connectivity Extraction 90
- Connectivity Extraction 45
- Connectivity Extraction
- Property Merge 90
- Property Merge 45
- Property Merge

### Other Resources

- GTL Boostcon 2009 Paper
- GTL Boostcon 2009 Presentation
- Performance Analysis
- Layout Versus Schematic Tutorial
- Minkowski Sum Tutorial

### Polygon Sponsor

# 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 inline coordinate_type get(const T& point, orientation_2d orient) {
return point.get(orient);
}
};
template <typename T>
struct point_mutable_traits {
static inline void set(T& point, orientation_2d orient, typename point_traits<T>::coordinate_type value) {
point.set(orient, value);
}
static inline 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 T> coordinate_type get(const T& 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 T, typename coordinate_type> void set(T& 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 T> T construct(coordinate_type x, coordinate_type y) | Construct an object that is a model of point given x and y coordinate values.
template <typename T1, typename T2> T1& assign(T1& left, const T2& right) | Copies data from right object that models point into left object that models point.
template <typename T, typename T2> bool equivalence(const T& point1, const T2& 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 point_type> coordinate_type x(const point_type& point) | Returns the x coordinate of an object that models point.
template <typename point_type> coordinate_type y(const point_type& point) | Returns the y coordinate of an object that models point.
template <typename point_type> void x(point_type& point, coordinate_type ) | Sets the x coordinate of the object that models point to the coordinate value.
template <typename point_type> void y(point_type& point, coordinate_type ) | Sets the y coordinate of the object that models point to the coordinate value.
template <typename point_type> point_type& scale_up(point_type& point, unsigned_area_type factor) | Multiplies x and y coordinate of an object that models point by unsigned factor.
template <typename point_type> point_type& scale_down(point_type& point, unsigned_area_type factor) | Divides x and y coordinate of an object that models point by unsigned factor.
template <typename point_type, typename scaling_type> point_type& scale(point_type& 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 point_type, typename transform_type> point_type& transform(point_type& 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 point_type> point_type& move(point_type& 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 T1, typename T2> T1& convolve(T1& a, const T2& b) | Adds x coordinate of b to x coordinate of a and adds y coordinate of b to y coordinate of a.
template <typename T1, typename T2> T1& deconvolve(T1& a, const T2& b) | Subtracts x coordinate of b from x coordinate of a and subtracts y coordinate of b from y coordinate of a.
template <typename T1, typename T2> coordinate_distance euclidean_distance(const T1&, const T2&) | Returns the distance from an object that models point to a second object that models point.
template <typename T> coordinate_difference euclidean_distance(const T&, orientation_2d, coordinate_type) | Returns the distance from an object that models point to a coordinate in the given orientation_2d.
template <typename T1, typename T2> coordinate_difference manhattan_distance(const T1&, const T2&) | 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 T1, typename T2> coordinate_difference distance_squared(const T1&, const T2&) | 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

geometry_type | point_concept
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 T2> point_data& operator=(const T2& that) const | Assign from an object that is a model of point.
template <typename T2> bool operator==(const T2& that) const | Compare equality to an object that is a model of point.
template <typename T2> bool operator!=(const T2& that) const | Compare inequality to an object that is a model of point.
template <typename T2> bool operator<(const T2& that) const | Compares y coordinates then x coordinates to break ties.
template <typename T2> bool operator<=(const T2& that) const | Compares y coordinates then x coordinates to break ties.
template <typename T2> bool operator>(const T2& that) const | Compares low coordinates then high coordinates to break ties.
template <typename T2> bool operator>=(const T2& 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)