Skip to content

Commit 03bed4b

Browse files
committed
fix(SurfaceMesh): create Segment from PolygonEdge
1 parent 48c2759 commit 03bed4b

File tree

4 files changed

+36
-4
lines changed

4 files changed

+36
-4
lines changed

include/geode/geometry/basic_objects/triangle.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ namespace geode
8484
[[nodiscard]] const std::array< PointType, 3 >& vertices() const;
8585
[[nodiscard]] BoundingBox< dimension > bounding_box() const;
8686
[[nodiscard]] local_index_t longest_edge_index() const;
87+
[[nodiscard]] local_index_t smallest_edge_index() const;
8788
[[nodiscard]] double minimum_height() const;
8889
[[nodiscard]] bool is_degenerated() const;
8990
[[nodiscard]] std::string string() const;

include/geode/mesh/core/surface_mesh.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ namespace geode
4040
FORWARD_DECLARATION_DIMENSION_CLASS( Polygon );
4141
FORWARD_DECLARATION_DIMENSION_CLASS( Vector );
4242
FORWARD_DECLARATION_DIMENSION_CLASS( BoundingBox );
43+
FORWARD_DECLARATION_DIMENSION_CLASS( Segment );
4344
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceEdges );
4445
FORWARD_DECLARATION_DIMENSION_CLASS( SurfaceMeshBuilder );
4546

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

408+
[[nodiscard]] Segment< dimension > segment(
409+
const PolygonEdge& polygon_edge ) const;
410+
407411
/*!
408412
* Find the polygon edges corresponding to a pair of vertex indices.
409413
* @return Local indices of the edges found

src/geode/geometry/basic_objects/triangle.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,27 @@ namespace geode
256256
return max_length_edge_id;
257257
}
258258

259+
template < typename PointType, index_t dimension >
260+
local_index_t
261+
GenericTriangle< PointType, dimension >::smallest_edge_index() const
262+
{
263+
local_index_t min_length_edge_id{ NO_LID };
264+
auto edge_min_length = std::numeric_limits< double >::max();
265+
for( const auto edge_id : LRange{ 3 } )
266+
{
267+
const auto next_vertex = edge_id == 2 ? 0 : edge_id + 1;
268+
const Point< dimension >& point0 = vertices_.at( edge_id );
269+
const Point< dimension >& point1 = vertices_.at( next_vertex );
270+
const auto edge_length = point_point_distance( point0, point1 );
271+
if( edge_length < edge_min_length )
272+
{
273+
min_length_edge_id = edge_id;
274+
edge_min_length = edge_length;
275+
}
276+
}
277+
return min_length_edge_id;
278+
}
279+
259280
template < typename PointType, index_t dimension >
260281
double GenericTriangle< PointType, dimension >::minimum_height() const
261282
{

src/geode/mesh/core/surface_mesh.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,11 @@ namespace geode
274274

275275
public:
276276
Impl( SurfaceMesh& surface )
277-
: polygon_around_vertex_(
278-
surface.vertex_attribute_manager()
277+
: polygon_around_vertex_( surface.vertex_attribute_manager()
279278
.template find_or_create_attribute< VariableAttribute,
280279
PolygonVertex >(
281280
"polygon_around_vertex", PolygonVertex{} ) ),
282-
polygons_around_vertex_(
283-
surface.vertex_attribute_manager()
281+
polygons_around_vertex_( surface.vertex_attribute_manager()
284282
.template find_or_create_attribute< VariableAttribute,
285283
CachedPolygons >(
286284
POLYGONS_AROUND_VERTEX_NAME, CachedPolygons{} ) )
@@ -911,6 +909,14 @@ namespace geode
911909
return std::nullopt;
912910
}
913911

912+
template < index_t dimension >
913+
Segment< dimension > SurfaceMesh< dimension >::segment(
914+
const PolygonEdge& polygon_edge ) const
915+
{
916+
const auto vertices = polygon_edge_vertices( polygon_edge );
917+
return { this->point( vertices[0] ), this->point( vertices[1] ) };
918+
}
919+
914920
template < index_t dimension >
915921
PolygonsAroundEdge SurfaceMesh< dimension >::polygons_from_edge_vertices(
916922
absl::Span< const index_t > edge_vertices ) const

0 commit comments

Comments
 (0)