package CookieCutter.g2;

import java.io.Serializable;
import java.text.NumberFormat;

import CookieCutter.Vertex;

public class Point implements Serializable {

	double xpos;
	double ypos;
	char type;

	static NumberFormat nf;
	static {
		nf = NumberFormat.getInstance();
		nf.setMinimumFractionDigits(6);
		nf.setMaximumFractionDigits(6);
		nf.setMinimumIntegerDigits(1);
	}

	public Point(Point copy) {
		xpos = copy.xpos();
		ypos = copy.ypos();
	}

	public Point(Vertex copy) {
		try {
			xpos = copy.xpos();
			ypos = copy.ypos();
		} catch (Exception e) {
		}
	}

	public Vertex asVertex() {
		try {
			return new Vertex(xpos, ypos);
		} catch (Exception e) {
			return null;
		}
	}

	public Point(double xpos, double ypos) {
		this.xpos = xpos;
		this.ypos = ypos;
	}

	public Point(double xpos, double ypos, char type) {
		this.xpos = xpos;
		this.ypos = ypos;
		this.type = type;
	}

	public double xpos() {
		return xpos;
	}

	public void setXpos(double xpos) {
		this.xpos = xpos;
	}

	public double ypos() {
		return ypos;
	}

	public void setYpos(double ypos) {
		this.ypos = ypos;
	}

	public char type() {
		return type;
	}

	public void setType(char type) {
		this.type = type;
	}

	public Point copy() {
		return new Point(xpos, ypos, type);
	}

	public boolean equals(Object o) {
		Point v;

		if (o == null) {
			return false;
		}
		v = (Point) o;

		if (xpos == v.xpos && ypos == v.ypos && type == v.type) {
			return true;
		}
		return false;
	}

	public String toString() {
		StringBuffer sb = new StringBuffer();

		sb.append("[ ");
		sb.append(nf.format(xpos));
		sb.append(", ");
		sb.append(nf.format(ypos));
		sb.append(", ");
		sb.append(nf.format(type));
		sb.append("]");

		return new String(sb);
	}
}
