DGtal
2.2.0
Toggle main menu visibility
Loading...
Searching...
No Matches
testPointFunctorHolder.cpp
1
16
26
27
#include <iostream>
28
#include <cmath>
29
30
#include "DGtal/kernel/CPointFunctor.h"
31
#include "DGtal/kernel/PointVector.h"
32
#include "DGtal/kernel/PointFunctorHolder.h"
33
34
#include "DGtalCatch.h"
35
36
template
<
typename
T,
typename
Po
int
>
37
T kernel(
Point
const
& pt,
Point
const
& center, T radius)
38
{
39
return
(pt - center).norm() - radius;
40
}
41
42
template
<
typename
T,
typename
Po
int
>
43
struct
Functor
44
{
45
Point
center
;
46
T
radius
;
47
48
Functor
(
Point
const
& c, T r)
49
:
center
(c),
radius
(r)
50
{}
51
52
T
operator()
(
Point
const
& pt)
const
53
{
54
return
kernel<T>(pt,
center
,
radius
);
55
}
56
};
57
58
TEST_CASE
(
"2D PointFunctorHolder from functor by rvalue"
,
"[2D][functor][rvalue]"
)
59
{
60
using namespace
DGtal
;
61
using
Point
=
PointVector<2, int>
;
62
using
Value
= double;
63
64
auto
fn =
functors::holdPointFunctor<Point, Value>
(
Functor<Value, Point>
(
Point
(1, 0), 1 ) );
65
66
// Checks CPointFunctor concept.
67
BOOST_CONCEPT_ASSERT( (
DGtal::concepts::CPointFunctor
<
decltype
(fn)>) );
68
69
// Checking standard services
70
std::cout << fn << std::endl;
71
REQUIRE
( fn.isValid() );
72
73
// Checking operator()
74
REQUIRE
( fn(
Point
(2, 1)) == Approx( std::sqrt(2) - 1. ) );
75
}
76
77
TEST_CASE
(
"2D PointFunctorHolder from functor by lvalue"
,
"[2D][functor][lvalue]"
)
78
{
79
using namespace
DGtal
;
80
using
Point
=
PointVector<2, int>
;
81
using
Value
= double;
82
83
const
auto
functor =
Functor<Value, Point>
(
Point
(1, 0), 1 );
84
auto
fn =
functors::holdPointFunctor<Point>
( functor );
// auto deduction of the return type
85
86
// Checks CPointFunctor concept.
87
BOOST_CONCEPT_ASSERT( (
DGtal::concepts::CPointFunctor
<
decltype
(fn)>) );
88
89
// Checking standard services
90
std::cout << fn << std::endl;
91
REQUIRE
( fn.isValid() );
92
93
// Checking operator()
94
REQUIRE
( fn(
Point
(2, 1)) == Approx( std::sqrt(2) - 1. ) );
95
}
96
97
TEST_CASE
(
"2D PointFunctorHolder from lambda by rvalue"
,
"[2D][lambda][rvalue]"
)
98
{
99
using namespace
DGtal
;
100
using
Point
=
PointVector<2, int>
;
101
using
Value
= double;
102
103
const
Point
center
(1, 0);
104
const
Value
radius = 1;
105
106
auto
fn =
functors::holdPointFunctor<Point, Value>
(
107
[¢er, &radius] (
Point
const
& pt) {
return
kernel<Value>(pt, center, radius); }
108
);
109
110
// Checks CPointFunctor concept.
111
BOOST_CONCEPT_ASSERT( (
DGtal::concepts::CPointFunctor
<
decltype
(fn)>) );
112
113
// Checking standard services
114
std::cout << fn << std::endl;
115
REQUIRE
( fn.isValid() );
116
117
// Checking operator()
118
REQUIRE
( fn(
Point
(2, 1)) == Approx( std::sqrt(2) - 1. ) );
119
}
120
121
TEST_CASE
(
"2D PointFunctorHolder from lambda by lvalue"
,
"[2D][lambda][lvalue]"
)
122
{
123
using namespace
DGtal
;
124
using
Point
=
PointVector<2, int>
;
125
using
Value
= double;
126
127
const
Point
center
(1, 0);
128
const
Value
radius = 1;
129
130
const
auto
lambda = [&
center
, &radius] (
Point
const
& pt) {
return
kernel<Value>(pt, center, radius); };
131
auto
fn =
functors::holdPointFunctor<Point, Value>
( lambda );
132
133
// Checks CPointFunctor concept.
134
BOOST_CONCEPT_ASSERT( (
DGtal::concepts::CPointFunctor
<
decltype
(fn)>) );
135
136
// Checking standard services
137
std::cout << fn << std::endl;
138
REQUIRE
( fn.isValid() );
139
140
// Checking operator()
141
REQUIRE
( fn(
Point
(2, 1)) == Approx( std::sqrt(2) - 1. ) );
142
}
DGtal::PointVector
Aim: Implements basic operations that will be used in Point and Vector classes.
Definition
PointVector.h:593
DGtal::detail::center
Point center(const std::vector< Point > &points)
Definition
QuickHullKernels.h:67
DGtal::functors::holdPointFunctor
auto holdPointFunctor(TFunctor &&aFunctor) -> PointFunctorHolder< TPoint, TValue, decltype(holdFunctor(std::forward< TFunctor >(aFunctor)))>
PointFunctorHolder construction helper with specification of the return type.
Definition
PointFunctorHolder.h:196
DGtal
DGtal is the top-level namespace which contains all DGtal functions and types.
Definition
ClosedIntegerHalfPlane.h:49
DGtal::concepts::CPointFunctor
Aim: Defines a functor on points.
Definition
CPointFunctor.h:89
Functor
Definition
testFunctorHolder.cpp:45
Functor::operator()
double operator()(double v) const
Definition
testFunctorHolder.cpp:49
Functor::Functor
Functor(Point const &c, T r)
Definition
testPointFunctorHolder.cpp:48
Functor::radius
T radius
Definition
testPointFunctorHolder.cpp:46
Functor::center
Point center
Definition
testPointFunctorHolder.cpp:45
Point
MyPointD Point
Definition
testClone2.cpp:381
TEST_CASE
TEST_CASE("int container traits", "[int][traits]")
Definition
testContainerTraits.cpp:53
Value
double Value
Definition
testSimpleRandomAccessRangeFromPoint.cpp:41
REQUIRE
REQUIRE(domain.isInside(aPoint))
tests
kernel
testPointFunctorHolder.cpp
Generated on
for DGtal by
1.18.0