-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest2.cpp
121 lines (121 loc) · 3.82 KB
/
test2.cpp
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
///*
//* An implementation of "Efficient clipping of arbitrary polygons" See http://www.inf.usi.ch/hormann/papers/Greiner.1998.ECO.pdf
//* It is based on Jordan curve theorem https://people.math.osu.edu/fiedorowicz.1/math655/Jordan.html
//* Including intersection, union and difference
//* -----------------------------------------------------
//* Here is an inside example
//*/
//
//#include "PolyUtils.h"
//#include "PolygonClipping.h"
//#include <iostream>
//
//
//int main()
//{
// std::vector<PolyClip::Point2d> vertices1;
// vertices1.push_back(PolyClip::Point2d(10.0, 10.0));
// vertices1.push_back(PolyClip::Point2d(10.0, 100.0));
// vertices1.push_back(PolyClip::Point2d(100.0, 100.0));
// vertices1.push_back(PolyClip::Point2d(100.0, 10.0));
// PolyClip::Polygon polygon1(vertices1);
//
// std::vector<PolyClip::Point2d> vertices2;
// vertices2.push_back(PolyClip::Point2d(20, 20.0));
// vertices2.push_back(PolyClip::Point2d(20, 80.0));
// vertices2.push_back(PolyClip::Point2d(80, 80.0));
// PolyClip::Polygon polygon2(vertices2);
//
//
// std::cout << "#################### Intersection #####################\n";
// PolyClip::PloygonOpration::DetectIntersection(polygon1, polygon2);
// std::vector<std::vector<PolyClip::Point2d>> possible_result;
// if (PolyClip::PloygonOpration::Mark(polygon1, polygon2, possible_result, PolyClip::MarkIntersection))
// {
// std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractIntersectionResults(polygon1);
// for (int i = 0; i<results.size(); ++i)
// {
// for (auto p : results[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// else
// {
// if (possible_result.size() == 0)
// std::cout << "No intersection\n";
// else
// {
// for (int i = 0; i<possible_result.size(); ++i)
// {
// for (auto p : possible_result[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// }
//
// std::cout << "\n#################### Union #####################\n";
// possible_result.clear();
// PolyClip::Polygon poly1 = polygon1;
// PolyClip::Polygon poly2 = polygon2;
//
// PolyClip::PloygonOpration::DetectIntersection(poly1, poly2);
// if (PolyClip::PloygonOpration::Mark(poly1, poly2, possible_result, PolyClip::MarkUnion))
// {
// std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractUnionResults(poly1);
// for (int i = 0; i<results.size(); ++i)
// {
// for (auto p : results[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// else
// {
// if (possible_result.size() == 0)
// std::cout << "No intersection\n";
// else
// {
// for (int i = 0; i<possible_result.size(); ++i)
// {
// for (auto p : possible_result[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// }
//
// std::cout << "\n#################### Differentiate #####################\n";
// possible_result.clear();
// PolyClip::Polygon pol1 = polygon1;
// PolyClip::Polygon pol2 = polygon2;
//
// PolyClip::PloygonOpration::DetectIntersection(pol1, pol2);
// if (PolyClip::PloygonOpration::Mark(pol1, pol2, possible_result, PolyClip::MarkDifferentiate))
// {
// std::vector<std::vector<PolyClip::Point2d>> results = PolyClip::PloygonOpration::ExtractDifferentiateResults(pol1);
// for (int i = 0; i<results.size(); ++i)
// {
// for (auto p : results[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// else
// {
// if (possible_result.size() == 0)
// std::cout << "No intersection\n";
// else
// {
// for (int i = 0; i<possible_result.size(); ++i)
// {
// for (auto p : possible_result[i])
// std::cout << "(" << p.x_ << ", " << p.y_ << ")" << "---";
// std::cout << "\n";
// }
// }
// }
//
// return 0;
//}