All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mxgraph.util.mxLine Maven / Gradle / Ivy

Go to download

JGraphX Swing Component - Java Graph Visualization Library This is a binary & source redistribution of the original, unmodified JGraphX library originating from: "https://github.com/jgraph/jgraphx/archive/v3.4.1.3.zip". The purpose of this redistribution is to make the library available to other Maven projects.

There is a newer version: 3.4.1.3
Show newest version
/**
 * $Id: mxLine.java,v 1.8 2011-01-25 13:13:34 david Exp $
 * Copyright (c) 2007-2010, Gaudenz Alder, David Benson
 */
package com.mxgraph.util;

import java.awt.geom.Line2D;

/**
 * Implements a line with double precision coordinates.
 */

public class mxLine extends mxPoint
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4730972599169158546L;
	/**
	 * The end point of the line
	 */
	protected mxPoint endPoint;

	/**
	 * Creates a new line
	 */
	public mxLine(mxPoint startPt, mxPoint endPt)
	{
		this.setX(startPt.getX());
		this.setY(startPt.getY());
		this.endPoint = endPt;
	}
	
	/**
	 * Creates a new line
	 */
	public mxLine(double startPtX, double startPtY, mxPoint endPt)
	{
		x = startPtX;
		y = startPtY;
		this.endPoint = endPt;
	}

	/**
	 * Returns the end point of the line.
	 * 
	 * @return Returns the end point of the line.
	 */
	public mxPoint getEndPoint()
	{
		return this.endPoint;
	}

	/**
	 * Sets the end point of the rectangle.
	 * 
	 * @param value The new end point of the line
	 */
	public void setEndPoint(mxPoint value)
	{
		this.endPoint = value;
	}

	/**
	 * Sets the start and end points.
	 */
	public void setPoints(mxPoint startPt, mxPoint endPt)
	{
		this.setX(startPt.getX());
		this.setY(startPt.getY());
		this.endPoint = endPt;
	}
	
	/**
	 * Returns the square of the shortest distance from a point to this line.
	 * The line is considered extrapolated infinitely in both directions for 
	 * the purposes of the calculation.
	 *
	 * @param pt the point whose distance is being measured
	 * @return the square of the distance from the specified point to this line.
	 */
	public double ptLineDistSq(mxPoint pt)
	{
		return new Line2D.Double(getX(), getY(), endPoint.getX(), endPoint
				.getY()).ptLineDistSq(pt.getX(), pt.getY());
	}

	/**
	 * Returns the square of the shortest distance from a point to this 
	 * line segment.
	 *
	 * @param pt the point whose distance is being measured
	 * @return the square of the distance from the specified point to this segment.
	 */
	public double ptSegDistSq(mxPoint pt)
	{
		return new Line2D.Double(getX(), getY(), endPoint.getX(), endPoint
				.getY()).ptSegDistSq(pt.getX(), pt.getY());
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy