import { Vector3 } from "three";

/**
 * Generate a position for a constellation based on its index in a 3D spiral.
 * @param index Index of the constellation.
 * @param a Initial radial distance.
 * @param b Growth factor for radial distance.
 * @param angularStep Angular step in radians.
 * @param layerStep Vertical layer step in radians.
 * @param layers Number of layers per spiral rotation.
 * @returns A 3D position (Vector3).
 */
export const getSpiralPosition = (
  index: number,
  a: number = 0,
  b: number = 1.5,
  angularStep: number = Math.PI / 7,
  layerStep: number = Math.PI / 11,
  layers: number = 100
): Vector3 => {
  const r = a + b * index * 0.7; // Radial distance
  const θ = index * angularStep; // Azimuthal angle
  const φ = (index % layers) * layerStep; // Polar angle

  const x = r * Math.cos(θ) * Math.sin(φ);
  const y = r * Math.sin(θ) * Math.sin(φ);
  const z = r * Math.cos(φ);

  return new Vector3(x, y, z);
};

// const GOLDEN_RATIO = (1 + Math.sqrt(5)) / 2;

// export const getNonOverlappingPosition = (
//   index: number,
//   total: number,
//   a: number = 5,
//   b: number = 2,
//   D_min: number = 2
// ): Vector3 => {
//   // Determine which layer the constellation belongs to
//   const layer = Math.floor(index / total);
//   const r = a + b * layer; // Radial distance increases with the layer

//   // Total constellations per layer to maintain spacing
//   const total_in_layer = Math.max(1, Math.floor((4 * Math.PI * r ** 2) / (D_min ** 2)));

//   // Angular calculations
//   const theta = (2 * Math.PI * GOLDEN_RATIO * index) / total_in_layer; // Azimuthal angle
//   const phi = Math.acos(1 - 2 * ((index % total_in_layer) + 0.5) / total_in_layer); // Polar angle

//   // Convert spherical to Cartesian coordinates
//   const x = r * Math.sin(phi) * Math.cos(theta);
//   const y = r * Math.sin(phi) * Math.sin(theta);
//   const z = r * Math.cos(phi);

//   return new Vector3(x, y, z);
// };