64 , m_mode(SelectionMode::e_selection_line)
65 , m_is_pre_transformed(
true)
70 SelectionArea(
const SelectionArea& area)
71 : m_matrix(area.m_matrix)
72 , m_inverse_matrix(area.m_inverse_matrix)
74 , m_is_pre_transformed(area.m_is_pre_transformed)
75 , m_is_inverse(area.m_is_inverse)
76 , m_is_enabled(area.m_is_enabled)
80 case e_selection_point_2D:
81 case e_selection_point: m_point = area.m_point;
break;
82 case e_selection_line: m_line = area.m_line;
break;
83 case e_selection_bounds: m_bounds = area.m_bounds;
break;
84 case e_selection_polygon:
new (&m_polygon)
Polygon<t_type>(area.m_polygon);
break;
85 case e_selection_plane: m_plane = area.m_plane;
break;
86 default: lib_assert(
false,
"unknown selection copy");
91 , m_mode(e_selection_point)
92 , m_is_pre_transformed(
true)
98 , m_mode(e_selection_line)
99 , m_is_pre_transformed(
true)
100 , m_is_inverse(
false)
106 , m_mode(e_selection_polygon)
107 , m_is_pre_transformed(
true)
108 , m_is_inverse(
false)
113 : m_polygon(std::move(poly))
114 , m_mode(e_selection_polygon)
115 , m_is_pre_transformed(
true)
116 , m_is_inverse(
false)
122 , m_mode(e_selection_bounds)
123 , m_is_pre_transformed(
true)
124 , m_is_inverse(
false)
130 , m_mode(e_selection_plane)
131 , m_is_pre_transformed(
true)
132 , m_is_inverse(
false)
136 SelectionArea& operator=(
const SelectionArea& area)
139 m_mode = area.m_mode;
142 case e_selection_point_2D:
143 case e_selection_point: m_point = area.m_point;
break;
144 case e_selection_line: m_line = area.m_line;
break;
145 case e_selection_bounds: m_bounds = area.m_bounds;
break;
146 case e_selection_polygon:
new (&m_polygon)
Polygon<t_type>(area.m_polygon);
break;
147 case e_selection_plane: m_plane = area.m_plane;
break;
148 default: lib_assert(
false,
"unknown selection copy");
150 m_is_inverse = area.m_is_inverse;
151 m_is_pre_transformed = area.m_is_pre_transformed;
152 m_matrix = area.m_matrix;
153 m_inverse_matrix = area.m_inverse_matrix;
154 m_is_enabled = area.m_is_enabled;
164 m_mode = e_selection_point_2D;
165 m_point = point.template as<t_dims, t_type>(
cast<t_type>(1));
170 m_mode = e_selection_point;
177 m_mode = e_selection_line;
184 m_mode = e_selection_polygon;
191 m_mode = e_selection_polygon;
193 std::swap(poly, m_polygon);
199 m_mode = e_selection_bounds;
206 m_mode = e_selection_plane;
233 m_inverse_matrix = matrix.invert();
242 return m_inverse_matrix;
248 case e_selection_point_2D:
251 case e_selection_bounds:
return m_bounds;
252 case e_selection_polygon:
return m_polygon.bounds().template as<t_dims, t_type>();
253 case e_selection_plane:
256 for (
uint01 dim = 0; dim < t_dims; dim++)
258 if (m_plane.normal[dim] == 1)
259 bounds[dim][MAX] = bounds[dim][MIN] = m_plane.d;
260 else if (m_plane.normal[dim] == -1)
261 bounds[dim][MAX] = bounds[dim][MIN] = -m_plane.d;
265 default: lib_assert(
false,
"Unknown selection area mode in as()");
break;
270 template<u
int01 t_new_dims,
class t_new_type>
271 SelectionArea<t_new_dims, t_new_type> as()
const
273 SelectionArea<t_new_dims, t_new_type> new_selection;
276 case e_selection_point_2D:
277 new_selection.setSelection(m_point.template as<2, t_new_type>());
280 case e_selection_point: new_selection.setSelection(m_point.template as<t_new_dims, t_new_type>());
break;
281 case e_selection_line: new_selection.setSelection(m_line.template as<t_new_dims, t_new_type>());
break;
282 case e_selection_bounds: new_selection.setSelection(m_bounds.template as<t_new_dims, t_new_type>());
break;
283 case e_selection_polygon: new_selection.setSelection(m_polygon.template as<t_new_type>());
break;
284 case e_selection_plane: new_selection.setSelection(m_plane.template as<t_new_dims, t_new_type>());
break;
285 default: lib_assert(
false,
"Unknown selection area mode in as()");
break;
287 new_selection.setTransform(m_matrix.template as<t_new_type>());
288 new_selection.setIsInverse(m_is_inverse);
289 new_selection.setIsEnabled(m_is_enabled);
290 return new_selection;
292 bool isPreTransformed()
const
294 return m_is_pre_transformed;
296 template<u
int01 t_new_dims,
class t_new_type>
297 SelectionArea<t_new_dims, t_new_type> preTransformed()
const
299 SelectionArea<t_new_dims, t_new_type> area;
300 if (
sizeof(t_new_type) >
sizeof(t_type))
306 case e_selection_point_2D:
309 setSelection(p.template as<2, t_new_type>());
310 set2DDistanceCutoff(p[Z]);
312 area.setSelection((matrix * m_point.template as<t_new_dims, t_new_type>()).template as<2, t_new_type>());
break;
313 case e_selection_point: area.setSelection(matrix * m_point.template as<t_new_dims, t_new_type>());
break;
314 case e_selection_line: area.setSelection(matrix * m_line.template as<t_new_dims, t_new_type>());
break;
315 case e_selection_bounds: area.setSelection(matrix * m_bounds.template as<t_new_dims, t_new_type>());
break;
316 case e_selection_polygon: area.setSelection(matrix * m_polygon.template as<t_new_type>());
break;
317 default: lib_assert(
false,
"Unknown object to pre-transform");
325 case e_selection_point_2D:
328 setSelection(p.template as<2, t_new_type>());
329 set2DDistanceCutoff(p[Z]);
331 case e_selection_point: area.setSelection((matrix * m_point).
template as<t_new_dims, t_new_type>());
break;
332 case e_selection_line: area.setSelection((matrix * m_line).
template as<t_new_dims, t_new_type>());
break;
333 case e_selection_bounds: area.setSelection((matrix * m_bounds).
template as<t_new_dims, t_new_type>());
break;
334 case e_selection_polygon: area.setSelection((matrix * m_polygon).
template as<t_new_type>());
break;
335 default: lib_assert(
false,
"Unknown object to pre-transform");
338 area.setIsEnabled(m_is_enabled);
339 area.setIsInverse(m_is_inverse);
347 case e_selection_point_2D:
350 setSelection(p.template as<2, t_type>());
351 set2DDistanceCutoff(p[Z]);
353 case e_selection_point: setSelection(mat * m_point);
break;
354 case e_selection_line: setSelection(mat * m_line);
break;
355 case e_selection_bounds: setSelection(mat * m_bounds);
break;
356 case e_selection_polygon: setSelection(mat * m_polygon);
break;
357 default: lib_assert(
false,
"Unknown object to pre-transform");
360 bool isInverse()
const
364 void setIsInverse(
bool is_inverse)
366 m_is_inverse = is_inverse;
368 bool isEnabled()
const
372 void setIsEnabled(
bool is_enabled)
374 m_is_enabled = is_enabled;
376 void set2DDistanceCutoff(t_type distance)
378 m_point[Z] = distance;
382 if (point[MIN][Z] > m_point[Z])
386 for (
uint01 i = 0; i < 2; i++)
397 if (point[Z] > m_point[Z])
401 for (
uint01 i = 0; i < 2; i++)
412 if (seg[A][Z] > m_point[Z] && seg[B][Z] > m_point[Z])
420 if (seg[A][Z] > m_point[Z] && seg[B][Z] > m_point[Z] && seg[C][Z] > m_point[Z])
426 template<
class t_other_type>
427 bool check2DContains(
const t_other_type&)
const
433 return seg.
contains(m_point.template as<2, t_type>());
435 bool operator==(
const SelectionArea& area)
const
437 if(m_mode != area.m_mode)
442 case SelectionMode::e_selection_bounds:
443 if(m_bounds != area.m_bounds)
446 case SelectionMode::e_selection_line:
447 if(m_line != area.m_line)
450 case SelectionMode::e_selection_polygon:
451 if(m_polygon != area.m_polygon)
454 case SelectionMode::e_selection_point_2D:
455 case SelectionMode::e_selection_point:
456 if(m_point != area.m_point)
459 case SelectionMode::e_selection_plane:
460 if (m_plane != area.m_plane)
464 lib_assert(
false,
"unknown selection mode");
466 return m_matrix == area.m_matrix;
468 bool operator!=(
const SelectionArea& area)
const
470 if(m_mode != area.m_mode)
474 case SelectionMode::e_selection_bounds:
475 if(m_bounds != area.m_bounds)
478 case SelectionMode::e_selection_line:
479 if(m_line != area.m_line)
482 case SelectionMode::e_selection_polygon:
483 if(m_polygon != area.m_polygon)
486 case SelectionMode::e_selection_point_2D:
487 case SelectionMode::e_selection_point:
488 if(AreSame(m_point, area.m_point))
491 case SelectionMode::e_selection_plane:
492 if (m_plane != area.m_plane)
496 lib_assert(
false,
"unknown selection mode");
498 return m_matrix != area.m_matrix;
503 if(m_mode == e_selection_polygon)
505 m_polygon.~Polygon<t_type>();
506 m_mode = e_selection_point;
521 bool m_is_pre_transformed;