package com.persagy.adm.diagram.core.line;

import com.persagy.adm.diagram.core.model.base.XY;

/**
 * 连线的终点
 * @author zhaoyk
 */
public class LineEnd {

	/**
	 * 与真正连接点的偏移量
	 */
	public static int offset = 8;

	/**
	 * 模式1，点（锚点）
	 */
	private XY point;

	/**
	 * 模式2，线段（干管）
	 */
	private XY[] line;

	public XY getPoint() {
		return point;
	}

	public void setPoint(XY point) {
		this.point = point;
	}

	public XY[] getLine() {
		return line;
	}

	public void setLine(XY[] line) {
		this.line = line;
	}

	public boolean isLineHorizontal(){
		return isHorizontal(line);
	}

	public int getLineTrackPos(){
		return isHorizontal(line) ? line[0].y : line[0].x;
	}

	public int getLineFromPos(){
		return isHorizontal(line) ? line[0].x : line[0].y;
	}

	public int getLineToPos(){
		return isHorizontal(line) ? line[1].x : line[1].y;
	}

	public int[] getLineScope(){
		return isHorizontal(line) ? new int[]{line[0].x, line[1].x} : new int[]{line[0].y, line[1].y};
	}

	public static void orderLine(XY[] line) {
		boolean needOrder = false;
		if(isHorizontal(line)) {
			if(line[0].x > line[1].x) {
				needOrder = true;
			}
		} else {
			if(line[0].y > line[1].y) {
				needOrder = true;
			}
		}
		if(needOrder) {
			XY tmp = line[0];
			line[0] = line[1];
			line[1] = tmp;
		}
	}

	public static boolean isHorizontal(XY[] line){
		return line[0].y == line[1].y;
	}

}
