Skip to content

Instantly share code, notes, and snippets.

View ngocvantran's full-sized avatar

Ngoc Van Tran ngocvantran

  • Berlin, Germany
View GitHub Profile
@DanielWJudge
DanielWJudge / LargestTriangleThreeBuckets.cs
Last active March 16, 2024 15:23
Largest-Triangle-Three Bucket Downsampling Graphs in C#
public static IEnumerable<Tuple<double, double>> LargestTriangleThreeBuckets(List<Tuple<double, double>> data, int threshold)
{
int dataLength = data.Count;
if (threshold >= dataLength || threshold == 0)
return data; // Nothing to do
List<Tuple<double, double>> sampled = new List<Tuple<double, double>>(threshold);
// Bucket size. Leave room for start and end data points
double every = (double)(dataLength - 2) / (threshold - 2);