added Polygon::add(), Polygon::containsPoint(); initial attempt at rendering Extrude objects
git-svn-id: svn://anubis/fart/trunk@272 7f9b0f55-74a9-4bce-be96-3c2cd072584d
This commit is contained in:
1 parent
b51d11d043
commit
7bac2fb076
4 files changed
+94
-2
No files matched your search
@@ -1,2 +1,20 @@
|
||||
|
||||
#include <math.h> /* acos(), M_PI */
|
||||
|
||||
#include "Polygon.h"
|
||||
|
||||
#define FP_EQUAL(x,y) (fabs((x)-(y)) < 1E-6)
|
||||
|
||||
bool Polygon::containsPoint(const Vector & v)
|
||||
{
|
||||
double angle_sum = 0.0;
|
||||
for (int i = 0, sz = size(); i < sz; i++)
|
||||
{
|
||||
Vector v1 = *(*this)[i] - v;
|
||||
Vector v2 = *(*this)[(i+1) % sz] - v;
|
||||
double cosine = (v1 % v2) / (v1.mag() * v2.mag());
|
||||
double angle = acos(cosine);
|
||||
angle_sum += angle;
|
||||
}
|
||||
return FP_EQUAL(angle_sum, 2.0 * M_PI);
|
||||
}
|
||||
@@ -9,6 +9,18 @@
|
||||
|
||||
class Polygon : public std::vector< refptr<Vector> >
|
||||
{
|
||||
public:
|
||||
Polygon & add(const Vector & v)
|
||||
{
|
||||
push_back(new Vector(v));
|
||||
return *this;
|
||||
}
|
||||
Polygon & add(refptr<Vector> v)
|
||||
{
|
||||
push_back(v);
|
||||
return *this;
|
||||
}
|
||||
bool containsPoint(const Vector & v);
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in new issue
Block a user