Refactor liner interpolation to use (1-w)*v0+w*v1
Using v0+w*(v1-v0) can be numerically unstaqble due to floating point arithmatic errors. Additionaly, the newer form also resolves type conversion warnings.
This commit is contained in:
parent
635f8c7987
commit
af7bba062a
@ -46,7 +46,7 @@ ValueType Lerp(const ValueType &value0,
|
||||
const ValueType &value1,
|
||||
const WeightType &weight)
|
||||
{
|
||||
return static_cast<ValueType>(value0 + weight * (value1-value0));
|
||||
return static_cast<ValueType>((WeightType(1)-weight)*value0+weight*value1);
|
||||
}
|
||||
template<typename ValueType, vtkm::IdComponent N, typename WeightType>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
@ -54,7 +54,7 @@ vtkm::Vec<ValueType,N> Lerp(const vtkm::Vec<ValueType,N> &value0,
|
||||
const vtkm::Vec<ValueType,N> &value1,
|
||||
const WeightType &weight)
|
||||
{
|
||||
return value0 + static_cast<ValueType>(weight) * (value1-value0);
|
||||
return (WeightType(1)-weight)*value0+weight*value1;
|
||||
}
|
||||
template<typename ValueType, vtkm::IdComponent N>
|
||||
VTKM_EXEC_CONT_EXPORT
|
||||
@ -62,7 +62,8 @@ vtkm::Vec<ValueType,N> Lerp(const vtkm::Vec<ValueType,N> &value0,
|
||||
const vtkm::Vec<ValueType,N> &value1,
|
||||
const vtkm::Vec<ValueType,N> &weight)
|
||||
{
|
||||
return value0 + weight * (value1-value0);
|
||||
static const vtkm::Vec<ValueType,N> One(ValueType(1));
|
||||
return (One-weight)*value0+weight*value1;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user