From 356efaf89afdad141b313767e1a2b89de3c08d0a Mon Sep 17 00:00:00 2001 From: neoraider Date: Sun, 6 Apr 2008 13:29:03 +0000 Subject: zoomedit: Recreated ZoomEdit based on Glademm. --- Triangle.cpp | 70 ------------------------------------------------------------ 1 file changed, 70 deletions(-) delete mode 100644 Triangle.cpp (limited to 'Triangle.cpp') diff --git a/Triangle.cpp b/Triangle.cpp deleted file mode 100644 index 7587589..0000000 --- a/Triangle.cpp +++ /dev/null @@ -1,70 +0,0 @@ -#include "Triangle.h" -#include "Line.h" -#include -#include - - -Triangle::Direction Triangle::getDirection() const { - float c = (va.getX()-vb.getX())*(vc.getY()-vb.getY()) - (vc.getX()-vb.getX())*(va.getY()-vb.getY()); - - return (c < 0) ? CW : (c > 0) ? CCW : UNKNOWN; -} - -float Triangle::area() const { - float a = vb.distanceSq(vc); - float b = vc.distanceSq(va); - float c = va.distanceSq(vb); - - return sqrt((a+b+c)*a+b+c - 2*(a*a+b*b+c*c))/4; -} - -float Triangle::perimeter() const { - return va.distance(vb) + vb.distance(vc) + vc.distance(va); -} - -bool Triangle::contains(const Vertex &v) const { - float a = (v.getX()-vb.getX())*(vc.getY()-vb.getY()) - (vc.getX()-vb.getX())*(v.getY()-vb.getY()); - float b = (v.getX()-vc.getX())*(va.getY()-vc.getY()) - (va.getX()-vc.getX())*(v.getY()-vc.getY()); - float c = (v.getX()-va.getX())*(vb.getY()-va.getY()) - (vb.getX()-va.getX())*(v.getY()-va.getY()); - - switch(getDirection()) { - case CW: - return ((a < 1E-6) && (b < 1E-6) && (c < 1E-6)); - case CCW: - return ((a > -1E-6) && (b > -1E-6) && (c > -1E-6)); - default: - return false; - } -} - -bool Triangle::onEdge(const Vertex &v) const { - return (Line(va, vb).contains(v) || Line(vb, vc).contains(v) || Line(vc, va).contains(v)); -} - -int Triangle::intersectionCount(const Line &l) const { - int ret = 0; - Vertex v1, v2, v3; - - printf("Testing line: (%f %f) (%f %f)\n", l.getVertex1().getX(), l.getVertex1().getY(), l.getVertex2().getX(), l.getVertex2().getY()); - if(Line(va, vb).intersects(l, &v1) == INTERSECTION_SEGMENT_SEGMENT) { - printf("Intersection: (%f %f)\n", v1.getX(), v1.getY()); - ret++; - } - - if(Line(vb, vc).intersects(l, &v2) == INTERSECTION_SEGMENT_SEGMENT) { - printf("Intersection: (%f %f)\n", v2.getX(), v2.getY()); - if(v2.distanceSq(v1) >= 1E-6) - ret++; - } - - if(Line(vc, va).intersects(l, &v3) == INTERSECTION_SEGMENT_SEGMENT) { - printf("Intersection: (%f %f)\n", v3.getX(), v3.getY()); - if(v3.distanceSq(v1) >= 1E-6 && v3.distanceSq(v2) >= 1E-6) - ret++; - } - - printf("Found %i intersections.\n", ret); - - - return ret; -} -- cgit v1.2.3