wg_engine: prevent adding duplicate points while trimming

In cases where the distance between points is 0, further
processing of the points results in division by zero.
To avoid this check, we ensure that duplicate points are
not added during trimming.
This commit is contained in:
Mira Grudzinska 2024-09-25 23:12:15 +02:00 committed by Hermet Park
parent 2fc0aad2d1
commit dc754833bc

View file

@ -174,9 +174,11 @@ struct WgVertexBuffer {
// append points
float t_beg = len_seg_beg > 0.0f ? 1.0f - (len_total_beg - len_beg) / len_seg_beg : 0.0f;
float t_end = len_seg_end > 0.0f ? 1.0f - (len_total_end - len_end) / len_seg_end : 0.0f;
if (index_beg > 0) append(lerp(buff.vbuff[index_beg-1], buff.vbuff[index_beg], t_beg));
//t_beg == 1 handled in appendRange
if (index_beg > 0 && t_beg != 1.0f) append(lerp(buff.vbuff[index_beg-1], buff.vbuff[index_beg], t_beg));
appendRange(buff, index_beg, index_end);
if (index_end > 0) append(lerp(buff.vbuff[index_end-1], buff.vbuff[index_end], t_end));
//t_end == 0 handled in appendRange
if (index_end > 0 && t_end != 0.0f) append(lerp(buff.vbuff[index_end-1], buff.vbuff[index_end], t_end));
}