import java.awt.Graphics;
import java.util.*;

public class Point
{
	double x, y;
	int X, Y;
	public static double splitting_y;

	public Point()
	{
		x = 0;
		y = 0;
	}

	public Point(int _x, int _y)
	{
		x = _x;
		y = _y;
	}

	public void scaleToSize(int xbound, int ybound)
	{
		X = (int) Math.floor(x);
		Y = (int) Math.floor(y);
	}

	public void draw(Graphics g)
	{
		// poly.draw() should be called before this, or else X
		// and Y might not be right
		g.fillOval(X - 3, Y - 3, 6, 6);
	}

	// a whole bunch of stuff to sort the points

	public static int left(int i)
	{
		return i * 2 + 1;
	}

	public static int right(int i)
	{
		return i * 2 + 2;
	}

	public static void max_heapify(Point a[], int i, int heap_size, PointComparer c)
	{
		int l = left(i);
		int r = right(i);
		int largest;
		if(l < heap_size && c.compare(a[l], a[i]) > 0){
			largest = l;
		} else {
			largest = i;
		}
		if(r < heap_size && c.compare(a[r], a[largest]) > 0){
			largest = r;
		}
		if(largest != i){
			exchange(a, i, largest);
			max_heapify(a, largest, heap_size, c);
		}
	}

	public static void build_max_heap(Point a[], PointComparer c)
	{
		int heap_size = a.length;
		int i;
		for(i = (a.length - 1) / 2; i >= 0; i--){
			max_heapify(a, i, heap_size, c);
		}
	}

	public static void exchange(Point a[], int p1, int p2)
	{
		Point temp = a[p1];
		a[p1] = a[p2];
		a[p2] = temp;
	}

	public static void sort(Point a[], PointComparer c)
	{
		int i;
		int length = a.length - 1;
		int heap_size;
		build_max_heap(a, c);
		heap_size = a.length;
		for(i = length; i >= 1; i--){
			exchange(a, 0, i);
			heap_size--;
			max_heapify(a, 0, heap_size, c);
		}
	}
}


syntax highlighted by Code2HTML, v. 0.9