DGtal  1.5.beta
PointUtils.h
1 
17 #pragma once
18 
28 #if defined(PointUtils_RECURSES)
29 #error Recursive header files inclusion detected in PointUtils.h
30 #else // defined(PointUtils_RECURSES)
32 #define PointUtils_RECURSES
33 
34 #if !defined PointUtils_h
36 #define PointUtils_h
37 
39 // Inclusions
40 #include <vector>
41 #include "DGtal/base/Common.h"
42 
43 namespace DGtal{
45  template<typename TPointType>
46  typename TPointType::Coordinate det( const TPointType& p, const TPointType& q ) {
47  return p[ 0 ] * q[ 1 ] - p[ 1 ] * q[ 0 ];
48  }
49 
52  template<typename TPointType>
53  bool less( const TPointType& p, const TPointType& q ) {
54  return ( p[ 0 ] * q[ 1 ] - p[ 1 ] * q[ 0 ] ) > 0;
55  }
56 
57 
58 
61  template<typename TPointType>
62  bool less( const TPointType& p, const TPointType& q );
63 
67  template<typename TPointType>
68  std::vector< TPointType > nextNeighbors( TPointType p ) {
69  std::vector< TPointType > V;
70  TPointType zero( 0, 0 );
71  TPointType p0( p[ 0 ]+1, p[ 1 ] );
72  if ( less( p, p0 ) ) V.push_back( p0 );
73  TPointType p1( p[ 0 ]+1, p[ 1 ]+1 );
74  if ( less( p, p1 ) ) V.push_back( p1 );
75  TPointType p2( p[ 0 ], p[ 1 ]+1 );
76  if ( less( p, p2 ) ) V.push_back( p2 );
77  TPointType p3( p[ 0 ]-1, p[ 1 ]+1 );
78  if ( less( p, p3 ) ) V.push_back( p3 );
79  TPointType p4( p[ 0 ]-1, p[ 1 ] );
80  if ( less( p, p4 ) ) V.push_back( p4 );
81  TPointType p5( p[ 0 ]-1, p[ 1 ]-1 );
82  if ( less( p, p5 ) ) V.push_back( p5 );
83  TPointType p6( p[ 0 ], p[ 1 ]-1 );
84  if ( less( p, p6 ) ) V.push_back( p6 );
85  TPointType p7( p[ 0 ]+1, p[ 1 ]-1 );
86  if ( less( p, p7 ) ) V.push_back( p7 );
87  return V;
88  }
89 
91  template<typename TPointType>
92  typename TPointType::Coordinate distance2( TPointType p, TPointType q ) {
93  typename TPointType::Coordinate d2 = (p[ 0 ] - q[ 0 ])*(p[ 0 ] - q[ 0 ])+(p[ 1 ] - q[ 1 ])*(p[ 1 ] - q[ 1 ]);
94  return d2;
95  }
96 
97 
98 
100  template<typename TPointType1,typename TPointType2>
101  typename TPointType2::Coordinate distance2( TPointType1 p, TPointType2 q ) {
102  typename TPointType2::Coordinate d2 = (p[ 0 ] - q[ 0 ])*(p[ 0 ] - q[ 0 ])+(p[ 1 ] - q[ 1 ])*(p[ 1 ] - q[ 1 ]);
103  return d2;
104  }
105 
106 
107 }
108 #endif //PointUtils
109 #undef PointUtils_RECURSES
110 #endif // else defined(PointUtils_RECURSES)
DGtal is the top-level namespace which contains all DGtal functions and types.
std::vector< TPointType > nextNeighbors(TPointType p)
Definition: PointUtils.h:68
TPointType::Coordinate distance2(TPointType p, TPointType q)
Definition: PointUtils.h:92
TPointType::Coordinate det(const TPointType &p, const TPointType &q)
Definition: PointUtils.h:46
bool less(const TPointType &p, const TPointType &q)
Definition: PointUtils.h:53