package jp.ac.kyutech.mns.ist.play;

import java.awt.geom.Point2D;
import java.util.ArrayList;

/**
 * 仮想ペンの，筆記と筆記のあいだの補間
 * @author miuramo
 *
 */
public class TimePlayMove implements TimePlayable {
	ArrayList<Point2D> points;

	Point2D tp1, tp2;

	public TimePlayMove(Point2D pp1, Point2D pp2) {
		tp1 = pp1;
		tp2 = pp2;
		points = new ArrayList<Point2D>();
		prepareShapes();
	}

	/**
	 * 点o1 と点o2をr:(1-r)で分割する点
	 * 
	 * @param o1
	 * @param o2
	 * @param r
	 * @return 分割した，中間点
	 */
	public static Point2D mid(Point2D o1, Point2D o2, double r) {
		double ox1 = o1.getX();
		double oy1 = o1.getY();
		double ox2 = o2.getX();
		double oy2 = o2.getY();
		double nox = (ox2 - ox1) * r + ox1;
		double noy = (oy2 - oy1) * r + oy1;
		return new Point2D.Double(nox, noy);
	}

	public Point2D getPenPoint(int localp) {
		return points.get(localp);
	}

	public int getSteps() {
		return points.size();
	}

	public void prepareShapes() {
		points.clear();
		double dist = tp1.distance(tp2);
		double bunkatsu = 3 + dist / 9;
		for (double d = 0; d <= 1.0; d += 1.0 / bunkatsu) {
			points.add(mid(tp1, tp2, d));
		}
	}

	public void resetShapes() {
		// points.clear();
	}

	public void setVisible(boolean f) {
	}

	public void showSubpath(int localp) {
	}

	public Point2D getFirstPoint() {
		return points.get(0);
	}

	public Point2D getLastPoint() {
		return points.get(points.size() - 1);
	}
}
