Switch to make_zero()

This commit is contained in:
Andreas Fabri 2018-09-26 11:46:22 +02:00
parent 41946b72d6
commit c5f85b212d
5 changed files with 74 additions and 48 deletions

View File

@ -11,48 +11,6 @@ typedef CGAL::Interpolation_traits_2<K> Traits;
typedef K::Vector_3 Vector_3;
typedef K::Point_2 Point_2;
namespace boost {
template<class K>
class value_initialized<CGAL::Vector_3<K> >
{
private :
typedef CGAL::Vector_3<K> T;
T m_data;
public :
value_initialized()
:
m_data(0,0,0)
{ }
T const & data() const
{
return m_data;
}
T& data()
{
return m_data;
}
operator T const &() const
{
return m_data;
}
operator T&()
{
return m_data;
}
} ;
} // nammespace boost
int main()
{
Delaunay_triangulation T;
@ -65,14 +23,14 @@ int main()
for (int y=0 ; y<255 ; y++){
for (int x=0 ; x<255 ; x++){
K::Point_2_2 p(x,y);
K::Point_2 p(x,y);
T.insert(p);
value_function.insert(std::make_pair(p, Vector_3(x,y,1)));
}
}
//coordinate computation
K::Point_2_2 p(1.3, 0.34);
K::Point_2 p(1.3, 0.34);
std::vector<std::pair<Point_2, double> > coords;
double norm = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)).second;

View File

@ -26,9 +26,9 @@
#include <CGAL/Interpolation/internal/helpers.h>
#include <CGAL/double.h>
#include <CGAL/use.h>
#include <CGAL/make_zero.h>
#include <boost/utility/result_of.hpp>
#include <boost/utility/value_init.hpp>
#include <iterator>
#include <utility>
#include <vector>
@ -65,7 +65,6 @@ typename boost::result_of<
::type::first_type
linear_interpolation(ForwardIterator first, ForwardIterator beyond,
const typename std::iterator_traits<ForwardIterator>::value_type::second_type& norm,
//const Norm& norm,
ValueFunctor value_function)
{
CGAL_precondition(norm > 0);
@ -74,13 +73,13 @@ linear_interpolation(ForwardIterator first, ForwardIterator beyond,
typedef typename boost::result_of<ValueFunctor(arg_type)>::type result_type;
typedef typename result_type::first_type Value_type;
boost::value_initialized<Value_type> result;
Value_type result = make_zero<Value_type>();
result_type val;
for(; first!=beyond; ++first)
{
val = value_function(first->first);
CGAL_assertion(val.second);
get(result) += (first->second / norm) * val.first;
result += (first->second / norm) * val.first;
}
return result;
}

View File

@ -35,6 +35,7 @@
#include <CGAL/representation_tags.h>
#include <CGAL/Dimension.h>
#include <CGAL/result_of.h>
#include <CGAL/make_zero.h>
#include <CGAL/IO/io.h>
namespace CGAL {
@ -389,6 +390,15 @@ operator>>(std::istream& is, Vector_2<R>& v)
return extract(is, v, typename R::Kernel_tag() );
}
template <class R>
struct Make_zero<Vector_2<R> >
{
Vector_2<R> operator()() const
{
return CGAL::NULL_VECTOR;
}
};
} //namespace CGAL
#endif // CGAL_VECTOR_2_H

View File

@ -35,6 +35,7 @@
#include <CGAL/Kernel/Return_base_tag.h>
#include <CGAL/Dimension.h>
#include <CGAL/result_of.h>
#include <CGAL/make_zero.h>
#include <CGAL/IO/io.h>
namespace CGAL {
@ -371,6 +372,16 @@ operator>>(std::istream& is, Vector_3<R>& v)
return extract(is, v, typename R::Kernel_tag() );
}
template <class R>
struct Make_zero<Vector_3<R> >
{
Vector_3<R> operator()() const
{
return CGAL::NULL_VECTOR;
}
};
} //namespace CGAL
#endif // CGAL_VECTOR_3_H

View File

@ -0,0 +1,48 @@
// Copyright (c) 2018
// Utrecht University (The Netherlands),
// ETH Zurich (Switzerland),
// INRIA Sophia-Antipolis (France),
// Max-Planck-Institute Saarbruecken (Germany),
// and Tel-Aviv University (Israel). All rights reserved.
//
// This file is part of CGAL (www.cgal.org); you can redistribute it and/or
// modify it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 3 of the License,
// or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// SPDX-License-Identifier: LGPL-3.0+
//
//
// Author(s) : Andreas Fabri
#ifndef CGAL_MAKE_ZERO_H
#define CGAL_MAKE_ZERO_H
namespace CGAL {
template <class T>
struct Make_zero {
T operator()()const
{
return T();
}
};
template <class T>
T make_zero()
{
Make_zero<T> mz;
return mz();
}
} //namespace CGAL
#endif // CGAL_MAKE_ZERO_H