-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.cc
65 lines (48 loc) · 1.74 KB
/
example.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* This example is illustrative of the API.
* dpch::DynamicHull and dpch::OnlineHull have similar APIs,
* except DynamicHull also has a fast real time remove_point implementation.
*/
#include <iostream>
#include <vector>
#include <dpch/util/Point.hh>
#include <dpch/dynamic/DynamicHull.hh>
int main() {
using Field = int64_t;
using dpch::DynamicHull;
using dpch::Point;
DynamicHull<Field> hull;
auto points = std::vector<Point<Field>>{
Point<Field>(0, 0), Point<Field>(3, 0), Point<Field>(0, 4)};
hull.add_point(points[0]);
hull.add_point(points[1]);
hull.add_point(points[2]);
auto internal_point = Point<Field>(1, 1);
auto should_be_nothing = hull.get_tangents(internal_point);
assert(should_be_nothing == std::nullopt);
auto external_point = Point<Field>(-5, 2);
auto external_tangents = hull.get_tangents(external_point);
assert(external_tangents != std::nullopt);
assert(external_tangents.value().first == points[0]);
assert(external_tangents.value().second == points[2]);
auto direction = Point<Field>(4, 3);
{
auto far_points = hull.get_extremal_points(direction);
assert(far_points.first == points[2]);
assert(far_points.second == points[1]);
}
{
auto far_points = hull.get_extremal_points(-direction);
assert(far_points.first == points[0]);
assert(far_points.second == points[0]);
}
hull.add_point(Point<Field>(0, -5));
external_tangents = hull.get_tangents(external_point);
assert(external_tangents != std::nullopt);
assert(external_tangents.value().first == Point<Field>(0, -5));
assert(external_tangents.value().second == points[2]);
// hull.remove_point(points[2]);
// ...and so on...
std::cout << "All assertions validated" << std::endl;
return 0;
}