Skip to content

Commit 162e9eb

Browse files
committed
fix
1 parent 981ba43 commit 162e9eb

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/geode/geometry/quality.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525

2626
#include <limits>
2727

28+
#include <geode/basic/logger.hpp>
29+
2830
#include <geode/geometry/basic_objects/tetrahedron.hpp>
2931
#include <geode/geometry/basic_objects/triangle.hpp>
3032
#include <geode/geometry/mensuration.hpp>
@@ -42,7 +44,8 @@ namespace
4244
geode::Vector< dimension >{ point, point_prev }.normalize();
4345
const auto next =
4446
geode::Vector< dimension >{ point, point_next }.normalize();
45-
const auto angle = std::acos( prev.dot( next ) );
47+
const auto dot = std::clamp( prev.dot( next ), -1.0, 1.0 );
48+
const auto angle = std::acos( dot );
4649
if( std::isnan( angle ) )
4750
{
4851
return 0;
@@ -272,14 +275,18 @@ namespace geode
272275
const auto point_next = vertices[( v + 1 ) % 3].get();
273276
const auto angle =
274277
compute_angle( point, point_prev, point_next );
278+
DEBUG( angle );
275279
sinus[v] = std::sin( angle );
280+
DEBUG( sinus[v] );
276281
}
277-
const auto quality = 4 * sinus[0] * sinus[1] * sinus[2]
278-
/ ( sinus[0] + sinus[1] + sinus[2] );
279-
if( std::isnan( quality ) )
282+
const auto denominator = sinus[0] + sinus[1] + sinus[2];
283+
if( denominator == 0 )
280284
{
281285
return 0;
282286
}
287+
const auto quality =
288+
4 * sinus[0] * sinus[1] * sinus[2] / ( denominator );
289+
DEBUG( quality );
283290
return quality;
284291
}
285292
catch( ... )

0 commit comments

Comments
 (0)