Skip to content

Commit 5a3bd11

Browse files
author
ParkerTomatoes
committed
2 parents fdd30c4 + e0e2f20 commit 5a3bd11

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

include/lttb.hpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ struct LargestTriangleThreeBuckets
2929
}
3030

3131
// Bucket size. Leave room for start and end data points
32-
TData every = static_cast<TData>(sourceSize - 2) / static_cast<TData>(destinationSize - 2);
32+
// Note: We cast to double to avoid floored window propagation
33+
double every = static_cast<double>(sourceSize - 2) / static_cast<double>(destinationSize - 2);
3334

3435
size_t aIndex = 0; // Initially a is the first point in the triangle
3536

@@ -74,7 +75,9 @@ struct LargestTriangleThreeBuckets
7475
TData area = std::abs(
7576
((pointAX - avgX) * (source[rangeOffs].*y - pointAY)) -
7677
((pointAX - source[rangeOffs].*x) * (avgY - pointAY))
77-
) / 2;
78+
);
79+
// Note: Normally you need to also divide area by 2, but all we care about
80+
// is the largest area, so we can skip the division by a constant factor of 2
7881
if (area > maxArea)
7982
{
8083
maxArea = area;

0 commit comments

Comments
 (0)