Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/geode/geometry/intersection_detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
if( length2 > max_length2 )
{
max_length2 = length2;
normal = std::move( candidate );

Check warning on line 91 in src/geode/geometry/intersection_detection.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/intersection_detection.cpp:91:26 [hicpp-move-const-arg]

std::move of the variable 'candidate' of the trivially-copyable type 'Vector<3>' has no effect; remove std::move()
}
}
if( max_length2 > 0 )
Expand All @@ -106,14 +106,19 @@
return max_abs_axis( normal.value() );
}
const auto& vertices = triangle.vertices();
const auto& segment_vertices = segment.vertices();
const geode::Vector3D segment_direction{ segment_vertices[0],
segment_vertices[1] };
const auto longest_edge = triangle.longest_edge_index();
if( longest_edge == geode::NO_LID )
{
return coplanar_projection_axis(
segment_vertices[0], segment_direction, { vertices[0] } );
}
const geode::Point3D& origin = vertices[longest_edge];
const geode::Point3D& next =
vertices[longest_edge == 2 ? 0 : longest_edge + 1];
const geode::Vector3D direction{ origin, next };
const auto& segment_vertices = segment.vertices();
const geode::Vector3D segment_direction{ segment_vertices[0],
segment_vertices[1] };
if( segment_direction.length2() > direction.length2() )
{
return coplanar_projection_axis( segment_vertices[0],
Expand All @@ -124,7 +129,7 @@
segment_vertices[1] } );
}

geode::SegmentSegmentIntersection segment_segment_intersection_detection2D(

Check warning on line 132 in src/geode/geometry/intersection_detection.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/intersection_detection.cpp:132:39 [readability-identifier-naming]

invalid case style for function 'segment_segment_intersection_detection2D'

Check warning on line 132 in src/geode/geometry/intersection_detection.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/intersection_detection.cpp:132:39 [readability-function-cognitive-complexity]

function 'segment_segment_intersection_detection2D' has cognitive complexity of 17 (threshold 10)
const geode::Segment2D& segment0, const geode::Segment2D& segment1 )
{
const auto s0_p0_side =
Expand Down Expand Up @@ -180,7 +185,7 @@
}

geode::SegmentTriangleIntersection
segment_triangle_plane_intersection_detection(

Check warning on line 188 in src/geode/geometry/intersection_detection.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/intersection_detection.cpp:188:9 [readability-function-cognitive-complexity]

function 'segment_triangle_plane_intersection_detection' has cognitive complexity of 17 (threshold 10)
const geode::Segment3D& segment, const geode::Triangle3D& triangle )
{
const auto projection_axis = best_projection_axis( triangle, segment );
Expand Down Expand Up @@ -243,7 +248,7 @@
return result;
}

geode::SegmentSegmentIntersection segment_segment_intersection_detection3D(

Check warning on line 251 in src/geode/geometry/intersection_detection.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/intersection_detection.cpp:251:39 [readability-identifier-naming]

invalid case style for function 'segment_segment_intersection_detection3D'
const geode::Segment3D& segment0, const geode::Segment3D& segment1 )
{
if( geode::tetrahedron_volume_sign( geode::Tetrahedron{
Expand Down Expand Up @@ -312,7 +317,7 @@
return segment_segment_intersection_detection3D( segment0, segment1 );
}

SegmentSegmentIntersection colinear_segment_segment_intersection_detection(

Check warning on line 320 in src/geode/geometry/intersection_detection.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/intersection_detection.cpp:320:32 [readability-function-cognitive-complexity]

function 'colinear_segment_segment_intersection_detection' has cognitive complexity of 18 (threshold 10)
const Segment2D& segment0, const Segment2D& segment1 )
{
OpenGeodeGeometryException::check_assertion(
Expand Down
6 changes: 6 additions & 0 deletions src/geode/geometry/radial_sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
}

private:
void recursive_sort( absl::FixedArray< geode::index_t >& result,

Check warning on line 58 in src/geode/geometry/radial_sort.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/radial_sort.cpp:58:14 [readability-function-cognitive-complexity]

function 'recursive_sort' has cognitive complexity of 13 (threshold 10)
geode::index_t begin,
geode::index_t end )
{
Expand All @@ -70,7 +70,7 @@
std::vector< geode::index_t > same;
for( const auto i : geode::Range{ size - 1 } )
{
const auto id = begin + i + 1;

Check warning on line 73 in src/geode/geometry/radial_sort.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/radial_sort.cpp:73:28 [readability-identifier-length]

variable name 'id' is too short, expected at least 3 characters
const auto side = geode::point_side_to_triangle(
points_[result[id]], { segment_.vertices()[0].get(),
segment_.vertices()[1].get(),
Expand Down Expand Up @@ -107,7 +107,7 @@
}
}
}
for( const auto id : same )

Check warning on line 110 in src/geode/geometry/radial_sort.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/radial_sort.cpp:110:29 [readability-identifier-length]

variable name 'id' is too short, expected at least 3 characters
{
sorted[left_id++] = id;
}
Expand All @@ -115,7 +115,7 @@
left_id == right_id, "[RadialSort::recursive_sort] left and "
"right ids are different" );
sorted[left_id] = result[begin];
absl::c_copy( sorted, result.begin() + begin );

Check warning on line 118 in src/geode/geometry/radial_sort.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/geometry/radial_sort.cpp:118:50 [cppcoreguidelines-pro-bounds-pointer-arithmetic]

do not use pointer arithmetic
const auto left_middle_id = begin + left_id - same.size();
if( left_middle_id != begin )
{
Expand All @@ -140,6 +140,12 @@
absl::FixedArray< index_t > radial_sort(
const Segment3D& segment, absl::Span< const Point3D > points )
{
if( points.size() < 3 )
{
absl::FixedArray< index_t > identity( points.size() );
absl::c_iota( identity, 0 );
return identity;
}
RadialSort radial_sort{ segment, points };
return radial_sort.sort();
}
Expand Down
10 changes: 10 additions & 0 deletions tests/geometry/test-intersection-detection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,16 @@ void test_segment_degenerated_triangle_intersection_detection()
geode::POSITION::parallel, geode::POSITION::parallel ),
"Wrong result for segment_triangle_intersection_detection with "
"segment crossing a cap triangle in its plane" );

const geode::Triangle3D point_triangle{ c, c, c };
const auto far_from_point = geode::segment_triangle_intersection_detection(
geode::Segment3D{ d, e }, point_triangle );
geode::OpenGeodeGeometryException::test(
far_from_point
== std::make_pair(
geode::POSITION::outside, geode::POSITION::outside ),
"Wrong result for segment_triangle_intersection_detection with "
"triangle collapsed to a point far from the segment" );
}

void test_segment_line_intersection_detection()
Expand Down
13 changes: 13 additions & 0 deletions tests/geometry/test-radial-sort.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,23 @@ void test_2()
sorted == answer, "Wrong radial sorting" );
}

void test_degenerated_segment()
{
geode::Point3D s0{ { 0, 0, 1 } };
geode::Point3D a{ { 0, 0.5, 1.5 } };
geode::Point3D b{ { 0, 0, 0.5 } };

const auto sorted = geode::radial_sort( { s0, s0 }, { a, b } );
const absl::FixedArray< geode::index_t > answer{ 0, 1 };
geode::OpenGeodeGeometryException::test(
sorted == answer, "Wrong radial sorting on degenerated segment" );
}

void test()
{
test_1();
test_2();
test_degenerated_segment();

geode::Logger::info( "TEST SUCCESS" );
}
Expand Down
Loading