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
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Checks: >
-misc-no-recursion,
-misc-include-cleaner,
-misc-const-correctness,
-modernize-use-scoped-lock,
-modernize-use-trailing-return-type,
-portability-avoid-pragma-once,
-readability-use-anyofallof,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,15 +51,11 @@
{
struct ComponentOverlap
{
bool operator()(
geode::index_t first_component, geode::index_t second_component )
[[nodiscard]] bool operator()( geode::index_t /*first_component*/,
geode::index_t /*second_component*/ ) const
{
component_pairs.emplace_back( first_component, second_component );
return false;
return true;
}

std::vector< std::pair< geode::index_t, geode::index_t > >
component_pairs;
};

[[nodiscard]] absl::InlinedVector< geode::PolygonVertices, 1 >
Expand All @@ -82,7 +78,7 @@
{
public:
BRepLineSurfacesIntersection( const geode::BRep& model,
const geode::uuid& surface_id,

Check warning on line 81 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:81:13 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'BRepLineSurfacesIntersection' of similar type ('const geode::uuid &') are easily swapped by mistake
const geode::uuid& line_id )
: surface_( model.surface( surface_id ) ),
line_( model.line( line_id ) ),
Expand Down Expand Up @@ -164,7 +160,7 @@
class ModelIntersectionBase
{
public:
ModelIntersectionBase( const Model& model ) : model_( model ) {}

Check warning on line 163 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:163:9 [google-explicit-constructor]

single-argument constructors must be marked explicit to avoid unintentional implicit conversions

[[nodiscard]] std::vector< std::pair< geode::index_t, geode::index_t > >
intersecting_elements()
Expand Down Expand Up @@ -205,9 +201,15 @@
{
}

[[nodiscard]] bool self_intersect(
geode::index_t p1_id, geode::index_t p2_id ) const
{
return p1_id != p2_id && polygons_intersect( p1_id, p2_id );
}

protected:
[[nodiscard]] bool polygons_intersect(
geode::index_t p1_id, geode::index_t p2_id ) const

Check warning on line 212 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:212:13 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'polygons_intersect' of similar type ('geode::index_t') are easily swapped by mistake
{
const auto p1_vertices = this->mesh1().polygon_vertices( p1_id );
const auto p2_vertices = this->mesh2().polygon_vertices( p2_id );
Expand Down Expand Up @@ -249,7 +251,7 @@

[[nodiscard]] absl::InlinedVector< std::array< geode::index_t, 2 >, 3 >
triangles_common_vertices(
const geode::PolygonVertices& t1_vertices,

Check warning on line 254 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:254:17 [bugprone-easily-swappable-parameters]

2 adjacent parameters of 'triangles_common_vertices' of similar type ('const geode::PolygonVertices &') are easily swapped by mistake
const geode::PolygonVertices& t2_vertices ) const
{
absl::InlinedVector< std::array< geode::index_t, 2 >, 3 >
Expand Down Expand Up @@ -425,7 +427,7 @@

template <>
[[nodiscard]] bool
ModelSurfacesIntersectionBase< geode::Section >::triangles_intersect(

Check warning on line 430 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:430:58 [readability-function-cognitive-complexity]

function 'triangles_intersect' has cognitive complexity of 28 (threshold 10)
const geode::PolygonVertices& t1_vertices,
const geode::PolygonVertices& t2_vertices,
absl::Span< const std::array< geode::index_t, 2 > >
Expand Down Expand Up @@ -505,7 +507,7 @@
return false;
}

[[nodiscard]] bool triangle_intersects_other(

Check warning on line 510 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:510:24 [readability-function-size]

function 'triangle_intersects_other' exceeds recommended size/complexity thresholds

Check warning on line 510 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:510:24 [readability-function-cognitive-complexity]

function 'triangle_intersects_other' has cognitive complexity of 22 (threshold 10)
const geode::Triangle3D& triangle1,
const geode::Triangle3D& triangle2,
const geode::PolygonVertices& t1_vertices,
Expand Down Expand Up @@ -574,7 +576,7 @@
const auto triangle1 = mesh_triangle( mesh1_, t1_vertices );
return triangle_intersects_other( triangle1, triangle2, t1_vertices,
t2_vertices, common_vertices, 1 )
|| triangle_intersects_other( triangle2, triangle1, t2_vertices,

Check warning on line 579 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:579:19 [readability-suspicious-call-argument]

3rd argument 't2_vertices' (passed to 't1_vertices') looks like it might be swapped with the 4th, 't1_vertices' (passed to 't2_vertices')

Check warning on line 579 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:579:19 [readability-suspicious-call-argument]

1st argument 'triangle2' (passed to 'triangle1') looks like it might be swapped with the 2nd, 'triangle1' (passed to 'triangle2')
t1_vertices, common_vertices, 0 );
}

Expand Down Expand Up @@ -609,8 +611,14 @@
return false;
}

[[nodiscard]] bool self_intersect(
geode::index_t e1_id, geode::index_t e2_id ) const
{
return e1_id != e2_id && lines_intersect( e1_id, e2_id );
}

private:
bool lines_intersect( geode::index_t p1_id, geode::index_t p2_id ) const

Check warning on line 621 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:621:9 [modernize-use-nodiscard]

function 'lines_intersect' should be marked [[nodiscard]]
{
const auto [position1, position2] =
geode::segment_segment_intersection_detection(
Expand All @@ -626,6 +634,25 @@
const geode::EdgedCurve< dimension >& mesh2_;
const bool same_line_{ false };
};

template < typename Action >
class SelfIntersectionTest
{
public:
explicit SelfIntersectionTest( const Action& action )
: action_( action )
{
}

[[nodiscard]] bool operator()(
geode::index_t element1, geode::index_t element2 ) const
{
return action_.self_intersect( element1, element2 );
}

private:
const Action& action_;
};
} // namespace

namespace geode
Expand Down Expand Up @@ -785,17 +812,19 @@
for( const auto& surface : model_.active_surfaces() )
{
tasks.emplace_back( async::spawn( [this, &surface] {
Action surfaces_intersection_action{ model_, surface.id(),
surface.id() };
surfaces_model_tree_
.mesh_trees_[surfaces_model_tree_.mesh_tree_ids_.at(
surface.id() )]
.compute_self_element_bbox_intersections(
surfaces_intersection_action );
const Action surfaces_intersection_action{ model_,
surface.id(), surface.id() };
const auto intersecting_elements =
surfaces_model_tree_
.mesh_trees_[surfaces_model_tree_.mesh_tree_ids_.at(
surface.id() )]
.compute_self_element_bbox_intersections(

Check failure on line 821 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:821:30 [clang-diagnostic-error]

no matching member function for call to 'compute_self_element_bbox_intersections'
SelfIntersectionTest< Action >{
surfaces_intersection_action } );
IntersectionsResult result;
const auto surface_id = surface.component_id();
for( const auto& [polygon1, polygon2] :
surfaces_intersection_action.intersecting_elements() )
intersecting_elements )
{
result.emplace_back(
ComponentMeshElement{ surface_id, polygon1 },
Expand All @@ -804,10 +833,11 @@
return result;
} ) );
}
ComponentOverlap surfaces_overlap;
surfaces_model_tree_.components_tree_
.compute_self_element_bbox_intersections( surfaces_overlap );
for( const auto& components : surfaces_overlap.component_pairs )
const auto surfaces_overlap =
surfaces_model_tree_.components_tree_
.compute_self_element_bbox_intersections(

Check failure on line 838 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:838:22 [clang-diagnostic-error]

no matching member function for call to 'compute_self_element_bbox_intersections'
ComponentOverlap{} );
for( const auto& components : surfaces_overlap )
{
tasks.emplace_back( async::spawn( [this, &components] {
const auto surface_uuid1 =
Expand Down Expand Up @@ -865,17 +895,20 @@
for( const auto& line : model_.active_lines() )
{
tasks.emplace_back( async::spawn( [this, &line] {
LineLineIntersection lines_intersection_action{ model_,
line.id(), line.id() };
lines_model_tree_
.mesh_trees_[lines_model_tree_.mesh_tree_ids_.at(
line.id() )]
.compute_self_element_bbox_intersections(
lines_intersection_action );
const LineLineIntersection lines_intersection_action{
model_, line.id(), line.id()
};
const auto intersecting_elements =
lines_model_tree_
.mesh_trees_[lines_model_tree_.mesh_tree_ids_.at(
line.id() )]
.compute_self_element_bbox_intersections(

Check failure on line 905 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:905:30 [clang-diagnostic-error]

no matching member function for call to 'compute_self_element_bbox_intersections'
SelfIntersectionTest<
LineLineIntersection< Model > >{
lines_intersection_action } );
IntersectionsResult result;
const auto line_id = line.component_id();
for( const auto& [edge1, edge2] :
lines_intersection_action.intersecting_elements() )
for( const auto& [edge1, edge2] : intersecting_elements )
{
result.emplace_back(
ComponentMeshElement{ line_id, edge1 },
Expand All @@ -884,10 +917,11 @@
return result;
} ) );
}
ComponentOverlap lines_overlap;
lines_model_tree_.components_tree_
.compute_self_element_bbox_intersections( lines_overlap );
for( const auto& components : lines_overlap.component_pairs )
const auto lines_overlap =
lines_model_tree_.components_tree_
.compute_self_element_bbox_intersections(

Check failure on line 922 in src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/model_intersections.cpp:922:22 [clang-diagnostic-error]

no matching member function for call to 'compute_self_element_bbox_intersections'
ComponentOverlap{} );
for( const auto& components : lines_overlap )
{
tasks.emplace_back( async::spawn( [this, &components] {
const auto line_uuid1 =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,55 +41,28 @@
class PolygonPolygonIntersection
{
public:
PolygonPolygonIntersection( const geode::SurfaceMesh< dimension >& mesh,
bool stop_at_first_intersection )
: mesh_( mesh ),
stop_at_first_intersection_{ stop_at_first_intersection }
explicit PolygonPolygonIntersection(
const geode::SurfaceMesh< dimension >& mesh )
: mesh_( mesh )
{
}

std::vector< std::pair< geode::index_t, geode::index_t > >
intersecting_polygons()
{
return std::move( intersecting_polygons_ );
}

bool operator()( geode::index_t p1_id, geode::index_t p2_id )
[[nodiscard]] bool operator()(
geode::index_t p1_id, geode::index_t p2_id ) const
{
if( p1_id == p2_id )
{
return false;
}
const auto p1_vertices = this->mesh().polygon_vertices( p1_id );
const auto p2_vertices = this->mesh().polygon_vertices( p2_id );
if( geode::detail::polygons_intersection_detection<
geode::SurfaceMesh< dimension > >(
mesh_, p1_vertices, p2_vertices ) )
{
this->emplace( p1_id, p2_id );
return stop_at_first_intersection_;
}
return false;
}

protected:
void emplace( geode::index_t p1_id, geode::index_t p2_id )
{
std::lock_guard< std::mutex > lock( mutex_ );
intersecting_polygons_.emplace_back( p1_id, p2_id );
}

const geode::SurfaceMesh< dimension >& mesh() const
{
return mesh_;
const auto p1_vertices = mesh_.polygon_vertices( p1_id );
const auto p2_vertices = mesh_.polygon_vertices( p2_id );
return geode::detail::polygons_intersection_detection<
geode::SurfaceMesh< dimension > >(
mesh_, p1_vertices, p2_vertices );
}

private:
const geode::SurfaceMesh< dimension >& mesh_;
bool stop_at_first_intersection_;
std::vector< std::pair< geode::index_t, geode::index_t > >
intersecting_polygons_;
std::mutex mutex_;
};
} // namespace

Expand All @@ -106,7 +79,7 @@

bool mesh_has_self_intersections() const
{
const auto intersections = intersecting_polygons( true );
const auto intersections = intersecting_polygons();
if( intersections.empty() )
{
return false;
Expand All @@ -117,7 +90,7 @@
InspectionIssues< std::pair< index_t, index_t > >
intersecting_elements() const
{
const auto intersections = intersecting_polygons( false );
const auto intersections = intersecting_polygons();
InspectionIssues< std::pair< index_t, index_t > > issues{
"intersections between polygons"
};
Expand All @@ -132,14 +105,13 @@
}

private:
std::vector< std::pair< index_t, index_t > > intersecting_polygons(
bool stop_at_first_intersection ) const
std::vector< std::pair< index_t, index_t > >
intersecting_polygons() const
{
const auto surface_aabb = create_aabb_tree( mesh_ );
PolygonPolygonIntersection< dimension > action{ mesh_,
stop_at_first_intersection };
surface_aabb.compute_self_element_bbox_intersections( action );
return action.intersecting_polygons();
const PolygonPolygonIntersection< dimension > action{ mesh_ };
return surface_aabb.compute_self_element_bbox_intersections(

Check failure on line 113 in src/geode/inspector/inspection/criterion/intersections/surface_intersections.cpp

View workflow job for this annotation

GitHub Actions / test / tidy

src/geode/inspector/inspection/criterion/intersections/surface_intersections.cpp:113:20 [clang-diagnostic-error]

no viable conversion from returned value of type 'void' to function return type 'std::vector<std::pair<index_t, index_t>>' (aka 'vector<pair<unsigned int, unsigned int>>')
action );
}

private:
Expand Down
Loading