28 #if defined(PointUtils_RECURSES)
29 #error Recursive header files inclusion detected in PointUtils.h
32 #define PointUtils_RECURSES
34 #if !defined PointUtils_h
41 #include "DGtal/base/Common.h"
45 template<
typename TPo
intType>
46 typename TPointType::Coordinate
det(
const TPointType& p,
const TPointType& q ) {
47 return p[ 0 ] * q[ 1 ] - p[ 1 ] * q[ 0 ];
52 template<
typename TPo
intType>
53 bool less(
const TPointType& p,
const TPointType& q ) {
54 return ( p[ 0 ] * q[ 1 ] - p[ 1 ] * q[ 0 ] ) > 0;
61 template<
typename TPo
intType>
62 bool less(
const TPointType& p,
const TPointType& q );
67 template<
typename TPo
intType>
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 );
91 template<
typename TPo
intType>
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 ]);
100 template<
typename TPo
intType1,
typename TPo
intType2>
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 ]);
109 #undef PointUtils_RECURSES
DGtal is the top-level namespace which contains all DGtal functions and types.
std::vector< TPointType > nextNeighbors(TPointType p)
TPointType::Coordinate distance2(TPointType p, TPointType q)
TPointType::Coordinate det(const TPointType &p, const TPointType &q)
bool less(const TPointType &p, const TPointType &q)