-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathwykobi_nd.hpp
365 lines (249 loc) · 14.7 KB
/
wykobi_nd.hpp
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
/*
(***********************************************************************)
(* *)
(* 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 *)
(* *)
(***********************************************************************)
*/
#ifndef INCLUDE_WYKOBI_ND
#define INCLUDE_WYKOBI_ND
#include <vector>
#include <limits>
#include <algorithm>
#include <cassert>
#include "wykobi.hpp"
#include "wykobi_math.hpp"
namespace wykobi
{
template <typename T, std::size_t D>
inline bool parallel(const line<T,D>& line1, const line<T,D>& line2);
template <typename T, std::size_t D>
inline bool parallel(const segment<T,D>& segment1, const segment<T,D>& segment2);
template <typename T, std::size_t D>
inline bool perpendicular(const line<T,D>& line1, const line<T,D>& line2);
template <typename T, std::size_t D>
inline bool perpendicular(const segment<T,D>& segment1, const segment<T,D>& segment2);
template <typename T, std::size_t D>
inline bool collinear(const pointnd<T,D>& point1, const pointnd<T,D>& point2, const pointnd<T,D>& point3);
template <typename T, std::size_t D>
inline bool robust_collinear(const pointnd<T,D>& point1, const pointnd<T,D>& point2, const pointnd<T,D>& point3);
template <typename T, std::size_t D>
inline bool is_point_collinear(const segment<T,D>& segment, const pointnd<T,D>& point, const bool robust = false);
template <typename T, std::size_t D>
inline bool intersect(const segment<T,D>& segment1, const segment<T,D>& segment2, const T& fuzzy = T(0.0));
template <typename T, std::size_t D>
inline bool intersect(const line<T,D>& line1, const line<T,D>& line2, const T& fuzzy = T(0.0));
template <typename T, std::size_t D>
inline pointnd<T,D> intersection_point(const segment<T,D>& segment1, const segment<T,D>& segment2, const T& fuzzy = T(0.0));
template <typename T, std::size_t D>
inline pointnd<T,D> intersection_point(const line<T,D>& line1, const line<T,D>& line2, const T& fuzzy = T(0.0));
template <typename T, std::size_t D>
inline T distance(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline T distance(const pointnd<T,D>& point, const segment<T,D>& segment);
template <typename T, std::size_t D>
inline T distance(const pointnd<T,D>& point, const line<T,D>& line);
template <typename T, std::size_t D>
inline T distance(const segment<T,D>& segment1, const segment<T,D>& segment2);
template <typename T, std::size_t D>
inline T distance(const line<T,D>& line1, const line<T,D>& line2);
template <typename T, std::size_t D>
inline T lay_distance(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline T lay_distance(const pointnd<T,D>& point, const segment<T,D>& segment);
template <typename T, std::size_t D>
inline T lay_distance(const pointnd<T,D>& point, const line<T,D>& line);
template <typename T, std::size_t D>
inline T lay_distance(const segment<T,D>& segment1, const segment<T,D>& segment2);
template <typename T, std::size_t D>
inline T lay_distance(const line<T,D>& line1, const line<T,D>& line2);
template <typename T, std::size_t D>
inline T manhattan_distance(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline T chebyshev_distance(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline T manhattan_distance(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline T inverse_chebyshev_distance(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline bool point_in_box(const pointnd<T,D>& point, const box<T,D>& box);
template <typename T, std::size_t D>
inline bool point_in_sphere(const pointnd<T,D>& point, const hypersphere<T,D>& hypersphere);
template <typename T, std::size_t D>
inline pointnd<T,D> closest_point_on_segment_from_point(const segment<T,D>& segment, const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline pointnd<T,D> closest_point_on_line_from_point(const line<T,D>& segment, const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline pointnd<T,D> closest_point_on_sphere_from_point(const hypersphere<T,D>& sphere, const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline pointnd<T,D> closest_point_on_plane_from_point(const plane<T,D>& plane, const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline pointnd<T,D> closest_point_on_box_from_point(const box<T,D>& box, const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline pointnd<T,D> project_point_t(const pointnd<T,D>& source_point,
const pointnd<T,D>& destination_point,
const T& t);
template <typename T, std::size_t D>
inline pointnd<T,D> project_point(const pointnd<T,D>& source_point,
const pointnd<T,D>& destination_point,
const T& distance);
template <typename T, std::size_t D>
inline pointnd<T,D> mirror(const pointnd<T,D>& point, const line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline segment<T,D> mirror(const segment<T,D>& segment, const line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline line<T,D> mirror(const line<T,D>& line, const wykobi::line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline box<T,D> mirror(const box<T,D>& box, const line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline triangle<T,D> mirror(const triangle<T,D>& triangle, const line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline quadix<T,D> mirror(const quadix<T,D>& quadix, const line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline hypersphere<T,D> mirror(const hypersphere<T,D>& sphere, const line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline polygon<T,D> mirror(const polygon<T,D>& polygon, const line<T,D>& mirror_axis);
template <typename T, std::size_t D>
inline segment<T,D> project_onto_axis(const pointnd<T,D>& point, const line<T,D>& axis);
template <typename T, std::size_t D>
inline segment<T,D> project_onto_axis(const triangle<T,D>& triangle, const line<T,D>& axis);
template <typename T, std::size_t D>
inline segment<T,D> project_onto_axis(const box<T,D>& box, const line<T,D>& axis);
template <typename T, std::size_t D>
inline segment<T,D> project_onto_axis(const quadix<T,D>& quadix, const line<T,D>& axis);
template <typename T, std::size_t D>
inline segment<T,D> project_onto_axis(const hypersphere<T,D>& sphere, const line<T,D>& axis);
template <typename T, std::size_t D>
inline segment<T,D> project_onto_axis(const polygon<T,D>& polygon, const line<T,D>& axis);
template <typename T, std::size_t D>
inline T perimeter(const triangle<T,D>& triangle);
template <typename T, std::size_t D>
inline T perimeter(const quadix<T,D>& quadix);
template <typename T, std::size_t D>
inline T perimeter(const polygon<T,D>& polygon);
template <typename T, std::size_t D>
inline pointnd<T,D> generate_random_point(const segment<T,D>& segment);
template <typename T, std::size_t D>
inline pointnd<T,D> generate_random_point(const triangle<T,D>& triangle);
template <typename T, std::size_t D>
inline pointnd<T,D> generate_random_point(const quadix<T,D>& quadix);
template <typename T, std::size_t D>
inline pointnd<T,D> generate_random_point(const box<T,D>& box);
template <typename T, std::size_t D, typename OutputIterator>
inline void generate_random_points(const box<T,D>& box, const std::size_t& point_count, OutputIterator out);
template <typename T, std::size_t D, typename OutputIterator>
inline void generate_random_points(const segment<T,D>& segment, const std::size_t& point_count, OutputIterator out);
template <typename T, std::size_t D, typename OutputIterator>
inline void generate_random_points(const triangle<T,D>& triangle, const std::size_t& point_count, OutputIterator out);
template <typename T, std::size_t D, typename OutputIterator>
inline void generate_random_points(const quadix<T,D>& quadix, const std::size_t& point_count, OutputIterator out);
template <typename T, std::size_t D>
inline T vector_norm(const vectornd<T,D>& v);
template <typename T, std::size_t D>
inline vectornd<T,D> normalize(const vectornd<T,D>& v);
template <typename T, std::size_t D>
inline vectornd<T,D> operator+(const vectornd<T,D>& v1, const vectornd<T,D>& v2);
template <typename T, std::size_t D>
inline vectornd<T,D> operator-(const vectornd<T,D>& v1, const vectornd<T,D>& v2);
template <typename T, std::size_t D>
inline T dot_product(const vectornd<T,D>& v1, const vectornd<T,D>& v2);
template <typename T, std::size_t D>
inline vectornd<T,D> operator*(const vectornd<T,D>& v1, const T& scale);
template <typename T, std::size_t D>
inline vectornd<T,D> operator*(const T& scale, const vectornd<T,D>& v1);
template <typename T, std::size_t D>
inline pointnd<T,D> operator*(const pointnd<T,D>& point, const T& scale);
template <typename T, std::size_t D>
inline pointnd<T,D> operator*(const T& scale, const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline vectornd<T,D> operator/(const vectornd<T,D>& v1, const T& scale);
template <typename T, std::size_t D>
inline pointnd<T,D> operator/(const pointnd<T,D>& point, const T& scale);
template <typename T, std::size_t D>
inline pointnd<T,D> operator+(const pointnd<T,D>& point, const vectornd<T,D>& v);
template <typename T, std::size_t D>
inline pointnd<T,D> operator+(const vectornd<T,D>& v, const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline vectornd<T,D> operator-(const pointnd<T,D>& p1, const pointnd<T,D>& p2);
template <typename T, std::size_t D>
inline pointnd<T,D> operator+(const pointnd<T,D>& p1, const pointnd<T,D>& p2);
template <typename T>
inline T operator*(const vectornd<T,2>& v1, const vectornd<T,2>& v2);
template <typename T>
inline vectornd<T,3> operator*(const vectornd<T,3>& v1, const vectornd<T,3>& v2);
template <typename T, std::size_t D>
inline bool operator < (const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline bool operator > (const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline bool operator == (const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline bool is_equal(const pointnd<T,D>& point1, const pointnd<T,D>& point2, const T& epsilon);
template <typename T, std::size_t D>
inline bool is_equal(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline bool not_equal(const pointnd<T,D>& point1, const pointnd<T,D>& point2, const T& epsilon);
template <typename T, std::size_t D>
inline bool not_equal(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline pointnd<T,D> degenerate_pointnd();
template <typename T, std::size_t D>
inline vectornd<T,D> degenerate_vectornd();
template <typename T, std::size_t D>
inline ray<T,D> degenerate_raynd();
template <typename T, std::size_t D>
inline line<T,D> degenerate_linend();
template <typename T, std::size_t D>
inline segment<T,D> degenerate_segmentnd();
template <typename T, std::size_t D>
inline triangle<T,D> degenerate_trianglend();
template <typename T, std::size_t D>
inline quadix<T,D> degenerate_quadixnd();
template <typename T, std::size_t D>
inline box<T,D> degenerate_box();
template <typename T, std::size_t D>
inline hypersphere<T,D> degenerate_hypersphere();
template <typename T, std::size_t D>
inline pointnd<T,D> positive_infinite_pointnd();
template <typename T, std::size_t D>
inline pointnd<T,D> negative_infinite_pointnd();
template <typename T, std::size_t D>
inline void swap(pointnd<T,D>& point1, pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline vectornd<T,D> make_vector(const pointnd<T,D>& point);
template <typename T, std::size_t D>
inline ray<T,D> make_ray(const pointnd<T,D>& origin, const vectornd<T,D>& direction);
template <typename T, std::size_t D>
inline segment<T,D> make_segment(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline line<T,D> make_line(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline box<T,D> make_box(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline triangle<T,D> make_triangle(const pointnd<T,D>& point1, const pointnd<T,D>& point2, const pointnd<T,D>& point3);
template <typename T, std::size_t D>
inline quadix<T,D> make_quadix(const pointnd<T,D>& point1, const pointnd<T,D>& point2, const pointnd<T,D>& point3, const pointnd<T,D>& point4);
template <typename T, std::size_t D>
inline hypersphere<T,D> make_sphere(const pointnd<T,D>& point, const T& radius);
template <typename T, std::size_t D>
inline hypersphere<T,D> make_sphere(const pointnd<T,D>& point1, const pointnd<T,D>& point2);
template <typename T, std::size_t D>
inline polygon<T,D> make_polygon(const std::vector< pointnd<T,D> >& point_list);
template <typename T, std::size_t D>
inline polygon<T,D> make_polygon(const triangle<T,D>& triangle);
template <typename T, std::size_t D>
inline polygon<T,D> make_polygon(const quadix<T,D>& quadix);
} // wykobi namespace
#include "wykobi_nd.inl"
#endif