-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathwykobi_naive_group_intersections.inl
107 lines (92 loc) · 3.49 KB
/
wykobi_naive_group_intersections.inl
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
/*
(***********************************************************************)
(* *)
(* Wykobi Computational Geometry Library *)
(* Release Version 0.0.5 *)
(* http://www.wykobi.com *)
(* Copyright (c) 2005-2019 Arash Partow, All Rights Reserved. *)
(* *)
(* The Wykobi computational geometry library and its components are *)
(* supplied under the terms of the open source MIT License. *)
(* The contents of the Wykobi computational geometry library and its *)
(* components may not be copied or disclosed except in accordance with *)
(* the terms of the MIT License. *)
(* *)
(* URL: https://opensource.org/licenses/MIT *)
(* *)
(***********************************************************************)
*/
#include "wykobi.hpp"
#include "wykobi_algorithm.hpp"
#include <vector>
#include <algorithm>
namespace wykobi
{
namespace algorithm
{
template <typename T>
struct naive_group_intersections< segment<T,2> >
{
public:
template <typename InputIterator, typename OutputIterator>
naive_group_intersections(InputIterator begin, InputIterator end, OutputIterator out)
{
for (InputIterator i = begin; i != end; ++i)
{
for (InputIterator j = (i + 1); j != end; ++j)
{
if (intersect((*j),(*i)))
{
(*out++) = intersection_point((*j),(*i));
}
}
}
}
};
template <typename T>
struct naive_group_intersections< segment<T,3> >
{
public:
template <typename InputIterator, typename OutputIterator>
naive_group_intersections(InputIterator begin, InputIterator end, OutputIterator out)
{
for (InputIterator i = begin; i != end; ++i)
{
for (InputIterator j = (i + 1); j != end; ++j)
{
if (intersect((*j),(*i)))
{
(*out++) = intersection_point((*j),(*i));
}
}
}
}
};
template <typename T>
struct naive_group_intersections< circle<T> >
{
public:
template <typename InputIterator, typename OutputIterator>
naive_group_intersections(InputIterator begin, InputIterator end, OutputIterator out)
{
for (InputIterator i = begin; i != end; ++i)
{
for (InputIterator j = (i + 1); j != end; ++j)
{
if (
(distance((*i).x,(*i).y,(*j).x,(*j).y) >= std::abs((*i).radius - (*j).radius)) &&
intersect((*j),(*i))
)
{
point2d<T> p1;
point2d<T> p2;
intersection_point((*j),(*i),p1,p2);
(*out++) = p1;
(*out++) = p2;
}
}
}
}
};
} // namespace wykobi::algorithm
} // namespace wykobi