Commit 83b360f1 authored by Robert Maynard's avatar Robert Maynard

vtkm::Lerp now casts integer types to an appropriate scalar type.

Previously types such as vtkm::Id or vtkm::U/Int32 would be cast to whatever
the weight type was. This is problematic as they should actually be casted to
a double type as the weight type could be a float and therefore the results
parent 0d45c5cf
......@@ -41,11 +41,13 @@ namespace vtkm
/// extrapolates. If w=0 => v0 is returned if w=1 => v1 is returned.
///
template <typename ValueType, typename WeightType>
VTKM_EXEC_CONT ValueType Lerp(const ValueType& value0,
const ValueType& value1,
const WeightType& weight)
inline VTKM_EXEC_CONT ValueType Lerp(const ValueType& value0,
const ValueType& value1,
const WeightType& weight)
{
return static_cast<ValueType>((WeightType(1) - weight) * value0 + weight * value1);
using ScalarType = typename detail::FloatingPointReturnType<ValueType>::Type;
return static_cast<ValueType>((WeightType(1) - weight) * static_cast<ScalarType>(value0) +
weight * static_cast<ScalarType>(value1));
}
template <typename ValueType, vtkm::IdComponent N, typename WeightType>
VTKM_EXEC_CONT vtkm::Vec<ValueType, N> Lerp(const vtkm::Vec<ValueType, N>& value0,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment