public Segment(Punto p1, Punto p2) { P1 = p1; P2 = p2; }
//public double Closest(Punto[] points) //{ // QuickSort3.Sort(points, 0, points.Length - 1, (p1, p2) => p1.CompareXTo(p2)); // return ClosestRect(points); //} //private double ClosestRect(Punto[] p) //{ // const int threshold = 2048; // if (p.Length <= 3) return BruteForce(p); // Punto[] pxLeft = new Punto[p.Length / 2]; // Array.Copy(p, pxLeft, p.Length / 2); // Punto[] pxRight = new Punto[p.Length - (p.Length / 2)]; // Array.Copy(p, p.Length / 2, pxRight, 0, p.Length - (p.Length / 2)); // double distL = 0; // double distR = 0; // if (p.Length / 2 > threshold) // { // Parallel.Invoke( // () => distL = ClosestRect(pxLeft), // () => distR = ClosestRect(pxRight) // ); // } // else // { // distL = ClosestRect(pxLeft); // distR = ClosestRect(pxRight); // } // double dist = Math.Min(distL, distR); // Punto[] strip = new Punto[p.Length]; // Punto mid = pxLeft[(p.Length / 2) - 1]; // int size = 0; // for (int i = 0; i < p.Length; i++) // { // if (Math.Abs(mid.X - p[i].X) <= dist) // { // strip[size++] = p[i]; // } // } // QuickSort3.Sort(strip, 0, size - 1, (p1, p2) => p1.CompareYTo(p2)); // for (int i = 0; i < size - 1; i++) // { // Punto lower = strip[i]; // for (int j = i + 1; j < size; j++) // { // Punto upper = strip[j]; // if (upper.Y - lower.Y >= dist) break; // double luDist = Punto.Distance(lower, upper); // if (luDist < dist) // { // dist = luDist; // p1 = upper; // p2 = lower; // } // } // } // return dist; //} //private static double StripClosest(Punto[] strip, int size, double distance) //{ // double min = distance; // for (int i = 0; i < size; i++) // { // for (int j = i + 1; j < size && (strip[j].Y - strip[i].Y) < min; j++) // { // double dist = Punto.Distance(strip[i], strip[j]); // if (dist < min) // { // min = dist; // } // } // } // return min; //} public static double distancia(Punto p1, Punto p2) { return(Math.Sqrt(Math.Pow(Math.Abs(p1.X - p2.X), 2) + Math.Pow(Math.Abs(p1.Y - p2.Y), 2))); }
public int CompareYTo(Punto other) => Y.CompareTo(other.Y);
public static double Distance(Punto p1, Punto p2) => Math.Sqrt((p1.X - p2.X) * (p1.X - p2.X) + (p1.Y - p2.Y) * (p1.Y - p2.Y));
public int CompareXTo(Punto other) => X.CompareTo(other.X);