diff --git a/face.cpp b/face.cpp index 8b81939..9dae758 100644 --- a/face.cpp +++ b/face.cpp @@ -7,6 +7,7 @@ #include #include #include + #include "face.h" #include "edge.h" @@ -187,4 +188,28 @@ double face::calc_area() const return(0.5*(A|B).length()); } +/*! +* Checks wether the face is an obtuse triangle. This requires evaluating +* the `is_obtuse` flag. If the value of this flag has not yet been set, +* the function performs an obtusity test, sets the flag, and returns its +* value. +* +* @return true if the face is an obtuse triangle, else false +*/ + +bool face::is_obtuse() +{ + using boost::logic::tribool; + if(indeterminate(obtuse)) + { + double a = E[0].e->calc_length(); + double b = E[1].e->calc_length(); + double c = E[2].e->calc_length(); + + obtuse = (a*a+b*b < c*c) || (b*b* + c*c < a*a) || (c*c + a*a < b*b); + } + + return(obtuse == true); +} + } // end of namespace "psalm" diff --git a/face.h b/face.h index daaf067..8248968 100644 --- a/face.h +++ b/face.h @@ -6,6 +6,8 @@ #ifndef __FACE_H__ #define __FACE_H__ +#include + #include "vertex.h" #include "directed_edge.h" @@ -50,6 +52,8 @@ class face bool is_on_boundary() const; void set_on_boundary(bool boundary = true); + bool is_obtuse(); + void reconstruct_from_edges(); double calc_area() const; @@ -64,6 +68,16 @@ class face bool boundary; ///< Flag signalling that the face is a ///< boundary face. + + /*! + * Flag signalling that the face is an obtuse triangle. + * This makes only sense for triangles, of course. By + * using the tribool, the function `is_obtuse()` may + * decide whether it is required to _calculate_ the value + * of the flag or can simply return it. + */ + + boost::logic::tribool obtuse; }; } // end of namespace "psalm"