package schema;


class Line {
	public var start : Point;
	public var end : Point;
	//public var center : Point;

	public function new( start : Point, end : Point) {
		this.start = start;
		this.end = end;
		//this.center = { x : Std.int (start.x + end.x / 2), y : Std.int (start.y + end.y / 2) };
	}

	public function getSteering() : Float { //x1 != x2 && y = steering . x + offset
		return (end.y - start.y) / (end.x - start.x);
	}

	public function getOffset() : Float {
		return end.y - getSteering() * end.x;
	}

	public function getLabelPos (card: String, inverted: Bool, pos : Int) : Point {
		var rStart = inverted ? end : start;
		var rEnd = inverted ? start : end;
		var x = rEnd.x >= rStart.x ? rStart.x + Svg.PADDING : rStart.x - Std.int (Params.LETTER_WIDTH * card.length) - Svg.PADDING;
		var y = rEnd.y >= rStart.y ? rStart.y + Params.LETTER_HEIGHT * pos : rStart.y - Svg.PADDING - Params.LETTER_HEIGHT * (pos - 1);
		return { x : x, y : y };
	}
}
