Skip to content

Commit

Permalink
Added face::is_obtuse()
Browse files Browse the repository at this point in the history
  • Loading branch information
Pseudomanifold committed Feb 14, 2011
1 parent 37ec2b0 commit 65a9d5b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
25 changes: 25 additions & 0 deletions face.cpp
Expand Up @@ -7,6 +7,7 @@
#include <iostream>
#include <stdexcept>
#include <limits>

#include "face.h"
#include "edge.h"

Expand Down Expand Up @@ -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"
14 changes: 14 additions & 0 deletions face.h
Expand Up @@ -6,6 +6,8 @@
#ifndef __FACE_H__
#define __FACE_H__

#include <boost/logic/tribool.hpp>

#include "vertex.h"
#include "directed_edge.h"

Expand Down Expand Up @@ -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;
Expand All @@ -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"
Expand Down

0 comments on commit 65a9d5b

Please sign in to comment.