export const round = (num: number, decimals: number = 2): number => {
  return Math.round(num * Math.pow(10, decimals)) / Math.pow(10, decimals);
};

export const calculateDistanceSquared = (x1: number, y1: number, x2: number, y2: number): number => {
  return Math.pow(x1 - x2, 2) + Math.pow(y1 - y2, 2);
};

// Map a coordinate value to an SVG pixel value
export const scaleToSvg = (val: number, domainMin: number, domainMax: number, rangeMin: number, rangeMax: number) => {
  return ((val - domainMin) / (domainMax - domainMin)) * (rangeMax - rangeMin) + rangeMin;
};

// Map an SVG pixel value back to a coordinate value
export const scaleFromSvg = (val: number, domainMin: number, domainMax: number, rangeMin: number, rangeMax: number) => {
  return ((val - rangeMin) / (rangeMax - rangeMin)) * (domainMax - domainMin) + domainMin;
};
