package schema;


class Curve extends Line {
	public var middle : Point;

	public function new (start : Point, end : Point, xDst : Int, yDst : Int) {
		super (start, end);
		setMiddle (xDst, yDst);
	}

	public function setMiddle(xDst : Int, yDst : Int) {
		var cx = Std.int (start.x + (end.x - start.x) / 2);
		var cy = Std.int (start.y + (end.y - start.y) / 2);
		var mx = 0;
		var my = 0;
		if (start.x == end.x) { //if vertical line
			mx = start.x + xDst;
			my = cy;
		} else if (start.y == end.y) { //if horizontal line
			mx = cx;
			my = start.y - yDst;
		} else { //diagonal line
			var angle = Math.atan(-(end.x - start.x) / (end.y - start.y)); //inverted steering for perpendicular line
			mx = Std.int (cx + Math.cos(angle) * xDst);
			my = Std.int (cy + Math.sin(angle) * yDst);
			if (yDst < 0 && cy > my || yDst > 0 && cy < my) {
				my = Std.int (cy + Math.sin(angle) * (-yDst));
			}
		}
		this.middle =  { x : mx, y : my };
	}
}
