From d67b4a84d900bb9ec08f6d8ae8b59f5b66da4e1e Mon Sep 17 00:00:00 2001 From: vng Date: Mon, 5 Sep 2011 20:31:28 +0300 Subject: [PATCH] Robust triangles orientation checking in tesselator. --- indexer/tesselator.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/indexer/tesselator.cpp b/indexer/tesselator.cpp index a8ac5fc094..a5a8815014 100644 --- a/indexer/tesselator.cpp +++ b/indexer/tesselator.cpp @@ -1,6 +1,8 @@ #include "tesselator.hpp" #include "geometry_coding.hpp" +#include "../geometry/robust_orientation.hpp" + #include "../coding/writer.hpp" #include "../base/assert.hpp" @@ -256,9 +258,9 @@ namespace tesselator // When adding triangles, check that they all have identical orientation! m2::PointD arrP[] = { m_points[arr[0]], m_points[arr[1]], m_points[arr[2]] }; - double const cp = m2::CrossProduct(arrP[1] - arrP[0], arrP[2] - arrP[1]); + double const cp = m2::robust::OrientedS(arrP[0], arrP[1], arrP[2]); - if (fabs(cp) > 1.0E-4) + if (cp != 0.0) { bool const isCCW = (cp > 0.0); @@ -266,9 +268,9 @@ namespace tesselator m_isCCW = (isCCW ? 1 : -1); else CHECK_EQUAL ( m_isCCW == 1, isCCW, () ); - } - m_triangles.back().Add(arr); + m_triangles.back().Add(arr); + } } void TrianglesInfo::GetPointsInfo(m2::PointU const & baseP,