Skip to content

Commit

Permalink
Merge pull request #1066 from Geode-solutions/fix/surface-segment
Browse files Browse the repository at this point in the history
fix(SurfaceMesh): create Segment from PolygonEdge
  • Loading branch information
MelchiorSchuh authored Jan 3, 2025
2 parents 48c2759 + 000b0c1 commit cb7d015
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/geode/geometry/basic_objects/triangle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ namespace geode
[[nodiscard]] const std::array< PointType, 3 >& vertices() const;
[[nodiscard]] BoundingBox< dimension > bounding_box() const;
[[nodiscard]] local_index_t longest_edge_index() const;
[[nodiscard]] local_index_t smallest_edge_index() const;
[[nodiscard]] double minimum_height() const;
[[nodiscard]] bool is_degenerated() const;
[[nodiscard]] std::string string() const;
Expand Down
4 changes: 4 additions & 0 deletions include/geode/mesh/core/surface_mesh.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ namespace geode
FORWARD_DECLARATION_DIMENSION_CLASS( Polygon );
FORWARD_DECLARATION_DIMENSION_CLASS( Vector );
FORWARD_DECLARATION_DIMENSION_CLASS( BoundingBox );
FORWARD_DECLARATION_DIMENSION_CLASS( Segment );
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceEdges );
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMeshBuilder );

Expand Down Expand Up @@ -404,6 +405,9 @@ namespace geode
[[nodiscard]] std::optional< PolygonEdge > polygon_edge_from_vertices(
index_t from_vertex_id, index_t to_vertex_id ) const;

[[nodiscard]] Segment< dimension > segment(
const PolygonEdge& polygon_edge ) const;

/*!
* Find the polygon edges corresponding to a pair of vertex indices.
* @return Local indices of the edges found
Expand Down
21 changes: 21 additions & 0 deletions src/geode/geometry/basic_objects/triangle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,27 @@ namespace geode
return max_length_edge_id;
}

template < typename PointType, index_t dimension >
local_index_t
GenericTriangle< PointType, dimension >::smallest_edge_index() const
{
local_index_t min_length_edge_id{ NO_LID };
auto edge_min_length = std::numeric_limits< double >::max();
for( const auto edge_id : LRange{ 3 } )
{
const auto next_vertex = edge_id == 2 ? 0 : edge_id + 1;
const Point< dimension >& point0 = vertices_.at( edge_id );
const Point< dimension >& point1 = vertices_.at( next_vertex );
const auto edge_length = point_point_distance( point0, point1 );
if( edge_length < edge_min_length )
{
min_length_edge_id = edge_id;
edge_min_length = edge_length;
}
}
return min_length_edge_id;
}

template < typename PointType, index_t dimension >
double GenericTriangle< PointType, dimension >::minimum_height() const
{
Expand Down
8 changes: 8 additions & 0 deletions src/geode/mesh/core/surface_mesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -911,6 +911,14 @@ namespace geode
return std::nullopt;
}

template < index_t dimension >
Segment< dimension > SurfaceMesh< dimension >::segment(
const PolygonEdge& polygon_edge ) const
{
const auto vertices = polygon_edge_vertices( polygon_edge );
return { this->point( vertices[0] ), this->point( vertices[1] ) };
}

template < index_t dimension >
PolygonsAroundEdge SurfaceMesh< dimension >::polygons_from_edge_vertices(
absl::Span< const index_t > edge_vertices ) const
Expand Down

0 comments on commit cb7d015

Please sign in to comment.