Skip to content
Snippets Groups Projects
Commit 568dda59 authored by Dmitri Naumov's avatar Dmitri Naumov
Browse files

Replace uniqueListInsert() with uniquePushBack().

This also removes uniqueVectorInsert(). The new function is working for all containers, which provide begin() and end() and typedef value_type.
parent ed884801
No related branches found
No related tags found
No related merge requests found
...@@ -13,35 +13,17 @@ ...@@ -13,35 +13,17 @@
#ifndef UNIQUELISTINSERT_H_ #ifndef UNIQUELISTINSERT_H_
#define UNIQUELISTINSERT_H_ #define UNIQUELISTINSERT_H_
#include <list> #include <algorithm>
#include <vector>
namespace BaseLib { namespace BaseLib {
template<typename T> template<typename Container>
void uniqueListInsert (std::list<T>& list, T element) void uniquePushBack(Container& container, typename Container::value_type const& element)
{ {
// search element if (std::find(container.begin(), container.end(), element) == container.end())
typename std::list<T>::const_iterator it; container.push_back(element);
for (it = list.begin (); it != list.end(); it++) {
if (*it == element) return;
}
// element not found -> insert
list.push_back (element);
} }
template<typename T>
void uniqueVectorInsert (std::vector<T>& vec, T element)
{
// search element
typename std::vector<T>::const_iterator it;
for (it = vec.begin (); it != vec.end(); ++it)
if (*it == element) return;
// element not found -> insert
vec.push_back (element);
}
} // end namespace BaseLib } // end namespace BaseLib
#endif /* UNIQUELISTINSERT_H_ */ #endif /* UNIQUELISTINSERT_H_ */
...@@ -226,11 +226,11 @@ void EarClippingTriangulation::clipEars() ...@@ -226,11 +226,11 @@ void EarClippingTriangulation::clipEars()
MathLib::Orientation orientation = getOrientation(_pnts[*prevprev], _pnts[*prev], MathLib::Orientation orientation = getOrientation(_pnts[*prevprev], _pnts[*prev],
_pnts[*next]); _pnts[*next]);
if (orientation == CW) { if (orientation == CW) {
BaseLib::uniqueListInsert<std::size_t>(_convex_vertex_list, *prev); BaseLib::uniquePushBack(_convex_vertex_list, *prev);
// prev is convex // prev is convex
if (isEar(*prevprev, *prev, *next)) { if (isEar(*prevprev, *prev, *next)) {
// prev is an ear tip // prev is an ear tip
BaseLib::uniqueListInsert<std::size_t>(_ear_list, *prev); BaseLib::uniquePushBack(_ear_list, *prev);
} else { } else {
// if necessary remove prev // if necessary remove prev
_ear_list.remove(*prev); _ear_list.remove(*prev);
...@@ -265,11 +265,11 @@ void EarClippingTriangulation::clipEars() ...@@ -265,11 +265,11 @@ void EarClippingTriangulation::clipEars()
orientation = getOrientation(_pnts[*prev], _pnts[*next], orientation = getOrientation(_pnts[*prev], _pnts[*next],
_pnts[*nextnext]); _pnts[*nextnext]);
if (orientation == CW) { if (orientation == CW) {
BaseLib::uniqueListInsert<std::size_t>(_convex_vertex_list, *next); BaseLib::uniquePushBack(_convex_vertex_list, *next);
// next is convex // next is convex
if (isEar(*prev, *next, *nextnext)) { if (isEar(*prev, *next, *nextnext)) {
// next is an ear tip // next is an ear tip
BaseLib::uniqueListInsert<std::size_t>(_ear_list, *next); BaseLib::uniquePushBack(_ear_list, *next);
} else { } else {
// if necessary remove *next // if necessary remove *next
_ear_list.remove(*next); _ear_list.remove(*next);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment