func LTOB(data []Point, threshold int) []Point {
	if threshold >= len(data) || threshold == 0 {
		return data  
	}
	sampledData := make([]Point, 0, threshold)
	bucketSize := float64(len(data)-2) / float64(threshold-2)
	sampledData = append(sampledData, data[0])  
	for bucket := 1; bucket < threshold-1; bucket++ {
		startIdx := int(math.Floor(float64(bucket) * bucketSize))
		endIdx := int(math.Min(float64(len(data)-1), float64(bucket+1)*bucketSize))
		maxArea := -1.0
		maxAreaIdx := -1
		for i := startIdx; i < endIdx; i++ {
			area := calculateTriangleArea(data[i-1], data[i], data[i+1])
			if area > maxArea {
				maxArea = area
				maxAreaIdx = i
			}
		}
		sampledData = append(sampledData, data[maxAreaIdx])
	}
	sampledData = append(sampledData, data[len(data)-1])  
	return sampledData
}
Largest triangle one bucket(LTOB) data downsampling algorithm implementation
- Require: data . The original data
- Require: threshold . Number of data points to be returned
package core
import (
	"math"
)