| 56 | |
| 57 | private: |
| 58 | void recursive_sort( absl::FixedArray< geode::index_t >& result, |
| 59 | geode::index_t begin, |
| 60 | geode::index_t end ) |
| 61 | { |
| 62 | const auto size = end - begin + 1; |
| 63 | if( size < 2 ) |
| 64 | { |
| 65 | return; |
| 66 | } |
| 67 | geode::index_t left_id{ 0 }; |
| 68 | geode::index_t right_id{ size - 1 }; |
| 69 | absl::FixedArray< geode::index_t > sorted( size ); |
| 70 | std::vector< geode::index_t > same; |
| 71 | for( const auto i : geode::Range{ size - 1 } ) |
| 72 | { |
| 73 | const auto id = begin + i + 1; |
| 74 | const auto side = geode::point_side_to_triangle( |
| 75 | points_[result[id]], { segment_.vertices()[0].get(), |
| 76 | segment_.vertices()[1].get(), |
| 77 | points_[result[begin]] } ); |
| 78 | if( side == geode::SIDE::positive ) |
| 79 | { |
| 80 | sorted[left_id++] = result[id]; |
| 81 | } |
| 82 | else if( side == geode::SIDE::negative ) |
| 83 | { |
| 84 | sorted[right_id--] = result[id]; |
| 85 | } |
| 86 | else |
| 87 | { |
| 88 | const auto proj_begin = geode::point_plane_projection( |
| 89 | points_[result[begin]], plane_ ); |
| 90 | const auto proj = geode::point_plane_projection( |
| 91 | points_[result[id]], plane_ ); |
| 92 | const auto dot0 = |
| 93 | GEO::PCK::dot_3d( proj_begin, plane_.origin(), proj ); |
| 94 | const auto dot1 = |
| 95 | GEO::PCK::dot_3d( proj, plane_.origin(), proj_begin ); |
| 96 | const auto position = |
| 97 | geode::internal::point_segment_position( |
| 98 | geode::internal::side( dot0 ), |
| 99 | geode::internal::opposite_side( dot1 ) ); |
| 100 | if( position == geode::POSITION::inside ) |
| 101 | { |
| 102 | sorted[right_id--] = result[id]; |
| 103 | } |
| 104 | else |
| 105 | { |
| 106 | same.push_back( result[id] ); |
| 107 | } |
| 108 | } |
| 109 | } |
| 110 | for( const auto id : same ) |
| 111 | { |
| 112 | sorted[left_id++] = id; |
| 113 | } |
| 114 | geode::OpenGeodeGeometryException::check_assertion( |
| 115 | left_id == right_id, "[RadialSort::recursive_sort] left and " |
nothing calls this directly
no test coverage detected