package schema;

class Line {
	public var x1 : Int;
	public var y1 : Int;
	public var x2 : Int;
	public var y2 : Int;
	public var cx1 : Int; //position for cardinalities
	public var cy1 : Int;
	public var cx2 : Int;
	public var cy2 : Int;
	public var vOrientation : Int; //-1=top, 0=same row, 1=bottom
	public var hOrientation : Int; //-1=left, 0 same column, 1=right

	@SuppressWarnings("checkstyle:ParameterNumber")
	public function new(x1 : Int, y1 : Int, x2 : Int, y2 : Int, hOrientation : Int, vOrientation : Int) {
		this.x1 = x1;
		this.y1 = y1;
		this.x2 = x2;
		this.y2 = y2;
		cx1 = x1;
		cy1 = y1;
		cx2 = x2;
		cy2 = y2;
		this.hOrientation = hOrientation;
		this.vOrientation = vOrientation;
	}

	//~ public function getAngle() : Float { //in degrees (SVG requirement)
		//~ var angle : Float;
		//~ if (isVertical()) {
			//~ angle = y1 < y2 ? 90 : 270;
		//~ } else if (isHorizontal()) {
			//~ angle = x1 < x2 ? 0 : 180;
		//~ } else {
			//~ angle = Math.atan(getSteering()) / (Math.PI * 2) * 360;
		//~ }
		//~ return angle;
	//~ }

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

	public function getOffset() : Float {
		return y2 - getSteering() * x2;
	}

	public function isVertical() : Bool {
		return x1 == x2;
	}

	public function isHorizontal() : Bool {
		return y1 == y2;
	}
}
