mirror of
https://github.com/jhasse/poly2tri.git
synced 2024-11-26 15:26:12 +01:00
Add new function Triangle::CircumcicleContains
This commit is contained in:
parent
e9454880fb
commit
96b08ee75c
@ -14,6 +14,7 @@ boost_test_dep = dependency('boost', modules : [ 'unit_test_framework' ], requir
|
||||
if boost_test_dep.found()
|
||||
test('Unit Test', executable('unittest', [
|
||||
'unittest/main.cpp',
|
||||
'unittest/TriangleTest.cpp',
|
||||
], dependencies : [boost_test_dep, thread_dep], link_with : lib))
|
||||
endif
|
||||
|
||||
|
@ -365,4 +365,28 @@ void Triangle::DebugPrint()
|
||||
std::cout << *points_[0] << " " << *points_[1] << " " << *points_[2] << std::endl;
|
||||
}
|
||||
|
||||
bool Triangle::CircumcicleContains(const Point& point) const
|
||||
{
|
||||
assert(IsCounterClockwise());
|
||||
const double dx = points_[0]->x - point.x;
|
||||
const double dy = points_[0]->y - point.y;
|
||||
const double ex = points_[1]->x - point.x;
|
||||
const double ey = points_[1]->y - point.y;
|
||||
const double fx = points_[2]->x - point.x;
|
||||
const double fy = points_[2]->y - point.y;
|
||||
|
||||
const double ap = dx * dx + dy * dy;
|
||||
const double bp = ex * ex + ey * ey;
|
||||
const double cp = fx * fx + fy * fy;
|
||||
|
||||
return (dx * (fy * bp - cp * ey) - dy * (fx * bp - cp * ex) + ap * (fx * ey - fy * ex)) < 0;
|
||||
}
|
||||
|
||||
bool Triangle::IsCounterClockwise() const
|
||||
{
|
||||
return (points_[1]->x - points_[0]->x) * (points_[2]->y - points_[0]->y) -
|
||||
(points_[2]->x - points_[0]->x) * (points_[1]->y - points_[0]->y) >
|
||||
0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -207,8 +207,12 @@ Triangle& NeighborAcross(const Point& opoint);
|
||||
|
||||
void DebugPrint();
|
||||
|
||||
bool CircumcicleContains(const Point&) const;
|
||||
|
||||
private:
|
||||
|
||||
bool IsCounterClockwise() const;
|
||||
|
||||
/// Triangle points
|
||||
Point* points_[3];
|
||||
/// Neighbor list
|
||||
|
15
unittest/TriangleTest.cpp
Normal file
15
unittest/TriangleTest.cpp
Normal file
@ -0,0 +1,15 @@
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include <poly2tri/common/shapes.h>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(TriangleTest)
|
||||
{
|
||||
p2t::Point a(0, 0);
|
||||
p2t::Point b(1, 0);
|
||||
p2t::Point c(0.5, .5);
|
||||
p2t::Triangle triangle(a, b, c);
|
||||
BOOST_CHECK(triangle.Contains(&a));
|
||||
BOOST_CHECK(triangle.Contains(&b));
|
||||
BOOST_CHECK(triangle.Contains(&c));
|
||||
BOOST_CHECK(triangle.CircumcicleContains(p2t::Point(0.5, 0.1)));
|
||||
BOOST_CHECK(!triangle.CircumcicleContains(p2t::Point(1, 0.4)));
|
||||
}
|
Loading…
Reference in New Issue
Block a user